这是一个使用mcp-framework构建的Model Context Protocol (MCP)服务器。
# 安装依赖
npm install
# 构建项目
npm run build
filesystem/
├── 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 `处理:${input.message}`;
}
}
export default MyTool;
更新你的package.json:
name是唯一的,并遵循npm命名规范versiondescription、author、license等bin指向正确的入口文件在本地构建和测试:
npm run build
npm link
filesystem # 在本地测试你的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": {
"filesystem": {
"command": "node",
"args":["/绝对路径/to/filesystem/dist/index.js"]
}
}
}
在你的Claude Desktop配置文件中添加以下配置:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
“mcpServers”: {
“filesystem”: {
“command”: “npx”,
“args”: [“filesystem”]
}
}
}
npm run build进行编译