Skip to main content
Glama

execute_code

Destructive

Run C# code in the Unity Editor to manipulate scenes, assets, and game objects, enabling automated testing and scene adjustments.

Instructions

Execute arbitrary C# code in the Unity Editor context. This is the most powerful tool — it can do anything the Unity Editor API allows.

The code runs with full access to UnityEngine, UnityEditor, System, and all project assemblies.

For simple expressions, just provide the expression (e.g., "Selection.activeGameObject.name"). For multi-statement code, write full C# statements. A return statement determines the output. For void operations, the code runs and any Debug.Log output is captured.

Pre-imported namespaces: System, System.Collections.Generic, System.Linq, System.Reflection, System.IO, UnityEngine, UnityEditor, UnityEditor.SceneManagement, UnityEngine.SceneManagement, UnityEngine.UI

Examples:

  • "PlayerSettings.productName" → returns product name

  • "GameObject.FindObjectsOfType().Length" → returns camera count

  • "var go = new GameObject("MyObject"); return go.name;" → creates object, returns name

  • "Debug.Log("Hello"); return Selection.objects.Length;" → logs + returns count

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesC# code to execute. Can be a single expression, multiple statements, or a full class with an Execute method.
Behavior5/5

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

Annotations indicate destructiveHint=true. Description reinforces this by stating it can do anything the Unity Editor API allows, and provides details on namespaces, execution modes, and capture of Debug.Log output. No contradiction with annotations.

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?

The description is well-structured with key information first (powerful, access) followed by details and examples. It is slightly verbose but every sentence adds value; could be more concise but remains efficient.

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?

Given the tool's power and lack of output schema, the description covers all necessary aspects: how to write code, namespaces, examples, and what outputs to expect. It is fully complete for effective usage.

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

Parameters5/5

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

Only one parameter 'code' with 100% schema coverage. The description adds significant meaning by explaining how the code is evaluated (expression vs statements), the role of return statements, and pre-imported namespaces, going far beyond the schema's basic description.

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 clearly states it executes arbitrary C# code in the Unity Editor context. It distinguishes itself from sibling tools which are specific, targeted operations, making it clear this is the general-purpose code execution tool.

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

Usage Guidelines4/5

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

The description provides clear guidance on how to use it (expression vs multi-statement, examples) and implies it's for tasks not covered by sibling tools. However, it does not explicitly state when NOT to use it or mention alternatives.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/joel-wehr/unity-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server