Cover image
Try Now
2025-04-04

MCP Python intérprete: ejecutar código Python. Python-MCP-Server, MCP-Python-Server, ejecutor de código

3 years

Works with Finder

1

Github Watches

2

Github Forks

16

Github Stars

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

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • 林乔安妮
  • A fashion stylist GPT offering outfit suggestions for various scenarios.

  • apappascs
  • Descubra la colección más completa y actualizada de servidores MCP en el mercado. Este repositorio sirve como un centro centralizado, que ofrece un extenso catálogo de servidores MCP de código abierto y propietarios, completos con características, enlaces de documentación y colaboradores.

  • ShrimpingIt
  • Manipulación basada en Micrypthon I2C del expansor GPIO de la serie MCP, derivada de AdaFruit_MCP230xx

  • pontusab
  • La comunidad de cursor y windsurf, encontrar reglas y MCP

  • av
  • Ejecute sin esfuerzo LLM Backends, API, frontends y servicios con un solo comando.

  • 1Panel-dev
  • 🔥 1Panel proporciona una interfaz web intuitiva y un servidor MCP para administrar sitios web, archivos, contenedores, bases de datos y LLM en un servidor de Linux.

  • jae-jae
  • Servidor MCP para obtener contenido de la página web con el navegador sin cabeza de dramaturgo.

  • Mintplex-Labs
  • La aplicación AI de escritorio todo en uno y Docker con trapo incorporado, agentes de IA, creador de agentes sin código, compatibilidad de MCP y más.

  • ravitemer
  • Un poderoso complemento Neovim para administrar servidores MCP (protocolo de contexto del modelo)

  • GeyserMC
  • Una biblioteca para la comunicación con un cliente/servidor de Minecraft.

    Reviews

    1 (1)
    Avatar
    user_nltPo6k6
    2025-04-16

    I recently tried the mcp-python-interpreter by yzfly, and I must say it's impressive! The interpreter is very intuitive and efficient, handling various Python scripts smoothly. It's a perfect tool for both beginners and advanced programmers. I highly recommend checking it out through this [link](https://github.com/yzfly/mcp-python-interpreter). Kudos to the author for creating such a fantastic tool!