Skip to content
Back to search

mcp_code_executor

The MCP Code Executor is an MCP server that allows LLMs to execute Python code within a specified Conda environment.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/bazinga012--mcp-code-executor/badge.svg)](/listings/bazinga012--mcp-code-executor)

HTML

<a href="/listings/bazinga012--mcp-code-executor"><img src="/api/listings/bazinga012--mcp-code-executor/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

1. Clone this repository:

git clone https://github.com/bazinga012/mcp_code_executor.git

2. Navigate to the project directory:

cd mcp_code_executor

3. Install the Node.js dependencies:

npm install

4. Build the project:

npm run build

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 246 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # MCP Code Executor
  2. [![smithery badge](https://smithery.ai/badge/@bazinga012/mcp_code_executor)](https://smithery.ai/server/@bazinga012/mcp_code_executor)
  3. 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. It also supports incremental code generation for handling large code blocks that may exceed token limits.
  4. <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>
  5. ## Features
  6. - Execute Python code from LLM prompts
  7. - Support for incremental code generation to overcome token limitations
  8. - Run code within a specified environment (Conda, virtualenv, or UV virtualenv)
  9. - Install dependencies when needed
  10. - Check if packages are already installed
  11. - Dynamically configure the environment at runtime
  12. - Configurable code storage directory
  13. ## Prerequisites
  14. - Node.js installed
  15. - One of the following:
  16. - Conda installed with desired Conda environment created
  17. - Python virtualenv
  18. - UV virtualenv
  19. ## Setup
  20. 1. Clone this repository:
  21. ```bash
  22. git clone https://github.com/bazinga012/mcp_code_executor.git
  23. ```
  24. 2. Navigate to the project directory:
  25. ```bash
  26. cd mcp_code_executor
  27. ```
  28. 3. Install the Node.js dependencies:
  29. ```bash
  30. npm install
  31. ```
  32. 4. Build the project:
  33. ```bash
  34. npm run build
  35. ```
  36. ## Configuration
  37. To configure the MCP Code Executor server, add the following to your MCP servers configuration file:
  38. ### Using Node.js
  39. ```json
  40. {
  41. "mcpServers": {
  42. "mcp-code-executor": {
  43. "command": "node",
  44. "args": [
  45. "/path/to/mcp_code_executor/build/index.js"
  46. ],
  47. "env": {
  48. "CODE_STORAGE_DIR": "/path/to/code/storage",
  49. "ENV_TYPE": "conda",
  50. "CONDA_ENV_NAME": "your-conda-env"
  51. }
  52. }
  53. }
  54. }
  55. ```
  56. ### Using Docker
  57. ```json
  58. {
  59. "mcpServers": {
  60. "mcp-code-executor": {
  61. "command": "docker",
  62. "args": [
  63. "run",
  64. "-i",
  65. "--rm",
  66. "mcp-code-executor"
  67. ]
  68. }
  69. }
  70. }
  71. ```
  72. > **Note:** The Dockerfile has been tested with the venv-uv environment type only. Other environment types may require additional configuration.
  73. ### Environment Variables
  74. #### Required Variables
  75. - `CODE_STORAGE_DIR`: Directory where the generated code will be stored
  76. #### Environment Type (choose one setup)
  77. - **For Conda:**
  78. - `ENV_TYPE`: Set to `conda`
  79. - `CONDA_ENV_NAME`: Name of the Conda environment to use
  80. - **For Standard Virtualenv:**
  81. - `ENV_TYPE`: Set to `venv`
  82. - `VENV_PATH`: Path to the virtualenv directory
  83. - **For UV Virtualenv:**
  84. - `ENV_TYPE`: Set to `venv-uv`
  85. - `UV_VENV_PATH`: Path to the UV virtualenv directory
  86. ## Available Tools
  87. The MCP Code Executor provides the following tools to LLMs:
  88. ### 1. `execute_code`
  89. Executes Python code in the configured environment. Best for short code snippets.
  90. ```json
  91. {
  92. "name": "execute_code",
  93. "arguments": {
  94. "code": "import numpy as np\nprint(np.random.rand(3,3))",
  95. "filename": "matrix_gen"
  96. }
  97. }
  98. ```
  99. ### 2. `install_dependencies`
  100. Installs Python packages in the environment.
  101. ```json
  102. {
  103. "name": "install_dependencies",
  104. "arguments": {
  105. "packages": ["numpy", "pandas", "matplotlib"]
  106. }
  107. }
  108. ```
  109. ### 3. `check_installed_packages`
  110. Checks if packages are already installed in the environment.
  111. ```json
  112. {
  113. "name": "check_installed_packages",
  114. "arguments": {
  115. "packages": ["numpy", "pandas", "non_existent_package"]
  116. }
  117. }
  118. ```
  119. ### 4. `configure_environment`
  120. Dynamically changes the environment configuration.
  121. ```json
  122. {
  123. "name": "configure_environment",
  124. "arguments": {
  125. "type": "conda",
  126. "conda_name": "new_env_name"
  127. }
  128. }
  129. ```
  130. ### 5. `get_environment_config`
  131. Gets the current environment configuration.
  132. ```json
  133. {
  134. "name": "get_environment_config",
  135. "arguments": {}
  136. }
  137. ```
  138. ### 6. `initialize_code_file`
  139. Creates a new Python file with initial content. Use this as the first step for longer code that may exceed token limits.
  140. ```json
  141. {
  142. "name": "initialize_code_file",
  143. "arguments": {
  144. "content": "def main():\n print('Hello, world!')\n\nif __name__ == '__main__':\n main()",
  145. "filename": "my_script"
  146. }
  147. }
  148. ```
  149. ### 7. `append_to_code_file`
  150. Appends content to an existing Python code file. Use this to add more code to a file created with initialize_code_file.
  151. ```json
  152. {
  153. "name": "append_to_code_file",
  154. "arguments": {
  155. "file_path": "/path/to/code/storage/my_script_abc123.py",
  156. "content": "\ndef another_function():\n print('This was appended to the file')\n"
  157. }
  158. }
  159. ```
  160. ### 8. `execute_code_file`
  161. Executes an existing Python file. Use this as the final step after building up code with initialize_code_file and append_to_code_file.
  162. ```json
  163. {
  164. "name": "execute_code_file",
  165. "arguments": {
  166. "file_path": "/path/to/code/storage/my_script_abc123.py"
  167. }
  168. }
  169. ```
  170. ### 9. `read_code_file`
  171. Reads 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.
  172. ```json
  173. {
  174. "name": "read_code_file",
  175. "arguments": {
  176. "file_path": "/path/to/code/storage/my_script_abc123.py"
  177. }
  178. }
  179. ```
  180. ## Usage
  181. 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.
  182. LLMs can generate and execute code by referencing this MCP server in their prompts.
  183. ### Handling Large Code Blocks
  184. For larger code blocks that might exceed LLM token limits, use the incremental code generation approach:
  185. 1. **Initialize a file** with the basic structure using `initialize_code_file`
  186. 2. **Add more code** in subsequent calls using `append_to_code_file`
  187. 3. **Verify the file content** if needed using `read_code_file`
  188. 4. **Execute the complete code** using `execute_code_file`
  189. This approach allows LLMs to write complex, multi-part code without running into token limitations.
  190. ## Backward Compatibility
  191. 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.
  192. ## Contributing
  193. Contributions are welcome! Please open an issue or submit a pull request.
  194. ## License
  195. This project is licensed under the MIT License.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.