Skip to main content

MCP server providing a Python REPL with persistent session

Project description

Python REPL MCP Server

This is a fork of hdresearch/mcp-python, a Python REPL server for MCP protocol. But seems almost nothing is left from the original code.

This MCP server provides a Python REPL (Read-Eval-Print Loop) as a tool. It allows execution of Python code through the MCP protocol with a persistent session.

Setup

No setup needed! The project uses uv for dependency management. All dependencies are automatically managed through the pyproject.toml file.

Environment Variables

The server supports .env file for environment variables management. Create a .env file in the root directory to store your environment variables. These variables will be automatically loaded and accessible in your Python REPL session using:

import os

# Access environment variables
my_var = os.environ.get('MY_VARIABLE')
# or
my_var = os.getenv('MY_VARIABLE')

Running the Server

Simply run:

uv run mcp_python

Usage with Claude Desktop

Add this configuration to your Claude Desktop config file:

{
  "mcpServers": {
    "python-repl": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/python-repl-server",
        "run",
        "mcp_python"
      ]
    }
  }
}

Available Tools

The server provides the following tools:

  1. execute_python: Execute Python code with persistent variables

    • code: The Python code to execute
    • reset: Optional boolean to reset the session
  2. list_variables: Show all variables in the current session

  3. install_package: Install a package from PyPI using uv

    • package: Name of the package to install
  4. initialize_project: Create a new project directory with timestamp prefix

    • project_name: Name for the project directory
  5. create_file: Create a new file with specified content

    • filename: Path to the file (supports nested directories)
    • content: Content to write to the file
  6. load_file: Load and execute a Python script in the current session

    • filename: Path to the Python script to load

Features

  • Persistent Python REPL session
  • Automatic environment variable loading from .env files
  • Package management using uv
  • Project initialization with timestamped directories
  • File creation and management
  • Script loading and execution
  • Comprehensive logging system
  • Support for nested project structures

Examples

Initialize a new project:

# Create a new project directory
initialize_project("my_project")

Create and execute a script:

# Create a new Python file
create_file("script.py", """
def greet(name):
    return f"Hello, {name}!"
""")

# Load and execute the script
load_file("script.py")

# Use the loaded function
print(greet("World"))

Install and use a package:

# Install pandas
install_package("pandas")

# Use the installed package
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3]})
print(df)

List all variables:

# Show all variables in the current session
list_variables()

Reset the session:

# Use execute_python with reset=true to clear all variables
execute_python("", reset=True)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Here are some ways you can contribute:

  • Report bugs
  • Suggest new features
  • Improve documentation
  • Add test cases
  • Submit code improvements

Before submitting a PR, please ensure:

  1. Your code follows the existing style
  2. You've updated documentation as needed
  3. All tests pass
  4. You've added tests for new features

For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mseep_mcp_python-0.2.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mseep_mcp_python-0.2.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file mseep_mcp_python-0.2.1.tar.gz.

File metadata

  • Download URL: mseep_mcp_python-0.2.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for mseep_mcp_python-0.2.1.tar.gz
Algorithm Hash digest
SHA256 82b6650dfe6e2c544e196d5b109485de7811046c82777f0adb6f4144cd450076
MD5 65d5eca4f63ae8cb0aae3a69b92d5f92
BLAKE2b-256 72d576d7caf4ea0d742ced83415834196fd69b84a1a8d7fc2fc180674ad31253

See more details on using hashes here.

File details

Details for the file mseep_mcp_python-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mseep_mcp_python-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65e468d7b6d6ac173fc902201f0c81312b67d8156a2a784d2cac64adc65fa21d
MD5 db286d11cc0a040b2894fdd754c00d5d
BLAKE2b-256 f24c6610f8dcc282b7d8b6949a1000f7480626f9312ef575a91905f0728ec96a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page