MCP服务器模板

一个用于快速构建MCP服务器的TypeScript模板,适用于开发自定义集成、文档服务器和自动化工具。

  • by Launchery
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 Launchery/mcp-starter-typescript

使用说明

mcp起始字体

用于在TypeScript中构建MCP服务器的入门模板。克隆、定制、发货。

问题: 从头开始启动MCP服务器需要样板设置——传输、工具注册、TypeScript配置、构建管道。此模板可在5分钟内为您提供一个可用的MCP服务器。

这是给谁的: 开发人员为MCP(模型上下文协议)生态系统构建工具——自定义集成、文档服务器、自动化工具。

快速开始

# 1. Clone
git clone https://github.com/Launchery/mcp-starter-typescript.git my-mcp-server
cd my-mcp-server

# 2. Install
npm install

# 3. Build
npm run build

# 4. Test
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}' | node dist/index.js

包含内容

文件 目的
src/index.ts 服务器入口点(stdio传输)
src/tools/echo.ts 示例:回声工具
src/tools/add.ts 示例:算术工具
src/tools/search.ts 示例:数据搜索工具
.mcp.json 用于测试的本地MCP客户端配置
tsconfig.json 严格的TypeScript配置(ES2022,Node16)

添加您自己的工具

  1. 创建 src/tools/my-tool.ts:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";

export function myTool(server: McpServer): void {
  server.tool(
    "my-tool",
    "Description of what this tool does",
    {
      input: z.string().describe("Input parameter"),
    },
    async ({ input }) => ({
      content: [{ type: "text", text: `Result: ${input}` }],
    })
  );
}
  1. 注册于 src/tools/index.ts:
import { myTool } from "./my-tool.js";
// ...
myTool(server);
  1. 构建和测试:
npm run build
npm start

连接到MCP客户端

克劳德桌面

claude mcp add --scope user my-server -- node "/path/to/dist/index.js"

光标

创建 .cursor/mcp.json:

{
  "mcpServers": {
    "my-server": {
      "command": "node",
      "args": ["/path/to/dist/index.js"]
    }
  }
}

任何MCP客户端

{
  "mcpServers": {
    "my-server": {
      "command": "node",
      "args": ["/path/to/dist/index.js"]
    }
  }
}

发展

# Watch mode
npm run dev

# Lint
npm run lint

# Format
npm run format

路线图

看 ROADMAP.md 对于计划中的功能。

许可证

麻省 理工© 发射