comfy-native-apps 0.0.0-stage → 1.0.0
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/LICENSE +201 -0
- package/MCP-CONFIG.zh-CN.md +139 -0
- package/README.md +149 -3
- package/README.zh-CN.md +103 -0
- package/assert_media.mjs +179 -0
- package/comfy_native_apps.mjs +360 -0
- package/drive_safe.mjs +68 -0
- package/native_lib.mjs +1562 -0
- package/package.json +45 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# MCP 客户端配置示例
|
|
2
|
+
|
|
3
|
+
`comfy-native-apps` 是一个 **stdio 本地进程型 MCP 服务器**,每个客户端都通过
|
|
4
|
+
`node <本仓库的 comfy_native_apps.mjs>` 拉起。核心只有一条命令:
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
node C:/path/to/comfy-native-apps/comfy_native_apps.mjs
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
配置时把它拆成 `command`(`node`) + `args`(上面的 `.mjs` 路径) + `env`
|
|
11
|
+
(可选环境变量)即可。以 GitHub 克隆镜像为准,把路径换成你 clone 的位置。
|
|
12
|
+
|
|
13
|
+
> 注意:Claude Code / dsh / opencode 均**不支持**直接填 `https://github.com/…`
|
|
14
|
+
> 拉取,必须指向**本地文件绝对路径**(即本仓库 clone 或检出后的位置)。
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 通用最小配置(占位)
|
|
19
|
+
|
|
20
|
+
所有客户端下面四段都是同一套参数:
|
|
21
|
+
|
|
22
|
+
| 字段 | 值 |
|
|
23
|
+
|------|-----|
|
|
24
|
+
| `command` | `node` |
|
|
25
|
+
| `args` | `[ "<本仓库>/comfy_native_apps.mjs" ]` |
|
|
26
|
+
| `env` | `{ "COMFYUI_URL": "http://127.0.0.1:8188" }`(可选;等价于默认值) |
|
|
27
|
+
| `transport` | `stdio`(dsh/opencode 需要显式写;Claude Code 省略即 stdio) |
|
|
28
|
+
|
|
29
|
+
其余几个可选环境变量见 README:`COMFYUI_URL`、`COMFYUI_PUBLIC_URL`、`WORKFLOWS_ROOT`、`RUN_TIMEOUT_S`。旧的 `COMFYUI_HOST` + `COMFYUI_PORT` 仍兼容。
|
|
30
|
+
|
|
31
|
+
> **app 发现**:服务启动后直接通过 ComfyUI 的 `/userdata` 接口(Web 前端加载/保存工作流用的同一接口)列目录并读取 `workflows/**/*.app.json`,不需要配置任何本地路径,远程 ComfyUI 也直接可用。`WORKFLOWS_ROOT` 仅在服务器不提供 `/userdata` 或你想强制读本地目录时才需要设置。
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 1) Claude Code
|
|
36
|
+
|
|
37
|
+
**项目级**:`C:\path\to\project\.mcp.json`(仅在该项目生效;不加到
|
|
38
|
+
`~/.claude.json`,会变成全局)。
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"comfy-native-apps": {
|
|
44
|
+
"command": "node",
|
|
45
|
+
"args": ["C:/path/to/comfy-native-apps/comfy_native_apps.mjs"],
|
|
46
|
+
"env": { "COMFYUI_URL": "http://127.0.0.1:8188" }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
- 用正斜杠 `/` 的绝对路径(Windows 反斜杠在 JSON 里要转义,绕开)。
|
|
53
|
+
- `env` 里的 `COMFYUI_URL` 是 MCP 访问 ComfyUI 的地址,默认就是 `http://127.0.0.1:8188`,没改端口可以不写。
|
|
54
|
+
- 已接入。换机器/换 clone 路径时,把 `args` 里的路径换成实际位置即可。
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 2) dsh(DeepSeek Harness)
|
|
59
|
+
|
|
60
|
+
dsh 的 MCP 配置存在 `C:\Users\<you>\.dsh\storages\mcp_connector.json`,
|
|
61
|
+
结构分为 `connections`(你自己的)、`grants`、`catalog`(内置目录)。
|
|
62
|
+
|
|
63
|
+
**优先用 dsh UI 添加**(避免手改大文件):打开 dsh → 设置 → MCP 连接器
|
|
64
|
+
→ 添加本地连接,`command` 填 `node`,`args` 填上面的 `.mjs` 路径。
|
|
65
|
+
|
|
66
|
+
若手改 `mcp_connector.json`,在 `connections` 下加:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"connections": {
|
|
71
|
+
"comfy-native-apps": {
|
|
72
|
+
"schemaVersion": 1,
|
|
73
|
+
"name": "comfy-native-apps",
|
|
74
|
+
"servers": [
|
|
75
|
+
{
|
|
76
|
+
"serverKey": "main",
|
|
77
|
+
"command": "node",
|
|
78
|
+
"args": ["C:/path/to/comfy-native-apps/comfy_native_apps.mjs"],
|
|
79
|
+
"env": { "COMFYUI_URL": "http://127.0.0.1:8188" },
|
|
80
|
+
"cwd": "",
|
|
81
|
+
"transport": "stdio",
|
|
82
|
+
"headers": {}
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
(真实的 `connections` 键结构以 dsh UI 导出的为准;这里是该文件里 `catalog`
|
|
91
|
+
内置本地服务器的同构格式。)
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 3) opencode
|
|
96
|
+
|
|
97
|
+
opencode 的 MCP 在项目根 `opencode.json` 的 `mcp` 字段:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"mcp": {
|
|
102
|
+
"comfy-native-apps": {
|
|
103
|
+
"type": "local",
|
|
104
|
+
"command": ["node", "C:/path/to/comfy-native-apps/comfy_native_apps.mjs"],
|
|
105
|
+
"environment": { "COMFYUI_URL": "http://127.0.0.1:8188" }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- `type: "local"` 表示本地 stdio 进程;远程用 `type: "remote"` + `url`。
|
|
112
|
+
- `command` 是数组(命令 + 参数),非字符串。
|
|
113
|
+
- 未在全局/项目安装 opencode 时,此段直接可参考。
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 4) 其他 MCP 客户端
|
|
118
|
+
|
|
119
|
+
任何支持 **stdio 本地命令** 的 MCP 客户端,套路都一样,只要把
|
|
120
|
+
`command`/`args` 指向本仓库路径、`transport` 设 `stdio`。若客户端只支持
|
|
121
|
+
远程 `url`,需要把本服务器包一层 HTTP — `comfy-native-apps` 目前是纯
|
|
122
|
+
stdio,不支持 HTTP(sse/streamable)。如确有需要可提 issue。
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 环境变量速查
|
|
127
|
+
|
|
128
|
+
| 变量 | 默认 | 说明 |
|
|
129
|
+
|------|------|------|
|
|
130
|
+
| `COMFYUI_URL` | `http://127.0.0.1:8188` | MCP 服务端访问 ComfyUI 的地址 |
|
|
131
|
+
| `COMFYUI_PUBLIC_URL` | 同 `COMFYUI_URL` | 客户端可达的 ComfyUI 地址;MCP 主机能连、客户端连不上时(容器/反代/隧道)用于生成下载链接 |
|
|
132
|
+
| `WORKFLOWS_ROOT` | *(不设)* | 可选本地覆盖:从该目录读 `workflows/**/*.app.json` 代替服务器 API;普通情况下不需要 |
|
|
133
|
+
| `RUN_TIMEOUT_S` | `300` | 单次渲染等待上限(秒) |
|
|
134
|
+
| `DOWNLOAD_DIR` | `<MCP 进程 cwd>/downloads` | `download_output` 未给 `dest` 时的落盘目录 |
|
|
135
|
+
|
|
136
|
+
> 旧写法 `COMFYUI_HOST` + `COMFYUI_PORT` 仍兼容,但推荐统一用 `COMFYUI_URL`。
|
|
137
|
+
|
|
138
|
+
*路径说明:* 本文件例子用 `C:/path/to/comfy-native-apps`
|
|
139
|
+
(即本仓库本地位置)。clone 到别处请全局替换。
|
package/README.md
CHANGED
|
@@ -1,3 +1,149 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# comfy-native-apps
|
|
2
|
+
|
|
3
|
+
[中文文档](README.zh-CN.md) | [MCP 客户端配置示例](MCP-CONFIG.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
A 9-tool MCP server that drives **only** ComfyUI's native `.app.json` apps (the
|
|
6
|
+
built-in "构建应用 / Build App" feature) and manages the render queue. It does the
|
|
7
|
+
UI→API conversion itself and uses only ComfyUI's stable core HTTP API, so it works
|
|
8
|
+
against a **headless** OR a **frontend** ComfyUI — with **zero dependency on the
|
|
9
|
+
artokun comfyui-mcp / panel plugin**.
|
|
10
|
+
|
|
11
|
+
Node 18+ only (global `fetch`, `structuredClone`). No `npm install`.
|
|
12
|
+
|
|
13
|
+
Tested against ComfyUI **0.45.3** (frontend 1.58.5) with native `.app.json` apps.
|
|
14
|
+
|
|
15
|
+
## Why
|
|
16
|
+
|
|
17
|
+
artokun's comfyui-mcp exposes ~38 action-parameterized tools (plus 3 facade meta-tools
|
|
18
|
+
and a 96-tool panel surface). Even its compact mode forces a `list → describe_tool →
|
|
19
|
+
call_tool` chain that a 9B-class local model loops on `describe_tool` forever. This
|
|
20
|
+
server deletes the indirection: the model sees exactly nine single-purpose tools.
|
|
21
|
+
|
|
22
|
+
## Tools
|
|
23
|
+
|
|
24
|
+
| tool | what it does |
|
|
25
|
+
|------|--------------|
|
|
26
|
+
| `list_apps` | catalog only: number, name, id, short description and output types of every native `.app.json` app |
|
|
27
|
+
| `get_app_params(app)` | the parameter contract of ONE app: every input param (name + type + default; `COMBO` inputs also carry their full `options` list) and its outputs |
|
|
28
|
+
| `run_app(app, inputs, wait_s?)` | fill only the params you change, convert UI→API, enqueue and wait, return the image (and any string outputs); videos come back as an openable `/view` URL. `wait_s` caps how long it blocks; `0` returns the `prompt_id` immediately |
|
|
29
|
+
| `upload_file(path, subfolder?)` | upload a LOCAL file (image/video/audio/mask) into ComfyUI input dir; returns the ComfyUI-side relative path to pass as a file input value |
|
|
30
|
+
| `download_output(prompt_id, index?, dest?)` | download one finished output to a **local file** (bytes via `/view`), returning the real `saved_to` path. `dest` may be a file, a directory or a relative path; omit it to use `DOWNLOAD_DIR` (default `<cwd>/downloads`). Works for local and remote ComfyUI |
|
|
31
|
+
| `queue_status` | what is running + pending, plus a `recent` list of finished jobs (5 by default; `recent: 0` skips history) |
|
|
32
|
+
| `job_status(prompt_id, wait_s?)` | state + output files of one job; `wait_s` blocks until it finishes (or times out) so clients need no polling loop |
|
|
33
|
+
| `clear_queue` | clear the pending queue |
|
|
34
|
+
| `interrupt` | stop the current generation |
|
|
35
|
+
|
|
36
|
+
`list_apps` is a catalog only — call `get_app_params(app)` for an app's params, so a
|
|
37
|
+
long app list never buries the model in inputs it does not need. `run_app` `app` may be
|
|
38
|
+
the number from `list_apps`, the app name, or its id (relative workflows path); pass the
|
|
39
|
+
**id** when several apps share a name. `inputs` keys are the param labels from
|
|
40
|
+
`get_app_params` (`prompt`, `seed`, …). A `seed` of `-1` rolls a random seed.
|
|
41
|
+
Params go in the `inputs` object **only** — a stray top-level field is an error, not a
|
|
42
|
+
silently-ignored default, and a mistyped param name is reported with a pointer to
|
|
43
|
+
`get_app_params`. Both mistakes fail before anything is enqueued.
|
|
44
|
+
A `COMBO` input always carries `options` — the full list of legal values — so a client
|
|
45
|
+
can render a real dropdown and a model can pick without guessing filenames (a port
|
|
46
|
+
declared `STRING` has no choices).
|
|
47
|
+
Display-only nodes — `PreviewAny` / `PreviewImage` / `PreviewText` / `ShowText` / `Debug`
|
|
48
|
+
(prompt/resolution preview, etc.) — are stripped from the param list: a port whose targets
|
|
49
|
+
are *all* of those kinds is scaffolding, not a parameter, so it never shows up. A port that
|
|
50
|
+
also feeds a real node is kept.
|
|
51
|
+
`job_status` / `download_output` take the **UUID prompt_id** returned by `run_app`; the `queue_number` from `queue_status` is just a queue position and only works as a shortcut while the job is queued.
|
|
52
|
+
`queue_status` reads `recent` from ComfyUI's `/history` (cleared when ComfyUI restarts). Each entry only carries `prompt_id`, `state`, output filenames and the finish time; use `job_status` for the full result of one history job.
|
|
53
|
+
**Download**: `download_output` now writes the file to disk (bytes over `/view`) and returns `saved_to`. `dest` may be a file path (`E:/out/clip.mp4`, rename on the way), a directory (`E:/out`, `E:/out/`; no extension also means directory) or a relative path (against the MCP process cwd); omit it to use `DOWNLOAD_DIR`. The file lands on the **machine running this MCP server**, remote ComfyUI included.
|
|
54
|
+
`run_app` only returns the image preview block and the `/view` URL (videos: URL only) — **no ComfyUI / MCP server file paths**. For a local file call `download_output`; its `saved_to` is the real on-disk path. When a job produced both a saved file and a temp preview, the saved file is the one returned (`download_output` uses the same order).
|
|
55
|
+
**Waiting**: `run_app` blocks until the result by default; `wait_s: 0` only enqueues and returns the `prompt_id`. Then `job_status(prompt_id, wait_s)` blocks up to N seconds and returns `timed_out: true` plus the current `state` when the budget runs out — call it again to keep waiting instead of guessing client timeouts.
|
|
56
|
+
For apps with an image/video/audio/mask input: first call `upload_file` with a local path, then pass the returned **ComfyUI-side relative path** (e.g. `mybatch/wall.png`) as that param value in `run_app` - ComfyUI reads it from its input dir, not the Windows filesystem, so absolute paths like `E:/.../wall.png` wont resolve.
|
|
57
|
+
|
|
58
|
+
## How a native app is read
|
|
59
|
+
|
|
60
|
+
A `.app.json` wraps its whole graph in one subgraph. This server reads the declared
|
|
61
|
+
I/O from `definitions.subgraphs[0].inputs[]` / `.outputs[]` (each port has a `label`,
|
|
62
|
+
`type`, and a `linkIds` that points at the internal node+widget to fill). It then
|
|
63
|
+
converts the subgraph's `nodes` + `links` to an API-format prompt:
|
|
64
|
+
|
|
65
|
+
> A purely-linear app (frontend's "linear" layout) has **no subgraph**: the whole
|
|
66
|
+
> top-level graph is the app, with `extra.linearMode: true` and
|
|
67
|
+
> `extra.linearData.inputs` listing every exposed port (`"<uuid>:<nodeId>:<socket>"` +
|
|
68
|
+
> label). Such apps are recognized and converted through the same top-level machinery —
|
|
69
|
+
> every active top-level node is emitted and port values route to those nodes' widgets — so
|
|
70
|
+
> they can be driven from `run_app` exactly like subgraph apps.
|
|
71
|
+
|
|
72
|
+
- a socket linked from a real internal node → `[String(nodeId), slot]`
|
|
73
|
+
- a socket linked from the inputNode shell (`-10`) or not linked → its `widgets_values_named` default
|
|
74
|
+
- a model-filled value → the override (type-coerced to the port's declared type)
|
|
75
|
+
- widgets that aren't sockets (e.g. KSampler `control_after_generate`) → appended so the prompt is complete
|
|
76
|
+
- a **list-valued widget** (e.g. `BranchNode`'s `branch_names`, an `ARRAY` rendered as a widget) → `{"__value__": [...]}`, because the raw API reads any bare list as a `[node_id, slot]` link and rejects it with `bad_linked_input`
|
|
77
|
+
- top-level saver nodes (`SaveImage` / `SaveImageAdvanced` / `VHS_VideoCombine` / `SaveVideo` / `SaveAnimatedWEBM` …) are converted too — a native app keeps them outside the subgraph, and converting only the subgraph left video apps with a pile of loose PNG frames. A synthetic `SaveImage` / `SaveAnimatedWEBM` is only attached when an output has no real sink; a `PreviewImage` counts as a sink (the author chose not to persist that output, and its temp file is still downloadable from `/history`)
|
|
78
|
+
- filename tokens such as `%date:yyyy-MM-dd%` are expanded (the web frontend does this before submitting; the raw API does not)
|
|
79
|
+
- a **nested subgraph reference** (`class_type` is the UUID of another `definitions.subgraphs[]` entry) is **inlined**: its internal nodes are emitted under a `n<refId>_<id>` key, its `-10` shell sockets are resolved to the reference node's own input links (or its `widgets_values_named` when the socket is a plain widget), and its output slots map back to the top-level consumers. The reference node itself is never sent (the API can't run a UUID). Any computed top-level node feeding an inlined socket — a `ComfySwitchNode`, `ResolutionSelector`, `BranchNode`, even indirect feeders-of-feeders — is converted as a real node too, never collapsed to a literal (a switch would otherwise literalize to `true` and poison, say, a `NumberCalculator` resize-multiplier downstream of a saver)
|
|
80
|
+
- a media input port (`IMAGE` / `MASK` / `VIDEO` / `AUDIO`) is a file, not a literal: the path goes to the filename widget of the top-level loader (`LoadImage`, `LoadVideo`, `LoadAudio`, …) that feeds the subgraph reference node, and the internal consumers link to that loader's output. A port with no external loader gets a synthetic `LoadImage`; a filename is never written onto an `IMAGE` socket
|
|
81
|
+
|
|
82
|
+
**Where a port's real value lives.** In app mode the exposed input ports' *configured*
|
|
83
|
+
values are stored on the subgraph **reference node** — the top-level node whose `type`
|
|
84
|
+
is the subgraph's id — in its `widgets_values_named`, keyed by port *name*. The internal
|
|
85
|
+
nodes (e.g. a `UNETLoader`) keep the template's original defaults, which can be stale.
|
|
86
|
+
This server reads the port values from the reference node and applies them to every internal
|
|
87
|
+
node+socket the port feeds (as pre-populated overrides), so the app runs with the values
|
|
88
|
+
the user actually set — including model paths with their subfolder prefix (e.g.
|
|
89
|
+
`zimage\z_image_turbo_int8_convrot.safetensors`). A port can fan out to several nodes (one
|
|
90
|
+
"channel" string driving two `BranchNode`s, say); all of them receive the value, and user
|
|
91
|
+
`run_app` values layer on top the same way. Media ports are the exception: their value is a
|
|
92
|
+
file, so it is routed to the loader's filename widget instead of the internal `IMAGE` socket.
|
|
93
|
+
|
|
94
|
+
Because the conversion happens here, the same `run_app` works whether ComfyUI is
|
|
95
|
+
headless (`--front-end-version 0`, no UI) or running the web frontend — only the core
|
|
96
|
+
API is touched.
|
|
97
|
+
|
|
98
|
+
## App discovery
|
|
99
|
+
|
|
100
|
+
Apps are read from the ComfyUI server itself, through the same `/userdata` API the
|
|
101
|
+
web frontend uses to list and open workflows:
|
|
102
|
+
|
|
103
|
+
- `GET /userdata?dir=workflows&recurse=true&full_info=true` lists every workflow,
|
|
104
|
+
- `GET /userdata/<url-encoded path>` returns its JSON.
|
|
105
|
+
|
|
106
|
+
The listing is mirrored into a temp dir so the converter can read apps as files, and
|
|
107
|
+
only changed files are re-downloaded. Because discovery goes over HTTP, the MCP needs
|
|
108
|
+
no local filesystem access: it works against a remote ComfyUI, and apps added or edited
|
|
109
|
+
in ComfyUI appear on the next tool call without restarting the server.
|
|
110
|
+
|
|
111
|
+
If the server does not expose `/userdata` (old builds), the MCP falls back to scanning
|
|
112
|
+
a local `<ComfyUI user>` dir.
|
|
113
|
+
|
|
114
|
+
## Config (env vars)
|
|
115
|
+
|
|
116
|
+
| var | default | notes |
|
|
117
|
+
|-----|---------|-------|
|
|
118
|
+
| `COMFYUI_URL` | `http://127.0.0.1:8188` | address the MCP server uses to reach ComfyUI, e.g. `https://gpu.example.com/comfy` |
|
|
119
|
+
| `COMFYUI_PUBLIC_URL` | same as `COMFYUI_URL` | address clients use; set it only when this MCP host can reach ComfyUI but clients cannot (container / reverse proxy / tunnel), so download links stay reachable |
|
|
120
|
+
| `WORKFLOWS_ROOT` | *(unset)* | optional override: read `workflows/**/*.app.json` from this local dir instead of the server API |
|
|
121
|
+
| `RUN_TIMEOUT_S` | `300` | seconds to wait for a render |
|
|
122
|
+
| `DOWNLOAD_DIR` | `<MCP process cwd>/downloads` | where `download_output` writes when `dest` is omitted |
|
|
123
|
+
|
|
124
|
+
> The old `COMFYUI_HOST` + `COMFYUI_PORT` pair still works as a fallback, but `COMFYUI_URL` replaces it.
|
|
125
|
+
|
|
126
|
+
## Client config (Claude Code / any MCP client)
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"command": "node",
|
|
131
|
+
"args": ["C:/path/to/comfy-native-apps/comfy_native_apps.mjs"],
|
|
132
|
+
"env": { "COMFYUI_URL": "http://127.0.0.1:8188" }
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Wired into this workspace's `.mcp.json` as the server `comfy-native-apps`.
|
|
137
|
+
|
|
138
|
+
## Files
|
|
139
|
+
|
|
140
|
+
- `comfy_native_apps.mjs` — the MCP stdio server (9 tools, newline-delimited JSON-RPC 2.0)
|
|
141
|
+
- `native_lib.mjs` — workflows discovery, app loading, UI→API conversion, HTTP, queue
|
|
142
|
+
- `drive_safe.mjs` — non-destructive end-to-end test (list_apps + get_app_params + run_app + job_status)
|
|
143
|
+
- `assert_media.mjs` — offline assertions for the media-port conversion (no ComfyUI needed): `node assert_media.mjs`
|
|
144
|
+
|
|
145
|
+
## Note on models
|
|
146
|
+
|
|
147
|
+
An app's default model names must exist on the target machine. If an app was built
|
|
148
|
+
with a model that isn't installed, `run_app` returns ComfyUI's `value_not_in_list`
|
|
149
|
+
error naming the missing file; override the `*_name` params to an installed model.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# comfy-native-apps
|
|
2
|
+
|
|
3
|
+
ComfyUI原生应用工作流轻量执行器MCP,适合小模型
|
|
4
|
+
|
|
5
|
+
一个 9 工具的 MCP 服务器,只驱动 ComfyUI 原生的 `.app.json` 应用(内置的"构建应用 / Build App"功能),并管理渲染队列。它自己做 UI→API 转换,只用到 ComfyUI 稳定的核心 HTTP API,因此对接**无头**或**带前端**的 ComfyUI 都能用——**完全不依赖 artokun 的 comfyui-mcp / panel 插件**。
|
|
6
|
+
|
|
7
|
+
仅需 Node 18+(全局 `fetch`、`structuredClone`)。无需 `npm install`。
|
|
8
|
+
|
|
9
|
+
测试环境:ComfyUI **0.45.3**(前端 1.58.5),原生 `.app.json` 应用。
|
|
10
|
+
|
|
11
|
+
## 为什么
|
|
12
|
+
|
|
13
|
+
artokun 的 comfyui-mcp 暴露了约 38 个带 action 参数的工具(外加 3 个门面元工具和 96 个面板接口)。即使是它的紧凑模式,也会逼着模型走 `list → describe_tool → call_tool` 这条链,而 9B 级别的本地模型会在 `describe_tool` 上无限打转。这个服务器把中间层删掉:模型只看到 9 个单一用途的工具。
|
|
14
|
+
|
|
15
|
+
## 工具
|
|
16
|
+
|
|
17
|
+
| 工具 | 作用 |
|
|
18
|
+
|------|------|
|
|
19
|
+
| `list_apps` | 只给目录:所有原生 `.app.json` 应用的编号、名称、id、简短描述和输出类型 |
|
|
20
|
+
| `get_app_params(app)` | 单个应用的参数契约:每个输入参数(名称 + 类型 + 默认值;`COMBO` 输入还会带上完整的 `options` 可选值列表)和它的输出 |
|
|
21
|
+
| `run_app(app, inputs, wait_s?)` | 只填你要改的参数,做 UI→API 转换,入队并等待,返回图片(以及任何字符串输出);视频返回可直接打开的 `/view` 链接。`wait_s` 是本次最多阻塞多少秒,`0` 表示只入队、立刻返回 `prompt_id` |
|
|
22
|
+
| `upload_file(path, subfolder?)` | 把本地文件(图片/视频/音频/mask)上传进 ComfyUI 的 input 目录;返回可在 `run_app` 的输入参数里直接使用的 ComfyUI 侧相对路径 |
|
|
23
|
+
| `download_output(prompt_id, index?, dest?)` | 把已完成产物**下载到本地文件**(`/view` 取字节后落盘),返回真实路径 `saved_to`。`dest` 可以是文件、目录或相对路径;省略则用 `DOWNLOAD_DIR`(默认 `<cwd>/downloads`)。本地 / 远程 ComfyUI 通用 |
|
|
24
|
+
| `queue_status` | 正在运行 + 排队的任务,附带最近完成任务的 `recent` 列表(默认 5 条,`recent: 0` 只看队列) |
|
|
25
|
+
| `job_status(prompt_id, wait_s?)` | 单个任务的状态 + 输出文件;`wait_s` 让它阻塞到任务结束(或超时),不用客户端自己轮询 |
|
|
26
|
+
| `clear_queue` | 清空排队中的任务 |
|
|
27
|
+
| `interrupt` | 停止当前生成 |
|
|
28
|
+
|
|
29
|
+
`list_apps` 只返回目录——某个应用的参数要用 `get_app_params(app)` 单独查,这样应用一多也不会用无关的输入项把模型淹没。`run_app` 的 `app` 可以是 `list_apps` 返回的编号、应用名或它的 id(相对 workflows 路径);**同名应用要用 id 区分**。`inputs` 的键是 `get_app_params` 里的参数名(`prompt`、`seed`、…)。`seed` 设为 `-1` 会掷一个随机种子。
|
|
30
|
+
参数**只能**放在 `inputs` 对象里——顶层多出字段会被当成错误报出来,而不是静默改用默认值;参数名打错也会报错并提示去查 `get_app_params`。两种错误都在入队前拦下。
|
|
31
|
+
`COMBO` 输入**永远**带上 `options`——全部可选值——客户端据此画下拉框、模型直接选值,不用猜文件名;声明成 `STRING` 的端口没有可选值,自然不带。
|
|
32
|
+
显示类节点——`PreviewAny` / `PreviewImage` / `PreviewText` / `ShowText` / `Debug`(提示词预览、分辨率预览之类)——会被从参数列表里**自动过滤**掉:只要一个端口的目标全是这类节点,就当作脚手架而不是参数,`get_app_params` 里不会出现;若它还连着一个真实节点,则保留。
|
|
33
|
+
`job_status` / `download_output` 要的是 `run_app` 返回的 **UUID prompt_id**;`queue_status` 里的 `queue_number` 只是队列序号,仅任务排队期间可当作快捷方式使用。
|
|
34
|
+
`queue_status` 的 `recent` 读的是 ComfyUI 的 `/history`(ComfyUI 重启后清空),每条只给 `prompt_id`、`state`、输出文件名和完成时间;要某个历史任务的完整结果仍用 `job_status`。
|
|
35
|
+
**下载**:`download_output` 会把文件真正写到本地(从 `/view` 取字节),返回 `saved_to`。`dest` 传文件路径(`E:/out/clip.mp4`,可顺便改名)、目录(`E:/out`、`E:/out/`,没有扩展名也按目录处理)或相对路径(相对 MCP 进程的 cwd);省略则写到 `DOWNLOAD_DIR`。文件落在 **MCP 服务端所在机器**,远程 ComfyUI 也一样。
|
|
36
|
+
`run_app` 只返回图片预览块和 `/view` 链接(视频只有链接),**不再返回 ComfyUI / MCP 服务端的文件路径**——需要本地文件就调 `download_output`,它返回的 `saved_to` 才是真实落盘路径。同一个任务里既有落盘文件又有临时预览图时,优先返回落盘文件(`download_output` 的顺序一致)。
|
|
37
|
+
**等待**:`run_app` 默认会阻塞到出结果;`wait_s: 0` 只入队并立刻返回 `prompt_id`。之后用 `job_status(prompt_id, wait_s)` 阻塞最多 N 秒,超时会返回 `timed_out: true` 和当前 `state`,再调一次即可接着等,不会靠猜客户端超时。
|
|
38
|
+
有图片/视频/音频/mask 输入的应用:先调用 `upload_file`(给本地文件路径),再把返回的 **ComfyUI 侧相对路径**(如 `mybatch/wall.png`)作为该输入参数的值传给 `run_app` —— ComfyUI 是从它的 input 目录读文件的,不是从 Windows 文件系统,所以 `E:/.../wall.png` 这种绝对路径解析不到。
|
|
39
|
+
|
|
40
|
+
## 原生应用是如何被读取的
|
|
41
|
+
|
|
42
|
+
一个 `.app.json` 把整张图包在单个 subgraph 里。本服务器从 `definitions.subgraphs[0].inputs[]` / `.outputs[]` 读取声明的输入输出(每个端口有 `label`、`type`,以及指向内部节点+控件的 `linkIds`)。然后把 subgraph 的 `nodes` + `links` 转换成 API 格式的 prompt:
|
|
43
|
+
|
|
44
|
+
> **纯线性 app**(前端「线性」布局)没有 subgraph:整张顶层图就是 app 本体,靠 `extra.linearMode: true` 和 `extra.linearData.inputs`(每条 `"<uuid>:<nodeId>:<socket>"` + 标签)声明所有暴露端口。这类 app 同样会被识别并走同一套顶层机制转换——所有激活的顶层节点都会被发出,端口值路由到对应节点的控件——因此能像子图 app 一样用 `run_app` 驱动。
|
|
45
|
+
|
|
46
|
+
- 从真实内部节点连出的 socket → `[String(nodeId), slot]`
|
|
47
|
+
- 从 inputNode 外壳(`-10`)连出、或未连接的 socket → 其 `widgets_values_named` 默认值
|
|
48
|
+
- 模型填的值 → 覆盖值(按端口声明类型做类型强转)
|
|
49
|
+
- 非 socket 的控件(如 KSampler 的 `control_after_generate`)→ 追加,使 prompt 完整
|
|
50
|
+
- **值为列表的控件**(如 `BranchNode` 的 `branch_names`,即以控件形式渲染的 `ARRAY`)→ `{"__value__": [...]}`:裸数组会被原生 API 当成 `[node_id, slot]` 连线并报 `bad_linked_input`
|
|
51
|
+
- 顶层保存节点(`SaveImage` / `SaveImageAdvanced` / `VHS_VideoCombine` / `SaveVideo` / `SaveAnimatedWEBM` …)也会被转换——原生 app 把它们留在子图外面,只转子图会导致视频 app 只落一堆 PNG 帧。只有该输出没有任何真实落点时才挂一个合成的 `SaveImage` / `SaveAnimatedWEBM`;`PreviewImage` 也算落点(作者本就不想持久化这份输出,它的临时文件仍可从 `/history` 下载)
|
|
52
|
+
- 文件名里的 `%date:yyyy-MM-dd%` 一类令牌会被展开(这是前端提交前做的,直连 API 不会)
|
|
53
|
+
- **嵌套子图引用**(`class_type` 是另一段 `definitions.subgraphs[]` 的 UUID)会被**内联展开**:内部节点以 `n<refId>_<id>` 键发出,`-10` 壳输入 socket 解析到引用节点自己的顶层输入链接(若是普通控件 socket 则取引用节点的 `widgets_values_named`),输出槽再映射回顶层消费者。引用节点本身绝不发送(API 无法执行 UUID)。凡是给内联 socket 供数的计算型顶层节点——`ComfySwitchNode`、`ResolutionSelector`、`BranchNode`,乃至间接的"供数者之供数者"——都作为真实节点转换,绝不压成字面值(否则开关节点会被压成 `true`,污染下游的 `NumberCalculator` 缩放倍率,进而让保存链整个失效)
|
|
54
|
+
- 媒体输入端口(`IMAGE` / `MASK` / `VIDEO` / `AUDIO`)传的是文件而不是字面值:路径写进子图引用节点上游的顶层加载器(`LoadImage`、`LoadVideo`、`LoadAudio` …)的文件名控件,内部消费者则连到该加载器的输出。端口没有外部加载器时合成一个 `LoadImage`;文件名永远不会被写进 `IMAGE` socket
|
|
55
|
+
|
|
56
|
+
**端口的真实值存在哪。** 在 app 模式下,暴露的输入端口的*已配置*值存放在 subgraph **引用节点**上——即那个 `type` 等于 subgraph id 的顶层节点——在其 `widgets_values_named` 里,以端口*名称*为键。内部节点(如 `UNETLoader`)保存的是模板的原始默认值,可能是过期的。本服务器从引用节点读取端口值,并把它们应用到该端口所填充的**每一个**内部节点+socket 上(作为预填的覆盖值),这样应用就能用用户真正设置的值运行——包括带子目录前缀的模型路径(例如 `zimage\z_image_turbo_int8_convrot.safetensors`)。一个端口可以扇出到多个节点(比如一个"通道"字符串同时驱动两个 `BranchNode`),它们都会收到这个值;用户的 `run_app` 值同样会扇出叠加。媒体端口是例外:它的值是文件,会被路由到加载器的文件名控件,而不是内部 `IMAGE` socket。
|
|
57
|
+
|
|
58
|
+
因为转换发生在这里,同一个 `run_app` 无论 ComfyUI 是无头模式(`--front-end-version 0`,无 UI)还是跑着 Web 前端都能用——只碰核心 API。
|
|
59
|
+
|
|
60
|
+
## App 发现
|
|
61
|
+
|
|
62
|
+
app 直接来自 ComfyUI 服务器本身,走的是 Web 前端列出/打开工作流的那个 `/userdata` 接口:
|
|
63
|
+
|
|
64
|
+
- `GET /userdata?dir=workflows&recurse=true&full_info=true` 列出所有工作流,
|
|
65
|
+
- `GET /userdata/<整体 URL 编码的相对路径>` 取回文件内容。
|
|
66
|
+
|
|
67
|
+
列表会镜像到临时目录供转换器按文件读取,只有内容变化的文件才会重新下载。因为发现走 HTTP,MCP 不需要任何本地磁盘访问:远程 ComfyUI 也能用,而且你在 ComfyUI 里新增/修改 app 后,下一次调用工具就会看到,无需重启。
|
|
68
|
+
|
|
69
|
+
若服务器不提供 `/userdata`(旧版本),则回退到扫描本地 `<ComfyUI user>` 目录。
|
|
70
|
+
|
|
71
|
+
## 配置(环境变量)
|
|
72
|
+
|
|
73
|
+
| 变量 | 默认值 | 说明 |
|
|
74
|
+
|------|--------|------|
|
|
75
|
+
| `COMFYUI_URL` | `http://127.0.0.1:8188` | MCP 服务端访问 ComfyUI 的地址,如 `https://gpu.example.com/comfy` |
|
|
76
|
+
| `COMFYUI_PUBLIC_URL` | 等于 `COMFYUI_URL` | 客户端访问 ComfyUI 的地址;仅当 MCP 主机能连、客户端连不上时(容器 / 反代 / 隧道)才需要设置,用于生成下载链接 |
|
|
77
|
+
| `WORKFLOWS_ROOT` | *(不设)* | 可选本地覆盖:从该目录读 `workflows/**/*.app.json` 代替服务器 API;普通情况不需要 |
|
|
78
|
+
| `RUN_TIMEOUT_S` | `300`(等待一次渲染的秒数) | 单次渲染等待上限 |
|
|
79
|
+
| `DOWNLOAD_DIR` | `<MCP 进程工作目录>/downloads` | `download_output` 未给 `dest` 时的落盘目录,可设成固定文件夹 |
|
|
80
|
+
|
|
81
|
+
> 旧写法 `COMFYUI_HOST` + `COMFYUI_PORT` 仍然兼容,但已被 `COMFYUI_URL` 取代。
|
|
82
|
+
|
|
83
|
+
## 客户端配置(Claude Code / 任意 MCP 客户端)
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"command": "node",
|
|
88
|
+
"args": ["C:/path/to/comfy-native-apps/comfy_native_apps.mjs"],
|
|
89
|
+
"env": { "COMFYUI_URL": "http://127.0.0.1:8188" }
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
已作为服务器 `comfy-native-apps` 接入本工作区的 `.mcp.json`。
|
|
94
|
+
|
|
95
|
+
## 文件
|
|
96
|
+
|
|
97
|
+
- `comfy_native_apps.mjs` — MCP stdio 服务器(9 个工具,换行分隔的 JSON-RPC 2.0)
|
|
98
|
+
- `native_lib.mjs` — 工作流发现、应用加载、UI→API 转换、HTTP、队列
|
|
99
|
+
- `drive_safe.mjs` — 非破坏性端到端测试(list_apps + get_app_params + run_app + job_status)
|
|
100
|
+
|
|
101
|
+
## 关于模型的说明
|
|
102
|
+
|
|
103
|
+
应用的默认模型名必须存在于目标机器上。如果某个应用用了未安装的模型构建,`run_app` 会返回 ComfyUI 的 `value_not_in_list` 错误并指明缺失的文件;把对应的 `*_name` 参数覆盖成一个已安装的模型即可。
|