fetch-elements-of-category
Retrieve BIM elements by category from IFC files using the Fragment MCP Server. Fetch specific attributes and relations for elements such as walls, doors, or other predefined categories.
Instructions
Fetch elements of a specified category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | Category name. e.g. IFCWALL | |
| config | Yes | Configuration for fetching elements |
Implementation Reference
- fragments.ts:50-64 (handler)Core handler function that implements the logic to fetch elements of a specified category from the fragments model. It uses safeRegExp to match the category, collects item IDs, and retrieves detailed data using getItemsData.export const fetchElementsOfCategory = ( fragments: FRAGS.SingleThreadedFragmentsModel, category: string, config: Partial<FRAGS.ItemsDataConfig> ) => { const elementsOfCategory = fragments.getItemsOfCategories([ safeRegExp(category), ]); const ids = Object.values(elementsOfCategory) .flat() .filter((id) => id !== undefined && id !== null); const itemsData = fragments.getItemsData(ids, config); return itemsData; };
- main.ts:102-147 (registration)Tool registration using McpServer.tool(), defining the tool name, description, input schema, and handler function that delegates to fetchElementsOfCategory after checking if fragments are loaded.server.tool( 'fetch-elements-of-category', 'Fetch elements of a specified category', { category: z.string().describe('Category name. e.g. IFCWALL'), config: z .object({ attributesDefault: z.boolean(), attributes: z.array(z.string()), relations: z.object({ HasAssociations: z.object({ attributes: z.boolean(), relations: z.boolean(), }), IsDefinedBy: z.object({ attributes: z.boolean(), relations: z.boolean(), }), }), }) .describe('Configuration for fetching elements'), }, ({ category, config }) => { if (!fragments) { return { content: [ { type: 'text', text: 'No fragments loaded. Please call load-frag first.', }, ], } } const itemsData = fetchElementsOfCategory(fragments, category, config) return { content: [ { type: 'text', text: JSON.stringify(itemsData), }, ], } } )
- main.ts:105-123 (schema)Input schema definition for the tool using Zod (z.object), specifying 'category' string and optional 'config' object for attributes and relations.{ category: z.string().describe('Category name. e.g. IFCWALL'), config: z .object({ attributesDefault: z.boolean(), attributes: z.array(z.string()), relations: z.object({ HasAssociations: z.object({ attributes: z.boolean(), relations: z.boolean(), }), IsDefinedBy: z.object({ attributes: z.boolean(), relations: z.boolean(), }), }), }) .describe('Configuration for fetching elements'), },
- utils.ts:3-10 (helper)Helper function safeRegExp used to safely create a RegExp from the category string, escaping special chars and fallback to non-matching regex on error.export const safeRegExp = (pattern: string) => { try { return new RegExp(escapeRegExp(pattern)); } catch { // Intentionally return a regex that matches nothing as a safe fallback return /$^/; } };