MCP 服务器模板
一个用于构建模型上下文协议服务器的启动模板,可以与Cursor或Claude Desktop集成,允许开发人员为人工智能助手创建自定义工具和扩展。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"your-mcp-name": {
"args": [
"ABSOLUTE_PATH_TO_MCP_SERVER/build/index.js"
],
"command": "node"
}
}
}
可用工具 (1 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
sample-tool 1 个参数 需填 1 项
A sample tool for demonstration purposes
必填参数:input
服务介绍
MCP 服务器模板 🛠️
一个用于构建你自己的模型上下文协议 (MCP) 服务器的起始模板。此模板提供了创建自定义 MCP 所需的基本结构和设置,这些 MCP 可以与 Cursor 或 Claude Desktop 一起使用。
特性
- 使用 TypeScript 的基本 MCP 服务器设置
- 示例工具实现
- 即用型项目结构
- 使用 @modelcontextprotocol/sdk 构建
项目结构
mcp-server-template/
├── index.ts # Main server implementation
├── package.json # Project dependencies
├── tsconfig.json # TypeScript configuration
└── build/ # Compiled JavaScript output
开始使用
- 克隆此模板:
git clone [your-repo-url] my-mcp-server
cd my-mcp-server
- 安装依赖项:
pnpm install
- 构建项目:
pnpm run build
这将生成 /build/index.js 文件 - 你的编译后的 MCP 服务器脚本。
与 Cursor 一起使用
- 前往 Cursor 设置 -> MCP -> 添加新的 MCP 服务器
- 配置你的 MCP:
- 名称:[选择你自己的名称]
- 类型:command
- 命令:
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:
- 修改
index.ts中的服务器配置:
const server = new McpServer({
name: "your-mcp-name",
version: "0.0.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",
},
],
};
}
);
- 构建并测试你的实现:
npm run build
贡献
欢迎提交问题和增强请求!
许可证
MIT