comfyui-mcp 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +90 -0
- package/CONTRIBUTING.md +137 -0
- package/README.md +17 -4
- package/ROADMAP.md +15 -0
- package/design/remote-and-cloud-modes.md +113 -0
- package/dist/services/download-auth.d.ts +7 -0
- package/dist/services/download-auth.d.ts.map +1 -1
- package/dist/services/download-auth.js +26 -1
- package/dist/services/download-auth.js.map +1 -1
- package/dist/services/download-cache.d.ts +3 -1
- package/dist/services/download-cache.d.ts.map +1 -1
- package/dist/services/download-cache.js +45 -9
- package/dist/services/download-cache.js.map +1 -1
- package/dist/services/health-check.d.ts +6 -0
- package/dist/services/health-check.d.ts.map +1 -0
- package/dist/services/health-check.js +103 -0
- package/dist/services/health-check.js.map +1 -0
- package/dist/services/image-convert.d.ts +29 -0
- package/dist/services/image-convert.d.ts.map +1 -0
- package/dist/services/image-convert.js +218 -0
- package/dist/services/image-convert.js.map +1 -0
- package/dist/services/manifest.d.ts +63 -0
- package/dist/services/manifest.d.ts.map +1 -0
- package/dist/services/manifest.js +333 -0
- package/dist/services/manifest.js.map +1 -0
- package/dist/services/model-resolver.d.ts.map +1 -1
- package/dist/services/model-resolver.js +7 -1
- package/dist/services/model-resolver.js.map +1 -1
- package/dist/services/node-authoring.d.ts +5 -0
- package/dist/services/node-authoring.d.ts.map +1 -1
- package/dist/services/node-authoring.js +56 -0
- package/dist/services/node-authoring.js.map +1 -1
- package/dist/services/node-verify.d.ts +35 -0
- package/dist/services/node-verify.d.ts.map +1 -0
- package/dist/services/node-verify.js +138 -0
- package/dist/services/node-verify.js.map +1 -0
- package/dist/services/registry-client.d.ts.map +1 -1
- package/dist/services/registry-client.js +53 -7
- package/dist/services/registry-client.js.map +1 -1
- package/dist/services/skill-cache.d.ts +26 -0
- package/dist/services/skill-cache.d.ts.map +1 -0
- package/dist/services/skill-cache.js +172 -0
- package/dist/services/skill-cache.js.map +1 -0
- package/dist/services/storage/azure-blob.d.ts +8 -0
- package/dist/services/storage/azure-blob.d.ts.map +1 -0
- package/dist/services/storage/azure-blob.js +146 -0
- package/dist/services/storage/azure-blob.js.map +1 -0
- package/dist/services/storage/hf.d.ts +7 -0
- package/dist/services/storage/hf.d.ts.map +1 -0
- package/dist/services/storage/hf.js +80 -0
- package/dist/services/storage/hf.js.map +1 -0
- package/dist/services/storage/http.d.ts +6 -0
- package/dist/services/storage/http.d.ts.map +1 -0
- package/dist/services/storage/http.js +41 -0
- package/dist/services/storage/http.js.map +1 -0
- package/dist/services/storage/index.d.ts +28 -0
- package/dist/services/storage/index.d.ts.map +1 -0
- package/dist/services/storage/index.js +42 -0
- package/dist/services/storage/index.js.map +1 -0
- package/dist/services/storage/s3.d.ts +12 -0
- package/dist/services/storage/s3.d.ts.map +1 -0
- package/dist/services/storage/s3.js +84 -0
- package/dist/services/storage/s3.js.map +1 -0
- package/dist/services/storage/types.d.ts +22 -0
- package/dist/services/storage/types.d.ts.map +1 -0
- package/dist/services/storage/types.js +2 -0
- package/dist/services/storage/types.js.map +1 -0
- package/dist/services/storage/utils.d.ts +6 -0
- package/dist/services/storage/utils.d.ts.map +1 -0
- package/dist/services/storage/utils.js +39 -0
- package/dist/services/storage/utils.js.map +1 -0
- package/dist/services/storage-upload.d.ts +18 -0
- package/dist/services/storage-upload.d.ts.map +1 -0
- package/dist/services/storage-upload.js +121 -0
- package/dist/services/storage-upload.js.map +1 -0
- package/dist/tools/health-check.d.ts +3 -0
- package/dist/tools/health-check.d.ts.map +1 -0
- package/dist/tools/health-check.js +30 -0
- package/dist/tools/health-check.js.map +1 -0
- package/dist/tools/image-convert.d.ts +3 -0
- package/dist/tools/image-convert.d.ts.map +1 -0
- package/dist/tools/image-convert.js +58 -0
- package/dist/tools/image-convert.js.map +1 -0
- package/dist/tools/image-management.d.ts.map +1 -1
- package/dist/tools/image-management.js +27 -83
- package/dist/tools/image-management.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +10 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/manifest.d.ts +3 -0
- package/dist/tools/manifest.d.ts.map +1 -0
- package/dist/tools/manifest.js +25 -0
- package/dist/tools/manifest.js.map +1 -0
- package/dist/tools/model-management.d.ts.map +1 -1
- package/dist/tools/model-management.js +9 -1
- package/dist/tools/model-management.js.map +1 -1
- package/dist/tools/node-authoring.d.ts.map +1 -1
- package/dist/tools/node-authoring.js +8 -2
- package/dist/tools/node-authoring.js.map +1 -1
- package/dist/tools/node-verify.d.ts +3 -0
- package/dist/tools/node-verify.d.ts.map +1 -0
- package/dist/tools/node-verify.js +42 -0
- package/dist/tools/node-verify.js.map +1 -0
- package/dist/tools/skill-generator.d.ts.map +1 -1
- package/dist/tools/skill-generator.js +16 -3
- package/dist/tools/skill-generator.js.map +1 -1
- package/dist/tools/storage-upload.d.ts +3 -0
- package/dist/tools/storage-upload.d.ts.map +1 -0
- package/dist/tools/storage-upload.js +57 -0
- package/dist/tools/storage-upload.js.map +1 -0
- package/package.json +11 -1
- package/scripts/gen-tool-docs.ts +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,94 @@ All notable changes to this project are documented here. This project adheres to
|
|
|
4
4
|
[Semantic Versioning](https://semver.org/) and the format follows
|
|
5
5
|
[Keep a Changelog](https://keepachangelog.com/).
|
|
6
6
|
|
|
7
|
+
## [0.8.1] - 2026-06-01
|
|
8
|
+
|
|
9
|
+
Bug-fix release picking up upstream contributions from
|
|
10
|
+
[@joaolvivas](https://github.com/joaolvivas)'s fork of comfyui-mcp.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`health_check`** — single-call pre-flight diagnostic that reports
|
|
15
|
+
ComfyUI/Python/PyTorch versions, GPU + VRAM, queue depth, per-category
|
|
16
|
+
`/models` populations (catches empty-dropdown surprises from a
|
|
17
|
+
misconfigured `extra_model_paths.yaml`), and recent errors from
|
|
18
|
+
`/internal/logs`. Read-only. Useful before a long batch or when triaging an
|
|
19
|
+
unexplained failure. Originally contributed by
|
|
20
|
+
[@joaolvivas](https://github.com/joaolvivas) in
|
|
21
|
+
[`joaolvivas/comfyui-mcp-byjlucas@de82ecda`](https://github.com/joaolvivas/comfyui-mcp-byjlucas/commit/de82ecda).
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **`search_custom_nodes`** — `api.comfy.org/nodes` accepts a `search` query
|
|
26
|
+
parameter but ignores it server-side, returning the same paginated default
|
|
27
|
+
list regardless of query. We now fetch a larger window (limit=100) and
|
|
28
|
+
rank-filter client-side by id / name / author / description with a
|
|
29
|
+
popularity boost, so query-relevant packs actually appear. Diagnosed and
|
|
30
|
+
patched by [@joaolvivas](https://github.com/joaolvivas) in
|
|
31
|
+
[`joaolvivas/comfyui-mcp-byjlucas@f066b597`](https://github.com/joaolvivas/comfyui-mcp-byjlucas/commit/f066b597);
|
|
32
|
+
port adds a guard so popularity no longer inflates non-matching packs.
|
|
33
|
+
- **`upload_image` / `upload_video` / `upload_audio`** — HTTP-only.
|
|
34
|
+
Previously these tools fell back to a local filesystem copy if HTTP upload
|
|
35
|
+
failed and `COMFYUI_PATH` was set. When `COMFYUI_PATH` was auto-detected to
|
|
36
|
+
an unrelated install (common for users targeting a remote `--comfyui-url`),
|
|
37
|
+
the fallback wrote the file to the wrong tree and reported success, while
|
|
38
|
+
the remote ComfyUI never received it — the next `LoadImage` then failed
|
|
39
|
+
mysteriously. Now HTTP-only against the connected ComfyUI's
|
|
40
|
+
`/upload/image` endpoint, which works for both local and remote. Diagnosed
|
|
41
|
+
and patched by [@joaolvivas](https://github.com/joaolvivas) in
|
|
42
|
+
[`joaolvivas/comfyui-mcp-byjlucas@089180ad`](https://github.com/joaolvivas/comfyui-mcp-byjlucas/commit/089180ad).
|
|
43
|
+
|
|
44
|
+
## [0.8.0] - 2026-05-26
|
|
45
|
+
|
|
46
|
+
Completes the custom-node authoring lifecycle, adds cloud storage I/O and
|
|
47
|
+
declarative setup, and adds node discovery — all built and reviewed in a
|
|
48
|
+
codex implement→review→fix loop.
|
|
49
|
+
|
|
50
|
+
### Added
|
|
51
|
+
|
|
52
|
+
- **`apply_manifest`** — declarative environment setup from an inline object or
|
|
53
|
+
a JSON/YAML manifest: `pip` packages, `custom_nodes` (registry ids or git URLs
|
|
54
|
+
with `@ref`), and `models`. Idempotent, per-item structured report; `apt`
|
|
55
|
+
entries are accepted but skipped (manual/root). Local-only.
|
|
56
|
+
- **`verify_custom_node`** — the "test" step of the author loop: restarts ComfyUI
|
|
57
|
+
(with a bounded readiness wait) and confirms a pack's `NODE_CLASS_MAPPINGS`
|
|
58
|
+
class_types registered in `/object_info` (a failed import simply never appears).
|
|
59
|
+
- **`scaffold_custom_node`** now also emits `.comfyignore`/`.gitignore` and, with
|
|
60
|
+
`with_ci`, a `.github/workflows/publish_action.yml` (Comfy-Org/publish-node-action).
|
|
61
|
+
- **`convert_image`** — re-encode a generated image (by `asset_id` or output-dir
|
|
62
|
+
path) to PNG/JPEG/WebP via `sharp`; returns inline base64 + optional file write
|
|
63
|
+
(output-dir confined), and reports bytes saved.
|
|
64
|
+
- **Cloud storage** — model downloads may be `s3://` or Azure Blob URLs
|
|
65
|
+
(`download_model` gains `s3` auth); new **`upload_output`** pushes a generated
|
|
66
|
+
output to S3 / Azure / HTTP / Hugging Face and returns URL(s).
|
|
67
|
+
- **`download_model` `auth`** — per-request `bearer`/`basic`/`header`/`query`
|
|
68
|
+
authentication for gated/private hosts (carried over and extended).
|
|
69
|
+
- **`comfy-researcher` agent** — turns a problem statement into ranked custom-node
|
|
70
|
+
pack recommendations (searches the Registry, evaluates, delegates deep dives to
|
|
71
|
+
`comfy-explorer`).
|
|
72
|
+
- **Cached `generate_node_skill`** — read-through cache keyed by source@version
|
|
73
|
+
(`COMFYUI_SKILL_CACHE_DIR`; `refresh` to bypass), so repeat analyses are instant.
|
|
74
|
+
|
|
75
|
+
### Security
|
|
76
|
+
|
|
77
|
+
- `apply_manifest` rejects pip argv-option injection; realpath/symlink-safe path
|
|
78
|
+
containment for manifest model paths, `convert_image`, and upload sources;
|
|
79
|
+
`convert_image` caps source size + sharp pixels.
|
|
80
|
+
- Cloud storage: Azure SAS / AWS presigned secrets redacted from logs/errors;
|
|
81
|
+
Azure URL-vs-env account mismatch rejected; HF-CLI remote-path argv hardening;
|
|
82
|
+
manual redirect handling (no cross-origin auth replay or upload-redirect SSRF).
|
|
83
|
+
|
|
84
|
+
### Fixed
|
|
85
|
+
|
|
86
|
+
- `generate_node_skill` cache resolves the current pack version before lookup
|
|
87
|
+
(no stale docs served after a pack updates) and writes atomically (temp +
|
|
88
|
+
rename with a content-hash check).
|
|
89
|
+
|
|
90
|
+
### Dependencies
|
|
91
|
+
|
|
92
|
+
- Added `yaml` (manifest parsing), `sharp` (image conversion), `@aws-sdk/client-s3`
|
|
93
|
+
and `@azure/storage-blob` (cloud storage). `npm audit`: 0 high vulnerabilities.
|
|
94
|
+
|
|
7
95
|
## [0.7.0] - 2026-05-25
|
|
8
96
|
|
|
9
97
|
Stability + authoring release: hardens model downloads and the ComfyUI process
|
|
@@ -120,6 +208,8 @@ subprocess fallback where the API can't do the job.
|
|
|
120
208
|
|
|
121
209
|
Earlier releases predate this changelog.
|
|
122
210
|
|
|
211
|
+
[0.8.1]: https://github.com/artokun/comfyui-mcp/releases/tag/v0.8.1
|
|
212
|
+
[0.8.0]: https://github.com/artokun/comfyui-mcp/releases/tag/v0.8.0
|
|
123
213
|
[0.7.0]: https://github.com/artokun/comfyui-mcp/releases/tag/v0.7.0
|
|
124
214
|
[0.6.1]: https://github.com/artokun/comfyui-mcp/releases/tag/v0.6.1
|
|
125
215
|
[0.6.0]: https://github.com/artokun/comfyui-mcp/releases/tag/v0.6.0
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Contributing to comfyui-mcp
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in improving **comfyui-mcp** — an MCP server (and Claude Code plugin)
|
|
4
|
+
that lets an AI agent drive [ComfyUI](https://github.com/comfyanonymous/ComfyUI). This guide covers
|
|
5
|
+
the dev setup, project conventions, how to add a tool, and how releases work.
|
|
6
|
+
|
|
7
|
+
By contributing you agree your contributions are licensed under the project's [MIT License](./LICENSE).
|
|
8
|
+
|
|
9
|
+
## Getting started
|
|
10
|
+
|
|
11
|
+
Requirements: **Node ≥ 22** and npm (the repo is committed with `package-lock.json`; npm is the
|
|
12
|
+
supported dev path).
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
git clone https://github.com/artokun/comfyui-mcp
|
|
16
|
+
cd comfyui-mcp
|
|
17
|
+
npm install # builds native deps (better-sqlite3, sharp)
|
|
18
|
+
npm run build # tsc → dist/
|
|
19
|
+
npm test # vitest
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- **`npm run build`** — type-checks and compiles to `dist/` (`tsc`).
|
|
23
|
+
- **`npm run lint`** — type-check only (`tsc --noEmit`).
|
|
24
|
+
- **`npm test`** / **`npm run test:watch`** — the vitest suite.
|
|
25
|
+
- **`npm run dev`** — run the server from source via `tsx`.
|
|
26
|
+
- **`npm run docs:gen`** — regenerate the docs tool reference from the live schemas (see [Docs](#documentation)).
|
|
27
|
+
|
|
28
|
+
> **pnpm users:** pnpm 10 blocks dependency build scripts unless allow-listed. The native deps are
|
|
29
|
+
> already declared in `package.json` `pnpm.onlyBuiltDependencies` (`better-sqlite3`, `sharp`); if you
|
|
30
|
+
> add a dependency that needs a build step at runtime, add it there too.
|
|
31
|
+
|
|
32
|
+
Before opening a PR, make sure **`npm run build` and `npm test` both pass**.
|
|
33
|
+
|
|
34
|
+
## Project layout
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
src/
|
|
38
|
+
tools/ # thin MCP tool wrappers — one registerXxxTools(server) per file
|
|
39
|
+
index.ts # registers every tool group (the one shared wiring file)
|
|
40
|
+
services/ # the actual logic (network, subprocess, filesystem)
|
|
41
|
+
comfyui/ # ComfyUI client + workflow types
|
|
42
|
+
utils/ # errors, logger, shared helpers
|
|
43
|
+
__tests__/ # vitest tests, mirroring the source path
|
|
44
|
+
scripts/ # build/docs/util scripts (gen-tool-docs.ts, postinstall.mjs, …)
|
|
45
|
+
docs/ # Mintlify docs site (tool reference is GENERATED — see below)
|
|
46
|
+
plugin/ # the Claude Code plugin (skills, agents, slash commands, hooks)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Separation of concerns:** business logic lives in `src/services/<name>.ts`; the matching
|
|
50
|
+
`src/tools/<name>.ts` is a thin wrapper that defines the MCP tool and calls the service.
|
|
51
|
+
|
|
52
|
+
## Conventions
|
|
53
|
+
|
|
54
|
+
- **ESM** — this is an ESM package; **relative imports must use the `.js` extension**
|
|
55
|
+
(`import { foo } from "./foo.js"`), even from `.ts` files.
|
|
56
|
+
- **Errors** — throw typed errors from `src/utils/errors.ts` (`ComfyUIError`, `ValidationError`,
|
|
57
|
+
`ProcessControlError`, …) and convert them at the tool boundary with `errorToToolResult(err)`.
|
|
58
|
+
- **Local vs remote** — comfyui-mcp can target a remote ComfyUI (`--comfyui-url`). Tools that need a
|
|
59
|
+
local install must read `config.comfyuiPath` and throw a clear error when it's undefined.
|
|
60
|
+
- **Security** (please respect these — they're enforced in review):
|
|
61
|
+
- Secrets (API tokens, registry keys, cloud credentials) travel in **headers or env**, never in
|
|
62
|
+
URLs, argv, or logs. Redact secrets from any logged URL.
|
|
63
|
+
- Validate filesystem paths against traversal/symlink escapes (resolve + contain to the intended root).
|
|
64
|
+
- Validate values that reach a subprocess argv (reject leading `-` / control chars; use
|
|
65
|
+
`--end-of-options` for git, etc.).
|
|
66
|
+
|
|
67
|
+
## Adding a new MCP tool
|
|
68
|
+
|
|
69
|
+
Use `src/tools/registry-search.ts` and `src/tools/process-control.ts` as canonical examples.
|
|
70
|
+
|
|
71
|
+
1. **Service** — add `src/services/<name>.ts` with the logic and an exported function. Keep network
|
|
72
|
+
in `fetch`, subprocess in `node:child_process`. Make I/O seams injectable so they're testable.
|
|
73
|
+
2. **Tool** — add `src/tools/<name>.ts` exporting `registerXxxTools(server: McpServer): void`. Inside,
|
|
74
|
+
call `server.tool(name, description, zodShape, handler)`. Handlers return
|
|
75
|
+
`{ content: [{ type: "text" as const, text }] }` and wrap failures with `errorToToolResult(err)`.
|
|
76
|
+
3. **Wire it** — add one import and one `registerXxxTools(server);` call in `src/tools/index.ts`,
|
|
77
|
+
**before** `await registerAutoloadedWorkflows(server);`.
|
|
78
|
+
4. **Categorize for docs** — add the new tool name to the right category in
|
|
79
|
+
`scripts/gen-tool-docs.ts` (`CATEGORIES`), then run `npm run docs:gen` (it warns about any
|
|
80
|
+
uncategorized tool).
|
|
81
|
+
5. **Test** — add `src/__tests__/…` mirroring the source path. Mock `global.fetch`,
|
|
82
|
+
`node:child_process`, and `node:fs` — **no real network, disk, or process side effects**.
|
|
83
|
+
|
|
84
|
+
### Tool descriptions matter
|
|
85
|
+
|
|
86
|
+
Descriptions are the agent's only guide to a tool. Write them to answer three questions:
|
|
87
|
+
**what it does to the world** (read-only? mutates disk? requires a running server? irreversible?),
|
|
88
|
+
**when to use it vs. a sibling tool**, and **what each parameter means beyond its type**. Don't just
|
|
89
|
+
restate the schema. (This is graded by Glama's TDQS — see the [blog post](https://comfyui-mcp.artokun.io/docs/blog/comfyui-mcp-tdqs-case-study).)
|
|
90
|
+
|
|
91
|
+
## Documentation
|
|
92
|
+
|
|
93
|
+
The hosted docs live in `docs/` (Mintlify). The **Tool Reference is generated** from the live tool
|
|
94
|
+
schemas — **do not hand-edit `docs/tools/*.mdx`**. After changing any tool (name, description,
|
|
95
|
+
params), run:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npm run docs:gen
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
and commit the regenerated MDX. Guide pages (`docs/*.mdx`) are hand-written; edit those directly.
|
|
102
|
+
Run `cd docs && npx mint broken-links` to validate links.
|
|
103
|
+
|
|
104
|
+
## Optional / experimental dependencies
|
|
105
|
+
|
|
106
|
+
Cloud storage (`@aws-sdk/client-s3`, `@azure/storage-blob`) and the experimental agent-panel POC
|
|
107
|
+
(`ai`, `@ai-sdk/*`, `cloudflared`) power optional/flag-gated features. Keep new heavy or
|
|
108
|
+
feature-specific dependencies out of the core hot path, and prefer lazy/dynamic imports so a base
|
|
109
|
+
install stays lean.
|
|
110
|
+
|
|
111
|
+
## Commits & pull requests
|
|
112
|
+
|
|
113
|
+
- **Branch** off `main` (`feat/…`, `fix/…`, `docs/…`).
|
|
114
|
+
- Use **Conventional Commit** prefixes (`feat:`, `fix:`, `docs:`, `chore:`, `test:`, `refactor:`).
|
|
115
|
+
- Keep PRs focused; include tests for behavior changes.
|
|
116
|
+
- **PR checklist:** `npm run build` ✓ · `npm test` ✓ · docs regenerated if tools changed ✓ ·
|
|
117
|
+
a clear description of what and why.
|
|
118
|
+
|
|
119
|
+
Open a GitHub issue first for large or potentially-breaking changes so we can align on the approach.
|
|
120
|
+
|
|
121
|
+
## Releases (maintainers)
|
|
122
|
+
|
|
123
|
+
Releases are automated — **never `npm publish` manually**. Bump + tag, and pushing the `v*` tag
|
|
124
|
+
triggers the GitHub Actions workflow that publishes to npm with provenance (OIDC):
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npm run release # patch
|
|
128
|
+
npm run release:minor # minor
|
|
129
|
+
npm run release:major # major
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Each script runs `npm version <bump>` (creating the commit + tag) and `git push --follow-tags`.
|
|
133
|
+
Update `CHANGELOG.md` (Keep a Changelog) and regenerate docs before tagging.
|
|
134
|
+
|
|
135
|
+
## Questions
|
|
136
|
+
|
|
137
|
+
Open a [GitHub issue](https://github.com/artokun/comfyui-mcp/issues) or start a discussion. Thanks for contributing! 🎨
|
package/README.md
CHANGED
|
@@ -641,10 +641,11 @@ Use `/comfy:install <pack>` to install missing node packs from the registry. The
|
|
|
641
641
|
|
|
642
642
|
## Contributing
|
|
643
643
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
644
|
+
Contributions are welcome! See **[CONTRIBUTING.md](./CONTRIBUTING.md)** for the dev setup, project
|
|
645
|
+
conventions, how to add an MCP tool, and the release process.
|
|
646
|
+
|
|
647
|
+
Quick version: fork → branch (`feat/my-feature`) → make changes (ensure `npm run build` and
|
|
648
|
+
`npm test` pass; run `npm run docs:gen` if you touched tools) → open a PR.
|
|
648
649
|
|
|
649
650
|
---
|
|
650
651
|
|
|
@@ -658,6 +659,18 @@ MIT — see [LICENSE](./LICENSE) for details.
|
|
|
658
659
|
|
|
659
660
|
The full, structured changelog lives in [CHANGELOG.md](./CHANGELOG.md). Recent highlights:
|
|
660
661
|
|
|
662
|
+
### 0.8.0 — 2026-05-26
|
|
663
|
+
|
|
664
|
+
**Lifecycle + I/O + discovery.**
|
|
665
|
+
|
|
666
|
+
- **`apply_manifest`** — declarative env setup (pip / custom_nodes / models) from an inline or JSON/YAML manifest; idempotent.
|
|
667
|
+
- **`verify_custom_node`** — restart + `/object_info` load-check that a scaffolded/installed pack's node types actually registered.
|
|
668
|
+
- **`scaffold_custom_node`** — now also emits `.comfyignore`/`.gitignore` and (with `with_ci`) a GitHub publish workflow.
|
|
669
|
+
- **`convert_image`** — re-encode outputs to PNG/JPEG/WebP via `sharp`.
|
|
670
|
+
- **Cloud storage** — `s3://` / Azure-Blob model downloads + a new **`upload_output`** (S3/Azure/HTTP/HF).
|
|
671
|
+
- **`comfy-researcher` agent** — problem → ranked custom-node recommendations; **`generate_node_skill`** is now cached (source@version).
|
|
672
|
+
- **Security** — pip/argv-injection guards, realpath/symlink-safe path containment, cloud-credential + SAS/presigned redaction, redirect-SSRF hardening.
|
|
673
|
+
|
|
661
674
|
### 0.7.0 — 2026-05-25
|
|
662
675
|
|
|
663
676
|
**Stability + authoring.**
|
package/ROADMAP.md
CHANGED
|
@@ -10,6 +10,21 @@ Comfy Registry.
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
+
## Status — 2026-05-26
|
|
14
|
+
|
|
15
|
+
- **Released:** `0.7.0` on npm — Theme E stability/hardening (E1–E4, E7, E2-auth), custom-node
|
|
16
|
+
authoring tools, experimental agent-panel backend, hosted docs.
|
|
17
|
+
- **Complete (on main, unreleased → queued for `0.8.0`):** Theme E additive (E5 `apply_manifest`,
|
|
18
|
+
E6/E2b cloud storage, E8 `convert_image`), Theme C (C3 `verify_custom_node`, C5 scaffold CI),
|
|
19
|
+
Theme D (D1 `comfy-researcher` + skill cache). **Epics A, C, D, E are closed.**
|
|
20
|
+
- **Pending release:** cut **`0.8.0`** for the unreleased surface above — `comfyui-mcp-yrp` (see beads).
|
|
21
|
+
- **Blocked:** **Theme B** (embedded agent panel UI, B3–B6) is gated on the upstream
|
|
22
|
+
**`@comfyorg/extension-api`** package being published to npm (PRs #12142–#12145 still open). The
|
|
23
|
+
panel *backend* POC (B1/B2) already shipped. Tracked by a watch bead under Epic B; resume the
|
|
24
|
+
codex build loop on B once the package lands.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
13
28
|
## ✅ Shipped (0.6.x)
|
|
14
29
|
- comfy-cli capability port (custom-node mgmt, snapshots, bisect, workflow deps, install/update,
|
|
15
30
|
models, workspace/env, API nodes, manager config) — tools surface ~70+.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Design — Remote ComfyUI and Comfy Cloud modes
|
|
2
|
+
|
|
3
|
+
**Status:** Draft, 2026-06-01
|
|
4
|
+
**Beads:** `comfyui-mcp-m1p` (Comfy Cloud evaluation)
|
|
5
|
+
**Sources surveyed:**
|
|
6
|
+
- `picoSols/comfyui-cloud-mcp` — added Comfy Cloud (`cloud.comfy.org`) as a deployment target
|
|
7
|
+
- `joaolvivas/comfyui-mcp-byjlucas` — HTTP-first refactor of file-bound tools for remote setups
|
|
8
|
+
|
|
9
|
+
## Why this doc
|
|
10
|
+
|
|
11
|
+
Today `comfyui-mcp` is **local-first**: many tools need `config.comfyuiPath` (process control, model removal, manifest, install, etc.) and the rest reach a "ComfyUI" identified by host:port. Two forks have independently pushed the project toward two related but distinct deployment shapes:
|
|
12
|
+
|
|
13
|
+
1. **Remote ComfyUI** — user runs ComfyUI on a RunPod / server / VPS, reaches it via `--comfyui-url`. The HTTP API works; filesystem and process control do not. Today some of our "remote-friendly" tools still have local-filesystem fallbacks that hide failures.
|
|
14
|
+
2. **Comfy Cloud** — `cloud.comfy.org` exposes a ComfyUI-shaped REST API (no WebSocket, no `/internal/logs`, no process control) authenticated with `X-API-Key`. Users in this mode don't have a "ComfyUI process" at all.
|
|
15
|
+
|
|
16
|
+
We have a strategic decision to make: do we want to be the canonical MCP for **all three** (local, remote, cloud), or stay opinionated about local-first?
|
|
17
|
+
|
|
18
|
+
## Survey: picoSols Comfy Cloud fork
|
|
19
|
+
|
|
20
|
+
PR-equivalent: `picoSols/comfyui-cloud-mcp@7a812069` (feat: Comfy Cloud API support).
|
|
21
|
+
|
|
22
|
+
### Architecture they shipped
|
|
23
|
+
|
|
24
|
+
- Added `comfyuiApiKey` + `comfyuiCloudUrl` to `configSchema`. New env vars: `COMFYUI_API_KEY`, `COMFYUI_CLOUD_URL` (defaults to `https://cloud.comfy.org`).
|
|
25
|
+
- `isCloudMode(): boolean` — returns `!!parsedConfig.comfyuiApiKey`. Acts as the dispatch switch.
|
|
26
|
+
- In cloud mode, **skip local port auto-detection** entirely (no `detectComfyUIPort` call).
|
|
27
|
+
- New file `src/comfyui/cloud-client.ts` (~346 LOC) — re-implements the surface area that `src/comfyui/client.ts` exposes (enqueue, history, system stats, queue, interrupt, view, object info, samplers/schedulers/checkpoints/loras/vaes/upscalers/logs) against `cloud.comfy.org` using `X-API-Key` headers and raw `fetch`.
|
|
28
|
+
- `src/comfyui/client.ts` becomes a **dispatcher**:
|
|
29
|
+
- Functions that have a cloud equivalent get an `if (isCloudMode()) return cloudClient.fn(...)` prologue.
|
|
30
|
+
- Functions that fundamentally can't work in cloud mode (`getClient`, `connectClient`, `ensureConnected` — anything WebSocket-bound) call `requireLocalMode("op")` that throws `ComfyUIError("CLOUD_UNSUPPORTED")`.
|
|
31
|
+
- `JobWatcher` gate: WebSocket attach is wrapped in `if (!isCloudMode())`. Cloud mode falls through to the existing HTTP-polling path that the local watcher already uses as a fallback.
|
|
32
|
+
|
|
33
|
+
### What's missing / opinionated
|
|
34
|
+
|
|
35
|
+
- No model-management tools touched. In cloud mode, models are pre-provisioned by Comfy-Org — `download_model`, `remove_model`, `list_local_models` should either be no-ops or surface a cloud-specific listing endpoint.
|
|
36
|
+
- No `/internal/logs` equivalent in cloud — picoSols returns `[]`. Our `health_check` (just landed from João Lucas) would degrade gracefully there.
|
|
37
|
+
- No process control coverage — the fork doesn't say what happens, but our `requireLocalMode` shim would correctly reject `start_comfyui`/`stop_comfyui`/`restart_comfyui`/`install_comfyui`/`apply_manifest`/etc.
|
|
38
|
+
|
|
39
|
+
## Survey: João Lucas remote-HTTP refactor
|
|
40
|
+
|
|
41
|
+
PR-equivalents:
|
|
42
|
+
- `joaolvivas/comfyui-mcp-byjlucas@089180ad` — `upload_image` HTTP-only (removed deceptive filesystem fallback)
|
|
43
|
+
- `joaolvivas/comfyui-mcp-byjlucas@e2ae39c8` — same pattern across `image-management.ts` + `model-resolver.ts`
|
|
44
|
+
|
|
45
|
+
### The deceptive-fallback bug
|
|
46
|
+
|
|
47
|
+
Current `src/tools/image-management.ts:104-119` (and `upload_video` / `upload_audio` mirrors at L:208–230):
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
try {
|
|
51
|
+
// HTTP first (works remote)
|
|
52
|
+
const result = await uploadImageAuto(...);
|
|
53
|
+
return success;
|
|
54
|
+
} catch (httpErr) {
|
|
55
|
+
// Fallback: filesystem copy if COMFYUI_PATH is set
|
|
56
|
+
const result = await uploadImage(...);
|
|
57
|
+
return success; // ← LIES when COMFYUI_PATH is auto-detected stale
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The auto-detection in `config.ts` happily resolves `~/ComfyUI` or `/opt/ComfyUI` even when the user is targeting a remote `--comfyui-url`. If HTTP fails (server down, wrong URL, network blip), the fallback writes the file into an **unrelated local install** and returns "success" — but the remote ComfyUI the agent will actually `enqueue` against never received the file. The next workflow run fails with "LoadImage: file not found" and the agent has no breadcrumb back to the upload step.
|
|
62
|
+
|
|
63
|
+
João's fix: drop the fallback entirely. HTTP-only, fail loud. His tool description updates to "Works with both local and remote ComfyUI instances" (because the local HTTP endpoint of course also works).
|
|
64
|
+
|
|
65
|
+
**Recommendation:** Pull this in, separately from cloud support, as a 0.8.1 fix. Affects three tools: `upload_image`, `upload_video`, `upload_audio`.
|
|
66
|
+
|
|
67
|
+
### Other João changes in scope
|
|
68
|
+
|
|
69
|
+
- `model-resolver.ts` (+37/-7) — likely makes model-existence checks remote-friendly (instead of `existsSync(localPath)`, ask ComfyUI via `/object_info` or `/models/{cat}`). Worth a closer read before deciding whether to port.
|
|
70
|
+
- `client.ts` (+70/-1) — HTTP-first paths for things we currently do filesystem-first.
|
|
71
|
+
- Partner-node auto-inject `api_key_comfy_org` (4b989e47) — comparison vs our existing `COMFY_API_KEY → extra_data` mechanism from 0.6.0. Likely duplicative.
|
|
72
|
+
|
|
73
|
+
## Proposed direction
|
|
74
|
+
|
|
75
|
+
### Three modes, three roles
|
|
76
|
+
|
|
77
|
+
| Mode | How user opts in | Local FS? | Process control? | WebSocket? | Process tools should… |
|
|
78
|
+
|---|---|---|---|---|---|
|
|
79
|
+
| **Local** | `COMFYUI_PATH` set or auto-detected | yes | yes | yes | work |
|
|
80
|
+
| **Remote** | `--comfyui-url` and no FS path (or FS path explicitly cleared) | no | no | yes | throw "remote-only target" |
|
|
81
|
+
| **Cloud** | `COMFYUI_API_KEY` set | no | no | no | throw "cloud-only target" |
|
|
82
|
+
|
|
83
|
+
Today we conflate "local" and "remote" because auto-detection silently fills in a local `COMFYUI_PATH` that may not match the `--comfyui-url` target. That's the root cause of João's deceptive-fallback bug.
|
|
84
|
+
|
|
85
|
+
### Phased adoption
|
|
86
|
+
|
|
87
|
+
**Phase 1 — Pull the bug fixes (no architecture change).** [0.8.1 patch]
|
|
88
|
+
- João's `upload_image`/`upload_video`/`upload_audio` HTTP-only fix.
|
|
89
|
+
- Read `model-resolver.ts` diff and decide on remote-aware model checks.
|
|
90
|
+
- Credit @joaolvivas in CHANGELOG.
|
|
91
|
+
|
|
92
|
+
**Phase 2 — Explicit remote mode.** [0.9.0]
|
|
93
|
+
- Add a `--remote-only` / `COMFYUI_REMOTE_ONLY=true` flag that suppresses `COMFYUI_PATH` auto-detection.
|
|
94
|
+
- All local-only tools (process control, install, manifest, model removal, model download cache materialization) check `config.comfyuiPath` and throw a clear `ProcessControlError("remote target — tool requires a local install path")` instead of silently degrading.
|
|
95
|
+
- Document the three modes explicitly in `docs/configuration.mdx`.
|
|
96
|
+
|
|
97
|
+
**Phase 3 — Comfy Cloud first-class.** [0.9.0 stretch or 0.10.0]
|
|
98
|
+
- Adopt picoSols's `isCloudMode()` + `cloud-client.ts` shape.
|
|
99
|
+
- Build the feature-parity matrix (which tools work in cloud? which throw?).
|
|
100
|
+
- Decide cloud-model-listing API (does `cloud.comfy.org` expose pre-provisioned model lists? if yes, wire `list_local_models` to it).
|
|
101
|
+
- Consider reaching out to Comfy-Org about a partnership listing.
|
|
102
|
+
- Credit @picoSols in CHANGELOG; consider co-authorship in commits.
|
|
103
|
+
|
|
104
|
+
### Open questions for the maintainer
|
|
105
|
+
|
|
106
|
+
1. Do we want to commit to cloud support? Strategic: it makes `comfyui-mcp` the right MCP for anyone using Comfy Cloud, which broadens the audience but also makes us a partner-of-record. If yes, an outreach to Comfy-Org alongside the implementation feels right.
|
|
107
|
+
2. For Phase 2's explicit remote mode — do we silently fix the auto-detection (don't fill in `COMFYUI_PATH` if `--comfyui-url` is a non-loopback host) or require users to opt in?
|
|
108
|
+
3. For the `upload_*` fix: ship as 0.8.1 patch alongside the search/health fixes from `df8050e`, or wait for the bigger 0.9.0 mode rework?
|
|
109
|
+
|
|
110
|
+
## Attribution
|
|
111
|
+
|
|
112
|
+
- **Comfy Cloud architecture, dispatch pattern, cloud-client.ts shape:** [@picoSols](https://github.com/picoSols) — `picoSols/comfyui-cloud-mcp@7a812069` (2026-03-25).
|
|
113
|
+
- **HTTP-first refactor + deceptive-fallback diagnosis:** [@joaolvivas](https://github.com/joaolvivas) — `joaolvivas/comfyui-mcp-byjlucas@089180ad` and `@e2ae39c8` (2026-05-12).
|
|
@@ -13,6 +13,13 @@ export type DownloadAuth = {
|
|
|
13
13
|
type: "query";
|
|
14
14
|
query_param: string;
|
|
15
15
|
query_value: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "s3";
|
|
18
|
+
access_key_id: string;
|
|
19
|
+
secret_access_key: string;
|
|
20
|
+
session_token?: string;
|
|
21
|
+
region?: string;
|
|
22
|
+
endpoint?: string;
|
|
16
23
|
};
|
|
17
24
|
export interface DownloadRequestAuth {
|
|
18
25
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download-auth.d.ts","sourceRoot":"","sources":["../../src/services/download-auth.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"download-auth.d.ts","sourceRoot":"","sources":["../../src/services/download-auth.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC3D;IACE,IAAI,EAAE,IAAI,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEN,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAyDD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,oBAAoB,GAAE,MAAM,EAAO,GAClC,MAAM,CAcR;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,YAAY,GAClB,mBAAmB,CAuCrB"}
|
|
@@ -3,6 +3,8 @@ const TOKEN_QUERY_RE = /token|key|secret|signature|auth|password|credential/i;
|
|
|
3
3
|
const REDACTED = "[REDACTED]";
|
|
4
4
|
const HEADER_NAME_RE = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
5
5
|
const ASCII_CONTROL_RE = /[\x00-\x1F\x7F]/;
|
|
6
|
+
const AZURE_BLOB_HOST_SUFFIX = ".blob.core.windows.net";
|
|
7
|
+
const AWS_PRESIGNED_QUERY_RE = /^x-amz-/i;
|
|
6
8
|
function rejectControlChars(label, value) {
|
|
7
9
|
if (ASCII_CONTROL_RE.test(value)) {
|
|
8
10
|
throw new ValidationError(`${label} cannot contain ASCII control characters.`);
|
|
@@ -25,17 +27,34 @@ function validateDownloadAuth(auth) {
|
|
|
25
27
|
rejectControlChars("Header auth header_value", auth.header_value);
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
30
|
+
if (auth.type === "s3") {
|
|
31
|
+
rejectControlChars("S3 access_key_id", auth.access_key_id);
|
|
32
|
+
rejectControlChars("S3 secret_access_key", auth.secret_access_key);
|
|
33
|
+
if (auth.session_token)
|
|
34
|
+
rejectControlChars("S3 session_token", auth.session_token);
|
|
35
|
+
if (auth.region)
|
|
36
|
+
rejectControlChars("S3 region", auth.region);
|
|
37
|
+
if (auth.endpoint)
|
|
38
|
+
rejectControlChars("S3 endpoint", auth.endpoint);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
28
41
|
if (auth.query_param.length === 0) {
|
|
29
42
|
throw new ValidationError("Query auth query_param must be a non-empty string.");
|
|
30
43
|
}
|
|
31
44
|
rejectControlChars("Query auth query_param", auth.query_param);
|
|
32
45
|
}
|
|
46
|
+
function shouldRedactAllQueryValues(parsed) {
|
|
47
|
+
if (parsed.hostname.endsWith(AZURE_BLOB_HOST_SUFFIX))
|
|
48
|
+
return true;
|
|
49
|
+
return [...parsed.searchParams.keys()].some((key) => AWS_PRESIGNED_QUERY_RE.test(key));
|
|
50
|
+
}
|
|
33
51
|
export function redactUrlForLogs(url, extraSensitiveParams = []) {
|
|
34
52
|
try {
|
|
35
53
|
const parsed = new URL(url);
|
|
54
|
+
const redactAll = shouldRedactAllQueryValues(parsed);
|
|
36
55
|
const sensitive = new Set(extraSensitiveParams.map((p) => p.toLowerCase()));
|
|
37
56
|
for (const key of [...parsed.searchParams.keys()]) {
|
|
38
|
-
if (sensitive.has(key.toLowerCase()) || TOKEN_QUERY_RE.test(key)) {
|
|
57
|
+
if (redactAll || sensitive.has(key.toLowerCase()) || TOKEN_QUERY_RE.test(key)) {
|
|
39
58
|
parsed.searchParams.set(key, REDACTED);
|
|
40
59
|
}
|
|
41
60
|
}
|
|
@@ -68,6 +87,12 @@ export function applyDownloadAuth(url, auth) {
|
|
|
68
87
|
headers: { [auth.header_name]: auth.header_value },
|
|
69
88
|
};
|
|
70
89
|
}
|
|
90
|
+
if (auth.type === "s3") {
|
|
91
|
+
return {
|
|
92
|
+
url,
|
|
93
|
+
headers: {},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
71
96
|
const parsed = new URL(url);
|
|
72
97
|
parsed.searchParams.set(auth.query_param, auth.query_value);
|
|
73
98
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download-auth.js","sourceRoot":"","sources":["../../src/services/download-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"download-auth.js","sourceRoot":"","sources":["../../src/services/download-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAqBrD,MAAM,cAAc,GAAG,sDAAsD,CAAC;AAC9E,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,cAAc,GAAG,gCAAgC,CAAC;AACxD,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAC3C,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AACxD,MAAM,sBAAsB,GAAG,UAAU,CAAC;AAE1C,SAAS,kBAAkB,CAAC,KAAa,EAAE,KAAa;IACtD,IAAI,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,eAAe,CAAC,GAAG,KAAK,2CAA2C,CAAC,CAAC;IACjF,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAkB;IAC9C,IAAI,IAAI,CAAC,IA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node:fs/promises";
|
|
2
|
+
import { type CloudStorageAuth } from "./storage/index.js";
|
|
2
3
|
export declare const downloadCacheFs: {
|
|
3
4
|
copyFile: typeof copyFile;
|
|
4
5
|
link: typeof link;
|
|
@@ -14,6 +15,7 @@ export interface DownloadCacheOptions {
|
|
|
14
15
|
headers: Record<string, string>;
|
|
15
16
|
targetPath: string;
|
|
16
17
|
logUrl?: string;
|
|
18
|
+
storageAuth?: CloudStorageAuth;
|
|
17
19
|
}
|
|
18
20
|
export interface DownloadCacheResult {
|
|
19
21
|
targetPath: string;
|
|
@@ -21,6 +23,6 @@ export interface DownloadCacheResult {
|
|
|
21
23
|
cachePath?: string;
|
|
22
24
|
materializedBy?: "hardlink" | "copy";
|
|
23
25
|
}
|
|
24
|
-
export declare function downloadUrlToFile(url: string, targetPath: string, headers: Record<string, string>, logUrl?: string): Promise<void>;
|
|
26
|
+
export declare function downloadUrlToFile(url: string, targetPath: string, headers: Record<string, string>, logUrl?: string, storageAuth?: CloudStorageAuth): Promise<void>;
|
|
25
27
|
export declare function downloadWithCache(options: DownloadCacheOptions): Promise<DownloadCacheResult>;
|
|
26
28
|
//# sourceMappingURL=download-cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download-cache.d.ts","sourceRoot":"","sources":["../../src/services/download-cache.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,OAAO,EACP,MAAM,EACN,EAAE,EACF,IAAI,EACJ,MAAM,EACP,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"download-cache.d.ts","sourceRoot":"","sources":["../../src/services/download-cache.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,OAAO,EACP,MAAM,EACN,EAAE,EACF,IAAI,EACJ,MAAM,EACP,MAAM,kBAAkB,CAAC;AAQ1B,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,oBAAoB,CAAC;AAO5B,eAAO,MAAM,eAAe;;;;;;;;;CAS3B,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;CACtC;AAoLD,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,MAAM,CAAC,EAAE,MAAM,EACf,WAAW,GAAE,gBAAqB,GACjC,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAgC9B"}
|
|
@@ -8,8 +8,10 @@ import { pipeline } from "node:stream/promises";
|
|
|
8
8
|
import { ModelError } from "../utils/errors.js";
|
|
9
9
|
import { logger } from "../utils/logger.js";
|
|
10
10
|
import { redactUrlForLogs } from "./download-auth.js";
|
|
11
|
+
import { downloadCloudUrlToFile, supportsCloudDownload, } from "./storage/index.js";
|
|
11
12
|
const DEFAULT_CACHE_DIR = join(homedir(), ".comfyui-mcp", "cache");
|
|
12
13
|
const HASH_CHARS = 32;
|
|
14
|
+
const MAX_HTTP_REDIRECTS = 5;
|
|
13
15
|
const inflight = new Map();
|
|
14
16
|
export const downloadCacheFs = {
|
|
15
17
|
copyFile,
|
|
@@ -46,10 +48,44 @@ async function touch(path) {
|
|
|
46
48
|
const now = new Date();
|
|
47
49
|
await downloadCacheFs.utimes(path, now, now);
|
|
48
50
|
}
|
|
49
|
-
async function streamUrlToFile(url, targetPath, headers, logUrl = redactUrlForLogs(url)) {
|
|
50
|
-
|
|
51
|
+
async function streamUrlToFile(url, targetPath, headers, logUrl = redactUrlForLogs(url), storageAuth = {}) {
|
|
52
|
+
if (supportsCloudDownload(url)) {
|
|
53
|
+
await downloadCloudUrlToFile(url, targetPath, storageAuth);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let currentUrl = url;
|
|
57
|
+
let currentHeaders = headers;
|
|
58
|
+
let res;
|
|
59
|
+
for (let redirectCount = 0;; redirectCount += 1) {
|
|
60
|
+
res = await fetch(currentUrl, { headers: currentHeaders, redirect: "manual" });
|
|
61
|
+
if (res.status < 300 || res.status >= 400)
|
|
62
|
+
break;
|
|
63
|
+
if (redirectCount >= MAX_HTTP_REDIRECTS) {
|
|
64
|
+
throw new ModelError("Download redirect limit exceeded", {
|
|
65
|
+
url: redactUrlForLogs(currentUrl),
|
|
66
|
+
status: res.status,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const location = res.headers.get("location");
|
|
70
|
+
if (!location)
|
|
71
|
+
break;
|
|
72
|
+
let nextUrl;
|
|
73
|
+
try {
|
|
74
|
+
nextUrl = new URL(location, currentUrl).toString();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw new ModelError("Download redirect location is invalid", {
|
|
78
|
+
url: redactUrlForLogs(currentUrl),
|
|
79
|
+
status: res.status,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const sameOrigin = new URL(nextUrl).origin === new URL(currentUrl).origin;
|
|
83
|
+
currentUrl = nextUrl;
|
|
84
|
+
if (!sameOrigin)
|
|
85
|
+
currentHeaders = {};
|
|
86
|
+
}
|
|
51
87
|
if (!res.ok) {
|
|
52
|
-
throw new ModelError(`Download failed: ${res.status} ${res.statusText}`, { url: logUrl, status: res.status });
|
|
88
|
+
throw new ModelError(`Download failed: ${res.status} ${res.statusText}`, { url: currentUrl === url ? logUrl : redactUrlForLogs(currentUrl), status: res.status });
|
|
53
89
|
}
|
|
54
90
|
if (!res.body) {
|
|
55
91
|
throw new ModelError("Download response has no body", { url: logUrl });
|
|
@@ -58,7 +94,7 @@ async function streamUrlToFile(url, targetPath, headers, logUrl = redactUrlForLo
|
|
|
58
94
|
const fileStream = createWriteStream(targetPath);
|
|
59
95
|
await pipeline(nodeStream, fileStream);
|
|
60
96
|
}
|
|
61
|
-
async function downloadIntoCache(url, headers, logUrl) {
|
|
97
|
+
async function downloadIntoCache(url, headers, logUrl, storageAuth = {}) {
|
|
62
98
|
const target = cachePathForUrl(url);
|
|
63
99
|
const key = target;
|
|
64
100
|
const existing = inflight.get(key);
|
|
@@ -78,7 +114,7 @@ async function downloadIntoCache(url, headers, logUrl) {
|
|
|
78
114
|
}
|
|
79
115
|
const tmp = join(cacheDir(), `.${basename(target)}.${process.pid}.${randomUUID()}.tmp`);
|
|
80
116
|
try {
|
|
81
|
-
await streamUrlToFile(url, tmp, headers, logUrl);
|
|
117
|
+
await streamUrlToFile(url, tmp, headers, logUrl, storageAuth);
|
|
82
118
|
await downloadCacheFs.rename(tmp, target);
|
|
83
119
|
await touch(target);
|
|
84
120
|
return target;
|
|
@@ -137,13 +173,13 @@ async function evictLruIfNeeded() {
|
|
|
137
173
|
break;
|
|
138
174
|
}
|
|
139
175
|
}
|
|
140
|
-
export async function downloadUrlToFile(url, targetPath, headers, logUrl) {
|
|
141
|
-
await streamUrlToFile(url, targetPath, headers, logUrl);
|
|
176
|
+
export async function downloadUrlToFile(url, targetPath, headers, logUrl, storageAuth = {}) {
|
|
177
|
+
await streamUrlToFile(url, targetPath, headers, logUrl, storageAuth);
|
|
142
178
|
}
|
|
143
179
|
export async function downloadWithCache(options) {
|
|
144
180
|
const logUrl = options.logUrl ?? redactUrlForLogs(options.url);
|
|
145
181
|
try {
|
|
146
|
-
const cachePath = await downloadIntoCache(options.url, options.headers, logUrl);
|
|
182
|
+
const cachePath = await downloadIntoCache(options.url, options.headers, logUrl, options.storageAuth);
|
|
147
183
|
const materializedBy = await materializeCacheFile(cachePath, options.targetPath);
|
|
148
184
|
await evictLruIfNeeded();
|
|
149
185
|
return {
|
|
@@ -160,7 +196,7 @@ export async function downloadWithCache(options) {
|
|
|
160
196
|
url: logUrl,
|
|
161
197
|
error: err instanceof Error ? err.message : String(err),
|
|
162
198
|
});
|
|
163
|
-
await downloadUrlToFile(options.url, options.targetPath, options.headers, logUrl);
|
|
199
|
+
await downloadUrlToFile(options.url, options.targetPath, options.headers, logUrl, options.storageAuth);
|
|
164
200
|
return { targetPath: options.targetPath, usedCache: false };
|
|
165
201
|
}
|
|
166
202
|
}
|