MCP服务器模板

一个用于构建自定义模型上下文协议(MCP)服务器的启动模板,提供基本结构和设置,适用于Cursor或Claude Desktop。

  • by hypermodel-labs
  • TypeScript
  • 本地部署
  • 14 星标
  • 更新于
在 GitHub 查看 jatinsandilya/mcp-server-template

使用说明

MCP服务器模板🛠️

用于构建自己的模型上下文协议(MCP)服务器的入门模板。此模板提供了创建可用于Cursor或Claude Desktop的自定义MCP所需的基本结构和设置。

特性

项目结构

mcp-server-template/
├── index.ts        # Main server implementation
├── package.json    # Project dependencies
├── tsconfig.json   # TypeScript configuration
└── build/         # Compiled JavaScript output

入门指南

  1. 克隆此模板:
git clone [your-repo-url] my-mcp-server
cd my-mcp-server
  1. 安装依赖项:
pnpm install
  1. 构建项目:
pnpm run build

这将生成 /build/index.js file-您编译的MCP服务器脚本。

与光标一起使用

  1. 转到光标设置->MCP->添加新的MCP服务器
  2. 配置您的MCP:
    • 姓名:[选择自己的姓名]
    • 类型:命令
    • 命令: node ABSOLUTE_PATH_TO_MCP_SERVER/build/index.js

与Claude Desktop一起使用

将以下MCP配置添加到您的Claude Desktop配置中:

{
  "mcpServers": {
    "your-mcp-name": {
      "command": "node",
      "args": ["ABSOLUTE_PATH_TO_MCP_SERVER/build/index.js"]
    }
  }
}

发展

该模板包含一个示例工具实现 index.ts.要创建自己的MCP:

  1. 在中修改服务器配置 index.ts:
const server = new McpServer({
  name: "your-mcp-name",
  version: "0.0.1",
});
  1. 使用定义自定义工具 server.tool() 方法:
server.tool(
  "your-tool-name",
  "Your tool description",
  {
    // Define your tool's parameters using Zod schema
    parameter: z.string().describe("Parameter description"),
  },
  async ({ parameter }) => {
    // Implement your tool's logic here
    return {
      content: [
        {
          type: "text",
          text: "Your tool's response",
        },
      ],
    };
  }
);
  1. 构建并测试您的实现:
npm run build

贡献

请随时提交问题和增强请求!

许可证

麻省理工学院