#anthropic #protocols #async #mcp #http-server

async-mcp

Async Implementation of Model Context Protocol (MCP)

4 releases

new 0.0.6 Jan 31, 2025
0.0.5 Jan 30, 2025

#402 in Asynchronous

Download history 133/week @ 2025-01-24

133 downloads per month

Apache-2.0

92KB
2.5K SLoC

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.

Crates.io

Note: This project is still early in development.

Installation

Add this to your Cargo.toml:

[dependencies]
async-mcp = "0.0.5"

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("<CMD>", &[])?;

// 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:

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

Dependencies

~22–36MB
~698K SLoC