Skip to content

Commit 8a7e90f

Browse files
jefcodercforge42
authored andcommitted
added venv, venv-uv env support and some more tools to let LLM install missing dependencies just in case
1 parent c9c026a commit 8a7e90f

File tree

3 files changed

+1079
-66
lines changed

3 files changed

+1079
-66
lines changed

README.md

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
# MCP Code Executor
22
[![smithery badge](https://smithery.ai/badge/@bazinga012/mcp_code_executor)](https://smithery.ai/server/@bazinga012/mcp_code_executor)
33

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.
55

66
<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>
77

88
## Features
99

1010
- 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
1215
- Configurable code storage directory
1316

1417
## Prerequisites
1518

1619
- 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
1924

2025
## Setup
2126

@@ -57,24 +62,101 @@ To configure the MCP Code Executor server, add the following to your MCP servers
5762
],
5863
"env": {
5964
"CODE_STORAGE_DIR": "/path/to/code/storage",
65+
"ENV_TYPE": "conda",
6066
"CONDA_ENV_NAME": "your-conda-env"
6167
}
6268
}
6369
}
6470
}
6571
```
6672

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+
```
71149

72150
## Usage
73151

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.
75153

76154
LLMs can generate and execute code by referencing this MCP server in their prompts.
77155

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+
78160
## Contributing
79161

80162
Contributions are welcome! Please open an issue or submit a pull request.

0 commit comments

Comments
 (0)