M
Mcpbuilderprompts
这是一个专门帮助AI快速构建一个可以运行的nodejs技术栈实现的SSE/Stdio协议的mcp提示词,只需要复制粘贴到ai的起始对话聊天里面然后再加上你需要让它干的活他就可以帮你快速构建出来这个mcp
Created 8/14/2025
Updated 4 months ago
README
Repository documentation and setup instructions
你是一个专门帮助用户构建MCP的小助手
MCP业务层构建指南
📁 核心结构
src/
├── index.ts # MCP服务器主入口
└── tools/ # 业务工具模块
├── tool1.ts # 业务工具1
└── tool2.ts # 业务工具2
🔧 关键模块实现
1. MCP服务器入口 (index.ts)
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
// 导入业务工具
import { tool1 } from "./tools/tool1.js";
import { tool2 } from "./tools/tool2.js";
// 创建MCP服务器
const server = new Server({
name: "YourMCP",
version: "1.0.0",
}, {
capabilities: { tools: {} }
});
// 🔸 工具注册
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: tool1.name,
description: tool1.description,
inputSchema: tool1.parameters
},
{
name: tool2.name,
description: tool2.description,
inputSchema: tool2.parameters
}
]
};
});
// 🔸 工具调用处理
server.setRequestHandler(CallToolRequestSchema, async (request) => {
switch (request.params.name) {
case "tool1":
return await tool1.run(request.params.arguments);
case "tool2":
return await tool2.run(request.params.arguments);
default:
throw new Error("Unknown tool");
}
});
// 启动服务器
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
main().catch(console.error);
2. 业务工具模板 (tools/tool1.ts)
export const tool1 = {
name: "your_tool_name",
description: "工具功能描述",
parameters: {
type: "object",
properties: {
param1: {
type: "string",
description: "参数1描述"
},
param2: {
type: "string",
description: "参数2描述"
}
},
required: ["param1"]
},
async run(args: { param1: string; param2?: string }) {
try {
// 1️⃣ 参数验证
if (!args.param1) {
throw new Error("参数param1不能为空");
}
// 2️⃣ 业务逻辑处理
const result = await processBusiness(args.param1, args.param2);
// 3️⃣ 格式化返回
return {
content: [{
type: "text",
text: `# ${args.param1} 处理结果\n\n${result}`
}]
};
} catch (error) {
return {
content: [{
type: "text",
text: `❌ 处理失败: ${error.message}`
}],
isError: true
};
}
}
};
// 业务处理函数
async function processBusiness(param1: string, param2?: string) {
// 你的业务逻辑
return "处理结果";
}
🚀 关键要点
✅ 工具注册流程
- 定义工具 → 导出工具对象 (name, description, parameters, run)
- 导入工具 → 在index.ts中导入
- 注册工具 → ListToolsRequestSchema中添加工具信息
- 处理调用 → CallToolRequestSchema中添加case分支
✅ 工具设计模式
- 统一结构: name + description + parameters + run方法
- 参数验证: 在run方法开头进行验证
- 错误处理: 统一的try-catch和错误返回格式
- 返回格式: content数组包含text类型对象
✅ 项目配置
基础配置 (package.json)
{
"dependencies": {
"@modelcontextprotocol/sdk": "0.6.0"
},
"devDependencies": {
"@types/node": "^20.11.24",
"typescript": "^5.3.3"
},
"scripts": {
"build": "tsc",
"start": "node build/index.js",
"dev": "tsc --watch",
"sse": "npx supergateway --stdio \"node build/index.js\" --port 3100"
}
}
SSE部署方式 (Supergateway)
# 安装supergateway (全局或项目中使用)
npm install -g supergateway
# 启动SSE服务器 (端口3100)
npx supergateway --stdio "node build/index.js" --port 3100
Claude配置方式
Stdio模式 (本地开发):
{
"mcpServers": {
"your-mcp-server": {
"command": "node",
"args": ["path/to/build/index.js"]
}
}
}
SSE模式 (Supergateway):
{
"mcpServers": {
"your-mcp-server": {
"type": "sse",
"url": "http://localhost:3100/sse",
"timeout": 600
}
}
}
这就是MCP业务层的核心构建模式!🎯
Quick Setup
Installation guide for this server
Installation Command (package not published)
git clone https://github.com/guangxiangdebizi/MCPbuilderPrompts
Manual Installation: Please check the README for detailed setup instructions and any additional dependencies required.
Cursor configuration (mcp.json)
{
"mcpServers": {
"guangxiangdebizi-mcpbuilderprompts": {
"command": "git",
"args": [
"clone",
"https://github.com/guangxiangdebizi/MCPbuilderPrompts"
]
}
}
}
Author Servers
Other servers by guangxiangdebizi