Python Interpreter MCP server

Provides a secure Python execution environment with isolated working directories, enabling code execution, file operations, and package management for development, data analysis, and educational tasks.
Back to servers
Provider
YZFly
Release date
Apr 04, 2025
Language
Python
Package
Stats
1.2K downloads
24 stars

The MCP Python Interpreter provides a seamless way for Large Language Models to interact with Python environments, execute code, manage files, and handle development workflows. It works as a Model Context Protocol (MCP) server, enabling tools like Claude to access Python functionality directly.

Installation

You can install the MCP Python Interpreter using pip:

pip install mcp-python-interpreter

Or with uv:

uv install mcp-python-interpreter

Prerequisites

Make sure you have uv installed first:

For Unix/Linux/macOS:

curl -LsSf https://astral.sh/uv/install.sh | sh

For Windows:

powershell -ExecutionPolicy Bypass -Command "iwr -useb https://astral.sh/uv/install.ps1 | iex"

Configuration with Claude Desktop

Setting Up

  1. Install Claude Desktop
  2. Open Claude Desktop, access the menu, and go to Settings
  3. Navigate to the Developer tab and click "Edit Config"
  4. Add the MCP server configuration to your claude_desktop_config.json:

For macOS/Linux:

{
  "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. The MCP tools icon should now appear in the chat interface

Important: The --dir parameter is required and defines where files will be saved and executed, maintaining security by isolating operations to this directory.

Available Tools

Environment and Package Management

  • list_python_environments: Displays all available Python environments (system and conda)
  • list_installed_packages: Shows packages installed in a specific environment
  • install_package: Installs Python packages in a specified environment

Code Execution

  • run_python_code: Executes Python code snippets in a chosen environment
  • run_python_file: Runs Python script files in a chosen environment

File Operations

  • read_file: Reads any file type with size limits and safety checks
    • Text files display with syntax highlighting
    • Binary files show as hex representation
  • write_file: Creates or overwrites files with text or binary content
  • write_python_file: Specifically for creating Python files
  • list_directory: Shows Python files in a directory

Available Resources

  • python://environments: Lists all available Python environments
  • python://packages/{env_name}: Shows installed packages for a specific environment
  • python://file/{file_path}: Retrieves content of a Python file
  • python://directory/{directory_path}: Lists Python files in a directory

Example Usage

You can ask Claude to perform tasks like:

  • "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"

Security Considerations

This MCP server accesses your Python environments and file system with several security features:

  • Operations restricted to the specified working directory
  • File size limits (up to 1MB)
  • Protection against writing outside the working directory
  • Explicit overwrite protection

Always review code before execution and be cautious with file operations.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later