一个具有自我意识的MCP Server,支持文件操作、代码补丁、命令执行和LSP语义分析等功能。
- 文件操作工具:读取、写入、列出、搜索文件
- 代码补丁工具:应用和验证代码修改
- 命令执行工具:运行命令和沙箱执行
- LSP语义工具:符号提取、引用查找、签名获取、调用者查找
- 规划器(Planner):将复杂任务分解为可执行的步骤
- 补丁器(Patcher):应用精确的代码修改
- 验证器(Verifier):验证修改的正确性和完整性
- 工作空间管理:根目录和忽略规则
- 文件集管理:文件白名单和扩展名过滤
- 依赖管理:解析Go、Node.js、Cargo、Python项目依赖
- 文件修改限制:访问控制和文件大小限制
- Diff限制:行数、添加、删除限制
- 规则限制:安全规则检查(硬编码密钥、调试语句等)
# 克隆仓库
git clone <repository-url>
cd mcp-server
# 构建服务器
go build -o mcp-server ./cmd/server
# 运行服务器
./mcp-server# 使用自定义配置
./mcp-server --config config.json服务器使用以下默认配置:
{
"server": {
"host": "localhost",
"port": 8080,
"protocol": "http",
"enableStdio": true,
"enableHTTP": true
},
"agent": {
"maxRetries": 3,
"timeoutSeconds": 300,
"enableSelfCheck": true
},
"guard": {
"maxFileSize": 10485760,
"maxPatchLines": 1000,
"maxAdditions": 500,
"maxDeletions": 500,
"allowedPaths": [],
"forbiddenPaths": [
"/etc",
"/usr",
"/bin",
"/sbin"
]
},
"tools": {
"file": {
"enabled": true
},
"patch": {
"enabled": true,
"maxPatchSize": 1000
},
"exec": {
"enabled": true,
"maxTimeout": 60,
"enableSandbox": true
},
"lsp": {
"enabled": true
}
},
"prompts": {
"plannerPath": "prompts/planner.md",
"patcherPath": "prompts/patch.md",
"verifierPath": "prompts/verify.md"
}
}创建 config.json 文件并修改配置项:
{
"server": {
"host": "0.0.0.0",
"port": 9000
},
"guard": {
"allowedPaths": [
"/path/to/project",
"/another/path"
]
}
}./mcp-server服务器将在 http://localhost:8080 启动。
可用的HTTP端点:
POST /initialize- 初始化MCP连接POST /tools/list- 列出所有可用工具POST /tools/call- 调用工具
./mcp-server --stdio服务器将通过标准输入/输出进行通信。
file_read- 读取文件内容file_write- 写入文件file_list- 列出目录文件file_search- 搜索文件内容
patch_apply- 应用代码补丁
exec_run- 执行命令
lsp_symbols- 获取文件符号lsp_references- 查找引用lsp_signature- 获取函数签名lsp_callers- 查找调用者
agent_process- 处理任务agent_diagnose- 诊断Agent状态
Agent具有自我检测能力,可以:
- 诊断状态:检查Agent是否处于错误状态
- 识别问题:识别初始化问题、配置问题等
- 请求升级:当发现能力不足时,请求必要的权限或功能升级
运行诊断:
# 通过HTTP
curl -X POST http://localhost:8080/tools/call \
-H "Content-Type: application/json" \
-d '{"name": "agent_diagnose", "arguments": {}}'运行测试套件:
# 运行所有测试
go test ./...
# 运行测试脚本
./scripts/run-tests.sh
# 格式化代码
./scripts/gofmt.sh- 默认禁止访问系统目录(/etc, /usr, /bin, /sbin)
- 支持配置允许的路径
- 文件大小限制
- 最大补丁行数限制
- 最大添加/删除行数限制
- 禁止包含敏感信息的补丁
- 命令黑名单(rm -rf /等)
- 沙箱执行模式
- 超时控制
- 硬编码密钥检测
- 调试语句检测
- TODO注释检测
mcp-server/
├── cmd/server/ # 服务器入口
├── internal/
│ ├── protocol/ # MCP协议层
│ ├── tools/ # 工具实现
│ ├── agent/ # Agent状态机
│ ├── project/ # 工程上下文
│ ├── guard/ # 约束与安全
│ └── config/ # 配置管理
├── prompts/ # Prompt文件
└── scripts/ # 测试脚本
- 在
internal/tools/下创建新包 - 实现工具函数
- 在
cmd/server/main.go中注册工具 - 添加测试
欢迎贡献!请:
- Fork项目
- 创建特性分支
- 提交更改
- 推送到分支
- 创建Pull Request
MIT License
如有问题或建议,请提交Issue。