# ComfyUI MCP — Future Work

## Node Discovery & Research Agent

**Priority**: High — addresses discoverability gap

### Problem
Users don't know what custom node packs exist for their use case. Finding, evaluating, and understanding nodes is a manual process (browsing the registry, reading READMEs, trial and error).

### Proposed Solution
A `comfy-researcher` agent (or enhanced `comfy-explorer`) that:

1. **Search phase**: Takes a user's problem description (e.g., "I need better face detail in my generations") and:
   - Searches the ComfyUI Registry (`api.comfy.org`) for relevant node packs
   - Cross-references with HuggingFace for related models
   - Checks community forums/GitHub for recommendations

2. **Analyze phase**: For each candidate node pack:
   - Runs `generate_node_skill` to deep-dive into the pack
   - Checks if it's already installed (`/object_info`)
   - Reviews GitHub stars, last update, compatibility
   - Evaluates if it actually solves the user's problem

3. **Recommend phase**: Returns a ranked list with:
   - Why each pack fits (or doesn't)
   - Installation instructions
   - Example workflow snippets showing how to integrate with the user's existing workflow

### Architecture Options

**Option A: Agent-only** — A Claude Code agent (`comfy-researcher.md`) that orchestrates existing tools:
- `search_custom_nodes` (already have)
- `get_node_pack_details` (already have)
- `generate_node_skill` (already have)
- WebSearch + WebFetch for community research
- Pros: Simple, uses existing infrastructure
- Cons: Slow (multiple API calls per session)

**Option B: Agent + Cache** — Same agent but with a skill cache layer:
- Skills generated by `generate_node_skill` are cached at `~/.claude/skills/comfyui-packs/{pack}@{version}/SKILL.md`
- Agent checks cache first before re-analyzing
- Cache hit = instant category/I/O lookup for visualization too
- Compound key: `{registry_id}@{version}` or `{github_owner}/{repo}@{commit_sha}`
- Pros: Fast repeat lookups, shared with visualizer
- Cons: Cache invalidation, storage

**Option C: MCP Resource** — Expose cached skills as MCP resources:
- `comfyui://skills/{pack_name}` returns cached SKILL.md content
- Claude Code auto-loads relevant skills when working with workflows
- Pros: Deep integration, always-available context
- Cons: More complex to implement

### Skill Cache Schema
```
~/.claude/skills/comfyui-packs/
├── comfyui-impact-pack@4.5.0/
│   ├── SKILL.md
│   └── metadata.json  # {version, category_map, output_type_map, cached_at}
├── comfyui-kjnodes@1.2.3/
│   ├── SKILL.md
│   └── metadata.json
└── index.json  # {pack_id: {version, categories: [...], node_count}}
```

### Cache Integration Points
1. **`visualize_workflow`** — Before fetching `/object_info`, check skill cache for category maps
2. **`generate_node_skill`** — Write to cache on generation, skip if cache hit with matching version
3. **`comfy-researcher` agent** — Read cache for instant analysis of previously-seen packs
4. **`comfy-explorer` agent** — Read cache to understand node context when exploring packs

### Next Steps
- [ ] Create `comfy-researcher` agent definition in `plugin/agents/researcher.md`
- [ ] Add skill cache layer to `generate_node_skill` tool
- [ ] Wire cache into `visualize_workflow` for category lookups
- [ ] Add `/comfy-research "better face detail"` slash command
