Execute Python
execute_pythonRun Python code in a persistent REPL that retains variables and imports across calls, supports top-level await, and calls MCP tools for batch automation.
Instructions
Persistent Python REPL — use instead of python3 -c, heredocs or
cmd | python3 via Bash. Also the way to BATCH MCP WORK: the injected
mcp bridge reaches your project, global (user-scope) and plugin MCP
servers, so one loop replaces N separate tool calls —
for f in files: mcp.call('telegram-mcp', 'download_media', **f).
State (variables, imports, functions) survives across calls: a warm
call takes ~0.1s vs ~3s for each fresh python3 Bash spawn. Full
filesystem access — open(), absolute paths, and ~ all work. Top-level
await is supported (e.g. await client.get(url) with httpx).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "execute_python"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python code to execute | |
| reset | No | Clear namespace (keeps sh/mcp helpers) | |
| timeout | No | Max execution seconds (default 120). Enforced for real: runaway code is interrupted (KeyboardInterrupt) with namespace state preserved. |