Skip to content

Commit a673448

Browse files
committed
docs(openspec): plan Comfy CLI and MCP parity
1 parent 6f033d0 commit a673448

3 files changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Design: comfy-java-sdk CLI and MCP parity
2+
3+
## Architecture
4+
5+
Application
6+
-> ComfyClient
7+
-> ComfyCli -> ComfyCliExecutor -> comfy
8+
-> ComfyMcpClient -> MCP stdio JSON-RPC -> comfy-mcp -> comfy
9+
10+
The Java SDK remains an orchestration/integration SDK. The Python CLI and MCP server stay authoritative for Comfy behavior.
11+
12+
## CLI design
13+
ComfyCli exposes typed methods for documented stable command families and keeps execute(String...) for newly-added or beta options. Option objects use Java 8-compatible mutable builders but support copy construction so high-level helpers never mutate caller-owned options.
14+
15+
Global JSON parsing uses ComfyJsonEnvelope, preserving JsonNode data/error fields to remain forward compatible with the CLI self-describing contract.
16+
17+
GenerateOptions models common stable flags and supports param(name,value) for model-specific beta parameters.
18+
19+
## MCP design
20+
ComfyMcpClient owns exactly one comfy-mcp child process. Lifecycle is NEW -> CONNECTING -> CONNECTED -> CLOSED. A failed connect cleans resources and returns to NEW so callers may retry.
21+
22+
Every JSON-RPC request owns:
23+
- a monotonically increasing id
24+
- one CompletableFuture
25+
- one timeout guard
26+
- one pending-map entry
27+
28+
Completion, timeout, serialization/write failure and close all remove the exact pending entry.
29+
30+
stdout is the MCP protocol channel. stderr is drained concurrently into a capped diagnostic tail so the child cannot deadlock on pipe backpressure.
31+
32+
close() is idempotent, closes stdin, destroys the process, waits a bounded grace interval, escalates to destroyForcibly, fails all pending RPCs and shuts down the scheduler.
33+
34+
## Resource and memory boundaries
35+
- CLI stdout/stderr capture limits are configurable; <=0 means unbounded.
36+
- MCP frame, accumulated content and stderr diagnostic caps are configurable.
37+
- Capped buffers retain a prefix and record truncation instead of growing without bound.
38+
- No long-lived executor exists on the CLI path.
39+
- MCP scheduler is daemon-backed and always shutdown by close().
40+
41+
## Security
42+
- Credentials are expected through environment variables (COMFY_API_KEY, COMFY_BIN); no SDK logging of environment values.
43+
- Arguments are passed as argv without a shell.
44+
- Executable paths are treated as a literal executable, not parsed shell text.
45+
- Network-exposure and spend-consent policy remains enforced by upstream comfy/comfy-mcp.
46+
47+
## Compatibility strategy
48+
The source is kept Java 8 syntax-compatible wherever possible. Branch 3 changes only Jackson imports/API details and Maven/JDK baseline. Tests assert identical command argv and MCP behavior.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Comfy CLI / MCP parity proposal
2+
3+
## Goal
4+
Bring comfy-java-sdk to parity with the documented Comfy CLI and the first-party local comfy-mcp surface while preserving one business contract across feature/1.0.x, feature/2.0.x and feature/3.0.x.
5+
6+
## Sources of truth
7+
- https://docs.comfy.org/agent-tools/cli
8+
- https://docs.comfy.org/comfy-cli/getting-started
9+
- https://docs.comfy.org/comfy-cli/reference
10+
- https://docs.comfy.org/agent-tools/mcp
11+
- https://docs.comfy.org/agent-tools/skills
12+
- https://github.com/Comfy-Org/comfy-cli
13+
- https://github.com/Comfy-Org/comfy-mcp
14+
- https://github.com/Comfy-Org/comfy-skills
15+
- easy-4-java/codex-java-sdk hardening patterns
16+
17+
## Branch contract
18+
All three feature branches expose the same Java-level business operations and tests. Only runtime baseline differences are allowed:
19+
- 1.0.x: Java 8 / Jackson 2
20+
- 2.0.x: Java 17 / Jackson 2
21+
- 3.0.x: Java 21 / Jackson 3 / Maven 4
22+
23+
## Scope
24+
1. Expand typed CLI wrappers for setup, cloud auth, routing, lifecycle, generate, workflows, jobs, templates, nodes, models, transfer, skills and tracking.
25+
2. Preserve raw execute(...) and generic MCP callTool(...) escape hatches.
26+
3. Add JSON envelope parsing and a doctor/environment report.
27+
4. Harden subprocess execution: independent probe timeout, literal executable handling, bounded captures, UTF-8, environment merge.
28+
5. Harden MCP stdio lifecycle: state machine, stderr draining, request timeout cleanup, write-failure cleanup, process reaping and idempotent close.
29+
6. Add typed convenience methods for stable first-party local comfy-mcp tools.
30+
7. Extend MCP content handling beyond text while retaining raw JSON.
31+
8. Add branch-equivalent tests and production-readiness review.
32+
33+
## Non-goals
34+
- Reimplement Comfy CLI business logic in Java.
35+
- Freeze beta partner-model flags. Dynamic model-specific flags remain extensible.
36+
- Replace comfy-mcp with a Java MCP server.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Tasks: comfy-java-sdk CLI / MCP parity
2+
3+
- [ ] T1 Add OpenSpec proposal/design/tasks to all three branches.
4+
- [ ] T2 Fix ComfyCliExecutor probe timeout to use localProbeTimeoutSeconds.
5+
- [ ] T3 Add configurable bounded stdout/stderr capture and truncation metadata.
6+
- [ ] T4 Treat localExecutable as literal argv executable and keep UTF-8 decoding branch-compatible.
7+
- [ ] T5 Expand ComfyCli typed wrappers for setup/cloud/lifecycle/generate/run/jobs/templates/workflow/nodes/models/upload/download/skills/tracking.
8+
- [ ] T6 Add dynamic generate param support and validate per-call --where.
9+
- [ ] T7 Make ComfyClient.generateJson copy options instead of mutating caller input.
10+
- [ ] T8 Add ComfyJsonEnvelope and ComfyDoctorReport plus discoverJson/doctor helpers.
11+
- [ ] T9 Harden ComfyMcpClient lifecycle and duplicate-connect behavior.
12+
- [ ] T10 Drain comfy-mcp stderr with a bounded diagnostic buffer.
13+
- [ ] T11 Remove pending RPCs on timeout, completion and write failure.
14+
- [ ] T12 Reap MCP process on close and keep close idempotent.
15+
- [ ] T13 Add structured ComfyMcpContent while preserving raw result JSON.
16+
- [ ] T14 Add typed convenience methods for core first-party local comfy-mcp tools.
17+
- [ ] T15 Add/extend unit and fake-server E2E tests for every regression.
18+
- [ ] T16 Port identical business behavior to 1.0.x / 2.0.x / 3.0.x with only Jackson/JDK differences.
19+
- [ ] T17 Run full Maven verify on each branch.
20+
- [ ] T18 Run dependency/vulnerability audit and inspect CI.
21+
- [ ] T19 Production readiness review: process/thread/stream/Future cleanup, deadlocks, backpressure, OOM boundaries, command injection, sensitive logging, race conditions and resource leaks.
22+
- [ ] T20 Record branch SHAs, test totals, CI status and residual risks.

0 commit comments

Comments
 (0)