Skip to main content
Glama
pzfreo

build123d-mcp

session_state

Return a structured JSON snapshot of the active build session, including geometry metrics, named objects, snapshots, and variable summaries, to confirm current state after resets or multi-step builds.

Instructions

Return a structured JSON snapshot of the current session: current_shape metrics, all named objects with geometry stats, snapshot names, and a variables summary of the Python namespace (type + volume for shapes, type + length for collections, type + value for scalars). Use this to orient after a reset, restore, or multi-step build to confirm what geometry and variables are active.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'session_state' tool. It collects current_shape metrics and named object diagnostics via _collect(), adds snapshot names, computes a variables summary of the Python namespace, and returns the result as a JSON string.
    def session_state(session) -> str:
        state = _collect(session.current_shape, session.objects)
        state["snapshots"] = list(session.snapshots.keys())
        state["variables"] = _namespace_summary(session.namespace)
        return json.dumps(state, indent=2)
  • _namespace_summary() iterates the user's namespace, filtering out builtins, imported build123d symbols, and private names, then returns a dict with type info (and volume for Shapes, length for collections, value for scalars).
    def _namespace_summary(namespace: dict) -> dict:
        global _BUILD123D_NAMES
        if _BUILD123D_NAMES is None:
            _BUILD123D_NAMES = _build123d_public_names()
    
        _shape_cls: type | None = None
        try:
            from build123d import Shape
            _shape_cls = Shape
        except ImportError:
            pass
    
        result = {}
        for name, val in namespace.items():
            if name.startswith("_") or name in _SKIP:
                continue
            if _is_imported_symbol(val):
                continue
            if name in _BUILD123D_NAMES:
                continue
            try:
                typ = type(val).__name__
                if _shape_cls is not None and isinstance(val, _shape_cls):
                    try:
                        result[name] = {"type": typ, "volume": round(val.volume, 4)}  # type: ignore[attr-defined]
                    except Exception:
                        result[name] = {"type": typ}
                elif isinstance(val, (list, tuple)):
                    result[name] = {"type": typ, "length": len(val)}
                elif isinstance(val, dict):
                    result[name] = {"type": "dict", "length": len(val)}
                elif isinstance(val, bool):
                    result[name] = {"type": "bool", "value": val}
                elif isinstance(val, (int, float)):
                    result[name] = {"type": typ, "value": val}
                elif isinstance(val, str):
                    result[name] = {"type": "str", "value": val[:80]}
                elif callable(val):
                    result[name] = {"type": "function"}
                else:
                    result[name] = {"type": typ}
            except Exception:
                pass
        return result
  • _is_imported_symbol() utility to detect if a namespace value is an imported class/function/module from build123d/cadquery/OCP (not a user-created value).
    def _is_imported_symbol(val) -> bool:
        """Return True if val is a class/function/module imported from build123d, not a user value."""
        if isinstance(val, types.ModuleType):
            return True
        mod = getattr(val, '__module__', '') or ''
        if mod.startswith('build123d') or mod.startswith('cadquery') or mod.startswith('OCP'):
            if isinstance(val, type) or (callable(val) and not isinstance(val, type)):
                return True
        return False
  • _build123d_public_names() helper that introspects the build123d module to get the set of all public names, used to filter them out of the variable summary.
    def _build123d_public_names() -> set[str]:
        try:
            import build123d
            return set(dir(build123d))
        except ImportError:
            return set()
  • _collect() is imported from diff.py. It takes current_shape and objects dict and produces geometry diagnostics (volume, faces, edges, vertices, bbox) for each.
    def _collect(current_shape, objects: dict) -> dict:
        result: dict = {"current_shape": None, "objects": {}}
        if current_shape is not None:
            try:
                result["current_shape"] = _shape_diag(current_shape)
            except Exception as e:
                result["current_shape"] = {"error": str(e)}
        for name, shape in objects.items():
            try:
                result["objects"][name] = _shape_diag(shape)
            except Exception as e:
                result["objects"][name] = {"error": str(e)}
        return result
Behavior4/5

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

With no annotations provided, the description clearly explains the tool's output and purpose. It implies a read-only operation but doesn't explicitly state non-destructive behavior or performance implications. However, the snapshot nature is transparent.

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

Conciseness5/5

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

The description is two sentences long, front-loading the core purpose and then expanding with specific contents and usage scenarios. Every word adds value, making it efficient.

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 has no parameters, no annotations, and an output schema exists, the description fully covers its purpose and usage context. It informs the agent exactly what information the snapshot contains and when to use it, which is sufficient for decision-making among siblings.

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?

The input schema has no parameters, so the description doesn't need to add parameter info. The baseline score of 4 is appropriate as there is nothing to add beyond the schema.

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 states it returns a structured JSON snapshot of the current session with specific metrics, objects, snapshot names, and variables summary. It differentiates from siblings by providing a comprehensive session overview, not just a list of objects.

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 explicitly advises using this tool after a reset, restore, or multi-step build to confirm active geometry and variables. While it doesn't mention when not to use it, the context is clear and helpful for agent decision-making.

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