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(
|
||||
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),
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue