MCP HubMCP Hub
linux-china

mcp-rs-template

by: linux-china

Model Context Protocol (MCP) CLI server template for Rust

68created 30/11/2024
Visit
Rust
CLI

📌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

  1. Clone the repository.
  2. Modify project information in Cargo.toml and src/mcp/mod.rs.
  3. Modify server handlers:
    • src/mcp/prompts.rs: prompts handlers
    • src/mcp/resources.rs: resources handlers
    • src/mcp/tools.rs: tools handlers
  4. 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

  1. Edit claude_desktop_config.json: Go to Claude Desktop → Settings → Developer → Edit Config.
  2. 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