Skip to content

Commit 656f887

Browse files
authored
fix: replace http code by jsonrpc (#1920)
1 parent 213cf99 commit 656f887

File tree

5 files changed

+7
-13
lines changed

5 files changed

+7
-13
lines changed

src/mcp/server/streamable_http_manager.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,7 @@ async def run_server(*, task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORE
281281
error_response = JSONRPCError(
282282
jsonrpc="2.0",
283283
id="server-error",
284-
error=ErrorData(
285-
code=INVALID_REQUEST,
286-
message="Session not found",
287-
),
284+
error=ErrorData(code=INVALID_REQUEST, message="Session not found"),
288285
)
289286
response = Response(
290287
content=error_response.model_dump_json(by_alias=True, exclude_none=True),

src/mcp/server/validation.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ def validate_sampling_tools(
5050
"""
5151
if tools is not None or tool_choice is not None:
5252
if not check_sampling_tools_capability(client_caps):
53-
raise McpError(
54-
ErrorData(
55-
code=INVALID_PARAMS,
56-
message="Client does not support sampling tools capability",
57-
)
58-
)
53+
raise McpError(ErrorData(code=INVALID_PARAMS, message="Client does not support sampling tools capability"))
5954

6055

6156
def validate_tool_use_result_messages(messages: list[SamplingMessage]) -> None:

src/mcp/shared/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import Any, Generic, Protocol, TypeVar
88

99
import anyio
10-
import httpx
1110
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
1211
from pydantic import BaseModel, TypeAdapter
1312
from typing_extensions import Self
@@ -18,6 +17,7 @@
1817
from mcp.types import (
1918
CONNECTION_CLOSED,
2019
INVALID_PARAMS,
20+
REQUEST_TIMEOUT,
2121
CancelledNotification,
2222
ClientNotification,
2323
ClientRequest,
@@ -272,7 +272,7 @@ async def send_request(
272272
except TimeoutError:
273273
raise McpError(
274274
ErrorData(
275-
code=httpx.codes.REQUEST_TIMEOUT,
275+
code=REQUEST_TIMEOUT,
276276
message=(
277277
f"Timed out while waiting for response to {request.__class__.__name__}. "
278278
f"Waited {timeout} seconds."

src/mcp/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
INVALID_REQUEST,
192192
METHOD_NOT_FOUND,
193193
PARSE_ERROR,
194+
REQUEST_TIMEOUT,
194195
URL_ELICITATION_REQUIRED,
195196
ErrorData,
196197
JSONRPCError,
@@ -402,6 +403,7 @@
402403
"INVALID_REQUEST",
403404
"METHOD_NOT_FOUND",
404405
"PARSE_ERROR",
406+
"REQUEST_TIMEOUT",
405407
"URL_ELICITATION_REQUIRED",
406408
"ErrorData",
407409
"JSONRPCError",

src/mcp/types/jsonrpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class JSONRPCResponse(BaseModel):
4242

4343
# SDK error codes
4444
CONNECTION_CLOSED = -32000
45-
# REQUEST_TIMEOUT = -32001 # the typescript sdk uses this
45+
REQUEST_TIMEOUT = -32001
4646

4747
# Standard JSON-RPC error codes
4848
PARSE_ERROR = -32700

0 commit comments

Comments
 (0)