get_selected_elements
Retrieve currently selected elements in Revit, with an option to limit the number of returned elements for focused data extraction.
Instructions
Get elements currently selected in Revit. You can limit the number of returned elements.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of elements to return |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"limit": {
"description": "Maximum number of elements to return",
"type": "number"
}
},
"type": "object"
}
Implementation Reference
- src/tools/get_selected_elements.ts:15-46 (handler)The main handler function for the 'get_selected_elements' MCP tool. It prepares parameters, sends the command to the Revit client using withRevitConnection, and formats the response as text content or handles errors.async (args, extra) => { const params = { limit: args.limit || 100, }; try { const response = await withRevitConnection(async (revitClient) => { return await revitClient.sendCommand("get_selected_elements", params); }); return { content: [ { type: "text", text: JSON.stringify(response, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `get selected elements failed: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- Zod input schema for the tool, defining an optional 'limit' number parameter to restrict the number of returned elements.{ limit: z .number() .optional() .describe("Maximum number of elements to return"), },
- src/tools/get_selected_elements.ts:5-47 (registration)The registration function that adds the 'get_selected_elements' tool to the MCP server, specifying name, description, input schema, and handler. This function is dynamically called from src/tools/register.ts.export function registerGetSelectedElementsTool(server: McpServer) { server.tool( "get_selected_elements", "Get elements currently selected in Revit. You can limit the number of returned elements.", { limit: z .number() .optional() .describe("Maximum number of elements to return"), }, async (args, extra) => { const params = { limit: args.limit || 100, }; try { const response = await withRevitConnection(async (revitClient) => { return await revitClient.sendCommand("get_selected_elements", params); }); return { content: [ { type: "text", text: JSON.stringify(response, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `get selected elements failed: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } ); }