|
1 | 1 | # MCP Code Executor |
2 | 2 | [](https://smithery.ai/server/@bazinga012/mcp_code_executor) |
3 | 3 |
|
4 | | -The MCP Code Executor is an MCP server that allows LLMs to execute Python code within a specified Conda environment. This enables LLMs to run code with access to libraries and dependencies defined in the Conda environment. |
| 4 | +The MCP Code Executor is an MCP server that allows LLMs to execute Python code within a specified Python environment. This enables LLMs to run code with access to libraries and dependencies defined in the environment. |
5 | 5 |
|
6 | 6 | <a href="https://glama.ai/mcp/servers/45ix8xode3"><img width="380" height="200" src="https://glama.ai/mcp/servers/45ix8xode3/badge" alt="Code Executor MCP server" /></a> |
7 | 7 |
|
8 | 8 | ## Features |
9 | 9 |
|
10 | 10 | - Execute Python code from LLM prompts |
11 | | -- Run code within a specified Conda environment |
| 11 | +- Run code within a specified environment (Conda, virtualenv, or UV virtualenv) |
| 12 | +- Install dependencies when needed |
| 13 | +- Check if packages are already installed |
| 14 | +- Dynamically configure the environment at runtime |
12 | 15 | - Configurable code storage directory |
13 | 16 |
|
14 | 17 | ## Prerequisites |
15 | 18 |
|
16 | 19 | - Node.js installed |
17 | | -- Conda installed |
18 | | -- Desired Conda environment created |
| 20 | +- One of the following: |
| 21 | + - Conda installed with desired Conda environment created |
| 22 | + - Python virtualenv |
| 23 | + - UV virtualenv |
19 | 24 |
|
20 | 25 | ## Setup |
21 | 26 |
|
@@ -57,24 +62,101 @@ To configure the MCP Code Executor server, add the following to your MCP servers |
57 | 62 | ], |
58 | 63 | "env": { |
59 | 64 | "CODE_STORAGE_DIR": "/path/to/code/storage", |
| 65 | + "ENV_TYPE": "conda", |
60 | 66 | "CONDA_ENV_NAME": "your-conda-env" |
61 | 67 | } |
62 | 68 | } |
63 | 69 | } |
64 | 70 | } |
65 | 71 | ``` |
66 | 72 |
|
67 | | -Replace the placeholders: |
68 | | -- `/path/to/mcp_code_executor` with the absolute path to where you cloned this repository |
69 | | -- `/path/to/code/storage` with the directory where you want the generated code to be stored |
70 | | -- `your-conda-env` with the name of the Conda environment you want the code to run in |
| 73 | +### Environment Variables |
| 74 | + |
| 75 | +#### Required Variables |
| 76 | +- `CODE_STORAGE_DIR`: Directory where the generated code will be stored |
| 77 | + |
| 78 | +#### Environment Type (choose one setup) |
| 79 | +- **For Conda:** |
| 80 | + - `ENV_TYPE`: Set to `conda` |
| 81 | + - `CONDA_ENV_NAME`: Name of the Conda environment to use |
| 82 | + |
| 83 | +- **For Standard Virtualenv:** |
| 84 | + - `ENV_TYPE`: Set to `venv` |
| 85 | + - `VENV_PATH`: Path to the virtualenv directory |
| 86 | + |
| 87 | +- **For UV Virtualenv:** |
| 88 | + - `ENV_TYPE`: Set to `venv-uv` |
| 89 | + - `UV_VENV_PATH`: Path to the UV virtualenv directory |
| 90 | + |
| 91 | +## Available Tools |
| 92 | + |
| 93 | +The MCP Code Executor provides the following tools to LLMs: |
| 94 | + |
| 95 | +### 1. `execute_code` |
| 96 | +Executes Python code in the configured environment. |
| 97 | +```json |
| 98 | +{ |
| 99 | + "name": "execute_code", |
| 100 | + "arguments": { |
| 101 | + "code": "import numpy as np\nprint(np.random.rand(3,3))", |
| 102 | + "filename": "matrix_gen" |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +### 2. `install_dependencies` |
| 108 | +Installs Python packages in the environment. |
| 109 | +```json |
| 110 | +{ |
| 111 | + "name": "install_dependencies", |
| 112 | + "arguments": { |
| 113 | + "packages": ["numpy", "pandas", "matplotlib"] |
| 114 | + } |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +### 3. `check_installed_packages` |
| 119 | +Checks if packages are already installed in the environment. |
| 120 | +```json |
| 121 | +{ |
| 122 | + "name": "check_installed_packages", |
| 123 | + "arguments": { |
| 124 | + "packages": ["numpy", "pandas", "non_existent_package"] |
| 125 | + } |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +### 4. `configure_environment` |
| 130 | +Dynamically changes the environment configuration. |
| 131 | +```json |
| 132 | +{ |
| 133 | + "name": "configure_environment", |
| 134 | + "arguments": { |
| 135 | + "type": "conda", |
| 136 | + "conda_name": "new_env_name" |
| 137 | + } |
| 138 | +} |
| 139 | +``` |
| 140 | + |
| 141 | +### 5. `get_environment_config` |
| 142 | +Gets the current environment configuration. |
| 143 | +```json |
| 144 | +{ |
| 145 | + "name": "get_environment_config", |
| 146 | + "arguments": {} |
| 147 | +} |
| 148 | +``` |
71 | 149 |
|
72 | 150 | ## Usage |
73 | 151 |
|
74 | | -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 Conda environment defined by `CONDA_ENV_NAME`. |
| 152 | +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. |
75 | 153 |
|
76 | 154 | LLMs can generate and execute code by referencing this MCP server in their prompts. |
77 | 155 |
|
| 156 | +## Backward Compatibility |
| 157 | + |
| 158 | +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. |
| 159 | + |
78 | 160 | ## Contributing |
79 | 161 |
|
80 | 162 | Contributions are welcome! Please open an issue or submit a pull request. |
|
0 commit comments