Skip to main content
Glama

send_code_to_revit

Execute custom C# code directly in Autodesk Revit to automate tasks, modify elements, or interact with project data using predefined templates and execution parameters.

Instructions

Send C# code to Revit for execution. The code will be inserted into a template with access to the Revit Document and parameters. Your code should be written to work within the Execute method of the template.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe C# code to execute in Revit. This code will be inserted into the Execute method of a template with access to Document and parameters.
parametersNoOptional execution parameters that will be passed to your code

Implementation Reference

  • The handler function for the 'send_code_to_revit' tool. It prepares parameters, sends the code to the Revit client using withRevitConnection, and returns a success or error message.
    async (args, extra) => { const params = { code: args.code, parameters: args.parameters || [], }; try { const response = await withRevitConnection(async (revitClient) => { return await revitClient.sendCommand("send_code_to_revit", params); }); return { content: [ { type: "text", text: `Code execution successful!\nResult: ${JSON.stringify( response, null, 2 )}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Code execution failed: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
  • Input schema for the tool using Zod: required 'code' string and optional 'parameters' array.
    { code: z .string() .describe( "The C# code to execute in Revit. This code will be inserted into the Execute method of a template with access to Document and parameters." ), parameters: z .array(z.any()) .optional() .describe( "Optional execution parameters that will be passed to your code" ), },
  • Function that registers the 'send_code_to_revit' tool on the MCP server, including name, description, input schema, and handler.
    export function registerSendCodeToRevitTool(server: McpServer) { server.tool( "send_code_to_revit", "Send C# code to Revit for execution. The code will be inserted into a template with access to the Revit Document and parameters. Your code should be written to work within the Execute method of the template.", { code: z .string() .describe( "The C# code to execute in Revit. This code will be inserted into the Execute method of a template with access to Document and parameters." ), parameters: z .array(z.any()) .optional() .describe( "Optional execution parameters that will be passed to your code" ), }, async (args, extra) => { const params = { code: args.code, parameters: args.parameters || [], }; try { const response = await withRevitConnection(async (revitClient) => { return await revitClient.sendCommand("send_code_to_revit", params); }); return { content: [ { type: "text", text: `Code execution successful!\nResult: ${JSON.stringify( response, null, 2 )}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Code execution failed: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } ); }

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

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