Skip to main content
Glama

convert-ifc-to-frag

Convert IFC files to .frag format using a file-system server for streamlined processing and querying of BIM data in the Fragment MCP Server.

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:15-62 (registration)
    Registration of the 'convert-ifc-to-frag' MCP tool, including name, description, input schema, and handler function.
    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) )}`, }, ], } } )
  • main.ts:18-23 (schema)
    Zod input schema defining 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:24-61 (handler)
    The inline handler function for the tool, which checks file existence and delegates conversion to the helper function.
    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 IFC to .frag conversion using @thatopen/fragments library.
    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 }

Other Tools

Related Tools

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