Skip to main content
Glama

Execute Python

execute_python

Run 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).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesPython code to execute
resetNoClear namespace (keeps sh/mcp helpers)
timeoutNoMax execution seconds (default 120). Enforced for real: runaway code is interrupted (KeyboardInterrupt) with namespace state preserved.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv2.1.1

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden, and it delivers: state persists across calls, performance characteristics are quantified, full filesystem access is disclosed, and top-level await is supported. The schema further clarifies that timeouts interrupt with KeyboardInterrupt and preserve namespace state.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Dense but purposeful: every sentence adds value, from purpose and alternatives to the MCP batch example and performance claims. Core concepts are front-loaded, and the inline example earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool, coverage is strong: persistence, MCP bridge, filesystem access, await, reset behavior, and timeout semantics are all covered. The only notable gap is that the description does not state what the tool returns (stdout, exceptions, etc.), which matters slightly more given no output schema is present.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, and the schema fully documents code, reset (clears namespace, keeps sh/mcp helpers), and timeout (real enforcement, KeyboardInterrupt, preserved state). The description enriches what code can do (await, mcp bridge) but adds no parameter-specific semantics, so the baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Persistent Python REPL'. It immediately differentiates itself from alternatives like `python3 -c`, heredocs, and `cmd | python3` via Bash, and highlights distinctive features (state persistence, MCP bridge, top-level await).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly says 'use instead of' Bash Python invocations and explains why (persistence and ~0.1s warm vs ~3s spawn). It also declares itself the way to batch MCP work, giving a concrete example, so an agent has clear grounds to select it over alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools