fix: replace http code by jsonrpc (#1920)
This commit is contained in:
parent
213cf993ca
commit
656f887aff
5 changed files with 7 additions and 13 deletions
|
|
@ -281,10 +281,7 @@ class StreamableHTTPSessionManager:
|
||||||
error_response = JSONRPCError(
|
error_response = JSONRPCError(
|
||||||
jsonrpc="2.0",
|
jsonrpc="2.0",
|
||||||
id="server-error",
|
id="server-error",
|
||||||
error=ErrorData(
|
error=ErrorData(code=INVALID_REQUEST, message="Session not found"),
|
||||||
code=INVALID_REQUEST,
|
|
||||||
message="Session not found",
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
response = Response(
|
response = Response(
|
||||||
content=error_response.model_dump_json(by_alias=True, exclude_none=True),
|
content=error_response.model_dump_json(by_alias=True, exclude_none=True),
|
||||||
|
|
|
||||||
|
|
@ -50,12 +50,7 @@ def validate_sampling_tools(
|
||||||
"""
|
"""
|
||||||
if tools is not None or tool_choice is not None:
|
if tools is not None or tool_choice is not None:
|
||||||
if not check_sampling_tools_capability(client_caps):
|
if not check_sampling_tools_capability(client_caps):
|
||||||
raise McpError(
|
raise McpError(ErrorData(code=INVALID_PARAMS, message="Client does not support sampling tools capability"))
|
||||||
ErrorData(
|
|
||||||
code=INVALID_PARAMS,
|
|
||||||
message="Client does not support sampling tools capability",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def validate_tool_use_result_messages(messages: list[SamplingMessage]) -> None:
|
def validate_tool_use_result_messages(messages: list[SamplingMessage]) -> None:
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ from types import TracebackType
|
||||||
from typing import Any, Generic, Protocol, TypeVar
|
from typing import Any, Generic, Protocol, TypeVar
|
||||||
|
|
||||||
import anyio
|
import anyio
|
||||||
import httpx
|
|
||||||
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
|
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
|
||||||
from pydantic import BaseModel, TypeAdapter
|
from pydantic import BaseModel, TypeAdapter
|
||||||
from typing_extensions import Self
|
from typing_extensions import Self
|
||||||
|
|
@ -18,6 +17,7 @@ from mcp.shared.response_router import ResponseRouter
|
||||||
from mcp.types import (
|
from mcp.types import (
|
||||||
CONNECTION_CLOSED,
|
CONNECTION_CLOSED,
|
||||||
INVALID_PARAMS,
|
INVALID_PARAMS,
|
||||||
|
REQUEST_TIMEOUT,
|
||||||
CancelledNotification,
|
CancelledNotification,
|
||||||
ClientNotification,
|
ClientNotification,
|
||||||
ClientRequest,
|
ClientRequest,
|
||||||
|
|
@ -272,7 +272,7 @@ class BaseSession(
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
raise McpError(
|
raise McpError(
|
||||||
ErrorData(
|
ErrorData(
|
||||||
code=httpx.codes.REQUEST_TIMEOUT,
|
code=REQUEST_TIMEOUT,
|
||||||
message=(
|
message=(
|
||||||
f"Timed out while waiting for response to {request.__class__.__name__}. "
|
f"Timed out while waiting for response to {request.__class__.__name__}. "
|
||||||
f"Waited {timeout} seconds."
|
f"Waited {timeout} seconds."
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,7 @@ from mcp.types.jsonrpc import (
|
||||||
INVALID_REQUEST,
|
INVALID_REQUEST,
|
||||||
METHOD_NOT_FOUND,
|
METHOD_NOT_FOUND,
|
||||||
PARSE_ERROR,
|
PARSE_ERROR,
|
||||||
|
REQUEST_TIMEOUT,
|
||||||
URL_ELICITATION_REQUIRED,
|
URL_ELICITATION_REQUIRED,
|
||||||
ErrorData,
|
ErrorData,
|
||||||
JSONRPCError,
|
JSONRPCError,
|
||||||
|
|
@ -402,6 +403,7 @@ __all__ = [
|
||||||
"INVALID_REQUEST",
|
"INVALID_REQUEST",
|
||||||
"METHOD_NOT_FOUND",
|
"METHOD_NOT_FOUND",
|
||||||
"PARSE_ERROR",
|
"PARSE_ERROR",
|
||||||
|
"REQUEST_TIMEOUT",
|
||||||
"URL_ELICITATION_REQUIRED",
|
"URL_ELICITATION_REQUIRED",
|
||||||
"ErrorData",
|
"ErrorData",
|
||||||
"JSONRPCError",
|
"JSONRPCError",
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ URL_ELICITATION_REQUIRED = -32042
|
||||||
|
|
||||||
# SDK error codes
|
# SDK error codes
|
||||||
CONNECTION_CLOSED = -32000
|
CONNECTION_CLOSED = -32000
|
||||||
# REQUEST_TIMEOUT = -32001 # the typescript sdk uses this
|
REQUEST_TIMEOUT = -32001
|
||||||
|
|
||||||
# Standard JSON-RPC error codes
|
# Standard JSON-RPC error codes
|
||||||
PARSE_ERROR = -32700
|
PARSE_ERROR = -32700
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue