Files
ethanfel-ComfyUI-Agent-Bridge/__init__.py
T
ethanfelandClaude Opus 4.8 783a294d43 feat: load nodes even when optional 'mcp' is missing; clearer hint
A missing 'mcp' package made the whole custom_node load fail with
ModuleNotFoundError. Now the Agent Emit/Receive nodes register regardless and the
bridge prints an actionable install hint (with ComfyUI's python path) instead of
crashing. Use __package__ to pick relative vs sys.path import so a broad except
no longer masks a missing-dependency error. Adds a no-mcp load test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 16:23:48 +02:00

47 lines
1.9 KiB
Python

"""ComfyUI-Agent-Bridge: in-graph bridge nodes + MCP server for coding agents."""
import os
import sys
# Import our internal package whether ComfyUI loads us as a package (relative
# imports work) or we're imported standalone (tests). Using __package__ as the
# signal — instead of a broad try/except — avoids masking real errors (e.g. a
# missing dependency) as an import-context problem. The node modules need only
# torch/numpy/Pillow (always present in ComfyUI), not `mcp`.
if __package__:
from .src.nodes.emit import AgentEmit
from .src.nodes.receive import AgentReceive
else:
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from src.nodes.emit import AgentEmit
from src.nodes.receive import AgentReceive
NODE_CLASS_MAPPINGS = {
"AgentEmit": AgentEmit,
"AgentReceive": AgentReceive,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"AgentEmit": "Agent Emit (→ agent)",
"AgentReceive": "Agent Receive (← agent)",
}
# The MCP bridge is optional: it needs the `mcp` package. If that isn't installed
# in ComfyUI's Python, keep the nodes working and tell the user how to enable it.
try:
if __package__:
from .src.bridge import mcp_server
else:
from src.bridge import mcp_server
mcp_server.start_in_background()
except ModuleNotFoundError as exc:
if (exc.name or "").split(".")[0] == "mcp":
print("[comfyui-agent-bridge] MCP bridge disabled: 'mcp' is not installed "
"in ComfyUI's Python. The Agent Emit/Receive nodes still load; "
"enable the bridge with:\n"
f" {sys.executable} -m pip install 'mcp>=1.2.0'")
else:
print(f"[comfyui-agent-bridge] MCP bridge failed to start: {exc}")
except Exception as exc: # never block ComfyUI startup
print(f"[comfyui-agent-bridge] MCP bridge failed to start: {exc}")
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]