Skip to main content
Glama
helenkwok

Fragment MCP Server

fetch-elements-of-category

Retrieve BIM elements by category from IFC files, enabling structured querying of building information model data with configurable attribute and relation options.

Instructions

Fetch elements of a specified category

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYesCategory name. e.g. IFCWALL
configYesConfiguration for fetching elements

Implementation Reference

  • main.ts:124-146 (handler)
    MCP server tool handler function. Checks if fragments are loaded, calls the core fetchElementsOfCategory helper, and returns the results as JSON text content.
    ({ 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),
          },
        ],
      }
    }
  • Zod schema for tool inputs: category (string) and config (object with attributesDefault, attributes array, and relations for HasAssociations and IsDefinedBy).
    {
      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'),
    },
  • main.ts:102-147 (registration)
    Registration of the 'fetch-elements-of-category' tool using server.tool(), including name, description, schema, and handler.
    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),
            },
          ],
        }
      }
    )
  • Core helper function that implements the logic to fetch elements of a category: gets items matching category regex, filters valid IDs, and retrieves items data with given config.
    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;
    };

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/helenkwok/openbim-mcp'

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