Skip to main content
Glama

yade_execute_code

Execute Python code synchronously in a running YADE simulation to inspect or modify live state and return stdout, even while a simulation is active.

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 the bridge (its command calls _mcpPyrunnerTick). 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.

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": "yade_execute_code"
  }
}

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.6/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: side effects persist, response is fire-and-return, not pollable, and the three timeout error codes (interrupted/terminated/timeout) are each explained with state-drift consequences. The bridge PyRunner caveat and BaseException warning are non-obvious behaviors an agent would otherwise get wrong.

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 purpose and the key sibling distinction, then structured under 'Typical uses', a PyRunner caveat, and 'Timeout behaviour'. It is long, but nearly every sentence carries an actionable warning; minor redundancy exists between 'fire-and-return' and 'cannot be interrupted or polled'.

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 code-execution tool with an output schema already describing return shape, the description covers everything an agent needs: environment state, persistence, sibling routing, timeout failure modes, and the bridge's own PyRunner engine. Nothing material is missing.

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 coverage is 100%, and the code/timeout parameters are already documented in the schema including the 'longer work belongs in yade_execute_task' note. The description adds no syntax or format guidance for these two parameters beyond what the schema supplies, so 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?

Opens with a specific verb and resource ('Execute Python code synchronously in the running YADE process') and immediately differentiates from yade_execute_task ('fire-and-return', 'NOT tracked by yade_list_tasks'). An agent can pick it without reading 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?

Explicitly names the alternative (yade_execute_task) and the condition selecting it ('anything expected to take more than a few seconds'), plus an explicit exclusion ('do NOT write except BaseException'). Typical-use bullet list grounds when the tool is appropriate.

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