fix: replace http code by jsonrpc (#1920)

This commit is contained in:
Marcelo Trylesinski 2026-01-21 18:37:55 +01:00 • committed by GitHub
commit 656f887aff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 7 additions and 13 deletions

View file

@ -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),

View file

@ -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:

View file

@ -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."

View file

@ -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",

View file

@ -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