The Rust MCP Template provides a foundation for developers to build Model Context Protocol (MCP) servers using Rust. This template simplifies the implementation of MCP servers by providing a structured framework with handlers for prompts, resources, and tools. Built on the rust-rpc-router library, it offers a clean approach to creating JSON-RPC based MCP servers that can seamlessly integrate with LLM applications.
The Rust MCP Template is designed to help developers quickly implement Model Context Protocol (MCP) servers in Rust. MCP is an open protocol that enables seamless integration between LLM applications and external data sources and tools, making it easier to build AI-powered applications with access to the context they need.
To use this template for your own MCP server:
Clone the repository:
git clone https://github.com/linux-china/mcp-rs-template.git
cd mcp-rs-template
Modify the project information in Cargo.toml
and src/mcp/mod.rs
to match your project details.
Customize the server handlers:
src/mcp/prompts.rs
: Implement your prompts handlerssrc/mcp/resources.rs
: Implement your resources handlerssrc/mcp/tools.rs
: Implement your tools handlersIf you prefer using JSON files for configuration, modify the templates in src/mcp/templates/*.json
.
The template includes several CLI options:
--mcp
: Enable the MCP server--resources
: Display available resources--prompts
: Display available prompts--tools
: Display available toolsTo run the server:
cargo run -- --mcp
To use your MCP server with Claude Desktop:
mcpServers
section:{
"mcpServers": {
"your-server-name": {
"command": "mcp-rs-template",
"args": [
"--mcp"
],
"env": {
"API_KEY": "your-api-key-if-needed"
}
}
}
}
You can monitor the MCP logs with:
tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
This template is based on rust-rpc-router, a JSON-RPC routing library for Rust. The structure follows the MCP specification, making it easy to extend with your own functionality.
For more information about MCP, refer to the official specification and the introduction to Model Context Protocol.