Skip to content

jsonrpc

This module follows the JSON-RPC 2.0 specification: https://www.jsonrpc.org/specification.

RequestId module-attribute

RequestId = Annotated[int, Field(strict=True)] | str

The ID of a JSON-RPC request.

JSONRPCRequest

Bases: BaseModel

A JSON-RPC request that expects a response.

Source code in src/mcp/types/jsonrpc.py
13
14
15
16
17
18
19
class JSONRPCRequest(BaseModel):
    """A JSON-RPC request that expects a response."""

    jsonrpc: Literal["2.0"]
    id: RequestId
    method: str
    params: dict[str, Any] | None = None

JSONRPCNotification

Bases: BaseModel

A JSON-RPC notification which does not expect a response.

Source code in src/mcp/types/jsonrpc.py
22
23
24
25
26
27
class JSONRPCNotification(BaseModel):
    """A JSON-RPC notification which does not expect a response."""

    jsonrpc: Literal["2.0"]
    method: str
    params: dict[str, Any] | None = None

JSONRPCResponse

Bases: BaseModel

A successful (non-error) response to a request.

Source code in src/mcp/types/jsonrpc.py
31
32
33
34
35
36
class JSONRPCResponse(BaseModel):
    """A successful (non-error) response to a request."""

    jsonrpc: Literal["2.0"]
    id: RequestId
    result: dict[str, Any]

URL_ELICITATION_REQUIRED module-attribute

URL_ELICITATION_REQUIRED = -32042

Error code indicating that a URL mode elicitation is required before the request can be processed.

ErrorData

Bases: BaseModel

Error information for JSON-RPC error responses.

Source code in src/mcp/types/jsonrpc.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class ErrorData(BaseModel):
    """Error information for JSON-RPC error responses."""

    code: int
    """The error type that occurred."""

    message: str
    """A short description of the error.

    The message SHOULD be limited to a concise single sentence.
    """

    data: Any = None
    """Additional information about the error.

    The value of this member is defined by the sender (e.g. detailed error information, nested errors, etc.).
    """

code instance-attribute

code: int

The error type that occurred.

message instance-attribute

message: str

A short description of the error.

The message SHOULD be limited to a concise single sentence.

data class-attribute instance-attribute

data: Any = None

Additional information about the error.

The value of this member is defined by the sender (e.g. detailed error information, nested errors, etc.).

JSONRPCError

Bases: BaseModel

A response to a request that indicates an error occurred.

Source code in src/mcp/types/jsonrpc.py
74
75
76
77
78
79
class JSONRPCError(BaseModel):
    """A response to a request that indicates an error occurred."""

    jsonrpc: Literal["2.0"]
    id: RequestId | None
    error: ErrorData