README

colmugx/mcp/transport does not have a README file

#
Transport

pub(open) trait Transport {
fn receive(Self) -> String? raise
TransportError

fn send(Self, String) -> Unit raise
TransportError

fn send_notification(Self,
Notification
) -> Unit raise
TransportError

fn send_event(Self, event_type~ : String, data~ : String) -> Unit
fn supports_streaming(Self) -> Bool
fn close(Self) -> Unit
}

#
AnyTransport

pub(all) enum AnyTransport {
Stdio(StdioTransport)
StdioClient(StdioClientTransport)
Http(HttpTransport)
HttpClient(HttpClientTransport)
}

#
AnyTransport::close

fn AnyTransport::close(self : AnyTransport) -> Unit

#
AnyTransport::receive

#
AnyTransport::send

async fn AnyTransport::send(self : AnyTransport, message : String) -> Unit raise
TransportError

#
AnyTransport::send_event

fn AnyTransport::send_event(self : AnyTransport, event_type~ : String, data~ : String) -> Unit

#
AnyTransport::send_notification

#
AnyTransport::supports_streaming

fn AnyTransport::supports_streaming(self : AnyTransport) -> Bool

#
AuthConfig

pub struct AuthConfig {
verify_token : (String) -> Bool
resource_metadata_url : String
authorization_servers : Array[String]
required_scopes : String?
allowed_origins : Array[String]?
}

Server-side authentication configuration (MCP spec 2026-07-28). Provides Bearer token validation, Protected Resource Metadata, and Origin header validation for DNS rebinding prevention.

#
AuthConfig::AuthConfig

fn AuthConfig::AuthConfig(verify_token~ : (String) -> Bool, resource_metadata_url~ : String, authorization_servers? : Array[String], required_scopes? : String, allowed_origins? : Array[String]) -> AuthConfig

#
HttpClientTransport

pub struct HttpClientTransport {
base_url : String
auth_token : String?
closed : Bool
pending_responses :
Queue
[String]
tool_header_schemas : Map[String, Array[(Array[String], String)]]
}

HttpClientTransport — MCP client connecting to a remote HTTP server.

Implements the stateless 2026-07-28 Streamable HTTP transport: every JSON-RPC request is its own POST, carrying the required request-metadata headers (MCP-Protocol-Version, Mcp-Method, Mcp-Name). A POST may be answered with either a single JSON object or an SSE stream scoped to that request; both are collected into pending_responses and surfaced one at a time by receive.

The legacy session model (Mcp-Session-Id, GET long-poll SSE, Last-Event-ID resumability, DELETE close) is removed. Server→client notifications now flow on per-request SSE response streams (progress) or subscriptions/listen (change events), not a standalone GET channel.

#
HttpClientTransport::HttpClientTransport

fn HttpClientTransport::HttpClientTransport(base_url : String, auth_token? : String) -> HttpClientTransport

#
HttpClientTransport::close

fn HttpClientTransport::close(self : HttpClientTransport) -> Unit

#
HttpClientTransport::receive

async fn HttpClientTransport::receive(self : HttpClientTransport) -> String? noraise

Drain the next response message (single JSON or one SSE event) queued by send. Blocks asynchronously until a message is available. Returns None when the transport is closed or the underlying queue is closed/empty.

#
HttpClientTransport::send

POST a JSON-RPC request to the server. Sets the required request-metadata headers (MCP-Protocol-Version, Mcp-Method, Mcp-Name) and accepts either a single JSON object or an SSE stream as the response. All response messages are pushed onto pending_responses for receive to drain.

#
HttpClientTransport::send_event

fn HttpClientTransport::send_event(_self : HttpClientTransport, event_type~ : String, data~ : String) -> Unit

Client transport does not push events to server.

#
HttpClientTransport::send_notification

Send a JSON-RPC notification (no id, fire-and-forget). Per spec §B, a notification POST is answered with 202 Accepted and no body.

#
HttpClientTransport::set_tool_header_schemas

