Skip to main content
Glama

unity_run_csharp

Compile and run C# snippets against the live Unity editor using Roslyn. Use custom logic, batch edits, or project-specific types; get compile errors with line numbers to fix and retry.

Instructions

Compile and run a C# snippet against the live editor with Unity's own Roslyn compiler. Use code for a method body (auto-wrapped, return a value to see it) or source for a complete file. Compile errors come back with line numbers so you can fix and retry. This is how you do anything the other tools do not cover: custom logic, batch edits, project-specific types. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "unity_run_csharp"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeNomethod body; returns whatever you `return`. Usings available: System, System.Linq, UnityEngine, UnityEditor, UnityEngine.SceneManagement
typeNoentry type for `source` mode, e.g. My.Ns.Thing
methodNoentry method, default Run
sourceNocomplete C# file instead of `code`
usingsNosemicolon-separated usings to override the defaults
referencesNoextra DLL paths to reference

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4.6/5.0
Behavior4/5

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

No annotations are supplied, so the description carries the full burden and mostly meets it: it discloses auto-wrapping of `code`, that returning a value surfaces it, that compile errors return line numbers for retry, and that the editor is currently offline so calls will fail. The main undisclosed behavior is side-effect scope — whether mutations made by the snippet persist in the live editor or are undoable — which matters greatly for an arbitrary-code tool.

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?

Front-loaded with the action, then mode selection, then failure/recovery behavior, then the availability caveat. No sentence is redundant — even the trailing offline note changes whether an agent should attempt the call.

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 six-parameter, high-power tool with no output schema and no annotations, this covers purpose, modes, error handling, and availability. The gap is the safety/persistence profile of executing arbitrary code against a live editor, which is the one thing an agent would still need to know before calling.

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; the description earns credit above that by explaining the semantics of the two central parameters beyond their schema text — `code` is auto-wrapped and its return value is surfaced, `source` requires an entry type/method pair. It says nothing about `usings` or `references` beyond the schema, which is acceptable since those are fully documented there.

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 ('Compile and run a C# snippet against the live editor') and pins down the mechanism (Unity's Roslyn compiler), which makes it unmistakable against siblings like unity_invoke or unity_create_script.

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 fallback role: 'This is how you do anything the other tools do not cover: custom logic, batch edits, project-specific types.' It also gives the internal alternative rule for its own two modes ('Use `code` for a method body ... or `source` for a complete file'), so an agent can pick a mode without reading the schema.

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