Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/mcp/server/streamable_http_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 1 addition & 6 deletions src/mcp/server/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/mcp/shared/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +17,7 @@
from mcp.types import (
CONNECTION_CLOSED,
INVALID_PARAMS,
REQUEST_TIMEOUT,
CancelledNotification,
ClientNotification,
ClientRequest,
Expand Down Expand Up @@ -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."
Expand Down
2 changes: 2 additions & 0 deletions src/mcp/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
INVALID_REQUEST,
METHOD_NOT_FOUND,
PARSE_ERROR,
REQUEST_TIMEOUT,
URL_ELICITATION_REQUIRED,
ErrorData,
JSONRPCError,
Expand Down Expand Up @@ -402,6 +403,7 @@
"INVALID_REQUEST",
"METHOD_NOT_FOUND",
"PARSE_ERROR",
"REQUEST_TIMEOUT",
"URL_ELICITATION_REQUIRED",
"ErrorData",
"JSONRPCError",
Expand Down
2 changes: 1 addition & 1 deletion src/mcp/types/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down