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
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that the tool modifies the workflow (mutation behavior) and returns the modified dict, but it lacks details on permissions, error handling, or side effects. It adds basic context but misses deeper behavioral traits like what happens on invalid inputs or if the node_id already exists.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with the core purpose. The examples are informative but slightly verbose; every sentence earns its place by illustrating usage, though it could be more streamlined without losing clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (4 parameters, nested objects, no output schema, and no annotations), the description is moderately complete. It covers the basics and includes examples, but it lacks details on error conditions, return format beyond 'modified workflow dict', and integration with sibling tools like 'validate_workflow'. For a mutation tool with rich context, it should do more to guide the agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds value by explaining the 'inputs' parameter with examples (e.g., using connections with source_node_id and output_index), clarifying semantics beyond the schema's generic 'Node inputs' description. However, it does not elaborate on 'workflow' or 'node_type' beyond what the schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Add a node to a workflow') and distinguishes it from siblings like 'remove_node' and 'update_node_input'. It specifies the resource (workflow) and verb (add) with precision, making its purpose immediately apparent.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for usage through examples and references to sibling tools (e.g., 'use list_nodes() to find' node types), but it does not explicitly state when NOT to use this tool or name alternatives for similar operations. The guidance is helpful but lacks explicit exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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