MCP CodeSavant 代码大师
提供代码操作、执行和版本控制功能。它允许AI助手读取、编写和执行代码,同时维护更改历史记录。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"codesavant": {
"args": [
"path/to/codesavant.py"
],
"command": "python"
}
}
}
服务介绍
MCP-CodeSavant
CodeSavant 是一个正在进行中的项目。
CodeSavant 是一个模型上下文协议(MCP)服务器,提供代码操作、执行和版本控制功能。它允许 AI 助手读取、写入和执行代码,同时维护更改历史记录。
功能
- 通过特定行操作读取和写入代码文件
- 在多种编程语言中执行代码(Python、Node.js)
- 在受控环境中执行 shell 命令
- 使用版本控制跟踪和管理代码更改
- 在代码文件中搜索
- 恢复到代码的先前版本
安装
- 克隆仓库:
git clone https://github.com/twolven/mcp-codesavant.git
cd mcp-codesavant
- 安装所需的依赖项:
pip install -r requirements.txt
- 将服务器配置添加到您的 Claude Desktop config.json 中:
{
"mcpServers": {
"codesavant": {
"command": "python",
"args": ["path/to/codesavant.py"]
}
}
}
目录结构
服务器创建并管理以下目录结构:
workspaces/
├── project1/
│ ├── .code_history.json
│ └── [code files]
├── project2/
│ ├── .code_history.json
│ └── [code files]
└── ...
工具参考
详细用法
1. read_code_file
读取代码文件的内容,可选地搜索特定部分。
{
"project": "string", // Project name
"path": "string", // Path to file relative to project workspace
"search": "string" // (Optional) Text/pattern to search for in file
}
响应:
{
"success": true,
"timestamp": 1234567890,
"data": {
"content": "string", // File content
"start_line": number, // (Only if search used) Starting line of found section
"end_line": number // (Only if search used) Ending line of found section
}
}
2. write_code_file
在代码文件中写入或更新特定行。
{
"project": "string", // Project name
"path": "string", // Path to file relative to workspace
"content": "string", // Content to write (just the lines being changed)
"start_line": number, // Starting line number for the change
"end_line": number // (Optional) Ending line number for the change
}
响应:
{
"success": true,
"timestamp": 1234567890,
"data": {
"diff": {
"changes": [ // List of changes made
[string, number, number, number, number] // (type, old_start, old_end, new_start, new_end)
],
"timestamp": number // When the change was made
}
}
}
3. get_code_history
获取代码文件的更改历史记录。
{
"path": "string" // Path to file relative to workspace
}
响应:
{
"success": true,
"timestamp": 1234567890,
"data": {
"history": [
{
"changes": [ // List of changes made
[string, number, number, number, number]
],
"timestamp": number
}
]
}
}
4. execute_code_command
执行与代码相关的 shell 命令。
{
"command": "string", // Shell command to execute
"timeout": number // (Optional) Command timeout in seconds (default: 30)
}
响应:
{
"success": true,
"timestamp": 1234567890,
"data": {
"state": "success|error|timeout|cancelled",
"output": "string", // Command output
"error": "string", // Error message if any
"runtime": number, // Execution time in seconds
"exit_code": number // Command exit code
}
}
5. execute_code
以指定语言执行代码。
{
"code": "string", // Code to execute
"language": "string", // Programming language ("python" or "node")
"timeout": number // (Optional) Execution timeout in seconds (default: 30)
}
响应:
{
"success": true,
"timestamp": 1234567890,
"data": {
"state": "success|error|timeout|cancelled",
"output": "string", // Code execution output
"error": "string", // Error message if any
"runtime": number, // Execution time in seconds
"exit_code": number // Execution exit code
}
}
6. revert_to_version
将代码文件恢复到特定版本。
{
"path": "string", // Path to file relative to workspace
"timestamp": number // Timestamp of version to revert to
}
响应:
{
"success": true,
"timestamp": 1234567890,
"data": {
"diff": {
"changes": [ // List of changes made
[string, number, number, number, number]
],
"timestamp": number // When the reversion was made
}
}
}
7. read_code_file_lines
从代码文件中读取特定行。
{
"project": "string", // Project name
"path": "string", // Path to file relative to project workspace
"start_line": number, // Starting line number to read
"end_line": number // (Optional) Ending line number to read
}
响应:
{
"success": true,
"timestamp": 1234567890,
"data": {
"content": "string" // Content of the specified lines
}
}
错误处理
服务器提供以下格式的详细错误响应:
{
"success": false,
"timestamp": 1234567890,
"data": null,
"error": "Error message"
}
错误类型包括:
CodeFileError:文件操作错误CodeValidationError:代码验证错误CodeExecutionError:代码执行错误
语言支持
目前支持的代码执行语言:
- Python(使用系统 Python 解释器)
- Node.js(使用 node 命令)
每种语言的执行都会在工作区目录中创建一个临时文件,并使用适当的解释器执行它。
贡献
- 叉分仓库
- 创建您的功能分支
- 提交您的更改
- 推送到该分支
- 创建新的 Pull Request
许可证
该项目根据 MIT 许可证许可 - 有关详细信息,请参阅 LICENSE 文件。
作者
Todd Wolven - (https://github.com/twolven)
致谢
- 使用 Anthropic 的模型上下文协议(MCP)构建
- 为与 Anthropic 的 Claude 一起使用而开发