CodeSavant

by twolven
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Provides version control capabilities for tracking and managing code changes, allowing users to revert to previous versions

  • Enables execution of Node.js code using the node command

  • Enables execution of Python code through the system Python interpreter

MCP-CodeSavant

CodeSavant 是一个 WIP 项目。

CodeSavant 是一个模型上下文协议 (MCP) 服务器,提供代码操作、执行和版本控制功能。它允许 AI 助手读取、写入和执行代码,同时保留更改历史记录。

特征

  • 使用特定于行的操作来读取和写入代码文件
  • 使用多种编程语言(Python、Node.js)执行代码
  • 在受控环境中执行 shell 命令
  • 使用版本控制跟踪和管理代码更改
  • 在代码文件中搜索
  • 恢复到以前版本的代码

安装

  1. 克隆存储库:
git clone https://github.com/twolven/mcp-codesavant.git cd mcp-codesavant
  1. 安装所需的依赖项:
pip install -r requirements.txt
  1. 将服务器配置添加到您的 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. 读取代码文件

读取代码文件的内容,可选择搜索特定部分。

{ "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. 写入代码文件

写入或更新代码文件中的特定行。

{ "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. 获取代码历史记录

获取代码文件的更改历史记录。

{ "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. 执行代码命令

执行与代码相关的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. 执行代码

以指定语言执行代码。

{ "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. 恢复到版本

将代码文件恢复到特定版本。

{ "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. 读取代码文件行

从代码文件中读取特定行。

{ "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 命令)

每种语言的执行都会在工作区目录中创建一个临时文件,并使用适当的解释器执行它。

贡献

  1. 分叉存储库
  2. 创建你的功能分支
  3. 提交你的更改
  4. 推送到分支
  5. 创建新的 Pull 请求

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

作者

托德·沃尔文 - ( https://github.com/tolven )

致谢

  • 使用 Anthropic 的模型上下文协议 (MCP) 构建
  • 专为与 Anthropic 的 Claude 配合使用而开发
-
security - not tested
A
license - permissive license
-
quality - not tested

提供代码操作、执行和版本控制功能。它允许 AI 助手读取、写入和执行代码,同时保留更改历史记录。

  1. Features
    1. Installation
      1. Directory Structure
        1. Tool Reference
          1. Detailed Usage
        2. Error Handling
          1. Language Support
            1. Contributing
              1. License
                1. Author
                  1. Acknowledgments
                    ID: rd4pozqg9r