Skip to main content

Crate tower_mcp_types

Crate tower_mcp_types 

Source
Expand description

Standalone MCP protocol and error types – zero runtime dependencies.

tower-mcp-types ships all Model Context Protocol (MCP 2025-11-25) types and JSON-RPC 2.0 primitives as a self-contained crate. It has no dependency on Tower, Tokio, axum, or any async runtime – only serde, serde_json, thiserror, and base64.

This makes it suitable for:

  • WASM targets (browser clients, edge runtimes, editor extensions)
  • Code generation tools that need to inspect or emit MCP messages
  • Thin clients and proxies that only need to parse/serialize MCP wire format without running a full server
  • Testing libraries that want MCP types without pulling in a server stack

§Stateless protocol support (2026-07-28)

This crate also tracks the next protocol version (2026-07-28) that adds stateless operation, per-request _meta, and the server/discover RPC. Key items:

§The only standalone Rust MCP types crate

Most Rust MCP libraries bundle their protocol types with their runtime. tower-mcp-types ships independently so that tools with narrower requirements – WASM, codegen, linters, CLI utilities – can take a dependency without pulling in an async server stack. The Zed editor team raised exactly this concern for the official rmcp crate, which has not yet split types from runtime.

§Feature flags

FeatureWhat it adds
(default: none)Core protocol types + serde serialization
testingWire-format assertion helpers for JSON-RPC test cases

§Usage

Add to Cargo.toml:

[dependencies]
tower-mcp-types = "0.10"

Parse an incoming JSON-RPC request:

use tower_mcp_types::protocol::JsonRpcRequest;

let json = r#"{"jsonrpc":"2.0","id":1,"method":"tools/list","params":null}"#;
let req: JsonRpcRequest = serde_json::from_str(json).unwrap();
assert_eq!(req.method, "tools/list");

Construct a JSON-RPC error response:

use tower_mcp_types::error::{ErrorCode, JsonRpcError};

let err = JsonRpcError::new(ErrorCode::MethodNotFound, "tools/call not found");
assert_eq!(err.code, -32601);
let serialized = serde_json::to_string(&err).unwrap();
assert!(serialized.contains("-32601"));

§Compatibility with tower-mcp

tower-mcp re-exports everything from this crate, so migrating from tower-mcp-types to the full server library requires only a dependency change – no import paths need to change:

tower-mcp = { version = "0.10", features = ["http"] }

§WASM support

tower-mcp-types compiles for wasm32-unknown-unknown out of the box. This is verified by a CI job on every commit.

The parent tower-mcp crate is not WASM-compatible today; it pulls in Tokio networking features that do not build for wasm32. See tower-mcp issue #777 for progress on client-side WASM support in the full crate.

Re-exports§

pub use error::BoxError;
pub use error::Error;
pub use error::ErrorCode;
pub use error::JsonRpcError;
pub use error::McpErrorCode;
pub use error::Result;
pub use error::ResultExt;
pub use error::ToolError;
pub use protocol::CallToolResult;
pub use protocol::Content;
pub use protocol::GetPromptResult;
pub use protocol::ReadResourceResult;

Modules§

error
Error types for MCP
protocol
MCP protocol types based on JSON-RPC 2.0