文件系统MCP服务器

一个提供全面文件系统访问和操作的模型上下文协议(MCP)服务器,允许AI助手通过标准化接口与文件系统交互。

  • by geekgod382
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 geekgod382/filesystem-mcp-server

使用说明

文件系统MCP服务器

一种模型上下文协议(MCP)服务器,提供全面的文件系统访问和操作。该服务器允许AI助手通过标准化的界面与您的文件系统进行交互。

特性

资源(只读访问)

  • 文件://{path} -读取文件内容
  • 目录://{path} -列出包含元数据的目录内容

工具(文件操作)

  • read_file_tool -使用编码支持读取文件内容
  • write_file_tool -创建或覆盖文件
  • list_directory_tool -列出目录内容(递归选项)
  • create_directory_tool -使用父级创建创建目录
  • delete_file_tool -删除文件
  • delete_directory_tool -删除目录(递归选项)
  • move_file工具 -移动或重命名文件/目录
  • copy_file_tool -复制文件或目录
  • 搜索文件工具 -按模式搜索文件(支持通配符)
  • get_file_info_tool -获取详细的文件/目录元数据

提示

  • analyze_directy_prompt -目录分析模板
  • find_and_read_prompt -查找和读取文件的模板

安全

默认情况下,服务器会限制对主目录的访问。您可以修改 ALLOWED_PATHS 列入 server.py 改变这一点。

ALLOWED_PATHS = [str(Path.home())]  # Modify this to add more paths
  • 访问仅限于配置的根目录
  • 无法访问系统路径
  • 用户必须明确授予权限

服务器版本

服务器.py -纯MCP SDK实现(目前处于活动状态)

  • 用途 mcp.server.Server 直接
  • 与Claude Desktop的兼容性更好
  • 低级控制

与Claude Desktop一起使用

要将此服务器与Claude Desktop一起使用,请将其添加到您的Claude配置文件中。

  1. 打开您的Claude Desktop配置文件:

    • 窗户: %APPDATA%\Claude\claude_desktop_config.json
  2. 添加服务器配置:

{
  "mcpServers": {
    "filesystem": {
      "command": "python",
      "args": ["C:\\Users\\<username>\\filesystem-mcp-server\\server.py"]
    }
  }
}
  1. 重新启动克劳德桌面

与MCP检查器一起使用

您可以使用MCP检查器测试和调试服务器:

npx @modelcontextprotocol/inspector python server.py

示例用法

连接到MCP客户端(如Claude Desktop)后,您可以:

列出目录中的文件

Can you list the files in my Documents folder?

读取文件

Read the contents of C:\Users\<username>\test.txt

搜索文件

Find all Python files in my projects directory

创建并写入文件

Create a new file called notes.txt with the content "Hello World"

获取文件信息

Get detailed information about myfile.pdf

项目结构

filesystem-mcp-server/
└── src/
    ├── __init__.py
    ├── config.py      ← ALLOWED_PATHS + is_path_allowed()
    ├── tools.py       ← all 10 tool implementations
    ├── tool_schemas.py ← the Tool(...) schema definitions for list_tools()
    ├── resources.py   ← list_resources() + read_resource()
    └── prompts.py     ← list_prompts() + get_prompt()
├── server.py           # Main MCP server implementation
├── requirements.txt    # Python dependencies
├── test_server        # Test file
└── README.md          # This file

扩展服务器

您可以通过遵循现有模式轻松添加更多工具:

@mcp.tool()
def your_custom_tool(param: str) -> dict:
    """Description of your tool"""
    # Your implementation
    return {"result": "success"}

故障排除

权限错误

如果您遇到权限错误,请检查路径是否在 ALLOWED_PATHS 在 server.py.

服务器无响应

检查服务器是否使用stdio传输运行,以及客户端是否配置正确。

需求

  • Python 3.8或更高版本
  • Windows(通过更改路径分隔符适应Linux/macOS)
  • MCP Python SDK 1.25或更高版本

资源