使用mcp-framework构建的Model Context Protocol (MCP)服务器。
# 安装依赖
npm install
# 构建项目
npm run build
mcp-framework-starter/
├── src/
│ ├── tools/ # MCP工具
│ │ └── ExampleTool.ts
│ └── index.ts # 服务器入口点
├── package.json
└── tsconfig.json
项目中包含一个示例工具在src/tools/ExampleTool.ts。你可以使用CLI添加更多工具:
# 添加新工具
mcp add tool my-tool
# 你可以创建的一些示例工具:
mcp add tool data-processor
mcp add tool api-client
mcp add tool file-handler
示例工具结构:
import { MCPTool } from "mcp-framework";
import { z } from "zod";
interface MyToolInput {
message: string;
}
class MyTool extends MCPTool<MyToolInput> {
name = "my_tool";
description = "描述你的工具做什么";
schema = {
message: {
type: z.string(),
description: "此输入参数的描述",
},
};
async execute(input: MyToolInput) {
// 你的工具逻辑在这里
return `Processed: ${input.message}`;
}
}
export default MyTool;
更新你的package.json:
name是唯一的,并遵循npm命名约定versiondescription、author、license等bin指向正确的入口文件在本地构建和测试:
npm run build
npm link
mcp-framework-starter # 在本地测试你的CLI
登录npm(如有必要,请先创建账户):
npm login
发布你的包:
npm publish
发布后,用户可以在他们的Claude桌面客户端中添加它(参见下文),或者使用npx运行它。
在你的Claude Desktop配置文件中添加以下配置:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"mcp-framework-starter": {
"command": "node",
"args":["/绝对路径/到/mcp-framework-starter/dist/index.js"]
}
}
}
在你的Claude Desktop配置文件中添加以下配置:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"mcp-framework-starter": {
"command": "npx",
"args": ["mcp-framework-starter"]
}
}
}
npm run build进行编译