Index
diapason.mcp
¶
MCP (Model Context Protocol) layer for Diapason.
InProcessTransport
¶
Bases: MCPTransport
Direct in-process transport for testing.
Routes requests directly to an MCPServer instance without
serialization overhead.
MCPClient
¶
Client that communicates with an MCP server via a transport.
Parameters¶
transport: The transport layer to use for communication.
call_tool(name, arguments=None)
¶
Call a tool on the server.
Returns the result dictionary with content and isError fields.
close()
¶
Close the transport connection.
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.
list_tools()
¶
Discover available tools from the server.
Returns a list of ToolSpec objects.
notify(method, params=None)
¶
Send a JSON-RPC notification (no response expected).
Per JSON-RPC 2.0 spec, notifications omit the id field entirely.
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).
MCPResponse
dataclass
¶
MCPServer
¶
MCP server that exposes Diapason tools via JSON-RPC.
Parameters¶
tools:
List of BaseTool instances to expose. If None, auto-discovers
all registered tools from ToolRegistry.
MCPTransport
¶
Bases: ABC
Abstract transport layer for MCP communication.
close()
abstractmethod
¶
Release transport resources.
send(request)
abstractmethod
¶
Send a request and return the response.
send_notification(request)
¶
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).
StdioTransport
¶
Bases: MCPTransport
JSON-RPC over stdin/stdout subprocess transport.
Launches a subprocess and communicates via JSON lines on stdin/stdout.
close()
¶
Terminate the subprocess.
send(request)
¶
Write request as JSON line, read response line.
send_notification(request)
¶
Send a JSON-RPC notification — write only, never read.
Overrides the base implementation: stdio servers do not reply
to notifications, so the default send() would block forever
on proc.stdout.readline().
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.
close()
¶
Close the underlying httpx client.
send(request)
¶
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.
send_notification(request)
¶
Send a notification — accept any 2xx, don't parse the body.