fn HttpClientTransport::set_tool_header_schemas(self : HttpClientTransport, schemas : Map[String, Array[(Array[String], String)]]) -> Unit

Install the x-mcp-header mirror schema set (called by the client layer after validating tools/list tool definitions). Emission itself is done by send when building tools/call request headers.

#
HttpClientTransport::supports_streaming

fn HttpClientTransport::supports_streaming(_self : HttpClientTransport) -> Bool

#
HttpTransport

pub struct HttpTransport {
port : Int
endpoint_path : String
auth : AuthConfig?
pending_requests :
Queue
[(String,
Queue
[String])]
pending_reply_queues : Map[String,
Queue
[String]]
}

#
HttpTransport::HttpTransport

fn HttpTransport::HttpTransport(port? : Int, endpoint_path? : String) -> HttpTransport

#
HttpTransport::close

fn HttpTransport::close(self : HttpTransport) -> Unit

#
HttpTransport::receive

#
HttpTransport::receive_request

#
HttpTransport::send

async fn HttpTransport::send(self : HttpTransport, message : String) -> Unit raise
TransportError

#
HttpTransport::send_event

fn HttpTransport::send_event(self : HttpTransport, event_type~ : String, data~ : String) -> Unit

#
HttpTransport::send_notification

fn HttpTransport::send_notification(self : HttpTransport, _notification :
Notification
) -> Unit

Trait-required stub. Server→client notifications over HTTP flow through MCPServer's per-subscription reply handles (subscriptions/listen), not through this transport; the legacy GET-SSE event queue is gone.

#
HttpTransport::start

#
HttpTransport::supports_streaming

fn HttpTransport::supports_streaming(_self : HttpTransport) -> Bool

#
HttpTransport::with_auth

fn HttpTransport::with_auth(self : HttpTransport, auth : AuthConfig) -> HttpTransport

#
JsonRpcKind

pub(all) enum JsonRpcKind {
Notification
FinalResponse
Other
} derive(Eq,
Debug
)

Classification of JSON-RPC messages arriving on the server-side reply queue. Used to decide whether a POST response is a single JSON object or an SSE stream.

#
StdioClientTransport

StdioClientTransport — MCP host/client connecting to a local MCP server via spawned child process.

Follows the MCP specification: the host spawns the server as a subprocess, communicates via newline-delimited JSON-RPC over stdin/stdout pipes. Stderr passes through to the parent for server-side logging.

Two-phase initialization:
  1. new() stores configuration (command, arguments, env)
  2. start(group) creates pipes and spawns the child process

Graceful shutdown (per MCP spec):
  1. Close stdin pipe → signals EOF to child
  2. Child detects EOF and exits
  3. TaskGroup cancel_handler (SIGTERM → 5s → SIGKILL) handles stubborn processes

#
StdioClientTransport::StdioClientTransport

fn StdioClientTransport::StdioClientTransport(cmd~ : String, args? : Array[String], extra_env? : Map[String, String]) -> StdioClientTransport

#
StdioClientTransport::close

fn StdioClientTransport::close(self : StdioClientTransport) -> Unit

Graceful shutdown per MCP spec:
  1. Close stdin writer → signals EOF to child process
  2. Close stdout reader → release pipe resources
  3. Mark transport as closed The TaskGroup's cancel_handler handles forced termination if needed.

#
StdioClientTransport::receive

Read one JSON-RPC message from the child's stdout. Returns None on EOF (child closed stdout / process exited).

#
StdioClientTransport::send

Send a JSON-RPC message to the child's stdin. Validates the message, writes it with a newline, and flushes immediately.

#
StdioClientTransport::send_event

fn StdioClientTransport::send_event(_self : StdioClientTransport, event_type~ : String, data~ : String) -> Unit

Client transport does not push events to child process.

#
StdioClientTransport::send_notification

Send a JSON-RPC notification (no id, fire-and-forget) to the child's stdin.

