Skip to main content
Glama
pzfreo

build123d-mcp

import_cad_file

Import STEP or STL files as named 3D objects, returning volume, topology, and bounding box for geometry queries and comparison.

Instructions

Import a STEP (.step/.stp) or STL (.stl) file as a named object in the session. path: absolute or relative path to the file. name: name to register the shape under (defaults to the filename stem). The shape becomes both the named object and the current_shape. Returns volume, topology, and bounding box of the imported shape. After importing, use render_view() to visualise the shape, measure() for geometry queries, or shape_compare() to diff against a show() object. Note: STL imports produce a shell (volume=0) rather than a solid — render_view and measure still work, but interference() and boolean operations require a solid. If you have both the original built shape and an imported copy in session.objects, render the imported one by name (e.g. objects='mypart') to avoid Z-fighting artifacts from two co-located shapes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
nameNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core implementation: imports a STEP/STL file, loads geometry via build123d, registers it in session.objects, sets it as current_shape, and returns JSON with volume, topology, and bounding box info.
    def import_cad_file(session, path: str, name: str = "") -> str:
        resolved = os.path.realpath(path)
        if not os.path.isfile(resolved):
            raise ValueError(f"File not found: '{path}'")
        ext = os.path.splitext(resolved)[1].lower()
        if ext not in _ALLOWED_EXTS:
            raise ValueError(f"Expected a .step, .stp, or .stl file, got '{ext}'")
    
        obj_name = name or os.path.splitext(os.path.basename(resolved))[0]
    
        if ext in _STEP_EXTS:
            shape = _load_step(resolved)
            fmt = "step"
        else:
            shape = _load_stl(resolved)
            fmt = "stl"
    
        session.objects[obj_name] = shape
        session.current_shape = shape
    
        bb = shape.bounding_box()
        result = {
            "imported": obj_name,
            "format": fmt,
            "path": resolved,
            "volume": round(shape.volume, 4),
            "faces": len(shape.faces()),
            "edges": len(shape.edges()),
            "vertices": len(shape.vertices()),
            "bbox": {
                "xsize": round(bb.size.X, 4),
                "ysize": round(bb.size.Y, 4),
                "zsize": round(bb.size.Z, 4),
            },
        }
        return json.dumps(result, indent=2)
  • Helper: _load_step loads a STEP file, handling multi-body shapes by fusing them together.
    def _load_step(resolved: str):
        from build123d import import_step as _import_step
    
        imported = _import_step(resolved)
        # Multi-body STEP returns an iterable without a .wrapped attribute
        if hasattr(imported, "__iter__") and not hasattr(imported, "wrapped"):
            shapes = list(imported)
            if not shapes:
                raise ValueError("STEP file contains no geometry")
            shape = shapes[0]
            for s in shapes[1:]:
                shape = shape + s  # type: ignore[assignment]
            return shape
        return imported
  • Helper: _load_stl loads an STL file using build123d's import_stl.
    def _load_stl(resolved: str):
        from build123d import import_stl
        return import_stl(resolved)
  • MCP tool registration: defines the import_cad_file tool with FastMCP @mcp.tool() decorator, delegates to _session.import_cad_file().
    @mcp.tool()
    def import_cad_file(path: str, name: str = "") -> str:
        """Import a STEP (.step/.stp) or STL (.stl) file as a named object in the session. path: absolute or relative path to the file. name: name to register the shape under (defaults to the filename stem). The shape becomes both the named object and the current_shape. Returns volume, topology, and bounding box of the imported shape. After importing, use render_view() to visualise the shape, measure() for geometry queries, or shape_compare() to diff against a show() object. Note: STL imports produce a shell (volume=0) rather than a solid — render_view and measure still work, but interference() and boolean operations require a solid. If you have both the original built shape and an imported copy in session.objects, render the imported one by name (e.g. objects='mypart') to avoid Z-fighting artifacts from two co-located shapes."""
        return _session.import_cad_file(path, name)
  • Worker dispatch: routes the 'import_cad_file' operation string to the handler function from import_step.py.
    if op == "import_cad_file":
        from build123d_mcp.tools.import_step import import_cad_file
        return import_cad_file(session, args["path"], args.get("name", ""))
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description fully covers behavioral traits: the shape becomes both a named object and the current_shape, returns volume/topology/bounding box, STL imports produce a shell (volume=0) instead of a solid (affecting boolean operations), and a Z-fighting advisory for co-located shapes. This is rich and actionable.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately detailed for a file import tool with two formats and STL-specific caveats. Every sentence adds value (format support, parameter explanation, return values, post-import guidance, limitation warnings). It is front-loaded with the core purpose, but slightly verbose in listing all post-import options.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (two file formats, STL limitations, multiple post-import actions), the description is comprehensive. It covers inputs, behavior, return values, and edge cases (STL shell, Z-fighting). The presence of an output schema is noted, but the description already details the returns adequately.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must explain parameters. It clarifies `path` as absolute or relative, and `name` as optional with default to filename stem. This adds meaningful context beyond the schema's bare type definitions, though it could mention the required nature of `path` explicitly.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly identifies the tool as importing STEP or STL files into the session as named objects, specifying file extensions and the resulting object status. It distinguishes from sibling tools like `render_view` or `measure`, which are post-import actions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear post-import workflow hints (e.g., use `render_view` to visualize, `measure` for geometry queries, `shape_compare` for diffing). It warns about STL limitations for interference and boolean operations, and advises against rendering co-located shapes to avoid Z-fighting. However, it does not explicitly contrast with sibling tools like `load_part` for alternative file imports.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/pzfreo/build123d-mcp'

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