diff --git a/src/mcp/server/streamable_http_manager.py b/src/mcp/server/streamable_http_manager.py index 3213eceff..964c52b6f 100644 --- a/src/mcp/server/streamable_http_manager.py +++ b/src/mcp/server/streamable_http_manager.py @@ -281,10 +281,7 @@ async def run_server(*, task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORE error_response = JSONRPCError( jsonrpc="2.0", id="server-error", - error=ErrorData( - code=INVALID_REQUEST, - message="Session not found", - ), + error=ErrorData(code=INVALID_REQUEST, message="Session not found"), ) response = Response( content=error_response.model_dump_json(by_alias=True, exclude_none=True), diff --git a/src/mcp/server/validation.py b/src/mcp/server/validation.py index 192b9d492..cfd663d43 100644 --- a/src/mcp/server/validation.py +++ b/src/mcp/server/validation.py @@ -50,12 +50,7 @@ def validate_sampling_tools( """ if tools is not None or tool_choice is not None: if not check_sampling_tools_capability(client_caps): - raise McpError( - ErrorData( - code=INVALID_PARAMS, - message="Client does not support sampling tools capability", - ) - ) + raise McpError(ErrorData(code=INVALID_PARAMS, message="Client does not support sampling tools capability")) def validate_tool_use_result_messages(messages: list[SamplingMessage]) -> None: diff --git a/src/mcp/shared/session.py b/src/mcp/shared/session.py index e01167956..d00fd764c 100644 --- a/src/mcp/shared/session.py +++ b/src/mcp/shared/session.py @@ -7,7 +7,6 @@ from typing import Any, Generic, Protocol, TypeVar import anyio -import httpx from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream from pydantic import BaseModel, TypeAdapter from typing_extensions import Self @@ -18,6 +17,7 @@ from mcp.types import ( CONNECTION_CLOSED, INVALID_PARAMS, + REQUEST_TIMEOUT, CancelledNotification, ClientNotification, ClientRequest, @@ -272,7 +272,7 @@ async def send_request( except TimeoutError: raise McpError( ErrorData( - code=httpx.codes.REQUEST_TIMEOUT, + code=REQUEST_TIMEOUT, message=( f"Timed out while waiting for response to {request.__class__.__name__}. " f"Waited {timeout} seconds." diff --git a/src/mcp/types/__init__.py b/src/mcp/types/__init__.py index 25e821cc9..c4df66f8d 100644 --- a/src/mcp/types/__init__.py +++ b/src/mcp/types/__init__.py @@ -191,6 +191,7 @@ INVALID_REQUEST, METHOD_NOT_FOUND, PARSE_ERROR, + REQUEST_TIMEOUT, URL_ELICITATION_REQUIRED, ErrorData, JSONRPCError, @@ -402,6 +403,7 @@ "INVALID_REQUEST", "METHOD_NOT_FOUND", "PARSE_ERROR", + "REQUEST_TIMEOUT", "URL_ELICITATION_REQUIRED", "ErrorData", "JSONRPCError", diff --git a/src/mcp/types/jsonrpc.py b/src/mcp/types/jsonrpc.py index eae3fc949..86066d80d 100644 --- a/src/mcp/types/jsonrpc.py +++ b/src/mcp/types/jsonrpc.py @@ -42,7 +42,7 @@ class JSONRPCResponse(BaseModel): # SDK error codes CONNECTION_CLOSED = -32000 -# REQUEST_TIMEOUT = -32001 # the typescript sdk uses this +REQUEST_TIMEOUT = -32001 # Standard JSON-RPC error codes PARSE_ERROR = -32700