Skip to main content
Glama

yade_execute_code

Run Python code synchronously inside the running YADE process to query or modify simulation state in real time, including during active simulations.

Instructions

Execute Python code synchronously in the running YADE process.

Returns stdout immediately. Code runs in the YADE Python environment where yade modules are already imported; side effects persist.

This tool remains responsive EVEN WHILE a simulation task is running (submitted via yade_execute_task). Use it as a live REPL to inspect simulation state in real time — no need to pre-script print statements.

Typical uses:

  • Query simulation state: O.bodies count, current iteration

  • Create/modify bodies, engines, interactions

  • Read or set material properties

  • Live inspection during a running simulation (e.g. check stress tensor, coordination number, energy balance, or capture viewport screenshots when GUI is available)

  • Development and REPL-style testing

O.engines[0] holds a PyRunner that belongs to yade-mcp-bridge (its command mentions "mcp bridge"). Ignore it: assign O.engines as usual, the bridge re-adds the PyRunner before every O.run().

Unlike yade_execute_task, this tool is fire-and-return: the response contains the full output. It is NOT tracked by yade_list_tasks and cannot be interrupted or polled.

Timeout behaviour: on timeout the bridge attempts to abort the running code. The response is an error envelope (ok=false) whose error.code is one of:

  • interrupted — the code was running a simulation cycle (O.run) and was paused cleanly at an iteration boundary. For long simulations or solving to equilibrium, switch to yade_execute_task — it tracks progress and stops cleanly via yade_interrupt_task.

  • terminated — a non-cycle abort succeeded (async exception injection); the pump thread is free, but YADE state may be partially modified by the code that ran before the abort fired. Inspect state before retrying.

  • timeout — abort failed (code stuck in a C extension, or nested inside a running task's PyRunner tick); the bridge may still be blocked. Restart if unresponsive.

WARNING: For anything expected to take more than a few seconds, use yade_execute_task instead — it has proper cancellation via yade_interrupt_task and does not leave state drift on timeout. Also, do NOT write except BaseException: in your code; it defeats bridge-initiated cancellation.

Input Schema

NameRequiredDescriptionDefault
codeYesPython code to execute in YADE process
timeoutNoSeconds before the bridge aborts the snippet; longer work belongs in yade_execute_task.

Output Schema

NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv0.11.2
    • changedInput schema / properties / timeout / description
      Previous value: -"Console execution timeout in seconds"New value: +"Seconds before the bridge aborts the snippet; longer work belongs in yade_execute_task."
    • changedInput schema / properties / timeout / maximum
      Previous value: -600New value: +20
  2. First observedv0.1.0

TDQS

A4.8/5.0
Behavior5/5

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

No annotations exist, so the description carries the full burden and does so thoroughly: fire-and-return semantics, no tracking/polling/interruption, persistent side effects, responsiveness during a running task, and a detailed timeout taxonomy (interrupted / terminated / timeout) with the state-drift consequences of each. It also flags the bridge PyRunner gotcha and the BaseException cancellation pitfall — exactly the behavioral context structured fields cannot convey.

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

Conciseness4/5

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

Front-loaded with the core behavior and well structured via the 'Typical uses' bullets and the labeled timeout codes, so a reader can stop early. It is nonetheless long, and the warning paragraph partially restates the earlier yade_execute_task/abort guidance rather than adding new information.

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

Completeness5/5

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

For a two-parameter code-execution tool with an output schema, everything an agent needs is present: when to use it, when to switch siblings, side-effect persistence, and the failure modes with their remedies. Return values are correctly left to the output schema, and the error-envelope shape is described only where it affects decisions.

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

Parameters4/5

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

Schema coverage is 100%, so the baseline is 3, but the description adds real meaning beyond the schema for timeout: it explains that on expiry the bridge attempts an abort and that the resulting error envelope's code varies by abort outcome, which effectively explains the parameter's consequences. The code parameter itself is only restated at a high level, keeping this below a 5.

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?

States a specific verb and resource ('Execute Python code synchronously in the running YADE process') plus the key scope trait (runs in the live process with yade modules pre-imported, side effects persist). It explicitly contrasts itself with yade_execute_task, so an agent can distinguish it from the nearest sibling without opening any schema.

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?

Provides both positive routing ('use as a live REPL to inspect state during a running simulation', with concrete examples) and negative routing ('for anything expected to take more than a few seconds, use yade_execute_task instead', plus the yade_interrupt_task path). The 'Unlike yade_execute_task ... not tracked by yade_list_tasks' sentence closes the alternative-selection question completely.

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