mcp-python-repl
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-python-replCalculate 10 factorial using a loop"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
๐ mcp-python-repl
A production-grade MCP server providing a persistent Python REPL with multi-session support, sandboxing, and timeout protection.
Built for LLM agents that need to execute Python code across multiple turns with variables that persist between calls.
โจ Features
Feature | Description |
Multi-session | Isolated sessions with unique IDs โ run parallel workflows |
Persistent namespace | Variables survive across calls within a session |
Timeout protection | Configurable execution timeout (SIGALRM on Unix) |
Sandboxing | Optional mode blocks dangerous modules ( |
Package install | Install pip packages on-the-fly (prefers |
File execution | Run |
Dual transport | stdio (local) and streamable-http (remote) |
Full introspection | List variables, get history, check server status |
Env-based config | All settings via |
Related MCP server: Sandbox MCP
๐ Quick Start
With Claude Desktop / Cursor (stdio)
Add to your MCP config:
{
"mcpServers": {
"python-repl": {
"command": "uvx",
"args": ["mcp-python-repl"]
}
}
}With uv (local dev)
# Clone and run
git clone https://github.com/soufiane-aazizi/mcp-python-repl.git
cd mcp-python-repl
uv run mcp-python-replHTTP transport (remote / multi-client)
REPL_TRANSPORT=streamable-http REPL_PORT=8000 uv run mcp-python-repl๐ ๏ธ Tools
Code Execution
Tool | Description |
| Execute Python code with persistent namespace |
| Execute a |
| Install a pip package (uses |
Namespace Management
Tool | Description |
| List all variables in a session |
| Get the full value of a variable |
| Inject a variable from JSON |
| Delete a specific variable |
| Clear all variables in a session |
Session Management
Tool | Description |
| List all active sessions |
| Delete a session and its data |
Debugging
Tool | Description |
| Get execution history for a session |
| Server config, Python version, session count |
๐ How Persistence Works
Call 1: repl_run_code(code="data = [1,2,3]; total = sum(data); result = total")
โ returns: {"result": 6, "session_id": "a1b2c3d4e5f6", "new_variables": ["data", "total"]}
Call 2: repl_run_code(code="doubled = [x*2 for x in data]; result = doubled", session_id="a1b2c3d4e5f6")
โ returns: {"result": [2,4,6], "new_variables": ["doubled"]}Important: The
resultvariable is for returning output to the caller. It does NOT persist. Use named variables instead.
โ๏ธ Configuration
All settings are configurable via environment variables:
Variable | Default | Description |
|
| Max execution time in seconds |
|
| Maximum concurrent sessions |
|
| Session expiry in minutes |
|
| Max stdout/stderr capture (bytes) |
|
| Enable sandboxing ( |
|
| Transport: |
|
| HTTP host (when using HTTP transport) |
|
| HTTP port (when using HTTP transport) |
|
| Working directory for executions |
Sandbox Mode
When REPL_SANDBOX=true, the following modules are blocked:
subprocess, shutil, ctypes, socket, http.server, xmlrpc, ftplib, smtplib, telnetlib, webbrowser
And the following builtins are removed: exec, eval, compile, __import__ (replaced with a restricted version).
๐งช Development
# Install dev dependencies
uv sync --extra dev
# Run tests
uv run pytest -v
# Lint
uv run ruff check src/ tests/
# Test with MCP Inspector
npx @modelcontextprotocol/inspector uv run mcp-python-repl๐ฆ Project Structure
mcp-python-repl/
โโโ src/mcp_python_repl/
โ โโโ __init__.py # Package metadata
โ โโโ config.py # Env-based configuration
โ โโโ session.py # Multi-session manager with TTL
โ โโโ executor.py # Python code executor (timeout + sandbox)
โ โโโ server.py # MCP server with all tools
โโโ tests/
โ โโโ test_core.py # Unit + integration tests
โโโ pyproject.toml # uv/hatch project config
โโโ LICENSE # MIT
โโโ README.md๐ License
MIT โ See LICENSE.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/aazizisoufiane/mcp-python-repl'
If you have feedback or need assistance with the MCP directory API, please join our Discord server