MCP-コードサヴァント
CodeSavant は現在進行中のプロジェクトです。
CodeSavantは、コード操作、実行、バージョン管理機能を提供するModel Context Protocol(MCP)サーバーです。AIアシスタントが変更履歴を維持しながらコードの読み取り、書き込み、実行を行うことを可能にします。
特徴
- 行単位の操作でコードファイルを読み書きする
- 複数のプログラミング言語(Python、Node.js)でコードを実行する
- 制御された環境でシェルコマンドを実行する
- バージョン管理でコードの変更を追跡および管理する
- コードファイル内を検索
- 以前のバージョンのコードに戻す
インストール
- リポジトリをクローンします。
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. コードファイルを読む
コード ファイルの内容を読み取り、オプションで特定のセクションを検索します。
{
"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. コードコマンドの実行
コード関連のシェル コマンドを実行します。
{
"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 コマンドを使用)
各言語の実行では、ワークスペース ディレクトリに一時ファイルが作成され、適切なインタープリターで実行されます。
貢献
- リポジトリをフォークする
- 機能ブランチを作成する
- 変更をコミットする
- ブランチにプッシュする
- 新しいプルリクエストを作成する
ライセンス
このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細についてはLICENSEファイルを参照してください。
著者
トッド・ウルブン - ( https://github.com/twolven )
謝辞
- Anthropicのモデルコンテキストプロトコル(MCP)を使用して構築
- アントロピックのクロードとの使用のために開発されました