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 2025-11-25). Provides Bearer token validation, Protected Resource Metadata, and Origin header validation for DNS rebinding prevention.

    AuthConfig::new

    fn AuthConfig::new(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?
    session_id : String?
    last_response : String?
    last_response_status : Int
    sse_client :
    Client
    ?
    sse_connected : Bool
    closed : Bool
    last_event_id : String?
    sse_pending_responses : Array[String]?
    sse_pending_index : Int
    protocol_version : String
    }

    HttpClientTransport — MCP client connecting to a remote HTTP server Uses Streamable HTTP transport (MCP spec 2025-11-25): POST for request-response, optional GET SSE for server→client notifications.

    HttpClientTransport::close

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

    HttpClientTransport::close_session

    async fn HttpClientTransport::close_session(self : HttpClientTransport) -> Unit

    Gracefully close the HTTP session by sending a DELETE request. Call this before close() for proper session termination.

    HttpClientTransport::new

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

    HttpClientTransport::receive

    Read response: drain SSE POST events, then stored POST JSON, then SSE GET. Returns None if no response is pending and SSE has no events.

    HttpClientTransport::send

    POST a JSON-RPC request to the server using streaming HTTP. Handles both single JSON and SSE streaming responses per MCP spec.

    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).

    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]]
    session_id : String?
    sse_active : Bool
    event_queue :
    Queue
    [
    Notification
    ]
    }

    HttpTransport::close

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

    HttpTransport::new

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

    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

    HttpTransport::start

    HttpTransport::supports_streaming

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

    HttpTransport::with_auth

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

    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::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::new

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

    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::close

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

    StdioTransport::new

    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

    validate_jsonrpc_message

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