Skip to main content
Glama
helenkwok

Fragment MCP Server

convert-ifc-to-frag

Convert IFC BIM files to fragment format for processing and querying building information model data.

Instructions

Convert an IFC file to a .frag file. Needs file-system server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesFull path of the IFC file to convert
outputPathYesFull path where the output .frags file will be saved

Implementation Reference

  • main.ts:24-61 (handler)
    The main tool handler function for 'convert-ifc-to-frag', which performs file existence checks, invokes the core conversion function, and formats the response.
    async ({ inputPath, outputPath }) => {
      if (!fs.existsSync(inputPath)) {
        return {
          content: [
            {
              type: 'text',
              text: 'IFC file not found. Please provide a valid .ifc file path.',
            },
          ],
        }
      }
    
      if (fs.existsSync(outputPath)) {
        return {
          content: [
            {
              type: 'text',
              text: 'Output .frag file already exists. Please call load-frag directly',
            },
          ],
        }
      }
    
     const model = await convertIfcToFragment(inputPath, outputPath)
    
      return {
        content: [
          {
            type: 'text',
            text: `Converted IFC file to .frag format. Output saved to ${outputPath}. Model contains ${
              model.getItemsWithGeometry().length
            } items with geometry: ${JSON.stringify(
              fetchCategoriesWithGeometry(fragments)
            )}`,
          },
        ],
      }
    }
  • main.ts:18-23 (schema)
    Zod schema defining the input parameters for the tool: inputPath and outputPath.
    {
      inputPath: z.string().describe('Full path of the IFC file to convert'),
      outputPath: z
        .string()
        .describe('Full path where the output .frags file will be saved'),
    },
  • main.ts:15-62 (registration)
    Registers the 'convert-ifc-to-frag' tool with MCP server, specifying name, description, schema, and handler.
    server.tool(
      'convert-ifc-to-frag',
      'Convert an IFC file to a .frag file. Needs file-system server',
      {
        inputPath: z.string().describe('Full path of the IFC file to convert'),
        outputPath: z
          .string()
          .describe('Full path where the output .frags file will be saved'),
      },
      async ({ inputPath, outputPath }) => {
        if (!fs.existsSync(inputPath)) {
          return {
            content: [
              {
                type: 'text',
                text: 'IFC file not found. Please provide a valid .ifc file path.',
              },
            ],
          }
        }
    
        if (fs.existsSync(outputPath)) {
          return {
            content: [
              {
                type: 'text',
                text: 'Output .frag file already exists. Please call load-frag directly',
              },
            ],
          }
        }
    
       const model = await convertIfcToFragment(inputPath, outputPath)
    
        return {
          content: [
            {
              type: 'text',
              text: `Converted IFC file to .frag format. Output saved to ${outputPath}. Model contains ${
                model.getItemsWithGeometry().length
              } items with geometry: ${JSON.stringify(
                fetchCategoriesWithGeometry(fragments)
              )}`,
            },
          ],
        }
      }
    )
  • Core helper function that performs the actual IFC to .frag conversion using FRAGS.IfcImporter and saves the output file.
    export const convertIfcToFragment = async (
      inputPath: string,
      outputPath: string
    ) => {
      const ifcFile = await fs.promises.readFile(inputPath)
      const typedArray = new Uint8Array(ifcFile)
      const serializer = new FRAGS.IfcImporter()
      serializer.wasm = {
        path: '/',
        absolute: false,
      }
      const bytes = await serializer.process({ bytes: typedArray, raw: false })
      const model = new FRAGS.SingleThreadedFragmentsModel('model', bytes)
    
      await fs.promises.writeFile(outputPath, bytes)
    
      return model
    }

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