
MCP Server Template

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协议的工具开发
工具列表
- TestClient:提供简单的工具测试方法
- MCP Inspector:提供可视化调试界面
- 工具测试的视觉界面
- 实时请求/响应监控
- 工具元数据检查
- 交互式测试环境
常见问题解答
- 如何测试本地MCP服务器?
- 使用TestClient进行单元测试
-
使用MCP Inspector进行可视化调试
-
如何将服务器添加到Cursor?
- 构建并链接包
- 在Cursor设置中添加服务器
- 选择"Command"类型并输入命令
使用教程
使用依赖
npm install
安装教程
- 启动开发服务器(带热重载):
bash npm run dev
- 构建项目:
bash npm run build
- 运行测试:
bash npm test
- 启动生产服务器:
bash npm start
调试方式
-
使用MCP Inspector进行可视化调试:
bash npx @modelcontextprotocol/inspector node dist/index.js
然后访问 http://localhost:5173 -
使用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