MCP Rust CLI server template

MCP Rust CLI server template

适用于Rust的模型上下文协议(MCP)CLI 服务器模板

简介

mcp-rs-template 是一个 Rust 实现的模型上下文协议(MCP)服务器模板,用于连接 LLM 与外部数据源和工具。

快速开始

  1. 克隆仓库

    git clone https://github.com/your-repo/mcp-rs-template.git
    cd mcp-rs-template
    
  2. 配置项目

    • 修改 Cargo.toml 中的项目信息
    • 更新 src/mcp/mod.rs 中的配置
  3. 自定义处理器

    • src/mcp/prompts.rs - 提示处理器
    • src/mcp/resources.rs - 资源处理器
    • src/mcp/tools.rs - 工具处理器
  4. 运行服务器

    cargo run -- --mcp
    

CLI 选项

mcp-rs-template --mcp        # 启动 MCP 服务器
mcp-rs-template --resources  # 显示可用资源
mcp-rs-template --prompts    # 显示可用提示
mcp-rs-template --tools      # 显示可用工具

与 Claude Desktop 集成

  1. 打开 Claude Desktop → 设置 → 开发者 → 编辑配置
  2. mcpServers 部分添加:
{
   "mcpServers": {
      "current-time": {
         "command": "mcp-rs-template",
         "args": ["--mcp"],
         "env": {
            "API_KEY": "xxxx"
         }
      }
   }
}
  1. 查看日志: tail -n 20 -f ~/Library/Logs/Claude/mcp*.log

参考资料