MCP Code Executor
MCP コードエグゼキューター
MCP Code Executor は、LLM が指定された Python 環境内で Python コードを実行できるようにする MCP サーバーです。これにより、LLM は環境で定義されたライブラリや依存関係にアクセスしながらコードを実行できます。また、トークン制限を超える可能性のある大規模なコードブロックを処理するための増分コード生成もサポートしています。
特徴
LLMプロンプトからPythonコードを実行する
トークン制限を克服するための増分コード生成のサポート
指定された環境(Conda、virtualenv、または UV virtualenv)内でコードを実行する
必要に応じて依存関係をインストールする
パッケージがすでにインストールされているかどうかを確認する
実行時に環境を動的に構成する
設定可能なコード保存ディレクトリ
Related MCP server: LLM Python Code Sandbox
前提条件
Node.jsがインストールされている
次のいずれか:
Conda がインストールされ、必要な Conda 環境が作成されました
Python仮想環境
UV仮想環境
設定
このリポジトリをクローンします:
git clone https://github.com/bazinga012/mcp_code_executor.gitプロジェクト ディレクトリに移動します。
cd mcp_code_executorNode.js の依存関係をインストールします。
npm installプロジェクトをビルドします。
npm run build構成
MCP Code Executor サーバーを構成するには、MCP サーバー構成ファイルに次の行を追加します。
Node.jsの使用
{
"mcpServers": {
"mcp-code-executor": {
"command": "node",
"args": [
"/path/to/mcp_code_executor/build/index.js"
],
"env": {
"CODE_STORAGE_DIR": "/path/to/code/storage",
"ENV_TYPE": "conda",
"CONDA_ENV_NAME": "your-conda-env"
}
}
}
}Dockerの使用
{
"mcpServers": {
"mcp-code-executor": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp-code-executor"
]
}
}
}注: Dockerfileはvenv-uv環境タイプでのみテストされています。他の環境タイプでは追加の設定が必要になる場合があります。
環境変数
必須変数
CODE_STORAGE_DIR: 生成されたコードが保存されるディレクトリ
環境タイプ(1つの設定を選択)
Condaの場合:
ENV_TYPE:condaに設定CONDA_ENV_NAME: 使用するConda環境の名前
標準 Virtualenv の場合:
ENV_TYPE:venvに設定VENV_PATH: 仮想環境ディレクトリへのパス
UV Virtualenvの場合:
ENV_TYPE:venv-uvに設定UV_VENV_PATH: UV仮想環境ディレクトリへのパス
利用可能なツール
MCP コード エグゼキュータは、LLM に次のツールを提供します。
1. execute_code
設定された環境でPythonコードを実行します。短いコードスニペットに最適です。
{
"name": "execute_code",
"arguments": {
"code": "import numpy as np\nprint(np.random.rand(3,3))",
"filename": "matrix_gen"
}
}2. install_dependencies
環境に Python パッケージをインストールします。
{
"name": "install_dependencies",
"arguments": {
"packages": ["numpy", "pandas", "matplotlib"]
}
}3. check_installed_packages
環境にパッケージがすでにインストールされているかどうかを確認します。
{
"name": "check_installed_packages",
"arguments": {
"packages": ["numpy", "pandas", "non_existent_package"]
}
}4. configure_environment
環境構成を動的に変更します。
{
"name": "configure_environment",
"arguments": {
"type": "conda",
"conda_name": "new_env_name"
}
}5. get_environment_config
現在の環境構成を取得します。
{
"name": "get_environment_config",
"arguments": {}
}6. initialize_code_file
初期コンテンツを含む新しいPythonファイルを作成します。トークン制限を超える可能性のある長いコードの最初のステップとしてこれを使用してください。
{
"name": "initialize_code_file",
"arguments": {
"content": "def main():\n print('Hello, world!')\n\nif __name__ == '__main__':\n main()",
"filename": "my_script"
}
}7. append_to_code_file
既存のPythonコードファイルにコンテンツを追加します。initialize_code_fileで作成されたファイルにコードを追加する場合に使用します。
{
"name": "append_to_code_file",
"arguments": {
"file_path": "/path/to/code/storage/my_script_abc123.py",
"content": "\ndef another_function():\n print('This was appended to the file')\n"
}
}8. execute_code_file
既存のPythonファイルを実行します。initialize_code_fileとappend_to_code_fileでコードをビルドした後の最終ステップとして使用してください。
{
"name": "execute_code_file",
"arguments": {
"file_path": "/path/to/code/storage/my_script_abc123.py"
}
}9. read_code_file
既存のPythonコードファイルの内容を読み取ります。ファイルの内容を追加したり実行したりする前に、ファイルの現在の状態を確認するために使用します。
{
"name": "read_code_file",
"arguments": {
"file_path": "/path/to/code/storage/my_script_abc123.py"
}
}使用法
MCP コード エグゼキュータが設定されると、指定されたCODE_STORAGE_DIRにファイルを生成し、設定された環境内で実行することで、LLM が Python コードを実行できるようになります。
LLM はプロンプトでこの MCP サーバーを参照してコードを生成および実行できます。
大きなコードブロックの処理
LLM トークン制限を超える可能性のある大きなコード ブロックの場合は、増分コード生成アプローチを使用します。
基本構造を持つファイルを
initialize_code_fileを使用して初期化するappend_to_code_fileを使用して後続の呼び出しにコードを追加します。必要に応じて
read_code_fileを使用してファイルの内容を確認します。execute_code_fileを使用して完全なコードを実行します。
このアプローチにより、LLM はトークンの制限に遭遇することなく、複雑な複数部分から成るコードを記述できます。
下位互換性
このパッケージは以前のバージョンとの下位互換性を維持しています。以前のバージョンでConda環境のみを指定していたユーザーは、設定を変更することなく引き続き作業できます。
貢献
貢献を歓迎します!問題を報告したり、プルリクエストを送信してください。
ライセンス
このプロジェクトは MIT ライセンスに基づいてライセンスされています。
Maintenance
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn interactive Python code execution environment that allows users and LLMs to safely execute Python code and install packages in isolated Docker containers.40Apache 2.0
- FlicenseNot gradedqualityDmaintenanceEnables LLMs to execute Python code in isolated sandboxes with file operations and MCP integration, supporting multi-round execution and plot capture.1
- FlicenseAqualityDmaintenanceEnables LLMs to interact with Python environments, execute code, manage files, and handle packages through the Model Context Protocol.9
- AlicenseNot gradedqualityCmaintenanceEnables LLMs to execute Python code securely in a sandboxed environment. Supports configurable restrictions like no network access and returns results including files.MIT
Related MCP Connectors
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Build, validate, and deploy multi-agent AI solutions from any AI environment.
Persistent cloud development environments that coding agents create, run and test software in.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/bazinga012/mcp_code_executor'
If you have feedback or need assistance with the MCP directory API, please join our Discord server