Skip to content

ric-yu/ComfyUI-MCP

Repository files navigation

ComfyUI-MCP

Model Context Protocol (MCP) integration for ComfyUI, enabling workflows to connect to and interact with any MCP-compatible server.

Features

  • 🔌 Connect to MCP Servers: Support for both local (stdio) and remote (SSE) MCP servers
  • 🛠️ Execute Tools: Run any tool exposed by MCP servers with automatic type conversion
  • 📁 Access Resources: Read resources from MCP servers with support for text, JSON, and binary data
  • 🔍 Discovery: Browse available tools and resources with detailed schema information
  • 🔄 Lifecycle Management: Automatic server start/stop with workflow execution
  • 🔁 Retry Logic: Built-in exponential backoff for resilient connections
  • 📊 Progress Tracking: Real-time progress updates during tool execution
  • 🗃️ Result Caching: Leverages ComfyUI's caching system to avoid redundant calls

Installation

  1. Navigate to your ComfyUI custom nodes directory:

    cd ComfyUI/custom_nodes/
  2. Clone or copy the ComfyUI-MCP folder

  3. Install dependencies:

    cd ComfyUI-MCP
    pip install -r requirements.txt
  4. Restart ComfyUI

Nodes

MCP Server Connect

Connects to an MCP server and manages its lifecycle.

Inputs:

  • server_id: Unique identifier for the connection
  • transport: Connection type (stdio or sse)
  • connection_string: Command for stdio or URL for sse
  • action: connect, disconnect, or status
  • command_args: Additional command arguments
  • env_vars: Environment variables (KEY=VALUE format)
  • capture_output: Capture server stdout/stderr

Outputs:

  • server_id: Server identifier
  • status: Connection status
  • info: Detailed server information

MCP Tool Execute

Executes tools on connected MCP servers.

Inputs:

  • server_id: Server to execute tool on
  • tool_name: Name of the tool to run
  • arguments: Tool arguments as JSON
  • retry_count: Number of retry attempts
  • retry_delay: Initial retry delay

Outputs:

  • result: Tool execution result
  • success: Whether execution succeeded
  • error: Error message if failed

MCP Resource Read

Reads resources from MCP servers.

Inputs:

  • server_id: Server to read from
  • resource_uri: URI of the resource
  • output_format: Format (text, json, base64)

Outputs:

  • content: Resource content
  • mime_type: Content MIME type
  • success: Whether read succeeded
  • error: Error message if failed

MCP Discover Tools/Resources

Lists available tools and resources from a server.

Inputs:

  • server_id: Server to query
  • discovery_type: What to discover (tools, resources, both)
  • output_format: Output format (summary, detailed, names_only)

Outputs:

  • discovery_info: Formatted discovery information
  • tools_count: Number of available tools
  • resources_count: Number of available resources
  • status: Discovery status

Example Workflows

Local File System Server

  1. Add "MCP Server Connect" node
  2. Set connection_string to: npx -y @modelcontextprotocol/server-filesystem /path/to/directory
  3. Connect to "MCP Tool Execute" node
  4. Use tool "read_file" with arguments: {"path": "file.txt"}

GitHub Integration

  1. Add "MCP Server Connect" node
  2. Set connection_string to: npx -y @modelcontextprotocol/server-github
  3. Set env_vars to: GITHUB_TOKEN=your_token
  4. Use discovery node to see available tools

Remote MCP Server

  1. Add "MCP Server Connect" node
  2. Set transport to: sse
  3. Set connection_string to server URL
  4. Add authentication token if required

Authentication

For servers requiring authentication:

  • Local servers: Use env_vars to pass tokens
  • Remote servers: ComfyUI will use MCP_AUTH_TOKEN from environment

Debugging

Enable output capture to see server logs:

  • Set capture_output to True in server node
  • Check ComfyUI console for stdout/stderr
  • Use status action to check connection state

Limitations

  • WebSocket transport not yet implemented
  • Dynamic tool discovery (UI updates) not supported
  • Limited to JSON-serializable data types

Development

To extend or modify:

  1. Follow ComfyUI node development guidelines
  2. Maintain compatibility with MCP protocol spec
  3. Test with various MCP server implementations

License

Same as ComfyUI

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published