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_stdcompatible: 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§
- Codec
Error - Wire format codec error
- Json
Codec - JSON codec using serde_json
- McpError
- Unified MCP error type
- MsgPack
Codec msgpack - MessagePack binary codec
- Simd
Json Codec simd - SIMD-accelerated JSON codec using sonic-rs
- Streaming
Json Decoder - Streaming JSON decoder for Server-Sent Events (SSE)
Enums§
- AnyCodec
- Enum wrapper for all codec types
Traits§
- Codec
- Wire format codec trait
Type Aliases§
- Codec
Result - Result type for codec operations