MCP Python Interpreter
This MCP server lets an LLM manage Python environments/packages, execute Python code or scripts, manage REPL sessions, and perform file operations under configured path controls.
List available Python environments and installed packages.
Install or upgrade packages in a selected environment.
Run Python code inline with persistent session state or in subprocess mode with optional environment, save_as, and timeout.
Run Python files with arguments, environment selection, and timeout.
Read files with size limits, write text/binary content with overwrite control, and list Python files in directories.
Clear and list active REPL sessions.
Use Python-focused prompt templates for function creation, refactoring, and debugging.
Allows interaction with Python environments, execution of Python code, management of packages, and Python-related file operations including reading, writing, and debugging Python files.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Python Interpreter run this Python code in my system environment: import pandas as pd; print(pd.__version__)"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Python Interpreter
A Model Context Protocol (MCP) server that allows LLMs to interact with Python environments, read and write files, execute Python code, and manage development workflows.
Features
Environment Management: List and use different Python environments (system and conda)
Code Execution: Run Python code or scripts in any available environment
Package Management: List installed packages and install new ones
File Operations:
Read files of any type (text, source code, binary)
Write text and binary files
Python Prompts: Templates for common Python tasks like function creation and debugging
Related MCP server: MCP Python Toolbox
Installation
You can install the MCP Python Interpreter using pip:
pip install mcp-python-interpreterOr with uv:
uv tool install mcp-python-interpreterUsage with Claude Desktop
Install Claude Desktop
Open Claude Desktop, click on menu, then Settings
Go to Developer tab and click "Edit Config"
Add the following to your
claude_desktop_config.json:
{
"mcpServers": {
"mcp-python-interpreter": {
"command": "uvx",
"args": [
"mcp-python-interpreter",
"--dir",
"/path/to/your/work/dir",
"--python-path",
"/path/to/your/python"
],
"env": {
"MCP_ALLOW_SYSTEM_ACCESS": "0"
}
}
}
}For Windows:
{
"mcpServers": {
"python-interpreter": {
"command": "uvx",
"args": [
"mcp-python-interpreter",
"--dir",
"C:\\path\\to\\your\\working\\directory",
"--python-path",
"/path/to/your/python"
],
"env": {
"MCP_ALLOW_SYSTEM_ACCESS": "0"
}
}
}
}Restart Claude Desktop
You should now see the MCP tools icon in the chat interface
The --dir parameter sets the working directory (default: the directory where the server starts). File tools and run_python_code(save_as=...) restrict paths to this directory unless MCP_ALLOW_SYSTEM_ACCESS=1 is set. It is not a sandbox for executed Python code.
Prerequisites
Make sure you have
uvinstalled. If not, install it using:curl -LsSf https://astral.sh/uv/install.sh | shFor Windows:
powershell -ExecutionPolicy Bypass -Command "iwr -useb https://astral.sh/uv/install.ps1 | iex"
Available Tools
The Python Interpreter provides the following tools:
Environment and Package Management
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
Code Execution
run_python_code: Execute Python code inline or in a subprocess. Optional
save_assaves a.pyfile before execution; existing files requireoverwrite=true. A rejected save does not execute the code.run_python_file: Execute a Python file in a specific environment
File Operations
read_file: Read contents of any file type, with size and safety limits
Supports text files with syntax highlighting
Displays hex representation for binary files
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
Available Resources
python://environments: List all available Python environments
python://packages/{env_name}: List installed packages for a specific environment
python://file/{file_path}: Get the content of a Python file
python://directory/{directory_path}: List all Python files in a directory
Prompts
python_function_template: Generate a template for a Python function
refactor_python_code: Help refactor Python code
debug_python_error: Help debug a Python error
Example Usage
Here are some examples of what you can ask Claude to do with this MCP server:
"Show me all available Python environments on my system"
"Run this Python code in my conda-base environment: print('Hello, world!')"
"Create a new Python file called 'hello.py' with a function that says hello"
"Read the contents of my 'data.json' file"
"Write a new configuration file with these settings..."
"List all packages installed in my system Python environment"
"Install the requests package in my system Python environment"
"Run data_analysis.py with these arguments: --input=data.csv --output=results.csv"
File Handling Capabilities
The MCP Python Interpreter now supports comprehensive file operations:
Read text and binary files up to 1MB
Write text and binary files
Syntax highlighting for source code files
Hex representation for binary files
File-tool path checks within the working directory by default, including
save_as
Security Considerations
File tools and run_python_code(save_as=...) check resolved paths, including symlinks, against the working directory unless MCP_ALLOW_SYSTEM_ACCESS=1 is explicitly enabled. Existing files require an explicit overwrite flag; saved snippets use exclusive creation by default.
Inline and subprocess execution run arbitrary Python with the server user's permissions. They can access files or the network independently of these file-tool checks. A subprocess separates interpreter state; it is not an operating-system sandbox. Run only trusted code, or isolate the entire server with a container or a restricted user account. Inline execution has no enforced timeout. sys.exit() is reported as an execution error without stopping the MCP server.
MCP SDK compatibility
Version 1.2.5 supports MCP Python SDK 1.x (FastMCP) and 2.x (MCPServer). The standalone fastmcp package is not required. The MCP_TRANSPORT, MCP_HOST, MCP_PORT, MCP_JSON_RESPONSE, MCP_STATELESS_HTTP, and transport-security environment settings work with either SDK version.
License
MIT
Available Tools
10 toolsclear_sessionC
Clear a REPL session's state and history.
Args:
session_id: Session ID to clear
Inputs: session_id. Returns: result
install_packageB
Install a Python package in the specified environment.
Args:
package_name: Name of the package to install
environment: Name of the Python environment
upgrade: Whether to upgrade if already installed
timeout: Maximum execution time in seconds
Inputs: package_name (required), timeout, upgrade, environment. Returns: result
list_directoryB
List all Python files in a directory.
Args:
directory_path: Path to directory (empty for working directory)
Inputs: directory_path. Returns: result
list_installed_packagesC
List installed packages for a specific Python environment.
Args:
environment: Name of the Python environment
Inputs: environment. Returns: result
list_python_environmentsB
List all available Python environments (system Python and conda environments).
Inputs: no named parameters. Returns: result
list_sessionsB
List all active REPL sessions.
Inputs: no named parameters. Returns: result
read_fileA
Read the content of any file, with size limits for safety.
Args:
file_path: Path to the file
max_size_kb: Maximum file size to read in KB
Inputs: file_path (required), max_size_kb. Returns: result
run_python_codeA
Execute Python code with flexible execution modes.
Args:
code: Python code to execute
execution_mode: Execution mode - "inline" (default, fast, in-process) or "subprocess" (isolated)
session_id: Session ID for inline mode to maintain state across executions
environment: Python environment name (only for subprocess mode)
save_as: Optional filename to save the code before execution (within --dir by default)
timeout: Maximum execution time in seconds (only enforced for subprocess mode)
overwrite: Allow replacing an existing save_as file (default: False)
Returns:
Execution result with output
Execution modes:
- "inline" (default): Executes code in the current process. Fast and reliable,
maintains session state. Use for most code execution tasks.
- "subprocess": Executes code in a separate Python process. Use when you need
environment isolation or a different Python environment.
Inputs: code (required), save_as, timeout, overwrite, +3 more. Returns: result
run_python_fileB
Execute a Python file (always uses subprocess for file execution).
Args:
file_path: Path to the Python file to execute
environment: Name of the Python environment to use
arguments: List of command-line arguments to pass to the script
timeout: Maximum execution time in seconds (default: 300)
Inputs: file_path (required), timeout, arguments, environment. Returns: result
write_fileB
Write content to a file.
Args:
file_path: Path to the file to write
content: Content to write
overwrite: Whether to overwrite if exists
Inputs: content (required), file_path (required), overwrite. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
Most tools target clearly distinct resources or actions (execution, files, environments, packages, sessions). The main potential confusion is between run_python_code and run_python_file, but the descriptions make the inline-code vs file-execution split explicit, so an agent can select correctly.
All ten tools follow a consistent snake_case verb_noun pattern: list_*, run_*, install_*, clear_*, read_*, write_*. No mixed conventions or vague single-word names.
Ten tools is a well-scoped surface for a Python interpreter server, covering execution, file I/O, environments, packages, and sessions without redundancy. Each tool earns its place.
Core lifecycle is covered: execute code/files, read/write files, list/install packages, list environments and sessions, and clear sessions. Minor gaps exist (no uninstall_package, no file delete, no environment creation), but agents can work around these via run_python_code.
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
A Model Context Protocol server for Wix AI tools
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
Enable secure connectivity between Sentry issues and debugging data, and LLM clients, using a Model Context Protocol (MCP) server.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that allows LLMs to execute shell commands and receive their output in a controlled manner.7MIT
- AlicenseNot gradedqualityFmaintenanceA Model Context Protocol server that enables AI assistants like Claude to perform Python development tasks through file operations, code analysis, project management, and safe code execution.9MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that allows AI models to safely access and interact with local file systems, enabling reading file contents, listing directories, and retrieving file metadata.8 npm10MIT
- FlicenseAqualityNot gradedmaintenanceA Model Context Protocol server that allows LLMs to interact with Python environments, enabling code execution, file operations, package management, and development workflows.9-