Mrmd Python
No description available
Ask AI about Mrmd Python
Powered by Claude Β· Grounded in docs
I know everything about Mrmd Python. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
rat-py
Run AnyThing: Python. MCP server for live Python execution. 3 tools, persistent state, real-time streaming.
Part of the rat family: rat-py, rat-r, rat-ju, rat-sh, rat-js β the same 3 tools for every REPL language, all driven by mcp2cli.
Install
pip install rat-py
rat-py install
That registers with mcp2cli as py. Done.
Use
mcp2cli py up # start persistent runtime
py run 'x = 42; print(x)' # β 42 β 3ms | 1 var
py run 'print(f"x is {x}")' # β x is 42 β 2ms | 1 var
py look # β python idle | 1 vars | exec #2
py look --at x # β x: int = 42
py ctl --op reset # β RESET | namespace cleared | 0 vars
mcp2cli py down # stop
Everything after mcp2cli py up goes through mcp2cli. The Python package is just the MCP server β mcp2cli handles the CLI, background process, shell completions, and output formatting.
Tools
| Tool | Purpose | Example |
|---|---|---|
run | Run code or provide input | py run 'df.head()' |
look | See variables, inspect, complete | py look or py look --at df |
ctl | Reset, cancel, restart, status | py ctl --op reset |
run β execute code
py run 'for i in range(3): print(i)'
β 0
1
2
β 12ms | 1 var
Streams stdout/stderr in real-time via MCP notifications. Handles input() calls:
py run 'name = input("Name: ")' β INPUT REQUESTED: "Name: "
py run --input Alice β β 50ms | 1 var
look β see state, inspect, drill down, complete
Overview:
py look
β python idle | 3 vars | exec #5
data dict {'name': 'Alice', 'scores': [90, 85, 92]}
x int 42
model Model <Model object at 0x...>
Inspect and drill down β dot syntax navigates dicts, lists, and object attributes:
py look --at data
β data: dict (3 items)
= {'name': 'Alice', 'scores': [90, 85, 92], 'info': {'age': 30}}
'name' str 'Alice'
βΈ 'scores' list [90, 85, 92]
βΈ 'info' dict {'age': 30}
py look --at data.scores
β data.scores: list (3 items)
= [90, 85, 92]
[0] int 90
[1] int 85
[2] int 92
py look --at model
β model: Model
= <Model object at 0x...>
lr float 0.01
βΈ layers list [{'type': 'dense', ...}, ...]
βΈ marks expandable children β keep drilling with py look --at model.layers.0.
Functions and modules:
py look --at math.sqrt
β math.sqrt: builtin_function_or_method (function)
Return the square root of x.
Completions β live from runtime state:
py look --code 'math.sq' --cursor 7
β sqrt function sqrt(x, /)
ctl β control
py ctl --op reset # clear namespace
py ctl --op reset --scope all # clear everything
py ctl --op cancel # cancel running execution
py ctl --op restart # restart interpreter
py ctl --op status # python idle | exec #5 | rev 17 | up 3600s
mcp2cli features you get for free
Because rat-py is just an MCP server, mcp2cli gives you all of this automatically:
mcp2cli py up # background daemon, instant responses
mcp2cli py down # stop
mcp2cli py tools # list tools
mcp2cli py tools run # inspect a tool's schema
mcp2cli py shell # interactive mode with history + tab completion
mcp2cli py doctor # diagnose problems
py run 'x = 42' -o json # JSON output for scripts
Connect from other hosts
Claude Desktop
{
"mcpServers": {
"python": {
"command": "rat-py",
"args": ["--cwd", "/path/to/project"]
}
}
}
Cursor
{
"mcpServers": {
"python": {
"command": "rat-py"
}
}
}
MCP Inspector
rat-py --http --port 8000
# Inspector β Transport: Streamable HTTP β URL: http://127.0.0.1:8000/mcp
Programmatic
from rat_py import create_mcp_server
mcp = create_mcp_server()
mcp.run() # STDIO
For notebook GUIs
Same 3 tools serve notebook UIs through MCP:
- Real-time output:
runstreams stdout/stderr as MCP logging notifications - Completions:
look(code=buffer, cursor=pos)returns typed completion items - Hover/inspect:
look(at=symbol)returns type, value, docstring - Variable explorer:
look()returns variable table;look(at="df")showsβΈexpandable children - Drill-down:
look(at="data.scores.0")navigates dicts, lists, objects
Features
- Persistent state β variables survive between executions
- Real-time streaming β stdout/stderr via MCP notifications (tqdm works)
- Live completions β from actual runtime state
- Symbol inspection β type, value, signature, docstring
- Variable drill-down β navigate dicts, lists, objects via dot syntax
- Interactive input β
input()calls becomerun(input="...")responses - Asset generation β matplotlib figures, HTML output served at
/assets/{id} - Auto venv detection β uses current venv or
VIRTUAL_ENV
Architecture
MCP Client (mcp2cli / Claude Desktop / Cursor / notebook GUI)
β
βββ run(code="...") β execute, stream output
βββ look(at="df") β inspect, complete, overview
βββ ctl(op="reset") β control
β
βΌ
FastMCP Server (mcp_server.py)
β
βΌ
RuntimeService (service.py) β execution lifecycle, event log
β
βΌ
IPythonWorker (worker.py) β Python execution engine (subprocess)
The rat family
Any language runtime
β wrap in MCP (rat-py, rat-r, rat-ju, ...)
MCP Server
β automatic
βββ mcp2cli β CLI
βββ mcp2py β Python library
βββ mcp2r β R library
βββ any MCP host β Claude Desktop, Cursor, notebooks
Same 3 tools β run, look, ctl β for every language. One interface to learn, works everywhere.
