Skip to main content
Glama

execute_python

Destructive

Run arbitrary Python inside the live Unreal Editor to query or mutate actors, Blueprints, and assets, and to read world state during Play-in-Editor sessions.

Instructions

Execute Python code inside the running Unreal Editor. DO NOT GUESS A FIELD NAME: most of this tool's errors are "object has no attribute" -- and the field usually EXISTS, just not where you reached for it: HitResult().impact_point raises, get_editor_property cannot find it, and only to_dict() returns it (Transform.translation is the reverse). The engine's own stub and Epic's web docs list it either way, so neither settles it -- ask the object (dir(x), x.to_dict(), x.get_editor_property(...)). PIE TRAP -- this tool is the ONE HOLE in the plugin's PIE guard: the commands that compile a Blueprint or write to disk are REFUSED while Play-in-Editor is live (McpPieSafety.gen.h), but arbitrary Python cannot be classified statically, so a script that reaches compile/save through unreal.* (BlueprintEditorLibrary.compile_blueprint, EditorAssetLibrary.save_asset, save_loaded_asset, anything that dirties a Blueprint) RUNS ANYWAY. With PIE live that ends either in a DEAD EDITOR -- the compiler's UREINST_* trampoline retains a world and CheckForWorldGCLeaks is Fatal, taking every unsaved edit with it -- or in a save that reports success without writing a byte (Editor.AllowSavingAssetsDuringPIE=0). So: call is_play_in_editor_active FIRST whenever your script compiles, saves, or mutates a Blueprint, and stop PIE before running it. READING the live world during PIE is safe and is exactly what this tool is for -- do not avoid it for that. BEFORE writing a loop, check what already answers it in ONE call: scripts that re-implement something a tool already does fail far more often than scripts doing something genuinely new -- hand-rolled scaffolding is where the errors are, and a bug in the scaffold reads exactly like a finding about the game. enumerate actors of a class -> get_actors_by_class. enumerate them AND read their properties, filtered by class or editor label, drilling into one component, with the answering world STAMPED on the result (this tool cannot tell you which world answered) -> get_actor_properties_by_class. read properties off ONE known object -> get_properties / get_property_value. list an actor's components -> get_actor_components. one line trace -> raycast_scene. sample a property across a whole PIE session ARMED BEFORE BeginPlay -- a window a post-tick callback cannot reach at all -> watch_pie_property. But do NOT read this as "always prefer the specific tool": only a minority of scripts are replaceable end-to-end. Python remains the right answer when the script does what those cannot: several classes in one round trip, walking components AND calling a method, filtering by name substring, correlating two values in the same tick, or anything that mutates. Do not trade one call for twelve. WARNING: log_output IS NOT THE LOG OF THE CALL -- it is Python's own prints only (UE fills it from a delegate broadcast solely by unreal.log/log_warning/log_error), so every UE_LOG the ENGINE emits during your script is absent from it. Read engine_log instead: it is the GLog slice bracketed to this call, Warning+Error by default. Example: build_meta_human can run, return None, write zero assets and report a clean log_output while "LogMetaHumanCoreTechLib: Error: Texture Synthesis has not been initialized" sits in GLog. When a call reports success and NOTHING HAPPENED, engine_log is the first place to look; widen with engine_log_level=Log, or pass log_cursor_before to get_output_log_lines(since_sequence_id=...) for the unfiltered rest.

Returns: { command, python_success, execution_mode, command_result, output, log_output, log_line_count, engine_log, engine_log_count, engine_log_truncated, log_cursor_before }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeNoAlias of `command` (same value, same meaning). Accepted because sibling tools spell this parameter differently; prefer `command`.
modeNoExecution mode: ExecuteFile, ExecuteStatement, or EvaluateStatement (default ExecuteFile)
scriptNoAlias of `command` (same value, same meaning). Accepted because sibling tools spell this parameter differently; prefer `command`.
commandNoPython code to run (single or multi-line).
capture_outputNoRun as a file and collect captured log (default true)
engine_log_maxNoMax lines in `engine_log` (default 50, 0 disables, hard cap 4096).
engine_log_levelNoMinimum severity of ENGINE log to return in `engine_log`: Error, Warning (default), Display, Log/All.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.1.0

TDQS

A4.3/5.0
Behavior3/5

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

Annotations already declare destructiveHint=true and openWorldHint=true, so the danger profile is present. The description adds substantial non-redundant context: the PIE guard hole that lets compile/save scripts run and dead-editor consequences, plus the log_output vs engine_log distinction. However, it stops short of stating required permissions or return-shape caveats beyond the field list, so it is rich but not fully exhaustive.

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

Conciseness3/5

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

Front-loaded correctly with the core purpose, but it is extremely long, uses heavy ALL CAPS emphasis, and packs multiple dense warnings into a single description. The content is relevant, but a script this large is hard to parse and could be tightened or structured with clearer sectioning.

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 high-risk arbitrary-execution tool with annotations but no output schema, it covers the critical gaps: the PIE safety trap and required guard calls, the common error pattern, the log interpretation pitfall, and a full enumeration of the return fields. An agent has everything needed to call and interpret it safely.

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 description coverage is 100%, so the baseline is 3. The description goes beyond it by explaining how to use engine_log_level ('widen with engine_log_level=Log') and the semantic meaning of log_output vs engine_log, which changes how the log-related parameters should be interpreted.

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+resource: 'Execute Python code inside the running Unreal Editor.' It then distinguishes this tool from the many specific siblings (get_actors_by_class, get_property_value, raycast_scene, watch_pie_property) and even names the sibling parameter alias issue, so an agent can place it precisely.

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 states when NOT to use it (don't re-implement existing tools in a loop), names the concrete alternative tools for each scenario, AND defends the complementary case ('do NOT read this as always prefer the specific tool... Python remains the right answer when...'). This is textbook when/when-not/alternatives guidance.

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