turbomcp-stdio

Crates.ioturbomcp-stdio
lib.rsturbomcp-stdio
version3.0.0-beta.3
created_at2026-01-12 20:04:16.565648+00
updated_at2026-01-22 16:44:30.812724+00
descriptionStandard I/O transport implementation for TurboMCP - newline-delimited JSON over stdin/stdout
homepagehttps://turbomcp.org
repositoryhttps://github.com/Epistates/turbomcp
max_upload_size
id2038742
size86,850
Nick Paterno (nicholasjpaterno)

documentation

README

turbomcp-stdio

Standard I/O transport implementation for the TurboMCP Model Context Protocol SDK.

Overview

This crate provides the StdioTransport implementation for MCP communication over stdin/stdout, which is the standard way MCP servers communicate with clients. It supports JSON-RPC over newline-delimited JSON.

MCP Specification Compliance

This implementation is fully compliant with the MCP stdio transport specification (2025-06-18):

  • Newline-delimited JSON: Uses LinesCodec for proper message framing
  • No embedded newlines: Validates messages don't contain \n or \r characters
  • UTF-8 encoding: All messages are UTF-8 encoded
  • stderr for logging: Uses tracing crate which outputs to stderr by default
  • Bidirectional communication: Supports both client→server and server→client messages
  • Valid JSON only: Validates all messages are well-formed JSON before sending

Usage

use turbomcp_stdio::{StdioTransport, Transport};

#[tokio::main]
async fn main() {
    let transport = StdioTransport::new();
    transport.connect().await.unwrap();

    // Send and receive messages...
}

Features

  • Zero-copy message handling with Bytes
  • Lock-free atomic metrics for high performance
  • Background reader task with bounded channel for backpressure
  • Configurable message size limits

Architecture

The transport follows the hybrid mutex pattern for optimal async performance:

  • std::sync::Mutex for state/config (short-lived locks, never cross .await)
  • AtomicMetrics for lock-free counter updates
  • tokio::sync::Mutex for I/O streams (necessary for async I/O)

License

MIT

Commit count: 572

cargo fmt