From 656f887aff327cf35dc677e88fe65a99f087bee4 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Wed, 21 Jan 2026 18:37:55 +0100 Subject: [PATCH] fix: replace http code by jsonrpc (#1920) --- src/mcp/server/streamable_http_manager.py | 5 +---- src/mcp/server/validation.py | 7 +------ src/mcp/shared/session.py | 4 ++-- src/mcp/types/__init__.py | 2 ++ src/mcp/types/jsonrpc.py | 2 +- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/mcp/server/streamable_http_manager.py b/src/mcp/server/streamable_http_manager.py index 3213ecef..964c52b6 100644 --- a/src/mcp/server/streamable_http_manager.py +++ b/src/mcp/server/streamable_http_manager.py @@ -281,10 +281,7 @@ class StreamableHTTPSessionManager: 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 192b9d49..cfd663d4 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 e0116795..d00fd764 100644 --- a/src/mcp/shared/session.py +++ b/src/mcp/shared/session.py @@ -7,7 +7,6 @@ from types import TracebackType 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.shared.response_router import ResponseRouter from mcp.types import ( CONNECTION_CLOSED, INVALID_PARAMS, + REQUEST_TIMEOUT, CancelledNotification, ClientNotification, ClientRequest, @@ -272,7 +272,7 @@ class BaseSession( 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 25e821cc..c4df66f8 100644 --- a/src/mcp/types/__init__.py +++ b/src/mcp/types/__init__.py @@ -191,6 +191,7 @@ from mcp.types.jsonrpc import ( INVALID_REQUEST, METHOD_NOT_FOUND, PARSE_ERROR, + REQUEST_TIMEOUT, URL_ELICITATION_REQUIRED, ErrorData, JSONRPCError, @@ -402,6 +403,7 @@ __all__ = [ "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 eae3fc94..86066d80 100644 --- a/src/mcp/types/jsonrpc.py +++ b/src/mcp/types/jsonrpc.py @@ -42,7 +42,7 @@ URL_ELICITATION_REQUIRED = -32042 # 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