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 ClientBuilder;
async
Note this won't work for any remote servers: they're not running locally.
Remote server support is unplanned.
Spec Compliance
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>
This spares you the hassle of manually constructing JSON requests and parsing raw JSON responses.
For example:
let resources = client.list_resources.await?;
println!;
let tool_result = client.call_tool.await?;
println!;
let read_result = client.read_resource.await?;
println!;
Contributing
Contributions are welcome! Please open an issue or submit a PR if you have improvements, bug fixes, or new features to propose.
- Fork the repo
- Create a new branch
- Add your changes and tests
- Submit a Pull Request
Credits
License
This project is licensed under the MIT License. See LICENSE for details.