Skip to content

protocol

diapason.mcp.protocol

MCP JSON-RPC 2.0 protocol message types.

MCPError dataclass

Bases: Exception

MCP protocol error with JSON-RPC error code.

MCPNotification dataclass

JSON-RPC 2.0 notification (no id, no response expected).

to_json()

Serialize to JSON string.

MCPRequest dataclass

JSON-RPC 2.0 request message.

Set id to None to create a JSON-RPC notification (no id field will appear in the serialized output, and no response is expected).

from_json(data) classmethod

Deserialize from JSON string.

to_dict()

Return a dict suitable for JSON serialization.

Omits the id key when it is None (notification).

to_json()

Serialize to JSON string.

MCPResponse dataclass

JSON-RPC 2.0 response message.

error_response(id, code, message, data=None) classmethod

Create an error response.

from_json(data) classmethod

Deserialize from JSON string.

to_json()

Serialize to JSON string.