computer_mcp
v1.0.8
Published
MCP Streamable HTTP Server with file and command execution tools
Readme
Computer MCP Server
一个基于 Model Context Protocol (MCP) 的 Streamable HTTP 服务器,提供命令执行、文件读写编辑、搜索与补丁能力。
功能特性
- ✅ bash - 运行系统命令并实时返回输出
- ✅ read - 读取文件或目录,支持分页
- ✅ write - 创建或覆盖文本文件
- ✅ edit - 按
oldString/newString修改文本文件 - ✅ grep - 按正则搜索文件内容
- ✅ glob - 按 glob 模式查找文件
- ✅ apply_patch - 应用补丁(支持 wrapped patch 和 unified diff)
- ✅ 实时通知 - 命令执行过程中发送 MCP 通知消息
- ✅ Streamable HTTP - 使用 HTTP 流式传输协议
安装
npm install启动服务器
# 生产模式
npm start
# 开发模式(自动重启)
npm run dev服务器默认运行在端口 3000,可以通过环境变量 PORT 修改:
PORT=8080 npm start端点
- MCP 端点:
POST http://localhost:3000/mcp - 健康检查:
GET http://localhost:3000/health
工具说明
1. bash - 执行命令
执行系统命令并返回结果。执行过程中会发送多条通知消息。
参数:
command(必需): 要执行的命令args(可选): 命令参数数组cwd(可选): 工作目录timeout(可选): 超时时间(毫秒,默认 30000)
示例:
{
"command": "ls",
"args": ["-la"],
"cwd": "/home/user"
}返回:
{
"exitCode": 0,
"stdout": "...",
"stderr": "...",
"success": true
}2. read - 读取文件/目录
读取文本文件或目录内容,支持 offset / limit 分页。
参数:
filePath(必需): 文件或目录路径offset(可选): 起始行号/条目序号(从 1 开始)limit(可选): 最多读取行数/条目数(默认 2000)
示例:
{
"filePath": "/path/to/file.txt",
"offset": 1,
"limit": 200
}3. write - 写入文件
写入内容到文本文件,如果文件已存在会被覆盖(自动创建父目录)。
参数:
filePath(必需): 文件路径content(必需): 要写入的内容
示例:
{
"filePath": "/path/to/file.txt",
"content": "Hello, World!"
}4. edit - 修改文件
修改文本文件的内容,按 oldString/newString 替换。
参数:
filePath(必需): 文件路径oldString(必需): 要替换的原文newString(必需): 替换后的文本replaceAll(可选): 是否替换全部匹配(默认 false)
示例:
{
"filePath": "/path/to/file.txt",
"oldString": "old text",
"newString": "new text",
"replaceAll": true
}5. grep - 内容搜索
按正则搜索文件内容。
参数:
pattern(必需): 正则模式path(可选): 搜索根路径(默认当前目录)include(可选): 文件过滤模式(如*.js)
6. glob - 文件匹配
按 glob 模式列出文件。
参数:
pattern(必需): glob 模式(如**/*.js)path(可选): 搜索目录(默认当前目录)
7. apply_patch - 应用补丁
应用补丁文本。支持两种格式:
- Wrapped patch(
*** Begin Patch...*** End Patch) - Unified diff(
---/+++/@@)
参数:
patchText(必需): 完整补丁文本
通知消息
在执行命令时,服务器会发送多条 MCP 通知消息:
- info: 命令开始执行、执行完成
- debug: 标准输出内容
- warning: 标准错误输出、超时警告
- error: 执行错误
Docker 部署
# 构建镜像
./dockerBuild.sh
# 运行容器
docker run -d -p 3000:3000 computer-mcp-server测试
使用 curl 测试健康检查:
curl http://localhost:3000/health测试 MCP 端点需要发送符合 MCP 协议的 JSON-RPC 请求。
技术栈
- Node.js
- Express.js
- @modelcontextprotocol/sdk
- ES Modules
许可证
ISC
