](https://www.npmjs.com/package/create-ts-mcp-server)
MCP服务器脚手架工具
一个使用Node.js快速创建标准化MCP(模型上下文协议)服务器的命令行工具
✨特性
🛠️ 交互式配置
- 为用户提供
- 友好指挥
- 线路交互界面
📦 多级API支持
- 同时支持High
- 水平和低
- API开发水平
⚡ 快速生成
- 基于模板引擎的快速项目生成
🔧 智能配置
- 自动生成package.json和TypeScript配置
快速开始
npx create-ts-mcp-server your-mcp-server-name🚀 使用指南
创建项目
# by npx
npx create-ts-mcp-server your-server-name
CLI初始化步骤
# config your project name
? What is the name of your MCP (Model Context Protocol) server? (your-mcp-server-name)
# config your project description
? What is the description of your server? (A Model Context Protocol server)
# @modelcontextprotocol/sdk API level,High-Level upper layer encapsulation of simple and easy-to-use API (suitable for most simple scenarios, more recommended), Low-Level API for underlying detail processing is suitable for complex scenarios
? What is the API level of your server?
High-Level use (Recommended): It is a commonly used and encapsulated interface for developers. It shields many complex details, is easy to use, and is suitable for most scenarios.
Low-Level use: It is a low-level interface, which is suitable for developers who need to customize the implementation details. (Use arrow keys)
❯ High-Level API
Low-Level API
# success message
✔ MCP server created successfully!
Next steps:
cd your-mcp-server-name
npm install
npm run build # build your server first
npm run inspector # debug your server发展指挥
cd your-server-name
npm install # install dependencies
npm run build # build project
npm run inspector # debug your server
目录结构
生成的典型项目结构如下:
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");
}
});