transport
diapason.mcp.transport
¶
MCP transport implementations.
InProcessTransport
¶
Bases: MCPTransport
Direct in-process transport for testing.
Routes requests directly to an MCPServer instance without
serialization overhead.
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.