文件编辑协议服务器

Edit-MCP是一个模型上下文协议(MCP)服务器,与Microsoft的Edit工具集成,为AI系统提供高级文件编辑功能。

  • by mixelpixx
  • Rust
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 mixelpixx/edit-mcp

使用说明

Edit MCP:Microsoft Edit的模型上下文协议服务器

Edit MCP是一个模型上下文协议(MCP)服务器,与微软的Edit工具集成,为人工智能系统提供高级文件编辑功能。它遵循一种混合架构,将直接文件系统操作与Microsoft Edit集成相结合,以实现复杂的编辑任务。

概述

Edit MCP服务器充当人工智能系统和文件编辑操作之间的复杂协调器。它公开了一个标准化的MCP接口,允许AI模型:

  • 读取和写入文件
  • 搜索和替换文本
  • 格式代码
  • 执行复杂的编辑操作
  • 协调多文件编辑
  • 还有更多。..

建筑

Edit MCP遵循混合架构,包含以下组件:

1.核心MCP服务器

  • 处理MCP协议通信
  • 将操作路由到适当的子系统
  • 管理文件状态和元数据
  • 多个Edit实例之间的坐标
  • 提供缓存和优化

2.文件系统管理器

  • 对简单任务执行直接文件操作
  • 处理基本的CRUD操作
  • 提供文本搜索和简单的查找/替换
  • 管理文件元数据操作
  • 支持跨多个文件的批处理操作

3.编辑实例管理器

  • 管理Microsoft Edit流程以进行复杂操作
  • 处理复杂的编辑场景
  • 协调多文件操作
  • 以编程方式管理Edit的TUI交互

4.操作路由器

  • 决定哪个子系统处理每个操作
  • 将简单操作路由到文件系统管理器
  • 将复杂操作路由到编辑实例管理器
  • 协调两个子系统之间的混合操作

安装

先决条件

  • Node.js 16或更高版本
  • Microsoft Edit已安装并可在PATH中使用

从源代码安装

# Clone the repository
git clone https://github.com/mixelpixx/edit-mcp.git
cd edit-mcp

# Install dependencies
npm install

# Build the project
npm run build

用法

启动服务器

您可以使用stdio或HTTP传输启动Edit MCP服务器:

# Start with stdio transport (for direct integration with AI systems)
npm run stdio

# Start with HTTP transport (for web-based integration)
npm run http

命令行选项

Usage: edit-mcp [options]

Options:
  -V, --version                output the version number
  -p, --port <port>            Port to listen on for HTTP transport (default: "3000")
  -e, --edit-path <path>       Path to the Edit executable
  -m, --max-instances <number> Maximum number of Edit instances (default: "5")
  -t, --timeout <milliseconds> Timeout for Edit instances in milliseconds (default: "300000")
  -c, --config <path>          Path to configuration file
  -d, --debug                  Enable debug logging
  -s, --stdio                  Use stdio transport instead of HTTP
  -h, --help                   display help for command

配置

您可以使用JSON配置文件配置Edit MCP:

{
  "editExecutable": "/path/to/edit",
  "maxEditInstances": 5,
  "instanceTimeout": 300000,
  "simpleOperationThreshold": 1000,
  "complexityFactors": {
    "fileSize": 0.3,
    "operationType": 0.4,
    "contextRequirement": 0.3
  }
}

可用工具

编辑MCP提供以下工具:

文件系统工具

  • read_file:读取文件内容
  • write_file:将内容写入文件
  • list_files:列出目录中的文件
  • find_in_file:查找文件中出现的模式

编辑工具

  • format_code:文件中的格式代码
  • complex_find_replace:执行高级查找和替换操作
  • interactive_edit_session:启动交互式编辑会话

混合工具

  • smart_refactor:跨多个文件智能重构代码
  • backup_and_edit:在编辑文件之前创建文件备份

HTTP传输

除了stdio之外,Edit-MCP现在还支持HTTP传输,允许远程访问和REST API端点。

从HTTP传输开始

# Start with default HTTP port (3000)
edit-mcp

# Start with custom port
edit-mcp --port 8080

# Start with configuration file
edit-mcp --config config.http.example.json

REST API端点

健康检查

GET /health

JSON-RPC端点

POST /jsonrpc
Content-Type: application/json

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "read_file",
    "arguments": {
      "path": "example.txt"
    }
  },
  "id": 1
}

REST API端点

  • GET /api/tools -列出可用工具
  • POST /api/tools/:toolName -调用特定工具
  • GET /api/files/:path -读取文件内容
  • PUT /api/files/:path -写入文件内容
  • GET /api/list/:directory -列出目录中的文件
  • POST /api/search -在文件中搜索模式
  • POST /api/format -格式代码
  • POST /api/refactor -跨文件重构符号
  • GET /api/docs -API文件

认证

通过设置启用API密钥身份验证 authEnabled: true 在您的配置中:

{
  "authEnabled": true,
  "apiKey": "your-secure-api-key"
}

在请求中包含API密钥:

  • 头球 X-API-Key: your-secure-api-key
  • 查询参数: ?apiKey=your-secure-api-key

CORS配置

在配置文件中配置允许的来源:

{
  "corsOrigins": ["http://localhost:*", "https://yourdomain.com"]
}

速率限制

配置速率限制以防止滥用:

{
  "rateLimitWindowMs": 900000,  // 15 minutes
  "rateLimitMax": 100           // 100 requests per window
}

发展

建设项目

# Build the project
npm run build

# Watch for changes and rebuild
npm run watch

以开发模式运行

# Run with hot reloading
npm run dev

许可证

麻省理工学院

致谢

  • Microsoft的编辑工具
  • 模型上下文协议社区