Note: The Dockerfile has been tested with the venv-uv environment type only. Other environment types may require additional configuration.
Environment Variables## Required Variables
CODE_STORAGE_DIR: Directory where the generated code will be stored
Environment Type (choose one setup)
For Conda:
ENV_TYPE: Set to conda
CONDA_ENV_NAME: Name of the Conda environment to use
For Standard Virtualenv:
ENV_TYPE: Set to venv
VENV_PATH: Path to the virtualenv directory
For UV Virtualenv:
ENV_TYPE: Set to venv-uv
UV_VENV_PATH: Path to the UV virtualenv directory
Available Tools
The MCP Code Executor provides the following tools to LLMs:
execute_code
install_dependencies
check_installed_packages
configure_environment
get_environment_config
initialize_code_file
append_to_code_file
execute_code_file
read_code_file
Usage
Once configured, the MCP Code Executor will allow LLMs to execute Python code by generating a file in the specified CODE_STORAGE_DIR and running it within the configured environment. LLMs can generate and execute code by referencing this MCP server in their prompts.
Handling Large Code Blocks
For larger code blocks that might exceed LLM token limits, use the incremental code generation approach:
Initialize a file with the basic structure using initialize_code_file
Add more code in subsequent calls using append_to_code_file
Verify the file content if needed using read_code_file
Execute the complete code using execute_code_file
This approach allows LLMs to write complex, multi-part code without running into token limitations.
Backward Compatibility
This package maintains backward compatibility with earlier versions. Users of previous versions who only specified a Conda environment will continue to work without any changes to their configuration.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.