M

MCP-文件系统访问服务器

@gabrielmaialva33/mcp-filesystem
0 Stars 425 次浏览 gabrielmaialva33 更新于 2026-08-23

一个安全的模型上下文协议服务器,提供在预定义目录内的受控文件系统访问,使人工智能模型能够执行带有严格路径验证的文件和目录操作。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "filesystem": {
      "args": [
        "/Users/gabrielmaia/Documents",
        "/Users/gabrielmaia/Desktop",
        "/Users/gabrielmaia/Downloads"
      ],
      "command": "mcp-filesystem"
    }
  }
}

该服务需要配置环境变量:PUBMED_API_KEY、PUBMED_EMAIL

服务介绍

:bookmark: 关于

MCP 文件系统服务器 通过 Model Context Protocol 为 AI 模型提供安全的文件系统访问。它执行严格的路径验证,并且只允许访问预定义的目录。

:computer: 技术栈

:wrench: 工具

:package: 安装

:heavy_check_mark: 先决条件

需要安装以下软件:

:arrow_down: 克隆仓库

git clone https://github.com/gabrielmaialva33/mcp-filesystem.git
  $ git clone https://github.com/gabrielmaialva33/mcp-filesystem.git
  $ cd mcp-filesystem

:arrow_forward: 运行应用程序

本地开发

  # Install dependencies
  $ pnpm install

  # Build the application
  $ pnpm build

  # Run the server (specify directory to allow access to)
  $ pnpm start /path/to/allowed/directory

  # Or use configuration file
  $ pnpm start --config=config.json

使用 NPM 包

  # Install globally
  $ npm install -g @gabrielmaialva33/mcp-filesystem

  # Run the server
  $ mcp-filesystem /path/to/allowed/directory

  # Or use with npx (no installation needed)
  $ npx @gabrielmaialva33/mcp-filesystem /path/to/allowed/directory

  # Create a sample configuration file
  $ npx @gabrielmaialva33/mcp-filesystem --create-config=config.json

使用 Docker

  # Build the Docker image
  $ docker build -t gabrielmaialva33/mcp-filesystem .

  # Run using Docker
  $ docker run -i --rm -v /path/to/data:/data:ro gabrielmaialva33/mcp-filesystem /data

  # Use with config file
  $ docker run -i --rm -v /path/to/config.json:/app/config.json -v /path/to/data:/data gabrielmaialva33/mcp-filesystem --config=/app/config.json

使用 Docker Compose

  # Create a data directory
  $ mkdir -p data

  # Start the server
  $ docker-compose up -d

:gear: 使用方法

与 Claude Desktop 一起使用

可以通过配置让 Claude Desktop 使用此 MCP 服务器进行文件系统访问。请在 claude_desktop_config.json 中添加以下内容:

使用本地安装(推荐)

{
  "mcpServers": {
    "filesystem": {
      "command": "mcp-filesystem",
      "args": [
        "/Users/gabrielmaia/Documents",
        "/Users/gabrielmaia/Desktop",
        "/Users/gabrielmaia/Downloads"
      ]
    }
  }
}

确保将可执行文件全局可用:

# Make the binary executable
chmod +x /Users/gabrielmaia/.nvm/versions/node/v22.14.0/bin/mcp-filesystem

使用 NPX

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@gabrielmaialva33/mcp-filesystem",
        "/Users/username/Desktop",
        "/path/to/other/allowed/dir"
      ]
    }
  }
}

使用 Docker

注意:当使用 Docker 时,默认情况下所有目录都必须挂载到 /projects。添加 ro 标志会使目录只读。

{
  "mcpServers": {
    "filesystem": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--mount",
        "type=bind,src=/Users/username/Desktop,dst=/projects/Desktop",
        "--mount",
        "type=bind,src=/path/to/other/allowed/dir,dst=/projects/other/allowed/dir,ro",
        "--mount",
        "type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt",
        "gabrielmaialva33/mcp-filesystem",
        "/projects"
      ]
    }
  }
}

可用工具

MCP 文件系统服务器提供这些工具:

文件系统操作

  • read_file: 读取文件内容
  • read_multiple_files: 一次读取多个文件
  • write_file: 创建或覆盖文件
  • edit_file: 通过差异预览进行精确编辑
  • create_directory: 递归创建目录
  • list_directory: 列出目录内容
  • directory_tree: 获取递归树视图
  • move_file: 移动或重命名文件
  • search_files: 查找匹配模式的文件
  • get_file_info: 获取文件元数据
  • list_allowed_directories: 查看可访问的目录

系统和网络操作

  • get_metrics: 查看服务器性能指标 (v0.3.0+)
  • execute_command: 安全地执行系统命令 (v0.3.1+)
  • curl_request: 执行对外部 API 的 HTTP 请求 (将在 v1.2.0 中提供)

使用 curl_request 工具(将在 v1.2.0 中提供)

curl_request 工具将允许您对外部 API 发起 HTTP 请求:

// Example: Making a GET request with authentication
curl_request({
  url: 'https://api.example.com/data',
  method: 'GET',
  headers: {
    Authorization: 'Bearer your_token_here',
  },
})

// Example: POST request with JSON data
curl_request({
  url: 'https://api.example.com/create',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  data: '{"name":"Example","value":123}',
})

有关更详细的示例,请参阅 docs/curl-tool-examples.md 文件。

:sparkles: 特性

核心特性

  • 安全访问:严格的路径验证防止未经授权的访问
  • 文件操作:读取、写入、编辑和移动文件
  • 目录操作:创建、列出、获取树视图和搜索目录
  • 元数据访问:查看文件和目录信息
  • 命令执行:通过严格验证安全地执行系统命令
  • Docker 支持:使用 Docker 和 Docker Compose 轻松部署

v0.3.0 中的新特性

  • 结构化日志:具有不同级别的详细日志记录(调试、信息、警告、错误)
  • 性能指标:跟踪操作次数、错误和执行时间
  • 配置管理:支持 JSON 配置文件
  • 路径缓存:提高频繁访问路径的性能
  • 改进的错误处理:带有结构化信息的专门错误类型
  • 文件大小验证:防止加载过大的文件
  • CLI 改进:帮助命令、版本信息和配置生成

配置选项

您可以使用以下命令创建配置文件:

$ mcp-filesystem --create-config=config.json

配置示例:

{
  "allowedDirectories": ["/path/to/allowed/dir1", "/path/to/allowed/dir2"],
  "logLevel": "info",
  "logFile": "/path/to/logs/mcp-filesystem.log",
  "serverName": "secure-filesystem-server",
  "serverVersion": "0.3.0",
  "cache": {
    "enabled": true,
    "maxSize": 1000,
    "ttlMs": 60000
  },
  "metrics": {
    "enabled": true,
    "reportIntervalMs": 60000
  },
  "security": {
    "maxFileSize": 10485760,
    "allowSymlinks": true,
    "validateRealPath": true
  }
}

:writing_hand: 作者

Gabriel Maia
Gabriel Maia

许可证

MIT 许可证

相关 MCP 服务