Skip to main content
Glama

add_node

Add nodes to ComfyUI workflows by specifying node types and connections to automate AI image generation processes.

Instructions

Add a node to a workflow.

    Args:
        workflow: Existing workflow dict
        node_id: Unique identifier for this node
        node_type: Node class name (use list_nodes() to find)
        inputs: Input values. For connections use ["source_node_id", output_index].

    Examples:
        # Simple value input
        add_node(wf, "1", "StringInput_fal", {"text": "a cat"})

        # Connection to another node
        add_node(wf, "2", "CLIPTextEncode", {
            "text": "prompt",
            "clip": ["1", 0]  # Connect to node "1" output 0
        })

    Returns the modified workflow dict.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workflowYesWorkflow dict to modify
node_idYesUnique node ID (e.g., '1', 'prompt')
node_typeYesNode class name
inputsYesNode inputs

Implementation Reference

  • The primary handler function for the 'add_node' MCP tool. It adds a new node to the provided workflow dictionary by setting workflow[node_id] = {"class_type": node_type, "inputs": inputs}. Includes input schema via Pydantic Field descriptions and registration via @mcp.tool() decorator.
    @mcp.tool()
    def add_node(
        workflow: dict = Field(description="Workflow dict to modify"),
        node_id: str = Field(description="Unique node ID (e.g., '1', 'prompt')"),
        node_type: str = Field(description="Node class name"),
        inputs: dict = Field(description="Node inputs"),
        ctx: Context = None,
    ) -> dict:
        """Add a node to a workflow.
    
        Args:
            workflow: Existing workflow dict
            node_id: Unique identifier for this node
            node_type: Node class name (use list_nodes() to find)
            inputs: Input values. For connections use ["source_node_id", output_index].
    
        Examples:
            # Simple value input
            add_node(wf, "1", "StringInput_fal", {"text": "a cat"})
    
            # Connection to another node
            add_node(wf, "2", "CLIPTextEncode", {
                "text": "prompt",
                "clip": ["1", 0]  # Connect to node "1" output 0
            })
    
        Returns the modified workflow dict.
        """
        if ctx:
            ctx.info(f"Adding node {node_id}: {node_type}")
    
        workflow[node_id] = {"class_type": node_type, "inputs": inputs}
        return workflow
  • The register_all_tools function which indirectly registers the add_node tool by calling register_workflow_tools(mcp), where the tool is defined.
    def register_all_tools(mcp):
        """Register all tools with the MCP server."""
        register_system_tools(mcp)
        register_discovery_tools(mcp)
        register_workflow_tools(mcp)
        register_execution_tools(mcp)
  • A helper method on the Workflow Pydantic model class that adds a node to the workflow's nodes dict, similar logic to the tool handler but typed.
    def add_node(self, node_id: str, class_type: str, inputs: dict) -> "Workflow":
        """Add a node to the workflow."""
        self.nodes[node_id] = WorkflowNode(class_type=class_type, inputs=inputs)
        return self

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/IO-AtelierTech/comfyui-mcp'

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