Skip to main content

Crate fastmcp_transport

Crate fastmcp_transport 

Source
Expand description

Transport layer for FastMCP.

This crate provides transport implementations for MCP communication:

  • Stdio: Standard input/output (primary transport)
  • SSE: Server-Sent Events (HTTP-based streaming)
  • WebSocket: Bidirectional web sockets

§Transport Design

Transports are designed around asupersync’s principles:

  • Cancel-correctness: All operations check cancellation via Cx::checkpoint()
  • Two-phase sends: Use reserve/commit pattern to prevent message loss
  • Budget awareness: Operations respect the request’s budget constraints

§Wire Format

MCP uses newline-delimited JSON (NDJSON) for message framing:

  • Each message is a single line of JSON
  • Messages are separated by \n
  • UTF-8 encoding is required

§Role in the System

fastmcp-transport is the I/O boundary for FastMCP. It is deliberately protocol-agnostic: transports move JsonRpcMessage values in and out while the server/client layers handle semantics. This keeps transport implementations small, testable, and reusable.

If you need to add a new transport (for example, QUIC or a custom IPC), this is the crate to extend.

Modules§

event_store
Event store for SSE resumability.
http
HTTP transport for FastMCP.
memory
In-memory transport for testing MCP servers without subprocess spawning.
sse
Server-Sent Events (SSE) transport for MCP.
websocket
WebSocket transport for MCP.

Structs§

AsyncLineReader
Async line reader with cancellation support.
AsyncStdin
Async wrapper for stdin.
AsyncStdioTransport
Async stdio transport with integrated cancellation support.
AsyncStdout
Async wrapper for stdout.
Codec
Codec for encoding/decoding JSON-RPC messages.
SendPermit
A permit for sending a message via two-phase commit.
StdioTransport
Stdio transport implementation.

Enums§

CodecError
Codec error types.
TransportError
Transport error types.

Traits§

Transport
Transport trait for cancel-correct message passing.
TwoPhaseTransport
Extension trait for two-phase send operations.