Skip to main content
Glama

insert_part_from_library

Insert pre-designed 3D parts from FreeCAD's library into your CAD project using a relative file path to streamline design assembly.

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
NameRequiredDescriptionDefault
relative_pathYes

Implementation Reference

  • MCP tool handler decorated with @mcp.tool(). Proxies the insertion request to FreeCADConnection RPC client and handles response with screenshot feedback.
    @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 in FreeCAD addon: constructs path to parts library FCStd file and merges it into active 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)
  • RPC server's private GUI-thread-safe method that invokes the parts library insertion function.
    def _insert_part_from_library(self, relative_path): try: insert_part_from_library(relative_path) return True except Exception as e: return str(e)
  • Proxy method in FreeCADConnection class that forwards RPC call to XML-RPC server.
    def insert_part_from_library(self, relative_path: str) -> dict[str, Any]: return self.server.insert_part_from_library(relative_path)
  • The @mcp.tool() decorator registers this function as an MCP tool.
    @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)}") ]

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