protocol
protocol
¶
MCP JSON-RPC 2.0 protocol message types.
Classes¶
MCPRequest
dataclass
¶
MCPRequest(method: str, params: Dict[str, Any] = dict(), id: Optional[int | str] = 0, jsonrpc: str = '2.0')
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).
Functions¶
to_dict
¶
Return a dict suitable for JSON serialization.
Omits the id key when it is None (notification).
Source code in src/openjarvis/mcp/protocol.py
to_json
¶
from_json
classmethod
¶
from_json(data: str) -> MCPRequest
Deserialize from JSON string.
Source code in src/openjarvis/mcp/protocol.py
MCPResponse
dataclass
¶
MCPResponse(result: Any = None, error: Optional[Dict[str, Any]] = None, id: int | str = 0, jsonrpc: str = '2.0')
JSON-RPC 2.0 response message.
Functions¶
to_json
¶
Serialize to JSON string.
from_json
classmethod
¶
from_json(data: str) -> MCPResponse
Deserialize from JSON string.
Source code in src/openjarvis/mcp/protocol.py
error_response
classmethod
¶
error_response(id: int | str, code: int, message: str, data: Any = None) -> MCPResponse
Create an error response.
Source code in src/openjarvis/mcp/protocol.py
MCPNotification
dataclass
¶
JSON-RPC 2.0 notification (no id, no response expected).
MCPError
dataclass
¶
Bases: Exception
MCP protocol error with JSON-RPC error code.