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),
55 lines • 2.22 kB
JavaScript
/** Public origins for processes running behind a known hosting proxy.
*
* These values are display/routing hints, never authorization. Environment
* variables are treated as untrusted input and invalid values are ignored so a
* malformed pod id or override cannot turn a local bind into an invented URL.
*/
const RUNPOD_POD_ID = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
export const RUNPOD_LOCAL_COMFYUI_PORT = 3001;
export function runpodPodId() {
const raw = process.env.RUNPOD_POD_ID?.trim();
return raw && RUNPOD_POD_ID.test(raw) ? raw : undefined;
}
/** The ComfyUI process port inside the project RunPod image. */
export function localComfyuiPort(defaultPort = 8188) {
return runpodPodId() ? RUNPOD_LOCAL_COMFYUI_PORT : defaultPort;
}
function validPort(port) {
return Number.isInteger(port) && port > 0 && port <= 65535;
}
/** An explicit public origin wins over hosting-provider inference. */
export function configuredPublicOrigin() {
const raw = process.env.COMFYUI_MCP_PUBLIC_URL?.trim();
if (!raw)
return undefined;
try {
const u = new URL(raw);
if (u.protocol !== "http:" && u.protocol !== "https:")
return undefined;
if (u.username || u.password || u.search || u.hash || !u.hostname)
return undefined;
return u.origin;
}
catch {
return undefined;
}
}
/** RunPod's HTTP proxy exposes each explicitly exposed port as `<pod>-<port>`. */
export function runpodProxyOrigin(port) {
const pod = runpodPodId();
return pod && validPort(port) ? `https://${pod}-${port}.proxy.runpod.net` : undefined;
}
/** The origin a user can actually reach for a given listener, if known. */
export function advertisedPublicOrigin(port) {
return configuredPublicOrigin() ?? runpodProxyOrigin(port);
}
/** Convert an advertised HTTP(S) origin to the matching WebSocket scheme. */
export function advertisedWebSocketOrigin(port) {
const origin = advertisedPublicOrigin(port);
if (!origin)
return undefined;
const u = new URL(origin);
u.protocol = u.protocol === "https:" ? "wss:" : "ws:";
return u.toString().replace(/\/$/, "");
}
//# sourceMappingURL=advertised-origin.js.map