mcp_client_rust

MCP.Pizza Chef: darinkishore

The mcp_client_rust is a Rust-based client implementation of the Model Context Protocol (MCP), designed to facilitate seamless communication between AI models and their runtime environments. It allows developers to spawn subprocess servers locally, managing their input/output streams efficiently. The client enforces protocol specification compliance, ensuring robust error handling when interacting with MCP servers. With typed convenience methods, it simplifies integration and interaction with MCP servers, making it ideal for Rust developers building AI-enhanced workflows and agents.

Use This MCP client To

Spawn local MCP servers as subprocesses for AI model interaction Manage real-time communication between AI models and runtime environments Enforce MCP protocol compliance with error handling Use typed methods for streamlined MCP server interactions Integrate MCP client functionality into Rust-based AI applications

README

Model Context Protocol (MCP) Rust SDK

A Rust implementation of the Client of the Model Context Protocol (MCP), designed for seamless communication between AI models and their runtime environments.

Usage

Spawning the Server

The ClientBuilder allows you to spawn a subprocess server easily, attaching to its stdin and stdout.

Minimal Working Example:

use mcp_rust_sdk::client::ClientBuilder;

#[tokio::main]
async fn main() -> Result<()> {
    let client = ClientBuilder::new("uvx")
        .arg("notes-simple")
        .spawn_and_initialize().await?;
    Ok(())
}

Note this won't work for any remote servers: they're not running locally.

Remote server support is unplanned.

Spec Compliance

The servers used with this client should implement the protocol to specification.

Tool call responses error out if the wrong schema is used or the server returns an error.

Typed Convenience Methods

The Client provides typed methods to interact with the server:

  • list_resources() -> Result<ListResourcesResult, Error>
  • call_tool(name, arguments) -> Result<CallToolResult, Error>
  • read_resource(uri) -> Result<ReadResourceResult, Error>

For example:

let resources = client.list_resources().await?;
println!("Resources: {:?}", resources);

let tool_result = client.call_tool("add-note", serde_json::json!({
    "name": "my_first_note",
    "content": "This is some note content."
})).await?;
println!("Tool result: {:?}", tool_result);

let read_result = client.read_resource("note://internal/my_first_note").await?;
println!("Read resource: {:?}", read_result);

Contributing

Contributions are welcome! Please open an issue or submit a PR if you have improvements, bug fixes, or new features to propose.

  1. Fork the repo
  2. Create a new branch
  3. Add your changes and tests
  4. Submit a Pull Request

Please @ darinkishore in the PR if you do send one over.

Credits

License

This project is licensed under the MIT License. See LICENSE for details.

mcp_client_rust FAQ

How do I spawn a local MCP server using mcp_client_rust?
Use the ClientBuilder to spawn a subprocess server attached to its stdin and stdout, as shown in the minimal working example.
Does mcp_client_rust support remote MCP servers?
No, remote server support is currently unplanned; it only supports local subprocess servers.
How does mcp_client_rust handle protocol compliance?
It enforces the MCP specification and errors out if the server returns invalid schemas or errors during tool calls.
What programming language is mcp_client_rust designed for?
It is a Rust SDK client designed specifically for Rust developers.
Can mcp_client_rust interact with multiple MCP servers simultaneously?
The documentation does not specify multi-server management; it focuses on spawning and managing local subprocess servers.
Are there typed methods available in mcp_client_rust?
Yes, the client provides typed convenience methods to simplify interaction with MCP servers.
Is mcp_client_rust compatible with LLM providers like OpenAI, Claude, or Gemini?
While the client is provider-agnostic, it can be used with any MCP-compliant server, including those interfacing with OpenAI, Claude, and Gemini models.
What are the prerequisites for using mcp_client_rust?
You need a local MCP server implementation to spawn as a subprocess; remote servers are not supported.