MCP Server Template

MCP Server Template

site icon
2025.02.17 0
TypeScriptMCP服务器开发TypeScript模板开发效率
这是一个用于创建Model Context Protocol (MCP)服务器的TypeScript模板。该模板提供了构建MCP兼容服务器的基础设施,包括工具链、类型安全和最佳实践。
View on GitHub

Overview

基本能力

产品定位

该模板旨在为开发者提供一个快速构建MCP兼容服务器的起点,特别适合需要遵循MCP协议的项目开发。

核心功能

  • 🚀 完整的TypeScript支持
  • 🏗️ 基于容器的依赖注入
  • 📦 服务导向架构,包含DataProcessor接口
  • 🛠️ 示例工具实现及测试
  • 🧪 Vitest测试框架
  • 📝 类型定义
  • 🔌 MCP SDK集成

适用场景

  • 需要快速启动MCP服务器开发的项目
  • 需要类型安全和现代JavaScript工具链的项目
  • 需要遵循MCP协议的工具开发

工具列表

  1. TestClient:提供简单的工具测试方法
  2. MCP Inspector:提供可视化调试界面
  3. 工具测试的视觉界面
  4. 实时请求/响应监控
  5. 工具元数据检查
  6. 交互式测试环境

常见问题解答

  1. 如何测试本地MCP服务器?
  2. 使用TestClient进行单元测试
  3. 使用MCP Inspector进行可视化调试

  4. 如何将服务器添加到Cursor?

  5. 构建并链接包
  6. 在Cursor设置中添加服务器
  7. 选择"Command"类型并输入命令

使用教程

使用依赖

npm install

安装教程

  1. 启动开发服务器(带热重载): bash npm run dev
  2. 构建项目: bash npm run build
  3. 运行测试: bash npm test
  4. 启动生产服务器: bash npm start

调试方式

  1. 使用MCP Inspector进行可视化调试: bash npx @modelcontextprotocol/inspector node dist/index.js 然后访问 http://localhost:5173

  2. 使用TestClient进行测试: ```typescript import { TestClient } from "./utils/TestClient";

describe("YourTool", () => { const client = new TestClient();

 it("should process data correctly", async () => {
   await client.assertToolCall(
     "your-tool-name",
     { input: "test" },
     (result) => {
       expect(result.toolResult.content).toBeDefined();
     }
   );
 });

}); ```

许可证

None