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
2.6K downloads
42 stars

The MCP Python Interpreter enables language models to interact with Python environments, execute code, manage packages, and perform file operations, all within a secure Model Context Protocol (MCP) server.

Installation

Install the MCP Python Interpreter using pip:

pip install mcp-python-interpreter

Or with uv:

uv install mcp-python-interpreter

Prerequisites

Install uv (required for running the MCP server):

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

Setting Up with Claude Desktop

Configuration Steps

  1. Install Claude Desktop
  2. Open Claude Desktop and navigate to Settings via the menu
  3. Go to the Developer tab and select "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 specifies the directory where files will be saved and executed, creating a security boundary.

Available Tools

Environment and Package Management

  • list_python_environments: View all available Python environments
  • list_installed_packages: See packages installed in a specific environment
  • install_package: Add new Python packages to an environment

Code Execution

  • run_python_code: Execute Python code snippets in your chosen environment
  • run_python_file: Run Python script files

File Operations

  • read_file: Access file contents with syntax highlighting for code files
  • write_file: Create or modify files (text or binary)
  • write_python_file: Create Python-specific files
  • list_directory: View Python files in a directory

Available Resources

  • python://environments: List all Python environments
  • python://packages/{env_name}: View packages in a specific environment
  • python://file/{file_path}: Access a Python file's content
  • python://directory/{directory_path}: List Python files in a directory

Usage Examples

Here are practical examples of what you can ask Claude to do:

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

The MCP Python Interpreter includes several security measures:

  • Operations confined to the specified working directory
  • File size limits (1MB maximum)
  • Prevention of writes outside the working directory
  • Explicit overwrite protection

Always review code before execution, especially when modifying files or installing packages.

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