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.

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.

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 src/python_repl/server.py

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"
      ]
    }
  }
}

The server provides three 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

Examples

Set a variable:

a = 42

Use the variable:

print(f"The value is {a}")

List all variables:

# Use the list_variables tool

Reset the session:

# Use execute_python with 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. Maybe write some tests?

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

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.1.4.tar.gz (5.7 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.1.4-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mseep_mcp_python-0.1.4.tar.gz
  • Upload date:
  • Size: 5.7 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.1.4.tar.gz
Algorithm Hash digest
SHA256 875163c09141a2e007aeef3cf8dbd51af5f80cc53268de83647336914e23f15c
MD5 72026170866cdbb9d3b255cc235dea7a
BLAKE2b-256 3a8372476209192b8fff2507a0b7a0c9f730eb67eceea7a167aea81c6ecccd51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mseep_mcp_python-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 23741166a7dcaa506f5e7d834fb50bf74c30988e719c65ca27d1996d452c9462
MD5 419226e3763a4c70fc5d91b2225a0b47
BLAKE2b-256 502086879f473452698e0ffe336b25abf6f69c093aac209918fa0ec0b6b92c61

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