Skip to main content
Glama

unity_execute_code

Run C# code inside the Unity Editor with full access to Unity and Editor APIs, returning a small JSON result so you can inspect changes, trigger actions, or query project state.

Instructions

Run C# in the Unity Editor with Unity API access. Return a small JSON result. If an error has executionCompleted=true, the code already ran; inspect its effects before retrying.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesC# code to execute. Must be a valid method body. Access UnityEngine and UnityEditor namespaces. Use 'return' to send data back.
portNoUnity instance port (from unity_select_instance). Always include it when multiple instances run.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv2.35.6
    • changedInput schema / properties / port / description
      Previous value: -"Target Unity instance port for parallel-safe routing. Get this from unity_select_instance. When working with multiple Unity instances, ALWAYS include this parameter."New value: +"Unity instance port (from unity_select_instance). Always include it when multiple instances run."
  2. Addedv2.28.1

TDQS

A3.6/5.0
Behavior3/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 does disclose two important traits: execution happens in the live editor and errors can indicate the code already executed with persistent side effects. However, for an arbitrary-code-execution tool it omits the safety profile entirely — no note on destructive potential, permissions, compile failures, or editor state disruption, which an agent invoking raw C# badly needs.

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?

Three short sentences with zero waste; purpose leads, return shape follows, and the retry hazard is placed last where it is most actionable.

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 2-param tool with full schema coverage and no output schema, the description covers purpose, return format ('small JSON result'), and the key execution/retry gotcha. The remaining gap is the absence of any safety or permission framing for a code-execution tool with no annotations.

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%: 'code' is documented as a method body with namespace access and return semantics, and 'port' explains multi-instance selection. The description adds nothing beyond the schema, so the baseline 3 applies.

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

Purpose4/5

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

States a specific verb ('Run') and resource ('C# in the Unity Editor') plus scope ('with Unity API access'), which clearly separates it from script-focused siblings like unity_script_create or unity_script_update. It never names an alternative tool explicitly, so it stops short of a 5.

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

Usage Guidelines3/5

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

The retry guidance ('if an error has executionCompleted=true, the code already ran; inspect its effects before retrying') is useful operational context, but there is no statement of when to prefer this tool over dedicated siblings (e.g. unity_script_update, unity_component_set_property) or any prerequisite/exclusion. Usage is implied rather than instructed.

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