comfyui-mcp
Version:
Local-first, agent-native control plane for ComfyUI — MCP server + autonomous sidebar agent that drives your live graph in natural language on ANY LLM: Claude/ChatGPT/Gemini on your subscription (no API key), free local models via Ollama (fully offline),
130 lines (120 loc) • 5.37 kB
JavaScript
/**
* Count the project's advertised assets from their SOURCE OF TRUTH, and
* optionally assert the README matches.
*
* Why this exists: the README claimed "108 MCP tools" for nearly a month while
* the real number climbed past 160, and the first hand-correction still landed
* one short because it was derived by grepping `server.tool(` instead of asking
* the registry. Numbers written by hand drift silently — nothing fails, the
* claim just quietly stops being true. This makes the claim testable.
*
* node scripts/asset-counts.mjs # print the counts
* node scripts/asset-counts.mjs --json # machine-readable
* node scripts/asset-counts.mjs --check # exit 1 if README disagrees
*
* --check requires a build (it imports dist/), which CI already does.
*/
import { readFileSync, readdirSync, existsSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const dirsContaining = (dir, file) => {
const p = join(root, dir);
if (!existsSync(p)) return 0;
return readdirSync(p, { withFileTypes: true }).filter(
(e) => e.isDirectory() && existsSync(join(p, e.name, file)),
).length;
};
const filesMatching = (dir, ext) => {
const p = join(root, dir);
if (!existsSync(p)) return 0;
return readdirSync(p).filter((f) => f.endsWith(ext)).length;
};
async function counts() {
// Tools come from the REGISTRY, not a grep — that is the whole point. A tool
// registered conditionally, or in a file the pattern missed, still counts.
// pathToFileURL: on Windows a bare absolute path ("C:\…") is rejected by the
// ESM loader as an unknown URL scheme.
const imp = (rel) => import(pathToFileURL(join(root, rel)).href);
const { collectToolCatalog } = await imp("dist/tools/index.js");
const { buildPanelToolDefs } = await imp("dist/orchestrator/panel-tools.js");
const catalog = await collectToolCatalog();
const mcpTools = catalog.tools instanceof Map ? catalog.tools.size : Object.keys(catalog.tools).length;
const panelTools = buildPanelToolDefs().length;
// Pack families: `packs/` holds one directory per VARIANT (anima-txt2img,
// anima-inpaint…), which is why a raw directory count overstates what a user
// would call a pack. Report both rather than pick one and be subtly wrong.
const packDirs = dirsContaining("packs", "pack.yaml");
const families = new Set();
const packsRoot = join(root, "packs");
if (existsSync(packsRoot)) {
for (const e of readdirSync(packsRoot, { withFileTypes: true })) {
if (!e.isDirectory()) continue;
const y = join(packsRoot, e.name, "pack.yaml");
if (!existsSync(y)) continue;
const m = readFileSync(y, "utf8").match(/^family:\s*(.+)$/m);
if (m) families.add(m[1].trim());
}
}
let hooks = 0;
const hooksFile = join(root, "plugin/hooks/hooks.json");
if (existsSync(hooksFile)) {
const h = JSON.parse(readFileSync(hooksFile, "utf8"));
const events = h.hooks ?? h;
for (const arr of Object.values(events)) {
if (!Array.isArray(arr)) continue;
hooks += arr.reduce((s, x) => s + (Array.isArray(x.hooks) ? x.hooks.length : 1), 0);
}
}
return {
mcp_tools: mcpTools,
panel_tools: panelTools,
total_tool_surface: mcpTools + panelTools,
skills: dirsContaining("plugin/skills", "SKILL.md"),
packs: packDirs,
pack_families: families.size,
slash_commands: filesMatching("plugin/commands", ".md"),
agents: filesMatching("plugin/agents", ".md"),
hooks,
};
}
/** Claims embedded in prose, and how to read each one back out. */
const CLAIMS = [
{ file: "README.md", key: "mcp_tools", re: /\*\*(\d+) MCP tools\*\*/ },
{ file: "README.md", key: "mcp_tools", re: /^(\d+) tools across/m },
{ file: "README.md", key: "skills", re: /\*\*(\d+) AI skills\*\*/ },
{ file: "README.md", key: "packs", re: /\*\*(\d+) installer packs\*\*/ },
{ file: "README.md", key: "slash_commands", re: /\*\*(\d+) slash commands\*\*/ },
{ file: "README.md", key: "agents", re: /\*\*(\d+) autonomous agents\*\*/ },
{ file: "README.md", key: "hooks", re: /\*\*(\d+) hooks\*\*/ },
{ file: "docs/plugin.mdx", key: "mcp_tools", re: /the (\d+) MCP tools/ },
];
const c = await counts();
if (process.argv.includes("--json")) {
console.log(JSON.stringify(c, null, 2));
} else if (process.argv.includes("--check")) {
const bad = [];
for (const { file, key, re } of CLAIMS) {
const p = join(root, file);
if (!existsSync(p)) continue;
const m = readFileSync(p, "utf8").match(re);
if (!m) {
bad.push(`${file}: could not find a claim matching ${re} (did the wording change?)`);
continue;
}
if (Number(m[1]) !== c[key]) {
bad.push(`${file}: claims ${m[1]} for ${key}, actual is ${c[key]}`);
}
}
if (bad.length) {
console.error("Asset counts in prose disagree with the source of truth:\n");
for (const b of bad) console.error(" - " + b);
console.error("\nRun `node scripts/asset-counts.mjs` and update the text.");
process.exit(1);
}
console.log("asset counts match the source of truth");
} else {
const w = Math.max(...Object.keys(c).map((k) => k.length));
for (const [k, v] of Object.entries(c)) console.log(`${k.padEnd(w)} ${v}`);
}