Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
PMCP - Pragmatic Model Context Protocol
A high-quality Rust implementation of the Model Context Protocol (MCP) SDK, maintaining full compatibility with the TypeScript SDK while leveraging Rust's performance and safety guarantees.
Code Name: Angel Rust
๐ Version 0.7.0 Features
- โ Full TypeScript SDK v1.17.2+ Compatibility: 100% protocol compatibility verified
- ๐ฏ Procedural Macros: Simplified tool/prompt/resource definitions with
#[tool]
macro - ๐ WASM/Browser Support: Run MCP clients directly in web browsers
- โก SIMD Optimizations: 10-50x performance improvements for JSON parsing
- ๐ Fuzzing Infrastructure: Comprehensive fuzz testing for protocol robustness
- ๐ Advanced Documentation: Complete protocol compatibility guide
- ๐งช Integration Tests: TypeScript SDK interoperability testing
- ๐ Performance: 16x faster than TypeScript SDK, 50x lower memory usage
Core Features
- ๐ Full Protocol Support: Complete implementation of MCP specification v1.0
- ๐ Multiple Transports: stdio, HTTP/SSE, and WebSocket with auto-reconnection
- ๐ก๏ธ Type Safety: Compile-time protocol validation
- โก Zero-Copy Parsing: Efficient message handling with SIMD acceleration
- ๐ Built-in Auth: OAuth 2.0, OIDC discovery, and bearer token support
- ๐ค LLM Sampling: Native support for model sampling operations
- ๐ Middleware System: Request/response interceptors for custom logic
- ๐ Retry Logic: Built-in exponential backoff for resilient connections
- ๐ฆ Message Batching: Efficient notification grouping and debouncing
- ๐ฌ Resource Subscriptions: Real-time resource change notifications
- โ Request Cancellation: Full async cancellation support with CancellationToken
- ๐ WebSocket Server: Complete server-side WebSocket transport implementation
- ๐ Roots Management: Directory/URI registration and management
- ๐ Comprehensive Testing: Property tests, fuzzing, and integration tests
- ๐๏ธ Quality First: Zero technical debt, no unwraps in production code
Installation
Add to your Cargo.toml
:
[]
= "0.7.0"
Examples
The SDK includes comprehensive examples for all major features:
# Client initialization and connection
# Basic server with tools
# Client tool usage
# Server with resources
# Client resource access
# Server with prompts
# Client prompts usage
# Logging
# Authentication (OAuth, Bearer tokens)
# Progress notifications
# Request cancellation
# Error handling patterns
# WebSocket transport
# LLM sampling operations
# Middleware and interceptors
# OAuth server with authentication
# Completable prompts
# Resource watching with file system monitoring
# Input elicitation
# OIDC discovery and authentication
# Procedural macros for tools
See the examples directory for detailed documentation.
What's New in v1.0 (In Development)
๐ฏ Procedural Macros
#[tool]
attribute for automatic tool handler generation#[tool_router]
for collecting tools from impl blocks- Automatic JSON schema generation from Rust types
- 70% reduction in boilerplate code
๐ WASM Support
- Full WebAssembly support for browser environments
- WebSocket transport for WASM clients
- Cross-platform runtime abstraction
- Interactive browser example with modern UI
- TypeScript definitions for seamless integration
๐ Enhanced Developer Experience
- Type-safe parameter handling with compile-time validation
- Automatic error conversion and handling
- Improved documentation with 200+ examples
- Property-based testing for all new features
What's New in v0.6.6
๐ OIDC Discovery Support
- Full OpenID Connect discovery implementation
- Automatic retry on CORS/network errors
- Token exchange with explicit JSON accept headers
- Comprehensive auth client module
๐ Transport Response Isolation
- Unique transport IDs prevent cross-transport response routing
- Enhanced protocol safety for multiple concurrent connections
- Request-response correlation per transport instance
๐ Enhanced Documentation
- 135+ doctests with real-world examples
- Complete property test coverage
- New OIDC discovery example (example 20)
What's New in v0.2.0
๐ WebSocket Transport with Auto-Reconnection
Full WebSocket support with automatic reconnection, exponential backoff, and keepalive ping/pong.
๐ HTTP/SSE Transport
HTTP transport with Server-Sent Events for real-time notifications and long-polling support.
๐ LLM Sampling Support
Native support for model sampling operations with the createMessage
API:
let result = client.create_message.await?;
๐ Middleware System
Powerful middleware chain for request/response processing:
use ;
let mut chain = new;
chain.add;
chain.add;
๐ Message Batching & Debouncing
Optimize notification delivery with batching and debouncing:
use ;
let batcher = new;
Quick Start
Client Example
use ;
async
Server Example
use ;
use async_trait;
use Value;
;
async
Transport Options
stdio (Default)
let transport = new;
HTTP/SSE
use ;
let config = HttpConfig ;
let transport = new;
WebSocket
use ;
let config = WebSocketConfig ;
let transport = new;
Development
Prerequisites
- Rust 1.80.0 or later
- Git
Setup
# Clone the repository
# Install development tools
# Run quality checks
Quality Standards
This project maintains pmat-level quality standards:
- Zero Technical Debt: No TODO/FIXME comments
- No
unwrap()
: All errors handled explicitly - 100% Documentation: Every public API documented
- Property Testing: Comprehensive invariant testing
- Benchmarks: Performance regression prevention
Testing
# Run all tests
# Run property tests (slower, more thorough)
# Generate coverage report
# Run mutation tests
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Ensure all quality checks pass (
make quality-gate
) - Commit your changes (following conventional commits)
- Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Architecture
pmcp/
โโโ src/
โ โโโ client/ # Client implementation
โ โโโ server/ # Server implementation
โ โโโ shared/ # Shared transport/protocol code
โ โโโ types/ # Protocol type definitions
โ โโโ utils/ # Utility functions
โโโ tests/
โ โโโ integration/ # Integration tests
โ โโโ property/ # Property-based tests
โโโ benches/ # Performance benchmarks
โโโ examples/ # Example implementations
Compatibility
Feature | TypeScript SDK | Rust SDK |
---|---|---|
Protocol Versions | 2024-10-07+ | 2024-10-07+ |
Transports | stdio, SSE, WebSocket | stdio, SSE, WebSocket |
Authentication | OAuth 2.0, Bearer | OAuth 2.0, Bearer |
Tools | โ | โ |
Prompts | โ | โ |
Resources | โ | โ |
Sampling | โ | โ |
Performance
Benchmarks show 10x improvement over TypeScript SDK:
- Message parsing: < 1ฮผs
- Round-trip latency: < 100ฮผs (stdio)
- Memory usage: < 10MB baseline
Run benchmarks:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Model Context Protocol specification
- TypeScript SDK for reference implementation
- PAIML MCP Agent Toolkit for quality standards
- Alternative implementation - official rust sdk - created before I knew this existed.