# mcp-python-interpreter [Health: Active]

**Category:** 👨‍💻 Code Execution  
**Repository:** https://github.com/yzfly/mcp-python-interpreter  
**GitHub Stars:** 104  
**Views:** 0  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/mcp-python-interpreter

## Description
MCP Python Interpreter: run python code. Python-mcp-server, mcp-python-server, Code Executor

## Tools
Capabilities this server exposes over MCP:

- **list_python_environments** — List all available Python environments (system and conda)
- **list_installed_packages** — List packages installed in a specific environment
- **install_package** — Install a Python package in a specific environment
- **run_python_code** — Execute Python code inline or in a subprocess. Optional `save_as` saves a `.py` file before execution; existing files require `overwrite=true`. A rejected save does not execute the code.
- **run_python_file** — Execute a Python file in a specific environment
- **read_file** — Read contents of any file type, with size and safety limits
- **write_file** — Create or overwrite files with text or binary content
- **write_python_file** — Create or overwrite a Python file specifically
- **list_directory** — List Python files in a directory

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "mcp-python-interpreter": {
    "command": "uvx",
    "args": ["mcp-python-interpreter"]
  }
}
```

## Documentation

## What mcp-python-interpreter does

The mcp-python-interpreter exposes local Python development operations through the Model Context Protocol. An MCP client can inspect available system and conda environments, check installed packages, install packages into a selected environment, run Python code, and execute Python files.

It also provides file operations for common development tasks. The server can read text and binary files, write text or binary content, create Python files, list Python files in a directory, and save code before execution. Text and source files can be shown with syntax highlighting, while binary data can be represented in hexadecimal form.

Prompt templates cover three recurring tasks: creating a Python function, refactoring Python code, and debugging a Python error. Resources expose environment lists, package lists, Python file contents, and directory listings through URI patterns.

## How it works

Install the package with pip or install it as a tool with uv. It runs as an MCP server and can be configured in an MCP-compatible client. The Claude Desktop example starts it with `uvx`, sets a working directory with `--dir`, and optionally selects a Python executable with `--python-path`.

The working directory controls the default scope for file tools and for the `save_as` option on `run_python_code`. Resolved paths, including symlinks, are checked against that directory. Setting `MCP_ALLOW_SYSTEM_ACCESS=1` allows system access for those path checks; the example configuration uses `MCP_ALLOW_SYSTEM_ACCESS=0`.

Code may run inline or in a subprocess. A subprocess has separate interpreter state, but neither execution mode provides an operating-system sandbox. Python code can access files and the network using the server user's permissions, regardless of the file-tool path checks.

## Setup and configuration

Install one of the supported package forms:

- `pip install mcp-python-interpreter`
- `uv tool install mcp-python-interpreter`

The documented Claude Desktop configuration uses `uvx mcp-python-interpreter`, along with `--dir` and `--python-path` arguments. The `--dir` value defaults to the directory in which the server starts when it is omitted. Existing files require an explicit overwrite setting when saved through the relevant tools.

The server supports MCP Python SDK 1.x through `FastMCP` and SDK 2.x through `MCPServer`. Transport-related settings include `MCP_TRANSPORT`, `MCP_HOST`, `MCP_PORT`, `MCP_JSON_RESPONSE`, and `MCP_STATELESS_HTTP`.

## Tools and capabilities

Available tools include:

- `list_python_environments` for system and conda environment discovery.
- `list_installed_packages` and `install_package` for package inspection and installation.
- `run_python_code` for inline or subprocess execution, with optional `.py` saving.
- `run_python_file` for running a Python file in a chosen environment.
- `read_file`, `write_file`, and `write_python_file` for text and binary file handling.
- `list_directory` for listing Python files.

Resources include `python://environments`, `python://packages/{env_name}`, `python://file/{file_path}`, and `python://directory/{directory_path}`. File reads support files up to 1 MB and include safety and size limits.

## Limitations and notes

Run only trusted Python code. Inline execution has no enforced timeout, and `sys.exit()` is returned as an execution error without stopping the MCP server. The working-directory checks apply to file tools and saved snippets, not to arbitrary file or network access performed by executed Python. For stronger isolation, run the complete server in a container or under a restricted user account.

_Full upstream README: https://allmcps.com/mcp/mcp-python-interpreter/readme_

