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
| Name | Required | Description | Default |
|---|---|---|---|
| workflow | Yes | Workflow dict to modify | |
| node_id | Yes | Unique node ID (e.g., '1', 'prompt') | |
| node_type | Yes | Node class name | |
| inputs | Yes | Node 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
- src/comfy_mcp_server/tools/__init__.py:23-28 (registration)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