send_code_to_revit
Execute custom C# code in Autodesk Revit by sending it to the Revit MCP Server. Insert your code into a template to access Revit Document and parameters within the Execute method for precise project modifications.
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
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | 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 | No | Optional execution parameters that will be passed to your code |
Implementation Reference
- src/tools/send_code_to_revit.ts:22-57 (handler)The handler function for the 'send_code_to_revit' tool. It constructs parameters from the input args, uses 'withRevitConnection' to send the 'send_code_to_revit' command to the Revit client, and returns a formatted text response with the result 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) }`, }, ], }; } }
- src/tools/send_code_to_revit.ts:9-21 (schema)Input schema for the 'send_code_to_revit' tool using Zod. Defines 'code' as required 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" ), },
- src/tools/send_code_to_revit.ts:5-59 (registration)The registration function that adds the 'send_code_to_revit' tool to the MCP server, specifying name, description, input schema, and handler. This function is dynamically called from src/tools/register.ts.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) }`, }, ], }; } } ); }