Python Runner MCP Server について
Python Runner MCP Serverは、データサイエンスや機械学習のワークフロー向けにPythonコードを実行します。分離実行、出力取得、科学計算ライブラリを必要とするMCPクライアント利用者を対象としています。
主な機能
- 01分離された名前空間でコード実行
- 02データサイエンス用ライブラリを同梱
- 03出力・エラー・戻り値の取得
- 04uvxまたはローカルで実行
活用シーン
- 01pandasとnumpyによる表形式データの分析
- 02scikit-learnの機械学習例の実行
- 03MCPクライアントからのPythonコード実行
MCP 対応
MCPを実装し、Claude Desktopを含む対応クライアントにPythonコード実行機能を公開します。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
ツール
ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。
詳細
Python Runner MCP Server
データサイエンスおよび機械学習のワークフロー向けに特化して設計された、FastMCP フレームワークベースの Python コード実行サーバーです。
🚀 特長
- 安全な Python コード実行:分離された名前空間で Python コードを実行します
- 豊富なデータサイエンスライブラリ:一般的に使用されるデータサイエンスおよび機械学習パッケージがあらかじめインストールされています
- リアルタイムの出力キャプチャ:標準出力、エラー出力、戻り値をキャプチャします
- MCP プロトコルのサポート:Model Context Protocol と完全に互換性があります
- 簡単に使えます:シンプルで使いやすい API インターフェイスを提供します
⚡ クイックスタート(推奨)
uvx を使えば、インストールせずにサーバーを直接実行できます:[TODO ..... ]
# Run directly (no pre-installation required)
uvx python-runner
Claude Desktop での設定
次の設定を Claude Desktop の設定ファイルに追加します。
{
"mcpServers": {
"python-runner": {
"command": "uvx",
"args": ["python-runner"]
}
}
}
設定ファイルの場所:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
デバッグとテスト
# Use MCP Inspector to debug the server
npx @modelcontextprotocol/inspector uvx python-runner
📦 インストール済みライブラリ
このプロジェクトには、一般的に使用される次のデータサイエンスおよび機械学習ライブラリがあらかじめインストールされています。
- データ処理:
numpy、pandas、scipy - 機械学習:
scikit-learn - データ可視化:
matplotlib、seaborn、plotly - 科学技術計算:
sympy - 画像処理:
pillow - ネットワーク分析:
networkx - インタラクティブ開発:
jupyter - HTTP リクエスト:
requests
🛠️ 手動インストール(開発者向け)
前提条件
- Python 3.12 以降
- uv パッケージマネージャー(推奨)または pip
uv でインストール(推奨)
# Clone the repository
git clone <repository-url>
cd python_runner
# Install dependencies
uv sync
pip でインストール
# Clone the repository
git clone <repository-url>
cd python_runner
# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -e .
🚀 使い方
Claude Desktop で使用する
設定後、Claude Desktop で Python コード実行機能を直接使用できます。
Please help me execute this Python code:
import pandas as pd
import numpy as np
# Create sample data
data = pd.DataFrame({
'sales': [100, 150, 200, 120, 180],
'profit': [20, 30, 50, 25, 40]
})
print("Sales data statistics:")
print(data.describe())
スタンドアロンの MCP サーバーとして実行する
# Using uvx (recommended)
uvx python-runner
# Or run locally
python main.py
API を直接呼び出す
from main import execute_python
# Execute simple Python code
result = execute_python("""
print("Hello, World!")
x = 1 + 2
print(f"Result: {x}")
""")
print(result)
# Output:
# {
# 'output': 'Hello, World!\nResult: 3\n',
# 'error': '',
# 'success': True
# }
データサイエンスの例
# Data analysis example
code = """
import pandas as pd
import numpy as np
# Create sample data
data = pd.DataFrame({
'x': np.random.randn(100),
'y': np.random.randn(100)
})
print(f"Data shape: {data.shape}")
print(f"Statistical summary:\n{data.describe()}")
"""
result = execute_python(code)
print(result['output'])
# Machine learning example
code = """
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
# Generate sample data
X, y = make_classification(n_samples=1000, n_features=20, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Train model
clf = RandomForestClassifier(random_state=42)
clf.fit(X_train, y_train)
# Predict and evaluate
y_pred = clf.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print(f"Model accuracy: {accuracy:.4f}")
"""
result = execute_python(code)
print(result['output'])
📋 API リファレンス
execute_python(code: str) -> dict
Python コードを実行し、結果を返します。
パラメーター:
code(str):実行する Python コード文字列
戻り値:
dict:次のキーを含む辞書:output(str):標準出力の内容error(str):エラーメッセージ(ある場合)success(bool):実行に成功したかどうか
🔒 セキュリティ
- 分離された名前空間でコードを実行します
- 標準出力とエラー出力をキャプチャしてリダイレクトします
- 詳細なエラー追跡情報を提供します
⚠️ 警告:このツールは任意の Python コードを実行します。信頼できる環境で使用してください。
🤝 コントリビューション
Issue やプルリクエストを歓迎します!
- このリポジトリをフォークします
- 機能ブランチを作成します(
git checkout -b feature/AmazingFeature) - 変更をコミットします(
git commit -m 'Add some AmazingFeature') - ブランチにプッシュします(
git push origin feature/AmazingFeature) - プルリクエストを作成します
📄 ライセンス
このプロジェクトは MIT ライセンスのもとで公開されています。詳細は LICENSE ファイルを参照してください。
🙏 謝辞
- FastMCP - 優れた MCP フレームワーク
- あらかじめインストールされているオープンソースのデータサイエンスライブラリのすべてのメンテナー
データサイエンスコミュニティのために ❤️ を込めて作成
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。