文件管理工具

一个基于Model Context Protocol (MCP)的文件管理工具,允许AI模型通过安全且标准化的方式与外部工具交互,适用于文件操作、数据管理和安全测试等场景。

  • by ggaillard
  • 本地部署
  • 更新于
在 GitHub 查看 ggaillard/mcp-server-client-demo

使用说明

🔌 MCP文件管理器演示

Anthropic开发的模型上下文协议(MCP)的教学演示

一个简单而全面的原型,说明了Claude(或任何其他人工智能模型)如何通过MCP协议与外部工具安全交互。

🎯 MCP怎么样?

乐 模型上下文协议(MCP) 是由Anthropic开发的开放标准,允许人工智能模型以安全和标准化的方式与外部数据源和工具交互。

🧠 简单的类比

想象一下克劳德是一个非常有才华的厨师,但被锁在办公室里。MCP允许他与助手通信,他们可以:

  • 🥕 获取配料(读取数据)
  • 🔪 使用厨房工具(执行操作)
  • 📊 向他报告厨房的状况(获取信息)

🏗️ 项目建筑

graph LR
    A[Client MCP<br/>Claude] -->|JSON-RPC| B[Serveur MCP<br/>File Manager]
    B -->|Operations| C[Sandbox<br/>Filesystem]
    
    subgraph "Communication"
        D[stdin/stdout]
        E[WebSocket]
    end
    
    subgraph "Sécurité"
        F[Validation chemins]
        G[Limite taille]
        H[Isolation sandbox]
    end

✨ 功能

🔧 MCP工具(Tools)

  • list_files -列出文件和文件夹
  • read_file -读取文件的内容
  • write_file -将内容写入文件
  • create_directory -创建新目录

📦 资源MCP(资源)

  • file_metadata -沙盒中所有文件的元数据

🔒 安全

  • 沙盒文件系统 -仅限于文件的操作 ./mcp_sandbox
  • 化学品验证 -防止 ../../../etc/passwd
  • 尺寸限制 -最大1MB文件
  • 完全隔离 -无法访问主机系统

🚀 安装和使用

先决条件

  • Python 3.7+
  • 没有外部依赖

安装速度快

# Cloner le repository
git clone https://github.com/votre-username/mcp-file-manager-demo.git
cd mcp-file-manager-demo

# Lancer la démonstration
python3 mcp_client.py

启动选项

1、🎬 自动演示

python3 mcp_client.py

运行完整的场景:创建文件、读取、安全测试。

2、🎮 互动模式

python3 mcp_client.py --interactive

允许手动测试MCP命令:

> tool:list_files path=.
> tool:write_file path=hello.txt content="Bonjour MCP!"
> tool:read_file path=hello.txt
> resource:file_metadata
> quit

3、🧪 自动测试

python3 mcp_test.py

全套测试:功能、安全和性能。

4。🖥️ 带菜单的启动器

# Linux/Mac
chmod +x start_demo.sh && ./start_demo.sh

# Windows
start_demo.bat

5.🌐 界面网页

打开 demo.html 在浏览器中进行交互式演示。

📡 MCP通信示例

初始化(握手)

// Client → Serveur
{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "initialize",
  "params": {
    "protocolVersion": "1.0",
    "clientInfo": {"name": "Claude"}
  }
}

// Serveur → Client
{
  "jsonrpc": "2.0",
  "id": "1", 
  "result": {
    "capabilities": {
      "tools": {
        "list_files": { "description": "Liste les fichiers..." },
        "read_file": { "description": "Lit un fichier..." }
      }
    }
  }
}

工具调用

// Client → Serveur
{
  "jsonrpc": "2.0",
  "id": "2",
  "method": "tools/call",
  "params": {
    "name": "write_file",
    "arguments": {
      "path": "hello.txt",
      "content": "Bonjour MCP!"
    }
  }
}

// Serveur → Client
{
  "jsonrpc": "2.0",
  "id": "2",
  "result": {
    "success": true,
    "message": "Fichier écrit : hello.txt"
  }
}

📂 项目结构

mcp-file-manager-demo/
├── 📄 README.md                 # Ce fichier
├── 📄 LICENSE                   # Licence CC BY-NC-SA 4.0
├── 📄 CONTRIBUTING.md           # Guide de contribution
├── 📄 CHANGELOG.md              # Historique des versions
├── 📄 .gitignore                # Fichiers à ignorer
├── 📁 src/
│   ├── 🐍 file_server.py        # Serveur MCP
│   ├── 🐍 mcp_client.py         # Client de test
│   └── 🐍 mcp_test.py           # Suite de tests
├── 📁 docs/
│   ├── 🌐 demo.html             # Interface web
│   ├── 📄 mcp_config.json       # Configuration
│   └── 📁 images/               # Screenshots
├── 📁 scripts/
│   ├── 📜 start_demo.sh         # Launcher Linux/Mac
│   └── 📜 start_demo.bat        # Launcher Windows
├── 📁 examples/
│   └── 📄 example_scenarios.md  # Exemples d'usage
└── 📁 mcp_sandbox/              # Dossier sécurisé (auto-créé)

🎓 教育价值

本项目说明了MCP的关键概念:

🔗 Les 3基元MCP

  1. 工具 -人工智能可以执行的操作
  2. 资源 -人工智能可以查看的数据
  3. 提示 -预定义模板

🛡️ 安全模型

  • 隔离 -沙盒文件系统
  • 验证 -入口控制
  • 权限 -颗粒访问
  • 审计 -操作日志

📡 建筑客户服务

  • 沟通 -JSON-RPC 2.0
  • 运输 -stdin/stdout或WebSocket
  • 发现 -能力谈判
  • 错误管理 -标准化错误代码

🌟 扩展用例

该原型可扩展以演示:

  • 🌐 外部API -天气、金融、新闻
  • 🗄️ 数据库 -SQL、NoSQL、研究
  • 🏠 物联网 -连接设备的控制
  • 📊 分析 -数据处理和可视化
  • 🔍 搜索 -商业搜索引擎
  • 🤖 自动化 -脚本和工作流

🧪 测试和质量

自动测试

python3 mcp_test.py

该项目包括:

  • ✅ 功能测试(CRUD文件)
  • ✅ 安全测试(沙盒、验证)
  • ✅ 性能测试(延迟、吞吐量)
  • ✅ 错误测试(故障案例管理)
  • ✅ 通信测试(JSON-RPC)

质量指标

  • 代码库 : 95%+
  • 安全测试 :沙盒的完全验证
  • 性能测试 :延迟<100ms
  • 兼容性 Linux/Mac/Windows上的Python 3.7+

🤝 贡献

欢迎捐款!查看 贡献.md 倾倒:

  • 🐛 报告bug
  • 💡 提供新功能
  • 📝 改进文档
  • 🔧 优化代码

地方发展

# Fork et clone
git clone https://github.com/votre-username/mcp-file-manager-demo.git
cd mcp-file-manager-demo

# Créer une branche
git checkout -b feature/nouvelle-fonctionnalite

# Développer et tester
python3 mcp_test.py

# Commit et push
git commit -m "feat: nouvelle fonctionnalité"
git push origin feature/nouvelle-fonctionnalite

📊 路线图

版本1.1

  • []支持WebSocket传输
  • []改进的web界面
  • []加上d’outils(复制、移动、删除)
  • []高级权限系统

版本1.2

  • []支持去插件
  • []API REST倾倒测试
  • []仪表板去监控
  • []交互式文档

📄 许可证

本项目根据CC BY-NC-SA 4.0许可。看 许可证 更多详情。