MCP Python Toolbox

local-only server

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

Integrations

  • Provides dependency management for Flask applications, allowing installation and version management of the web framework.

  • Supports running tests for Python projects through the testing framework.

  • Provides comprehensive Python development tools including code analysis, formatting with Black/PEP8, linting with Pylint, project management with virtual environments, dependency handling, and safe code execution capabilities.

MCP Python ツールボックス

Python 開発用の包括的なツール セットを提供する Model Context Protocol (MCP) サーバー。これにより、Claude のような AI アシスタントが Python コードやプロジェクトを効果的に操作できるようになります。

概要

MCP Python Toolboxは、モデルコンテキストプロトコルサーバーを実装しており、クロードは標準化されたインターフェースを通じてPython開発タスクを実行できます。これにより、クロードは以下のことが可能になります。

  • ワークスペース内でのファイルの読み取り、書き込み、管理
  • Python コードを分析、フォーマット、リンティングする
  • 仮想環境と依存関係を管理する
  • Pythonコードを安全に実行する

特徴

ファイル操作 ( FileOperations )

  • ワークスペースディレクトリ内での安全なファイル操作
  • ワークスペース外への不正アクセスを防ぐためのパス検証
  • 行単位の操作でファイルを読み書きする
  • ファイルとディレクトリの作成と削除
  • 詳細なメタデータ(サイズ、タイプ、変更時刻)を含むディレクトリの内容を一覧表示します
  • ファイル書き込み時の親ディレクトリの自動作成

コード分析 ( CodeAnalyzer )

  • AST を使用して Python コード構造を解析する
  • 以下の詳細情報を抽出します:
    • インポート文とそのエイリアス
    • 引数とデコレータを使用した関数定義
    • 基本クラスとメソッドを使用したクラス定義
    • グローバル変数の割り当て
  • 次を使用してコードをフォーマットします。
    • 黒(デフォルト)
    • PEP8 (autopep8 を使用)
  • Pylintを使用した包括的なコードリンティングと詳細なレポート

プロジェクト管理 ( ProjectManager )

  • pip サポートを使用して仮想環境を作成および管理します
  • 柔軟な依存関係管理:
    • requirements.txt からインストールする
    • pyproject.tomlからインストールする
    • 特定のパッケージバージョンのサポート
  • 高度な依存関係の処理:
    • パッケージ間のバージョンの競合を確認する
    • インストールされているすべてのパッケージをバージョンとともに一覧表示します
    • パッケージを特定のバージョンに更新する
    • 現在の環境から requirements.txt を生成する

コード実行 ( CodeExecutor )

  • 制御された環境でPythonコードを実行する
  • 一貫した依存関係のためにプロジェクトの仮想環境を使用する
  • コード実行のための一時ファイル管理
  • stdout、stderr、終了コードをキャプチャする
  • カスタム作業ディレクトリのサポート

インストール

  1. リポジトリをクローンします。
git clone https://github.com/gianlucamazza/mcp_python_toolbox.git cd mcp_python_toolbox
  1. 仮想環境を作成してアクティブ化します。
python -m venv .venv source .venv/bin/activate # Linux/Mac # or .venv\Scripts\activate # Windows
  1. 開発モードでパッケージをインストールします。
pip install -e ".[dev]"

使用法

CLIツールとして実行

サーバーを起動する最も簡単な方法は、CLI を使用することです。

# Start with current directory as workspace python -m mcp_python_toolbox # Or specify a workspace directory python -m mcp_python_toolbox --workspace /path/to/your/project

Claude Desktop の設定

Claude Desktopは、MCP Python Toolboxサーバーを自動的に起動・管理できます。設定方法は以下の通りです。

  1. 上記の説明に従ってMCP Python Toolboxをインストールしてセットアップします。
  2. Claude Desktop の MCP ツール構成に Python Toolbox の構成エントリを追加します。
"python-toolbox": { "command": "/Users/username/path/to/mcp_python_toolbox/.venv/bin/python", "args": [ "-m", "mcp_python_toolbox", "--workspace", "/Users/username/path/to/workspace" ], "env": { "PYTHONPATH": "/Users/username/path/to/mcp_python_toolbox/src", "PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", "VIRTUAL_ENV": "/Users/username/path/to/mcp_python_toolbox/.venv", "PYTHONHOME": "" } }
  1. 環境に合わせてパスをカスタマイズする
  2. Claude Desktopは必要に応じてMCPサーバーを自動的に起動します。
  3. クロードはMCPインターフェースを通じてPython開発ツールにアクセスできるようになりました

