get_parts_list
Retrieve a comprehensive list of parts from the parts library addon in FreeCAD for streamlined design and assembly processes.
Instructions
Get the list of parts in the parts library addon.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/freecad_mcp/server.py:550-564 (handler)MCP tool handler for 'get_parts_list'. Retrieves the parts list from the FreeCAD RPC server via the connection wrapper and returns it as JSON-formatted text content, or an error message if none found.@mcp.tool() def get_parts_list(ctx: Context) -> list[str]: """Get the list of parts in the parts library addon. """ freecad = get_freecad_connection() parts = freecad.get_parts_list() if parts: return [ TextContent(type="text", text=json.dumps(parts)) ] else: return [ TextContent(type="text", text=f"No parts found in the parts library. You must add parts_library addon.") ]
- src/freecad_mcp/server.py:87-88 (helper)Helper method in FreeCADConnection class that proxies the 'get_parts_list' RPC call to the FreeCAD XML-RPC server.def get_parts_list(self) -> list[str]: return self.server.get_parts_list()
- RPC server method in FreeCADRPC class that delegates to the parts_library.get_parts_list() function.def get_parts_list(self): return get_parts_list()
- Core implementation function that caches and returns a list of relative paths to all .FCStd files in the user's parts_library directory.@cache def get_parts_list() -> list[str]: parts_lib_path = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", "parts_library") if not os.path.exists(parts_lib_path): raise FileNotFoundError(f"Not found: {parts_lib_path}") parts = [] for root, _, files in os.walk(parts_lib_path): for file in files: if file.endswith(".FCStd"): relative_path = os.path.relpath(os.path.join(root, file), parts_lib_path) parts.append(relative_path) return parts