MCP Code Executor
MCP コードエグゼキューター
MCP Code Executor は、LLM が指定された Python 環境内で Python コードを実行できるようにする MCP サーバーです。これにより、LLM は環境で定義されたライブラリや依存関係にアクセスしながらコードを実行できます。また、トークン制限を超える可能性のある大規模なコードブロックを処理するための増分コード生成もサポートしています。
特徴
LLMプロンプトからPythonコードを実行する
トークン制限を克服するための増分コード生成のサポート
指定された環境(Conda、virtualenv、または UV virtualenv)内でコードを実行する
必要に応じて依存関係をインストールする
パッケージがすでにインストールされているかどうかを確認する
実行時に環境を動的に構成する
設定可能なコード保存ディレクトリ
Related MCP server: MCP Python Interpreter
前提条件
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 ライセンスに基づいてライセンスされています。
Available Tools
9 toolsappend_to_code_fileA
Append content to an existing Python code file. Use this to add more code to a file created with initialize_code_file, allowing you to build up larger code bases in parts.
Inputs: file_path (required), content (required).
check_installed_packagesC
Check if packages are installed in the conda environment
Inputs: packages (required).
configure_environmentC
Change the environment configuration settings
Inputs: type (required), conda_name, venv_path, uv_venv_path.
execute_codeA
Execute Python code in the conda environment. For short code snippets only. For longer code, use initialize_code_file and append_to_code_file instead.
Inputs: code (required), filename.
execute_code_fileA
Execute an existing Python file. Use this as the final step after building up code with initialize_code_file and append_to_code_file.
Inputs: file_path (required).
get_environment_configB
Get the current environment configuration
Inputs: no named parameters.
initialize_code_fileA
Create a new Python file with initial content. Use this as the first step for longer code that may exceed token limits. Follow with append_to_code_file for additional code.
Inputs: content (required), filename.
install_dependenciesC
Install Python dependencies in the conda environment
Inputs: packages (required).
read_code_fileA
Read the content of an existing Python code file. Use this to verify the current state of a file before appending more content or executing it.
Inputs: file_path (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool has a clearly distinct purpose with no ambiguity. For example, initialize_code_file, append_to_code_file, and read_code_file handle different file operations, while execute_code and execute_code_file target different execution methods. The descriptions explicitly differentiate tools like execute_code (for short snippets) versus the file-based workflow.
All tool names follow a consistent verb_noun pattern using snake_case, such as append_to_code_file, check_installed_packages, and configure_environment. There are no deviations in naming style or convention across the set, making them predictable and readable.
With 9 tools, the count is well-scoped for a code execution server. Each tool earns its place by covering distinct aspects like file management, environment configuration, dependency handling, and code execution, without being overly sparse or bloated.
The tool set provides complete coverage for the code execution domain, including CRUD-like operations for files (initialize, append, read), environment management (configure, get config, install dependencies), and execution (code snippets, files). There are no obvious gaps, and the workflow from file creation to execution is fully supported.
Maintenance
Related MCP Connectors
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Run Python and install PyPI packages from natural language. Hosted at https://cloudish.ai.
Build Apps and run code in 30 languages — sandboxed, with persistent sessions for agent loops.
I do everything related to coding and execution tasks
Related MCP Servers
- FlicenseNot gradedqualityNot gradedmaintenanceEnables LLMs to interact with Python environments, execute code or scripts, manage packages, and read/write files within an isolated working directory.-
- FlicenseNot gradedqualityAmaintenanceEnables LLMs to interact with Python environments, execute code, manage packages, and perform file operations within a configurable working directory.-
- FlicenseNot gradedqualityAmaintenanceEnables LLMs to interact with Python environments, execute code or scripts, manage packages, and read/write files within an isolated working directory.-
- FlicenseNot gradedqualityAmaintenanceEnables LLMs to execute Python code and scripts across system and conda environments, manage installed packages, and read or write text and binary files within an isolated working directory.-