Python REPL MCP servers provide a persistent Python execution environment that can be accessed by AI models through the Model Context Protocol (MCP). Several implementations offer package installation capabilities, allowing you to enhance your Python environment with additional libraries as needed.
MCP-Py-REPL
This is a Python REPL server that provides a persistent Python session with package installation capabilities.
Key Features:
Persistent Python session that maintains variables between executions
Package installation via UV package manager for fast dependency installation
Variable inspection via the list_variables tool
Directory awareness via MCP roots
Runs on Python 3.12[1]
Installation Options:
Via pip: pip install mcp-py-repl
Via Docker: docker pull ghcr.io/evalstate/mcp-py-repl[1]
Package Installation:
The server provides a dedicated tool called install_package that allows you to install Python packages directly from PyPI. This means you can enhance your Python environment with any package available on the Python Package Index without leaving your session[1][2].
Usage Example:
python
# Install a package
# Use the install_package tool to install numpy
# Then use the package in your code
import numpy as np
array = np.array([1, 2, 3])
print(array.mean())
Other Python REPL MCP Implementations
Several other implementations offer similar functionality:
Tynan Daly's Python REPL:
Uses UV for dependency management
Provides the same three core tools: execute_python, list_variables, and install_package
Can be configured to work with Claude Desktop[3]
Lyuhau's Python REPL:
Supports executing both Python code and shell commands
Enables complex data analysis and system administration tasks
Released on December 31, 2024[5]
Integration with AI Platforms
These Python REPL MCP servers can be integrated with various AI platforms:
Claude Desktop Integration:
Add the MCP server configuration to your Claude Desktop config file to enable Python code execution and package installation directly within your conversations[2][3].
Cursor Integration:
You can add the MCP server either globally in ~/.cursor/mcp.json or per-project in .cursor/mcp.json, allowing the Cursor agent to utilize the Python REPL tools[3].
Running the Server
Most implementations offer simple ways to run the server:
Docker Method:
code
docker run -it --rm --pull=always -v ./test_data:/mnt/data/ ghcr.io/evalstate/mcp-py-repl:latest
This mounts a local directory to allow file access from within the Python environment[1].
Direct Execution:
If installed via pip or another method, you can typically start the server with a simple command like mcp-py-repl[1].
The Python REPL MCP servers provide a powerful way to execute Python code with persistent state and dynamically install packages as needed, enhancing the capabilities of AI agents to perform complex data analysis and programming tasks.