MCP Filesystem Server

by gabrielmaialva33
Verified
MIT License
67
6
  • Linux
  • Apple

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Provides containerized deployment of the MCP server, with support for mounting host directories as read-only or read-write volumes, allowing secure file operations from within Docker containers.

:书签:关于

MCP 文件系统服务器通过模型上下文协议 (MCP Protocol) 为 AI 模型提供安全的文件系统访问。它强制执行严格的路径验证,并且仅允许访问预定义的目录。

:计算机:技术

扳手工具

:package: 安装

:heavy_check_mark:先决条件

必须安装以下软件:

:arrow_down:克隆存储库

$ 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 :使用 diff 预览进行精确编辑
  • 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:作者

加布里埃尔·玛雅

执照

MIT 许可证

-
security - not tested
A
license - permissive license
-
quality - not tested

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

  1. :computer: Technologies
    1. :wrench: Tools
      1. :package: Installation
        1. :heavy_check_mark: Prerequisites
        2. :arrow_down: Cloning the repository
        3. :arrow_forward: Running the application
      2. :gear: Usage
        1. Using with Claude Desktop
        2. Available Tools
      3. :sparkles: Features
        1. Core Features
        2. New Features in v0.3.0
        3. Configuration Options
        4. :writing_hand: Author
      4. License
        ID: f72blrvat4