insert_part_from_library
Add pre-designed parts to your FreeCAD project using a library addon. Specify the part's relative path to integrate it directly into your design.
Instructions
Insert a part from the parts library addon.
Args:
relative_path: The relative path of the part to insert.
Returns:
A message indicating the success or failure of the part insertion and a screenshot of the object.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relative_path | Yes |
Implementation Reference
- src/freecad_mcp/server.py:467-497 (handler)MCP handler for 'insert_part_from_library' tool. Proxies to FreeCADConnection RPC and adds response with optional screenshot.@mcp.tool() def insert_part_from_library(ctx: Context, relative_path: str) -> list[TextContent | ImageContent]: """Insert a part from the parts library addon. Args: relative_path: The relative path of the part to insert. Returns: A message indicating the success or failure of the part insertion and a screenshot of the object. """ freecad = get_freecad_connection() try: res = freecad.insert_part_from_library(relative_path) screenshot = freecad.get_active_screenshot() if res["success"]: response = [ TextContent(type="text", text=f"Part inserted from library: {res['message']}"), ] return add_screenshot_if_available(response, screenshot) else: response = [ TextContent(type="text", text=f"Failed to insert part from library: {res['error']}"), ] return add_screenshot_if_available(response, screenshot) except Exception as e: logger.error(f"Failed to insert part from library: {str(e)}") return [ TextContent(type="text", text=f"Failed to insert part from library: {str(e)}") ]
- Core implementation: merges the specified FCStd part file from the user's parts library into the active FreeCAD document.def insert_part_from_library(relative_path): parts_lib_path = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", "parts_library") part_path = os.path.join(parts_lib_path, relative_path) if not os.path.exists(part_path): raise FileNotFoundError(f"Not found: {part_path}") FreeCADGui.ActiveDocument.mergeProject(part_path)
- src/freecad_mcp/server.py:39-40 (helper)Proxy method in FreeCADConnection class that forwards the call to the XML-RPC server.def insert_part_from_library(self, relative_path: str) -> dict[str, Any]: return self.server.insert_part_from_library(relative_path)
- addon/FreeCADMCP/rpc_server/rpc_server.py:437-441 (registration)RPC server registration of FreeCADRPC instance, which exposes the insert_part_from_library method.rpc_server_instance = SimpleXMLRPCServer( (host, port), allow_none=True, logRequests=False ) rpc_server_instance.register_instance(FreeCADRPC())
- RPC method dispatcher: queues the insertion task for GUI thread safety and returns success/error response.def insert_part_from_library(self, relative_path): rpc_request_queue.put(lambda: self._insert_part_from_library(relative_path)) res = rpc_response_queue.get() if res is True: return {"success": True, "message": "Part inserted from library."} else: return {"success": False, "error": res}