add_node
Adds nodes to ComfyUI workflows by specifying node types, IDs, and input connections to build or modify automation pipelines.
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
- MCP tool handler for 'add_node': decorated with @mcp.tool(), defines parameters with Pydantic Field descriptions (serving as schema), and implements logic to insert node into workflow dict.@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:27-27 (registration)Within register_all_tools(mcp), calls register_workflow_tools(mcp) which defines and registers the add_node tool.register_workflow_tools(mcp)
- src/comfy_mcp_server/__init__.py:92-92 (registration)Initial registration call from main module: register_all_tools(mcp), which chains to workflow tools registration including add_node.register_all_tools(mcp)
- Supporting method on Workflow Pydantic model for adding nodes, similar logic to the tool handler.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