1 unstable release

Uses new Rust 2024

0.1.0 May 6, 2025

#704 in Network programming

Download history 120/week @ 2025-05-06

120 downloads per month

MIT OR Apache-2.0 OR CC0-1.0

18KB
278 lines

rust_mcp

a minimal rust implementation of the model completion protocol (MCP) server for building ai assistant tools.

overview

rust_mcp is a lightweight library that lets you build custom tools for ai assistants like claude using the model completion protocol. it handles the json-rpc communication layer and provides a simple api for registering tool handlers.

features

  • simple async api for registering tool handlers
  • json schema validation for tool parameters
  • bidirectional communication over stdin/stdout
  • minimal dependencies

usage

add to your project:

cargo add rust_mcp

import and use the library:

use rust_mcp::McpServer;
use serde_json::json;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // create a new mcp server
    let mut server = McpServer::new("my-tool-server", "0.1.0");
    
    // register your tools
    server.add_tool(
        "my_tool",
        "Tool description",
        your_schema,
        your_handler
    );
    
    // start the server
    server.run_stdio().await?
    
    Ok(())
}

see the examples directory for complete working examples.

mcp integration

this library allows your tools to be used directly by ai assistants that support the model completion protocol, providing seamless integration with systems like claude code.

implementation details

the server communicates over stdin/stdout using json-rpc messages defined by the mcp spec. tool handlers are async functions that take json parameters and return json results.

Dependencies

~4–11MB
~109K SLoC