Skip to main content
Glama

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
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 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) }`, }, ], }; } }
  • 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" ), },
  • 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) }`, }, ], }; } } ); }

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

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