Skip to main content
Glama

execute_csharp

Run custom C# code inside Revit with direct API access to query or modify the live model, wrapped in an undoable transaction by default.

Instructions

Run any C# code inside Revit with FULL Revit API access (the main tool).

Write a C# script body (statements, optional return value;). Available globals: uiapp (UIApplication), app (Application), uidoc (UIDocument), doc (active Document), print(obj) to add output lines, mm(feet)->mm, ft(mm)->feet, id(long)->ElementId. Namespaces already imported: System, System.Linq, System.Collections.Generic, System.IO, System.Text, Autodesk.Revit.DB (+ .Architecture .Structure .Mechanical .Plumbing .Electrical), Autodesk.Revit.UI(.Selection). Revit internal units are feet. With transaction=true (default) the code runs inside one named transaction that is committed on success and rolled back on any exception; the user can undo it with Ctrl+Z. Use transaction=false for read-only code or when the code opens/closes/saves documents or manages its own transactions. Example: return new FilteredElementCollector(doc).OfClass(typeof(Wall)).Count();

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

Input Schema

NameRequiredDescriptionDefault
codeYes
timeout_sNo
transactionNo
transaction_nameNo

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior5/5

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

With no annotations present, the description carries the full behavioral burden and does so well: it discloses that code runs inside one named transaction committed on success and rolled back on exception, that the user can undo with Ctrl+Z, that internal units are feet, which namespaces are pre-imported, and which globals are exposed. These are exactly the runtime facts an agent needs before emitting arbitrary code.

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-loads the core purpose in the first sentence, then moves through globals, imports, units, and transaction semantics in a scannable progression. Dense but nearly every line adds operational information; only the parenthetical '(the main tool)' is filler.

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 high-complexity arbitrary-code-execution tool, the description covers environment, transaction lifecycle, and units, and an output schema exists so return values need no explanation. The one real gap is the unexplained timeout_s parameter, which matters for long-running Revit scripts.

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 0%, so the description must compensate; it thoroughly explains 'code' (script body with optional `return value;`) and 'transaction' (default true, transactional wrapping). However, 'timeout_s' is never mentioned and 'transaction_name' is only obliquely implied by 'one named transaction', leaving two of four parameters under-specified.

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 ('Run any C# code inside Revit') and immediately scopes capability ('FULL Revit API access'), plus self-identifies as 'the main tool'. An agent can distinguish this from read-oriented siblings like list_elements or get_parameters without inspecting schemas.

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?

Gives explicit conditional guidance for the transaction flag: use transaction=false for read-only code or when the code opens/closes/saves documents or manages its own transactions. It does not explicitly say when to prefer the narrower sibling tools (e.g., list_elements, set_parameters) over raw code execution, leaving that inference to the agent.

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