Skip to main content
Glama

edit_object

Modify existing 3D objects in FreeCAD when creation tools cannot handle the task. Change object properties and update designs directly through the MCP server interface.

Instructions

Edit an object in FreeCAD. This tool is used when the create_object tool cannot handle the object creation.

Args:
    doc_name: The name of the document to edit the object in.
    obj_name: The name of the object to edit.
    obj_properties: The properties of the object to edit.

Returns:
    A message indicating the success or failure of the object editing and a screenshot of the object.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doc_nameYes
obj_nameYes
obj_propertiesYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary MCP handler for the 'edit_object' tool. Proxies the call to FreeCAD RPC server and handles response with screenshot.
    @mcp.tool()
    def edit_object(
        ctx: Context, doc_name: str, obj_name: str, obj_properties: dict[str, Any]
    ) -> list[TextContent | ImageContent]:
        """Edit an object in FreeCAD.
        This tool is used when the `create_object` tool cannot handle the object creation.
    
        Args:
            doc_name: The name of the document to edit the object in.
            obj_name: The name of the object to edit.
            obj_properties: The properties of the object to edit.
    
        Returns:
            A message indicating the success or failure of the object editing and a screenshot of the object.
        """
        freecad = get_freecad_connection()
        try:
            res = freecad.edit_object(doc_name, obj_name, {"Properties": obj_properties})
            screenshot = freecad.get_active_screenshot()
    
            if res["success"]:
                response = [
                    TextContent(type="text", text=f"Object '{res['object_name']}' edited successfully"),
                ]
                return add_screenshot_if_available(response, screenshot)
            else:
                response = [
                    TextContent(type="text", text=f"Failed to edit object: {res['error']}"),
                ]
                return add_screenshot_if_available(response, screenshot)
        except Exception as e:
            logger.error(f"Failed to edit object: {str(e)}")
            return [
                TextContent(type="text", text=f"Failed to edit object: {str(e)}")
            ]
  • RPC server method for edit_object that queues the GUI-safe edit task.
    def edit_object(self, doc_name: str, obj_name: str, properties: dict[str, Any]) -> dict[str, Any]:
        obj = Object(
            name=obj_name,
            properties=properties.get("Properties", {}),
        )
        rpc_request_queue.put(lambda: self._edit_object_gui(doc_name, obj))
        res = rpc_response_queue.get()
        if res is True:
            return {"success": True, "object_name": obj.name}
        else:
            return {"success": False, "error": res}
  • Core implementation that edits the FreeCAD object properties in the GUI thread, handling special properties like References.
    def _edit_object_gui(self, doc_name: str, obj: Object):
        doc = FreeCAD.getDocument(doc_name)
        if not doc:
            FreeCAD.Console.PrintError(f"Document '{doc_name}' not found.\n")
            return f"Document '{doc_name}' not found.\n"
    
        obj_ins = doc.getObject(obj.name)
        if not obj_ins:
            FreeCAD.Console.PrintError(f"Object '{obj.name}' not found in document '{doc_name}'.\n")
            return f"Object '{obj.name}' not found in document '{doc_name}'.\n"
    
        try:
            # For Fem::ConstraintFixed
            if hasattr(obj_ins, "References") and "References" in obj.properties:
                refs = []
                for ref_name, face in obj.properties["References"]:
                    ref_obj = doc.getObject(ref_name)
                    if ref_obj:
                        refs.append((ref_obj, face))
                    else:
                        raise ValueError(f"Referenced object '{ref_name}' not found.")
                obj_ins.References = refs
                FreeCAD.Console.PrintMessage(
                    f"References updated for '{obj.name}' in '{doc_name}'.\n"
                )
                # delete References from properties
                del obj.properties["References"]
            set_object_property(doc, obj_ins, obj.properties)
            doc.recompute()
            FreeCAD.Console.PrintMessage(f"Object '{obj.name}' updated via RPC.\n")
            return True
        except Exception as e:
            return str(e)
  • Utility function to set properties on FreeCAD objects, with special handling for Placement, Vectors, References, ShapeColor, etc.
    def set_object_property(
        doc: FreeCAD.Document, obj: FreeCAD.DocumentObject, properties: dict[str, Any]
    ):
        for prop, val in properties.items():
            try:
                if prop in obj.PropertiesList:
                    if prop == "Placement" and isinstance(val, dict):
                        if "Base" in val:
                            pos = val["Base"]
                        elif "Position" in val:
                            pos = val["Position"]
                        else:
                            pos = {}
                        rot = val.get("Rotation", {})
                        placement = FreeCAD.Placement(
                            FreeCAD.Vector(
                                pos.get("x", 0),
                                pos.get("y", 0),
                                pos.get("z", 0),
                            ),
                            FreeCAD.Rotation(
                                FreeCAD.Vector(
                                    rot.get("Axis", {}).get("x", 0),
                                    rot.get("Axis", {}).get("y", 0),
                                    rot.get("Axis", {}).get("z", 1),
                                ),
                                rot.get("Angle", 0),
                            ),
                        )
                        setattr(obj, prop, placement)
    
                    elif isinstance(getattr(obj, prop), FreeCAD.Vector) and isinstance(
                        val, dict
                    ):
                        vector = FreeCAD.Vector(
                            val.get("x", 0), val.get("y", 0), val.get("z", 0)
                        )
                        setattr(obj, prop, vector)
    
                    elif prop in ["Base", "Tool", "Source", "Profile"] and isinstance(
                        val, str
                    ):
                        ref_obj = doc.getObject(val)
                        if ref_obj:
                            setattr(obj, prop, ref_obj)
                        else:
                            raise ValueError(f"Referenced object '{val}' not found.")
    
                    elif prop == "References" and isinstance(val, list):
                        refs = []
                        for ref_name, face in val:
                            ref_obj = doc.getObject(ref_name)
                            if ref_obj:
                                refs.append((ref_obj, face))
                            else:
                                raise ValueError(f"Referenced object '{ref_name}' not found.")
                        setattr(obj, prop, refs)
    
                    else:
                        setattr(obj, prop, val)
                # ShapeColor is a property of the ViewObject
                elif prop == "ShapeColor" and isinstance(val, (list, tuple)):
                    setattr(obj.ViewObject, prop, (float(val[0]), float(val[1]), float(val[2]), float(val[3])))
    
                elif prop == "ViewObject" and isinstance(val, dict):
                    for k, v in val.items():
                        if k == "ShapeColor":
                            setattr(obj.ViewObject, k, (float(v[0]), float(v[1]), float(v[2]), float(v[3])))
                        else:
                            setattr(obj.ViewObject, k, v)
    
                else:
                    setattr(obj, prop, val)
    
            except Exception as e:
                FreeCAD.Console.PrintError(f"Property '{prop}' assignment error: {e}\n")
  • Proxy method in FreeCADConnection class that forwards edit_object calls to the XML-RPC server.
    def edit_object(self, doc_name: str, obj_name: str, obj_data: dict[str, Any]) -> dict[str, Any]:
        return self.server.edit_object(doc_name, obj_name, obj_data)
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the tool edits an object and returns a success/failure message with a screenshot, but doesn't disclose behavioral traits like required permissions, whether edits are destructive or reversible, error handling, or rate limits. This is inadequate for a mutation tool with zero annotation coverage.

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 sized and front-loaded, starting with the core purpose. The Args and Returns sections are structured clearly, though the second sentence could be more concise. Overall, it avoids unnecessary verbosity and organizes information effectively.

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

Completeness3/5

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

Given the tool's complexity (3 parameters, nested objects, no annotations) and the presence of an output schema (which covers return values), the description is moderately complete. It explains the purpose, parameters, and returns, but lacks behavioral context and detailed parameter semantics, making it adequate but with clear gaps.

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

Parameters3/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 compensate. It lists the three parameters (doc_name, obj_name, obj_properties) with brief explanations, adding meaning beyond the bare schema. However, it doesn't detail the format or constraints of obj_properties (e.g., what properties are editable), leaving some ambiguity. This partial compensation justifies a baseline score.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Edit an object in FreeCAD.' It specifies the verb ('edit') and resource ('object in FreeCAD'), making the action clear. However, it doesn't explicitly differentiate from siblings like 'get_object' or 'delete_object' beyond mentioning 'create_object' as an alternative, which slightly limits distinction.

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

Usage Guidelines3/5

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

The description provides some usage guidance by stating 'This tool is used when the `create_object` tool cannot handle the object creation,' which implies an alternative context. However, it lacks explicit when-not-to-use scenarios or comparisons to other siblings like 'delete_object' or 'get_object,' leaving gaps in comprehensive guidance.

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/heok-yongssun/freecad-mcp'

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