Skip to main content
Glama

create_document

Create a new FreeCAD document by specifying a name to start 3D modeling projects.

Instructions

Create a new document in FreeCAD.

Args:
    name: The name of the document to create.

Returns:
    A message indicating the success or failure of the document creation.

Examples:
    If you want to create a document named "MyDocument", you can use the following data.
    ```json
    {
        "name": "MyDocument"
    }
    ```

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes

Implementation Reference

  • Primary MCP tool handler for 'create_document'. Decorated with @mcp.tool() for registration. Calls FreeCADConnection to create document via RPC and returns success/error text content.
    @mcp.tool()
    def create_document(ctx: Context, name: str) -> list[TextContent]:
        """Create a new document in FreeCAD.
    
        Args:
            name: The name of the document to create.
    
        Returns:
            A message indicating the success or failure of the document creation.
    
        Examples:
            If you want to create a document named "MyDocument", you can use the following data.
            ```json
            {
                "name": "MyDocument"
            }
            ```
        """
        freecad = get_freecad_connection()
        try:
            res = freecad.create_document(name)
            if res["success"]:
                return [
                    TextContent(type="text", text=f"Document '{res['document_name']}' created successfully")
                ]
            else:
                return [
                    TextContent(type="text", text=f"Failed to create document: {res['error']}")
                ]
        except Exception as e:
            logger.error(f"Failed to create document: {str(e)}")
            return [
                TextContent(type="text", text=f"Failed to create document: {str(e)}")
            ]
  • Helper proxy method in FreeCADConnection class that forwards create_document call to the XML-RPC server.
    def create_document(self, name: str) -> dict[str, Any]:
        return self.server.create_document(name)
  • Proxy method in the FreeCADConnection class used by the MCP handler to invoke the RPC call.
    def create_document(self, name: str) -> dict[str, Any]:
        return self.server.create_document(name)
  • Core GUI-thread-safe implementation that creates the new FreeCAD document using FreeCAD.newDocument().
    def _create_document_gui(self, name):
        doc = FreeCAD.newDocument(name)
        doc.recompute()
        FreeCAD.Console.PrintMessage(f"Document '{name}' created via RPC.\n")
        return True
  • RPC server method that queues the document creation task on the GUI thread and returns success/error dict.
    def create_document(self, name="New_Document"):
        rpc_request_queue.put(lambda: self._create_document_gui(name))
        res = rpc_response_queue.get()
        if res is True:
            return {"success": True, "document_name": name}
        else:
            return {"success": False, "error": res}

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