MCP服务器脚手架工具

一个命令行工具,用于快速创建标准化的MCP(模型上下文协议)服务器,支持Node.js开发。

  • by Makoq
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 makoq/create-ts-mcp-server

使用说明

MCP服务器脚手架工具

一个使用Node.js快速创建标准化MCP(模型上下文协议)服务器的命令行工具

快速开始

npx @ad/create-mcp-server te your-mcp-server-name

✨特性

🛠️ 交互式配置-提供用户友好的命令行交互式界面 📦 多级API支持-同时支持高级和低级API开发 ⚡ 快速生成-基于模板引擎的快速项目生成 🔧 智能配置-自动生成package.json和TypeScript配置 🚀 使用指南

创建项目


# by npx

npx @ad/create-mcp-server your-server-name

# or by npm

npm install -g @ad/create-mcp-server

create-mcp-server your-server-name

命令

cd your-server-name

npm install # install dependencies

npm run build # build project

目录结构

生成的典型项目结构如下:

your-server-name/
├── src/
│   ├── index.ts      # Service entry file
├── test/             
├── package.json
└── tsconfig.json

📚 API等级说明

高级API

用例:快速开发标准服务功能:

预配置的通用中间件 自动错误处理 标准化路由配置 开箱即用的RESTful支持

例子:

// Quickly create a service instance
server.tool(
  "calculate-bmi",
  {
    weightKg: z.number(),
    heightM: z.number()
  },
  async ({ weightKg, heightM }) => ({
    content: [{
      type: "text",
      text: String(weightKg / (heightM * heightM))
    }]
  })
);

API低水平

用例:需要深度定制的场景功能:

对请求生命周期的完全控制 中间件链的手动管理 自定义协议处理 低级性能优化

例子:

server.setRequestHandler(CallToolRequestSchema, async (request) => {
  switch (request.params.name) {
    case "create_note": {
      const title = String(request.params.arguments?.title);
      const content = String(request.params.arguments?.content);
      if (!title || !content) {
        throw new Error("Title and content are required");
      }

      const id = String(Object.keys(notes).length + 1);
      notes[id] = { title, content };

      return {
        content: [{
          type: "text",
          text: `Created note ${id}: ${title}`
        }]
      };
    }

    default:
      throw new Error("Unknown tool");
  }
});