プログラムによる使用

from mcp_python_toolbox import PythonToolboxServer server = PythonToolboxServer(workspace_root="/path/to/your/project") server.setup() server.run()

コアモジュールの例

ファイル操作

from mcp_python_toolbox.core import FileOperations file_ops = FileOperations(workspace_root="/path/to/project") # Read file contents content = file_ops.read_file("src/example.py") # Read specific lines lines = file_ops.read_file("src/example.py", start_line=10, end_line=20) # Write to file file_ops.write_file("output.txt", "Hello, World!") # Append to file file_ops.write_file("log.txt", "New entry\n", mode='a') # List directory contents contents = file_ops.list_directory("src") for item in contents: print(f"{item['name']} - {item['type']} - {item['size']} bytes")

コード分析

from mcp_python_toolbox.core import CodeAnalyzer analyzer = CodeAnalyzer(workspace_root="/path/to/project") # Analyze Python file structure analysis = analyzer.parse_python_file("src/example.py") print(f"Found {len(analysis['functions'])} functions") print(f"Found {len(analysis['classes'])} classes") # Format code formatted = analyzer.format_code(code, style='black') # Lint code issues = analyzer.lint_code("src/example.py") for issue in issues: print(f"Line {issue['line']}: {issue['message']}")

プロジェクト管理

from mcp_python_toolbox.core import ProjectManager pm = ProjectManager(workspace_root="/path/to/project") # Create virtual environment pm.create_virtual_environment() # Install dependencies pm.install_dependencies() # from requirements.txt or pyproject.toml pm.install_dependencies("requirements-dev.txt") # from specific file # Check for conflicts conflicts = pm.check_dependency_conflicts() if conflicts: print("Found dependency conflicts:") for conflict in conflicts: print(f"{conflict['package']} requires {conflict['requires']}") # Update packages pm.update_package("requests") # to latest pm.update_package("flask", version="2.0.0") # to specific version

コード実行

from mcp_python_toolbox.core import CodeExecutor executor = CodeExecutor(workspace_root="/path/to/project") code = ''' def greet(name): return f"Hello, {name}!" print(greet("World")) ''' result = executor.execute_code(code) print(f"Output: {result['stdout']}") print(f"Errors: {result['stderr']}") print(f"Exit code: {result['exit_code']}")

発達

テストの実行

pytest

型チェック

mypy src/mcp_python_toolbox

リンティング

pylint src/mcp_python_toolbox

書式設定

black src/mcp_python_toolbox

貢献

  1. リポジトリをフォークする
  2. 機能ブランチを作成します( git checkout -b feature/amazing-feature
  3. 変更をコミットします ( git commit -m 'Add some amazing feature' )
  4. ブランチにプッシュする ( git push origin feature/amazing-feature )
  5. プルリクエストを開く

ライセンス

このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細については LICENSE ファイルを参照してください。

謝辞

  • モデルコンテキストプロトコル仕様を実装する
  • 最新のPython開発ツールとベストプラクティスに基づいて構築
  • 業界標準のフォーマット(Black)およびリンティング(Pylint)ツールを使用
-
security - not tested
F
license - not found
-
quality - not tested

Claude のような AI アシスタントがファイル操作、コード分析、プロジェクト管理、安全なコード実行を通じて Python 開発タスクを実行できるようにするモデル コンテキスト プロトコル サーバー。

  1. Overview
    1. Features
      1. File Operations (FileOperations)
      2. Code Analysis (CodeAnalyzer)
      3. Project Management (ProjectManager)
      4. Code Execution (CodeExecutor)
    2. Installation
      1. Usage
        1. Running as a CLI Tool
        2. Setting Up with Claude Desktop
        3. Programmatic Usage
        4. Core Module Examples
      2. Development
        1. Running Tests
        2. Type Checking
        3. Linting
        4. Formatting
      3. Contributing
        1. License
          1. Acknowledgments
            ID: wgz6nkycav