Skip to main content

Crate turbomcp_wire

Crate turbomcp_wire 

Source
Expand description

§TurboMCP Wire Format Codec

This crate provides wire format encoding/decoding abstractions for MCP messages. It enables pluggable serialization formats while maintaining MCP protocol compliance.

§Design Philosophy

  • Wire format: JSON-RPC 2.0 (MCP protocol standard)
  • Extensible: Support for alternative formats (MessagePack, etc.)
  • Zero-copy ready: Integration with rkyv for internal message passing
  • no_std compatible: Works in embedded and WASM environments

§Usage

use turbomcp_wire::{Codec, JsonCodec};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct MyMessage {
    id: u32,
    method: String,
}

let codec = JsonCodec::new();
let msg = MyMessage { id: 1, method: "test".into() };

// Encode to bytes
let bytes = codec.encode(&msg).unwrap();

// Decode from bytes
let decoded: MyMessage = codec.decode(&bytes).unwrap();

§Features

  • std - Standard library support (default)
  • json - JSON codec (default)
  • simd - SIMD-accelerated JSON (sonic-rs, simd-json)
  • msgpack - MessagePack binary format

Structs§

CodecError
Wire format codec error
JsonCodec
JSON codec using serde_json
McpError
Unified MCP error type
MsgPackCodecmsgpack
MessagePack binary codec
SimdJsonCodecsimd
SIMD-accelerated JSON codec using sonic-rs
StreamingJsonDecoder
Streaming JSON decoder for Server-Sent Events (SSE)

Enums§

AnyCodec
Enum wrapper for all codec types

Traits§

Codec
Wire format codec trait

Type Aliases§

CodecResult
Result type for codec operations