mcp-rs-template
by: linux-china
Model Context Protocol (MCP) CLI server template for Rust
📌Overview
Purpose: To provide a template for building an MCP CLI server in Rust, facilitating the integration of LLM applications with external data sources and tools.
Overview: The mcp-rs-template serves as a foundational application template demonstrating how to implement a Model Context Protocol (MCP) CLI server using Rust. It simplifies the creation of AI-driven applications by enabling developers to connect LLMs with relevant context seamlessly.
Key Features:
-
MCP Server Implementation: Offers a structured approach to set up an MCP server, enabling robust connections between language models and external resources.
-
Customizable Handlers: Provides flexibility for developers to modify prompt, resource, and tool handlers, adapting to specific application needs.
-
JSON-RPC Routing Integration: Built on the rust-rpc-router library, ensuring efficient JSON-RPC message handling within the server context.
MCP Rust CLI Server Template
Model Context Protocol (MCP) is an open protocol designed to enable seamless integration between LLM applications and external data sources and tools. MCP provides a standardized way to connect LLMs with the context they need, whether you’re building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows.
mcp-rs-template is a simple application template demonstrating how to implement an MCP CLI server in Rust.
How to Use the Template
- Clone the repository.
- Modify project information in
Cargo.toml
andsrc/mcp/mod.rs
. - Modify server handlers:
src/mcp/prompts.rs
: prompts handlerssrc/mcp/resources.rs
: resources handlerssrc/mcp/tools.rs
: tools handlers
- Modify
src/mcp/templates/*.json
if you prefer to use JSON files for prompts, resources, and tools.
The template is based on rust-rpc-router, a JSON-RPC routing library for Rust.
CLI Options
--mcp
: Enable MCP server--resources
: Display resources--prompts
: Display prompts--tools
: Display tools
How to Use MCP CLI Server in Claude Desktop
- Edit
claude_desktop_config.json
: Go to Claude Desktop → Settings → Developer → Edit Config. - Add the following configuration to the
servers
section:
{
"mcpServers": {
"current-time": {
"command": "mcp-rs-template",
"args": [
"--mcp"
],
"env": {
"API_KEY": "xxxx"
}
}
}
}
To check the MCP log, use the command:
tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
References
- MCP Specification: https://spec.modelcontextprotocol.io/
- Model Context Protocol (MCP): https://modelcontextprotocol.io/introduction
- rpc-router: JSON-RPC routing library - https://github.com/jeremychone/rust-rpc-router/
- Zed context_server: https://github.com/zed-industries/zed/tree/main/crates/context_server