Skip to main content

MseeP.ai Security Assessment Badge

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

Installation

You can install the MCP Python Interpreter using pip:

pip install mcp-python-interpreter

Or with uv:

uv install mcp-python-interpreter

Usage with Claude Desktop

  1. Install Claude Desktop
  2. Open Claude Desktop, click on menu, then Settings
  3. Go to Developer tab and click "Edit Config"
  4. 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"
        },
    }
  }
}
  1. Restart Claude Desktop
  2. You should now see the MCP tools icon in the chat interface

The --dir parameter is required and specifies where all files will be saved and executed. This helps maintain security by isolating the MCP server to a specific directory.

Prerequisites

  • Make sure you have uv installed. If not, install it using:
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  • For 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 in a specific environment
  • 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
  • Strict file path security (only within the working directory)

Security Considerations

This MCP server has access to your Python environments and file system. Key security features include:

  • Isolated working directory
  • File size limits
  • Prevented writes outside the working directory
  • Explicit overwrite protection

Always be cautious about running code or file operations that you don't fully understand.

License

MIT

Metadata

Release files for iflow-mcp_mcp-python-interpreter 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_mcp-python-interpreter 1.2.3
File Size Uploaded
iflow_mcp_mcp_python_interpreter-1.2.3.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_mcp-python-interpreter 1.2.3
File Interpreter ABI Platform
iflow_mcp_mcp_python_interpreter-1.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 23.2 kB

Release files / iflow_mcp_mcp_python_interpreter-1.2.3.tar.gz

Download URL iflow_mcp_mcp_python_interpreter-1.2.3.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a2472e629ccc14a03ada737320def09ba3254b849ecfcfb89b79365bbea16568
BLAKE2b-256 checksum
How to use checksums
74eb752759a9ba4e35f5bd0f3141d4fe8106a6249e8afde1cbdcf46e1f129737
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release files / iflow_mcp_mcp_python_interpreter-1.2.3-py3-none-any.whl

Download URL iflow_mcp_mcp_python_interpreter-1.2.3-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e853041ea51176249e0617a28605aae384bebd5710a0c50493dbf8db9570bfa
BLAKE2b-256 checksum
How to use checksums
67b2a018baa738e8cd667c9b99c0440c088e151cb5e955abd565b5c48cdbecbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release history Release notifications | RSS feed

This release

1.2.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page