tmcp
A Rust implementation of the Model Context Protocol for building AI-integrated applications.
Community
Want to contribute? Have ideas or feature requests? Come tell us about it on Discord.
Overview
A Rust implementation of the Model Context Protocol (MCP) - a JSON-RPC 2.0 based protocol for AI models to interact with external tools and services. Supports both client and server roles with async/await APIs.
Features
- Full MCP Protocol Support: Implements the latest MCP specification (2025-06-18)
- Client & Server: Build both MCP clients and servers with ergonomic APIs
- Multiple Transports: TCP/IP and stdio transport layers
- OAuth 2.0 Authentication: Complete OAuth 2.0 support including:
- Authorization Code Flow with PKCE
- Dynamic client registration (RFC7591)
- Automatic token refresh
- MCP-specific
resourceparameter support - Built-in callback server for browser flows
- Async/Await: Built on Tokio for high-performance async operations
Note: Batch operations in the previous protocol version are not supported.
Example
From ./examples/weather_server.rs
//! Minimal weather server example.
use json;
use ;
/// Example server.
;
/// Parameters for the weather tool.
// Tool input schema is automatically derived from the struct using serde and schemars.
/// Structured response for the weather tool.
/// Structured response for the ping tool.
/// Parameters for emitting a log message.
/// Result of emitting a log message.
// The `mcp_server` macro generates the necessary boilerplate to expose methods as MCP tools.
async