Back to MCP Catalog

Python Code Executor MCP Server

Developer ToolsTypeScript
Execute Python code within a specified environment
Available Tools

execute_code

Executes Python code in the configured environment. Best for short code snippets.

codefilename

install_dependencies

Installs Python packages in the environment.

packages

check_installed_packages

Checks if packages are already installed in the environment.

packages

configure_environment

Dynamically changes the environment configuration.

typeconda_name

get_environment_config

Gets the current environment configuration.

initialize_code_file

Creates a new Python file with initial content. Use this as the first step for longer code that may exceed token limits.

contentfilename

append_to_code_file

Appends content to an existing Python code file. Use this to add more code to a file created with initialize_code_file.

file_pathcontent

execute_code_file

Executes an existing Python file. Use this as the final step after building up code with initialize_code_file and append_to_code_file.

file_path

read_code_file

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.

file_path

The Python Code Executor allows LLMs to execute Python code within a specified environment (Conda, virtualenv, or UV virtualenv). This enables AI assistants to run code with access to libraries and dependencies defined in the environment. With support for incremental code generation, this tool overcomes token limitations by allowing code to be built up in stages. It provides a complete workflow for code execution, from environment configuration and dependency management to code generation and execution.

Overview

The Python Code Executor provides a secure and flexible way for AI assistants to execute Python code. It supports running code within different Python environments (Conda, virtualenv, or UV virtualenv), allowing access to specific libraries and dependencies.

One of the key features is support for incremental code generation, which helps overcome token limitations when working with large code blocks. The executor also provides tools for managing dependencies, checking installed packages, and configuring the environment dynamically.

Installation

Prerequisites

  • Node.js
  • One of the following:
    • Conda with desired environment created
    • Python virtualenv
    • UV virtualenv

Setup Options

Option 1: Using Node.js directly

  1. Clone the repository:
git clone https://github.com/bazinga012/mcp_code_executor.git
  1. Navigate to the project directory:
cd mcp_code_executor
  1. Install Node.js dependencies:
npm install
  1. Build the project:
npm run build
  1. Configure your MCP client to use the server (see Configuration section below)

Option 2: Using Docker

  1. Clone the repository:
git clone https://github.com/bazinga012/mcp_code_executor.git
  1. Build the Docker image:
docker build -t mcp-code-executor .
  1. Configure your MCP client to use the Docker container (see Configuration section below)

Configuration

Environment Variables

The server requires configuration through environment variables:

Required:

  • CODE_STORAGE_DIR: Directory where 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

Usage

Once configured, the Python Code Executor allows AI assistants to execute Python code by generating files in the specified storage directory and running them within the configured environment.

Working with Large Code Blocks

For code that might exceed token limits:

  1. Use initialize_code_file to create a new file with initial content
  2. Use append_to_code_file to add more code in subsequent messages
  3. Use execute_code_file to run the complete code

This approach allows building up complex code across multiple interactions.

Related MCPs

Apple Shortcuts
Developer ToolsJavaScript

Control Apple Shortcuts automations from AI assistants

Clojars Dependency Lookup
Developer ToolsJavaScript

Fetch dependency information from Clojars, the Clojure community's artifact repository

Simple Timeserver
Developer ToolsPython

Provides Claude with current time and timezone information

About Model Context Protocol

Model Context Protocol (MCP) allows AI models to access external tools and services, extending their capabilities beyond their training data.

Generate Cursor Documentation

Save time on coding by generating custom documentation and prompts for Cursor IDE.