R

async-mcp

...
Created 1/29/2025byv3g42

Categories

agentsanthropicllmsmcp

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.

Crates.io

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
Last updated: 4/3/2025

Publisher info

v3g42's avatar

Co-Founder @ LangDB | Building an AI Gateway!

30
followers
5
following
60
repos

More MCP servers built with Rust

macuse

Connect AI with any macOS app. Deep integration with native apps like Calendar, Mail, Notes, plus UI control for all applications. Works with Claude, Cursor, Raycast, and any MCP-compatible AI.

By macuse-app
cursor-rust-tools

A MCP server to allow the LLM in Cursor to access Rust Analyzer, Crate Docs and Cargo Commands.

By terhechte20
mcp-server-hello

A hello-world server for the Model Context Protocol

By TeamDman3