文件系统访问服务器

MCP服务器为Claude桌面提供文件系统和shell访问功能,简化开发环境中的文件操作和命令执行。

  • by kvas-it
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 kvas-it/mcp-server-dev

使用说明

用于软件开发的MCP服务器

一个MCP服务器,提供对Claude桌面的文件系统和shell访问。

建筑

Claude ←→ MCP Server ←→ Unix Socket ←→ Filesystem Daemon
       (2 tools)      (JSON RPC)     (file operations, shell)

关键利益

  • ✅ 单权限提示 (2个工具对比原始的15+)
  • ✅ 环境控制 (守护进程在正确的venv/目录下运行)
  • ✅ 航站楼能见度 (所有操作都记录了上下文)
  • ✅ 动态发现 (操作自动记录)
  • ✅ 丰富的错误处理 (详细错误及建议)
  • ✅ 类型安全性 (带验证的参数模式)

快速开始

  1. 启动文件系统守护进程 (在目标目录中):

    python fs_access.py           # Normal mode
    python fs_access.py --verbose # Verbose mode (shows shell output, file contents, edit details)
    
  2. 连接克劳德 通过配置连接到MCP服务器:

    {
      ...
      "mcpServers": {
        "Dev": {
          "command": "uv",
          "args": [
            "run",
            "--with",
            "fastmcp",
            "$path/mcp-server-dev/mcp_server.py"
          ]
        }
      }
    }
    
  3. 测试集成:

    • 检查Dev是否在Claude Desktop的“搜索和工具”菜单中可见
    • 运行文件系统访问服务器并与Claude交谈,看看它是否可以使用 工具。

Claude可用的MCP工具

1. get_available_operations()

  • 目的:发现可用的文件系统操作及其模式
  • 退货:包含操作模式的Dict,包括类型、描述、默认值

2. execute_fs_operation(operation, params)

  • 目的:通过守护进程执行文件系统操作
  • 参数:
    • operation:操作名称(字符串)
    • params:操作参数(dict)
  • 退货:带有成功状态、结果/错误和日志的骰子

可用操作

文件操作

ls(path=".")

列出指定路径中的文件和目录。

  • 示例: execute_fs_operation("ls", {})
  • 示例: execute_fs_operation("ls", {"path": "/tmp"})

read_file(path)

将文件内容读取为UTF-8字符串。

  • 示例: execute_fs_operation("read_file", {"path": "README.md"})

write_file(path, content)

将内容写入文件(创建或覆盖)。

  • 示例: execute_fs_operation("write_file", {"path": "test.txt", "content": "Hello world!"})

edit_file(path, changes)

对文件应用搜索/替换操作。

  • 示例:
execute_fs_operation("edit_file", {
    "path": "config.py",
    "changes": [
        ["DEBUG = False", "DEBUG = True"],
        ["localhost", "production.com"]
    ]
})

目录管理

mkdir(path)

创建目录和任何必要的父目录。

  • 示例: execute_fs_operation("mkdir", {"path": "project/src/utils"})

rmdir(path)

递归删除目录及其所有内容(小心使用!)。

  • 示例: execute_fs_operation("rmdir", {"path": "temp_project"})

文件和目录管理

rm(path)

删除文件或空目录。

  • 示例: execute_fs_operation("rm", {"path": "unwanted_file.txt"})
  • 示例: execute_fs_operation("rm", {"path": "empty_dir"}) (仅当为空时)

mv(src, dst)

移动或重命名文件和目录。

  • 示例: execute_fs_operation("mv", {"src": "old_name.txt", "dst": "new_name.txt"})
  • 示例: execute_fs_operation("mv", {"src": "temp", "dst": "project/temp"})

shell命令

shell(command, args=[], timeout=30)

执行shell命令并返回stdout、stderr、exit_code。

  • 示例: execute_fs_operation("shell", {"command": "git", "args": ["status"]})
  • 示例: execute_fs_operation("shell", {"command": "python", "args": ["--version"]})
  • 示例: execute_fs_operation("shell", {"command": "find", "args": [".", "-name", "*.py"], "timeout": 60})
  • 退货: {"stdout": "...", "stderr": "...", "exit_code": 0, "command": "...", "working_directory": "..."}

错误处理

  • 连接错误:守护进程未运行→ 提供了有用的提示
  • 无效操作:列出具有签名的可用操作
  • 文件错误:详细的错误类型(FileNotFoundError、PermissionError等)
  • 参数错误:类型验证和需求检查

Claude的使用模式

  1. 发现:呼叫 get_available_operations() 看看有什么可用的
  2. 执行:呼叫 execute_fs_operation(operation_name, params_dict)

核心文件

  • fs_access.py -具有所有操作的文件系统守护进程
  • mcp_server.py -提供Claude接口的MCP服务器
  • socket_protocol.py -Unix套接字通信层
  • shell_examples.py -shell命令示例