MCP ExplorerExplorer

Async Mcp

@v3g42on 9 months ago
18 Apache-2.0
FreeCommunity
AI Systems
#agents#anthropic#llms#mcp
A minimalistic async Rust implementation of the Model Context Protocol (MCP).

Overview

What is Async Mcp

async-mcp is a minimalistic async Rust implementation of the Model Context Protocol (MCP), designed to extend synchronous capabilities to support asynchronous operations and additional transports.

Use cases

Use cases for async-mcp include building a real-time web server that supports both SSE and WebSockets, implementing tools that require asynchronous requests, and developing applications that need to handle multiple concurrent connections efficiently.

How to use

To use async-mcp, add it as a dependency in your Cargo.toml file. You can implement servers and clients using various transports such as Stdio, WebSockets, and Server-Sent Events (SSE). Example code snippets are provided in the documentation.

Key features

Key features of async-mcp include support for multiple transports (SSE, Stdio, In-Memory Channel, Websockets), asynchronous operation capabilities, and a simple API for building servers and clients.

Where to use

async-mcp can be used in applications that require real-time communication, such as web servers, chat applications, or any system needing efficient asynchronous data handling.

Content

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.2"

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:

Related SDKs

Official

Community

For the complete feature set, please refer to the MCP specification.

Implementation Status

Core Protocol Features

  • [x] Basic Message Types
  • [ ] Error and Signal Handling
  • [x] Transport Layer
    • [x] Stdio
    • [x] In-Memory Channel
    • [x] SSE
    • [x] Websockets

Server Features

  • [x] Tools Support
  • [ ] Prompts
  • [ ] Resources
    • [x] Pagination
    • [x] Completion

Client Features

Compatible with Claude Desktop:

  • [x] Stdio Support
  • [x] In-Memory Channel
  • [x] SSE Support

Monitoring

  • [ ] Logging
  • [ ] Metrics

Utilities

  • [ ] Ping
  • [ ] Cancellation
  • [ ] Progress Tracking

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers