返回市场
mcp-文件系统

mcp-文件系统

作者:QuantGeekDev5 星标更新:2025-03-17

项目介绍

文件系统

这是一个使用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;

发布到npm

  1. 更新你的package.json:

    • 确保name是唯一的,并遵循npm命名规范
    • 设置适当的version
    • 添加descriptionauthorlicense
    • 检查bin指向正确的入口文件
  2. 在本地构建和测试:

    npm run build
    npm link
    filesystem  # 在本地测试你的CLI
    
  3. 登录npm(如有必要创建账户):

    npm login
    
  4. 发布你的包:

    npm publish
    

发布后,用户可以在他们的Claude桌面客户端中添加它(参见下文),或者使用npx运行它。

使用Claude Desktop

本地开发

在你的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”]
    }
  }
}

构建和测试

  1. 对你的工具进行修改
  2. 运行npm run build进行编译
  3. 服务器启动时会自动加载你的工具

更多学习资料