async-mcp
Categories
Language:
Rust
Stars:
12
Forks:
1
Async MCP
A minimalistic async Rust implementation of the Model Context Protocol (MCP). This library extends the synchronous implementation from mcp-sdk to support async operations and implements additional transports. Due to significant code changes, it is released as a separate crate.
Note: This project is still early in development.
Installation
Add this to your Cargo.toml
:
[dependencies]
async-mcp = "0.1.1"
Overview
This is an implementation of the Model Context Protocol defined by Anthropic.
Features
Supported Transports
- Server-Sent Events (SSE)
- Standard IO (Stdio)
- In-Memory Channel
- Websockets
Usage Examples
Server Implementation
Using Stdio Transport
let server = Server::builder(StdioTransport)
.capabilities(ServerCapabilities {
tools: Some(json!({})),
..Default::default()
})
.request_handler("tools/list", list_tools)
.request_handler("tools/call", call_tool)
.request_handler("resources/list", |_req: ListRequest| {
Ok(ResourcesListResponse {
resources: vec![],
next_cursor: None,
meta: None,
})
})
.build();
Run Http Server supporting both SSE and WS
run_http_server(3004, None, |transport| async move {
let server = build_server(transport);
Ok(server)
})
.await?;
Local Endpoints
WebSocket endpoint: ws://127.0.0.1:3004/ws
SSE endpoint: http://127.0.0.1:3004/sse
Client Implementation
Setting up Transport
// Stdio Transport
let transport = ClientStdioTransport::new("", &[])?;
// In-Memory Transport
let transport = ClientInMemoryTransport::new(|t| tokio::spawn(inmemory_server(t)));
// SSE Transport
let transport = ClientSseTransportBuilder::new(server_url).build();
// WS Transport
let transport = async_mcp::transport::ClientWsTransportBuilder::new("ws://localhost:3004/ws".to_string()).build();
Making Requests
// Initialize transport
transport.open().await?;
// Create and start client
let client = async_mcp::client::ClientBuilder::new(transport.clone()).build();
let client_clone = client.clone();
let _client_handle = tokio::spawn(async move { client_clone.start().await });
// Make a request
client
.request(
"tools/call",
Some(json!({"name": "ping", "arguments": {}})),
RequestOptions::default().timeout(Duration::from_secs(5)),
)
.await?
Complete Examples
For full working examples, check out:
Related SDKs
Official
Community
For the complete feature set, please refer to the MCP specification.
Implementation Status
Core Protocol Features
- Basic Message Types
- Error and Signal Handling
- Transport Layer
- Stdio
- In-Memory Channel
- SSE
- Websockets
Server Features
- Tools Support
- Prompts
- Resources
- Pagination
- Completion
Client Features
Compatible with Claude Desktop:
- Stdio Support
- In-Memory Channel
- SSE Support
Monitoring
- Logging
- Metrics
Utilities
- Ping
- Cancellation
- Progress Tracking
Publisher info
VG
Co-Founder @ LangDB | Building an AI Gateway!
More MCP servers built with Rust
A MCP server to allow the LLM in Cursor to access Rust Analyzer, Crate Docs and Cargo Commands.
MCP Dockmaster allows you to easily install and manage MCP servers. Available for Mac, Windows and Linux as a Desktop App, CLI and a library.