#
StdioClientTransport::start

Spawn the child process inside the given TaskGroup. Creates stdin/stdout pipes, spawns the process, and wraps the writer in a BufferedWriter (8KB) for efficient I/O.

Must be called before send() / receive().

#
StdioClientTransport::supports_streaming

fn StdioClientTransport::supports_streaming(_self : StdioClientTransport) -> Bool

#
StdioTransport

StdioTransport with buffered I/O for improved performance. Buffering reduces the number of syscalls and context switches, which is critical for high-frequency request/response patterns.

#
StdioTransport::StdioTransport

fn StdioTransport::StdioTransport() -> StdioTransport

#
StdioTransport::close

fn StdioTransport::close(self : StdioTransport) -> Unit

#
StdioTransport::receive

#
StdioTransport::send

async fn StdioTransport::send(self : StdioTransport, message : String) -> Unit raise
TransportError

#
StdioTransport::send_event

fn StdioTransport::send_event(_self : StdioTransport, event_type~ : String, data~ : String) -> Unit

#
StdioTransport::send_notification

#
StdioTransport::supports_streaming

fn StdioTransport::supports_streaming(_self : StdioTransport) -> Bool

#
classify_jsonrpc_message

fn classify_jsonrpc_message(message : String) -> JsonRpcKind

Classify a serialized JSON-RPC message for response-mode selection.

#
decode_base64

fn decode_base64(s : String) -> Bytes?

Decode a standard Base64 string back to raw bytes. Returns None on invalid input (fail-closed).

#
decode_base64_sentinel

fn decode_base64_sentinel(value : String) -> String?

Decode a Base64 sentinel value. Returns None if the value is not in sentinel form or if decoding fails (fail-closed).

#
encode_base64

fn encode_base64(bytes : Bytes) -> String

Encode raw bytes to a standard Base64 string (with padding).

#
encode_base64_sentinel

fn encode_base64_sentinel(value : String) -> String

Encode a string as a Base64 sentinel value: =?base64?<b64>?=. The input is first encoded as UTF-8 bytes.

#
encode_header_value

fn encode_header_value(value : String) -> String

Encode a header value according to the spec: plain when safe, otherwise Base64-sentinel encoded.

#
extract_argument_value

fn extract_argument_value(body : String, path : Array[String]) -> String?

Extract the value at a property path inside params.arguments for tools/call requests. Returns None when the path is absent or the final value is null. Converts string, safe integer, and boolean values to their header string representations.

#
is_header_safe

fn is_header_safe(value : String) -> Bool

Returns true if value can be transmitted as a plain HTTP header value: every character is visible ASCII (0x210x7E), space (0x20), or tab (0x09); it has no leading/trailing whitespace; and it does not match the sentinel pattern (to avoid ambiguity).

#
is_notification

fn is_notification(body : Json) -> Bool

Returns true when the JSON body is a JSON-RPC notification (method present, id absent).

#
is_valid_header_characters

fn is_valid_header_characters(value : String) -> Bool

Returns true if value contains only characters permitted in a non- sentinel HTTP header value: visible ASCII (0x210x7E), space (0x20), or tab (0x09). CR and LF are implicitly rejected because they are not in the allowed range.

#
jsonrpc_error_code

fn jsonrpc_error_code(message : String) -> Int?

Extract the JSON-RPC error code from a serialized response, if any.

#
looks_like_sentinel

fn looks_like_sentinel(value : String) -> Bool

Returns true if the value matches the Base64 sentinel pattern.

#
sse_event_line

fn sse_event_line(json : String) -> String

Format a JSON-RPC payload as one SSE event line.

#
unsupported_protocol_version_error

fn unsupported_protocol_version_error(requested : String) -> String

Build an UnsupportedProtocolVersion (-32022) JSON-RPC error response body. The response has no id because the failure is transport-level.

#
validate_jsonrpc_message

fn validate_jsonrpc_message(message : String) -> Result[Unit,
MCPError
]