home / mcp / mcp python interpreter mcp server
MCP Python Interpreter: run python code. Python-mcp-server, mcp-python-server, Code Executor
Configuration
View docs{
"mcpServers": {
"yzfly-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"
}
}
}
}You set up and run an MCP server that lets a language model interact with Python environments, execute code, read and write files, and manage development tasks with isolated working directories for safety and reproducibility.
You interact with the MCP Python Interpreter through an MCP client. You can list available Python environments (system and conda), inspect installed packages in a chosen environment, install new packages, run Python code or scripts in a specific environment, and perform file operations such as reading or writing files. Use dedicated prompts to generate Python functions, refactor code, or debug errors. Everything is scoped to a defined working directory to keep actions isolated and secure.
Prerequisites: you need Python installed on your system and a runtime to host the MCP server. You also need the MCP runtime tool for launching the server.
# Install the MCP Python Interpreter via pip
pip install mcp-python-interpreter
# Or install via uv (recommended for MCP workflow integration)
uv install mcp-python-interpreterWhen you run the MCP server, you provide a working directory where all files will be saved and executed. This directory keeps the server actions isolated for security.
{
"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
}
}
}
}If you are configuring on Windows, the same pattern applies with Windows paths.
{
"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"
}
}
}
}To connect your MCP client, load the configured MCP server and start the session. Use the available tools to list environments, manage packages, run code, and perform file operations. Always run within the specified working directory to maintain security boundaries.
This MCP server operates with access to your Python environments and file system within a defined working directory. It enforces strict file path boundaries, applies size limits to read/write operations, and requires explicit overwrite protection to prevent unintended changes. Treat code execution and file operations with caution, especially when running user-provided input.
Example tasks you can perform with this MCP server include listing environments, running a Python snippet in a chosen environment, creating a new Python file, reading a JSON configuration, listing packages, installing a package, and executing a Python file with arguments.
List all available Python environments (system and conda)
List packages installed in a specific environment
Install a Python package in a specific environment
Execute Python code in a specific environment
Execute a Python file in a specific environment
Read contents of any file type, with size and safety limits
Create or overwrite files with text or binary content
Create or overwrite a Python file specifically
List Python files in a directory
Generate a template for a Python function
Help refactor Python code
Help debug a Python error