Skip to main content
Glama
Demolinator

Revit MCP Server

by Demolinator

execute_revit_code

Execute custom IronPython code directly in Revit to automate tasks and access the Revit API when standard tools are insufficient.

Instructions

Execute IronPython code directly in Revit context.

This tool allows you to send IronPython 2.7.12 code to be executed inside Revit. The code has access to:

  • doc: The active Revit document

  • DB: Revit API Database namespace

  • revit: pyRevit module

  • print: Function to output text (returned in response)

Use this when the existing MCP tools cannot accomplish what you need.

Args: code: The IronPython code to execute (as a string) description: Optional description of what the code does ctx: MCP context for logging

Returns: Execution results including any output or errors

Example: code = ''' # encoding: utf-8 # Hello World example print("Hello from Revit!") from pyrevit import revit, DB, forms, script output = script.get_output() output.close_others() doc = revit.doc print("Document title:", doc.Title) print("Number of walls:", len(list(DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_Walls).WhereElementIsNotElementType()))) collector = DB.FilteredElementCollector(doc).OfClass(DB.TextNoteType).ToElements() print("Number of text note types:", len(collector)) '''

Tips for writing IronPython code in Revit:

  1. Accessing Element.Name property: Some Revit elements don't expose the 'Name' property directly in IronPython. Use defensive access patterns:

    Option 1: Use getattr with a default value

    name = getattr(element, 'Name', 'N/A')

    Option 2: Use try-except

    try: name = element.Name except AttributeError: name = 'Unable to retrieve name'

    Option 3: Use BuiltInParameter for element types

    param = element_type.get_Parameter(DB.BuiltInParameter.ALL_MODEL_TYPE_NAME) name = param.AsString() if param else 'N/A'

  2. Always check if elements exist before accessing properties: element = doc.GetElement(element_id) if element: # Safe to access element properties

  3. Use hasattr() before accessing optional properties: if hasattr(element_type, 'FamilyName'): family_name = element_type.FamilyName

  4. The Tool already wraps the code around a transaction.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
descriptionNoCode execution
Behavior5/5

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

Despite no annotations, the description fully discloses behavior: it executes IronPython 2.7.12, wraps code in a transaction, provides access to doc/DB/revit/print, and includes error-handling tips. This is comprehensive.

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 long but well-structured with sections, example, and tips. It could be trimmed slightly, but the content justifies the length for a complex code-execution tool.

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 no annotations or output schema, the description covers purpose, usage, behavioral details, parameter guidance, and even troubleshooting. It feels complete for the tool's complexity.

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?

Schema coverage is 0%, but the description compensates with a detailed example and tips for writing code, adding significant meaning to both parameters beyond the schema.

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 IronPython code in Revit context. It explicitly says to use this when existing MCP tools cannot accomplish what you need, distinguishing it from siblings.

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?

The description provides explicit usage guidance: use when other tools fail. It also lists available objects and gives tips, making it clear when and how to apply the tool.

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/Demolinator/revit-mcp-server'

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