mcp-client-rs

MCP.Pizza Chef: tim-schultz

mcp-client-rs is a Rust-based asynchronous client implementation of the Model Context Protocol (MCP), designed to facilitate structured communication between language models and external tools. It supports async/await with Tokio, capability negotiation, tool execution, resource management, and prompt handling. This client enables Rust projects to integrate MCP seamlessly, allowing them to interact with MCP servers and leverage real-time context and tool invocation in LLM workflows. It is ideal for developers building AI-enhanced applications requiring robust, protocol-compliant model interactions.

Use This MCP client To

Integrate MCP protocol in Rust-based AI applications Enable async tool execution in LLM workflows Manage resources and capabilities in model interactions Handle prompts and responses with structured context Build custom clients for MCP-compatible servers

README

MCP Protocol Client - Very Much a WIP

Rust client implementation for the Model Context Protocol - a structured communication protocol between language models and external tools.

Features

  • Client implementation to be used in rust projects that want to use the MCP protocol
  • Async/await support with tokio
  • Capability negotiation
  • Tool execution
  • Resource management
  • Prompt handling

Usage

use mcp_client_rs::{Protocol, ClientError};

#[tokio::main]
async fn main() -> Result<(), ClientError> {
    let client = Protocol::new(
        "0",  // Protocol version
        "npx", // Command
        vec!["-y", "@modelcontextprotocol/server-github"], // Args
        std::collections::HashMap::new(), // Environment variables
    ).await?;

    // Call tools
    let response = client
        .call_tool(
            "search_repositories",
            serde_json::json!({
                "query": "rust language:rust"
            }),
        )
        .await?;

    println!("{:?}", response);
    Ok(())
}

Installation

Add to your Cargo.toml:

[dependencies]
mcp-client-rs = { git = "https://github.com/tim-schultz/mcp-client-rs.git" }

License

MIT

mcp-client-rs FAQ

How do I install mcp-client-rs in my Rust project?
Add mcp-client-rs as a dependency in your Cargo.toml and use async/await with Tokio runtime.
Does mcp-client-rs support asynchronous operations?
Yes, it fully supports async/await using the Tokio runtime for efficient concurrency.
Can mcp-client-rs negotiate capabilities with MCP servers?
Yes, it includes capability negotiation to ensure compatible interactions with MCP servers.
How does mcp-client-rs handle tool execution?
It provides methods to call and execute tools exposed by MCP servers with structured JSON parameters.
Is mcp-client-rs limited to Anthropic models?
No, while developed with Anthropic's MCP in mind, it is protocol-compliant and can work with any MCP-compatible server, including those for OpenAI, Claude, and Gemini.
What kind of resource management does mcp-client-rs offer?
It manages resources such as tool handles and session state to maintain efficient and consistent model interactions.
Can I use mcp-client-rs for prompt handling?
Yes, it supports prompt management to structure and send prompts within the MCP framework.
Is mcp-client-rs production-ready?
It is currently a work in progress (WIP), so it may lack some features or stability for production use.