Index
mcp
¶
MCP (Model Context Protocol) layer for OpenJarvis.
Classes¶
MCPClient
¶
MCPClient(transport: MCPTransport)
Client that communicates with an MCP server via a transport.
| PARAMETER | DESCRIPTION |
|---|---|
transport
|
The transport layer to use for communication.
TYPE:
|
Source code in src/openjarvis/mcp/client.py
Functions¶
initialize
¶
Perform the MCP initialize handshake.
Sends the required client info and protocol version, then
confirms with a notifications/initialized notification
as required by the MCP specification.
Returns the server capabilities.
Source code in src/openjarvis/mcp/client.py
notify
¶
Send a JSON-RPC notification (no response expected).
Per JSON-RPC 2.0 spec, notifications omit the id field entirely.
Source code in src/openjarvis/mcp/client.py
list_tools
¶
list_tools() -> List[ToolSpec]
Discover available tools from the server.
Returns a list of ToolSpec objects.
Source code in src/openjarvis/mcp/client.py
call_tool
¶
Call a tool on the server.
Returns the result dictionary with content and isError fields.
Source code in src/openjarvis/mcp/client.py
MCPError
dataclass
¶
Bases: Exception
MCP protocol error with JSON-RPC error code.
MCPNotification
dataclass
¶
JSON-RPC 2.0 notification (no id, no response expected).
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
MCPServer
¶
MCPServer(tools: Optional[List[BaseTool]] = None)
MCP server that exposes OpenJarvis tools via JSON-RPC.
| PARAMETER | DESCRIPTION |
|---|---|
tools
|
List of
TYPE:
|
Source code in src/openjarvis/mcp/server.py
Functions¶
handle
¶
handle(request: MCPRequest) -> MCPResponse
Dispatch an MCP request and return a response.
Source code in src/openjarvis/mcp/server.py
InProcessTransport
¶
InProcessTransport(server: MCPServer)
Bases: MCPTransport
Direct in-process transport for testing.
Routes requests directly to an MCPServer instance without
serialization overhead.
Source code in src/openjarvis/mcp/transport.py
Functions¶
send
¶
send(request: MCPRequest) -> MCPResponse
MCPTransport
¶
Bases: ABC
Abstract transport layer for MCP communication.
Functions¶
send
abstractmethod
¶
send(request: MCPRequest) -> MCPResponse
send_notification
¶
send_notification(request: MCPRequest) -> None
Send a JSON-RPC notification (no response expected).
The default implementation delegates to :meth:send and discards the
response. Transports may override this when the server returns no
body for notifications (e.g. HTTP 202 Accepted).
Source code in src/openjarvis/mcp/transport.py
StdioTransport
¶
Bases: MCPTransport
JSON-RPC over stdin/stdout subprocess transport.
Launches a subprocess and communicates via JSON lines on stdin/stdout.
Source code in src/openjarvis/mcp/transport.py
Functions¶
send
¶
send(request: MCPRequest) -> MCPResponse
Write request as JSON line, read response line.
Source code in src/openjarvis/mcp/transport.py
StreamableHTTPTransport
¶
Bases: MCPTransport
MCP Streamable HTTP transport (JSON-RPC over HTTP).
Uses a persistent httpx.Client session, tracks the
Mcp-Session-Id header, and sends the Accept header
required by the MCP Streamable HTTP specification.
Source code in src/openjarvis/mcp/transport.py
Functions¶
send
¶
send(request: MCPRequest) -> MCPResponse
Send request via HTTP POST following the MCP Streamable HTTP spec.
Handles both application/json and text/event-stream responses
as allowed by the MCP Streamable HTTP specification.
Source code in src/openjarvis/mcp/transport.py
send_notification
¶
send_notification(request: MCPRequest) -> None
Send a notification — accept any 2xx, don't parse the body.