mcp-comfyui-proxy 0.3.4 → 0.3.5
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/README.md +6 -0
- package/package.json +2 -1
- package/src/adapter.js +18 -3
- package/src/cli-runner.js +22 -10
- package/src/cli.js +9 -3
- package/src/daemon.js +5 -3
- package/src/discovery-cache.js +114 -0
- package/src/mcp.js +11 -8
- package/src/stdio.js +3 -1
package/README.md
CHANGED
|
@@ -157,6 +157,12 @@ On Windows, `test-confy-server.cmd` starts the latest stable ComfyUI in CPU mode
|
|
|
157
157
|
|
|
158
158
|
## Diagnostics
|
|
159
159
|
|
|
160
|
+
Stdio initialization and legacy MCP ping are handled locally by the SDK. Tool discovery uses a shared cache in `%TEMP%\comfyui-mcp-runtime\discovery` on Windows (the user's temporary directory on other platforms). Fresh entries let additional wrapper processes list tools without launching CLI or HTTP. The default expiry is 10 minutes from a successful refresh; cache hits do not extend it. Real tool calls still invoke CLI and preserve cancellation without retrying uncertain operations.
|
|
161
|
+
|
|
162
|
+
Cache filenames are SHA-256 hashes of the CLI command, arguments, working directory and sorted environment. `CODEX_TOOL_CALL_ID` is excluded from the key; all original environment values still reach CLI. Windows environment names are case-insensitive. Only validated tool definitions and discovery metadata are stored, with atomic writes and a short writer lock. Tool-list notifications and observed CLI/runtime identity changes invalidate the shared entry. Cache corruption or expiry causes fresh discovery.
|
|
163
|
+
|
|
164
|
+
Optional environment settings: `COMFY_MCP_DISCOVERY_TTL_MS` changes expiry, `COMFY_MCP_CACHE_IGNORE_ENV` adds comma-separated environment names excluded from the key, and `COMFY_MCP_DISCOVERY_CACHE_DIR` selects another cache directory. The HTTP process starts with a one-minute lifetime, then uses a 30-minute idle limit after real activity. Active MCP tool calls keep it alive until completion; ping and cached discovery do not reset idle.
|
|
165
|
+
|
|
160
166
|
`status` includes `reverse_proxy_log_path`. Session logs record important requests, writes, status codes, errors and WebSocket lifecycle events. Request bodies, credential values and URL query values are omitted. Logs do not capture arbitrary browser JavaScript errors or full backend tracebacks.
|
|
161
167
|
|
|
162
168
|
Runtime files use the operating-system temporary directory:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-comfyui-proxy",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@modelcontextprotocol/client": "^2.4.0",
|
|
36
|
+
"@modelcontextprotocol/core": "^2.4.0",
|
|
36
37
|
"@modelcontextprotocol/node": "^2.1.2",
|
|
37
38
|
"@modelcontextprotocol/server": "^2.4.0",
|
|
38
39
|
"cross-spawn": "^7.0.6",
|
package/src/adapter.js
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/server';
|
|
2
2
|
import { serverInfo } from './settings.js';
|
|
3
|
+
import { validateCatalog } from './discovery-cache.js';
|
|
3
4
|
|
|
4
5
|
/** @param {(args: string[], input?: unknown, signal?: AbortSignal) => Promise<unknown>} runCli */
|
|
5
|
-
export async function createAdapter(runCli) {
|
|
6
|
+
export async function createAdapter(runCli, cache) {
|
|
6
7
|
const mcp = new Server(serverInfo, { capabilities: { tools: { listChanged: true } } });
|
|
7
8
|
let previous;
|
|
8
9
|
const refresh = async (signal) => {
|
|
9
|
-
const
|
|
10
|
+
const load = async () => validateCatalog(await runCli(['--tool-manifest'], undefined, signal));
|
|
11
|
+
const catalog = cache ? await cache.get(load, signal) : await load();
|
|
12
|
+
const manifest = { tools: catalog.tools };
|
|
10
13
|
const current = JSON.stringify(manifest);
|
|
11
14
|
if (previous !== undefined && previous !== current) await mcp.sendToolListChanged();
|
|
12
15
|
previous = current;
|
|
13
16
|
return manifest;
|
|
14
17
|
};
|
|
15
|
-
|
|
18
|
+
let runtimeIdentity;
|
|
19
|
+
const unsubscribe = runCli.onCatalog?.(async info => {
|
|
20
|
+
const stored = await cache?.read();
|
|
21
|
+
const changed = info.listChanged || (stored?.serverInfo && JSON.stringify(stored.serverInfo) !== JSON.stringify(info.cli))
|
|
22
|
+
|| (runtimeIdentity && JSON.stringify(runtimeIdentity) !== JSON.stringify(info.runtime));
|
|
23
|
+
runtimeIdentity = info.runtime;
|
|
24
|
+
if (changed) {
|
|
25
|
+
await cache?.clear();
|
|
26
|
+
await mcp.sendToolListChanged();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const close = mcp.close.bind(mcp);
|
|
30
|
+
mcp.close = async () => { unsubscribe?.(); await close(); };
|
|
16
31
|
mcp.setRequestHandler('tools/list', (_request, context) => refresh(context.mcpReq.signal));
|
|
17
32
|
mcp.setRequestHandler('tools/call', async (request, context) => {
|
|
18
33
|
try {
|
package/src/cli-runner.js
CHANGED
|
@@ -2,14 +2,15 @@ import spawn from 'cross-spawn';
|
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { packageInfo } from './settings.js';
|
|
4
4
|
|
|
5
|
-
/** @param {{local?: boolean}} [options] */
|
|
6
|
-
export function createCliRunner({ local = false } = {}) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/** @param {{local?: boolean, command?: string, args?: string[], cwd?: string, env?: NodeJS.ProcessEnv}} [options] */
|
|
6
|
+
export function createCliRunner({ local = false, command = local ? process.execPath : 'npx', args, cwd = process.cwd(), env } = {}) {
|
|
7
|
+
const prefix = args ?? (local ? [fileURLToPath(new URL('./cli.js', import.meta.url))]
|
|
8
|
+
: ['-y', '--prefer-online', `${packageInfo.name}@latest`]);
|
|
9
|
+
const listeners = new Set();
|
|
10
10
|
/** @param {string[]} args @param {unknown} [input] @param {AbortSignal} [signal] */
|
|
11
|
-
|
|
12
|
-
const
|
|
11
|
+
const run = (args, input, signal) => new Promise((resolve, reject) => {
|
|
12
|
+
const target = run.target(args);
|
|
13
|
+
const child = spawn(target.command, target.args, { cwd: target.cwd, env: target.env, windowsHide: true, signal, timeout: 180_000, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
13
14
|
let stdout = '', stderr = '', bytes = 0;
|
|
14
15
|
const collect = (chunk, diagnostic) => {
|
|
15
16
|
bytes += Buffer.byteLength(chunk);
|
|
@@ -20,12 +21,23 @@ export function createCliRunner({ local = false } = {}) {
|
|
|
20
21
|
child.stdout.on('data', chunk => collect(chunk, false));
|
|
21
22
|
child.stderr.on('data', chunk => collect(chunk, true));
|
|
22
23
|
child.once('error', reject);
|
|
23
|
-
child.once('close', (code, exitSignal) => {
|
|
24
|
+
child.once('close', async (code, exitSignal) => {
|
|
24
25
|
if (code !== 0) { reject(new Error(`CLI_FAILED (${exitSignal ?? code}): ${stderr.trim().slice(-2000)}`)); return; }
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
let result;
|
|
27
|
+
try { result = JSON.parse(stdout); }
|
|
28
|
+
catch { reject(new Error('CLI_INVALID_RESPONSE')); return; }
|
|
29
|
+
const info = result?._meta?.['comfyui/discovery'];
|
|
30
|
+
if (info && args[0] === '--execute-tool') {
|
|
31
|
+
for (const listener of listeners) await Promise.resolve().then(() => listener(info)).catch(() => {});
|
|
32
|
+
delete result._meta['comfyui/discovery'];
|
|
33
|
+
if (!Object.keys(result._meta).length) delete result._meta;
|
|
34
|
+
}
|
|
35
|
+
resolve(result);
|
|
27
36
|
});
|
|
28
37
|
child.stdin.on('error', () => {});
|
|
29
38
|
child.stdin.end(input === undefined ? '' : JSON.stringify(input));
|
|
30
39
|
});
|
|
40
|
+
run.target = args => ({ command, args: [...prefix, ...args], cwd, env: { ...(env ?? process.env) } });
|
|
41
|
+
run.onCatalog = listener => { listeners.add(listener); return () => listeners.delete(listener); };
|
|
42
|
+
return run;
|
|
31
43
|
}
|
package/src/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { configuredPort, serverInfo } from './settings.js';
|
|
2
|
+
import { configuredPort, serverInfo, protocolVersion } from './settings.js';
|
|
3
3
|
|
|
4
4
|
// Use the real SDK for both manifest generation and argument validation, offline.
|
|
5
5
|
/** @template T @param {(client: import('@modelcontextprotocol/client').Client) => Promise<T>} action @returns {Promise<T>} */
|
|
@@ -8,16 +8,19 @@ async function withTools(action) {
|
|
|
8
8
|
import('@modelcontextprotocol/client'), import('./tools.js'), import('./daemon.js'),
|
|
9
9
|
]);
|
|
10
10
|
let backend;
|
|
11
|
+
let listChanged = false;
|
|
11
12
|
const mcp = createToolServer(async (name, args, signal) => {
|
|
12
13
|
backend ??= new HttpBackend(configuredPort());
|
|
13
14
|
const client = await backend.getClient();
|
|
15
|
+
client.setNotificationHandler('notifications/tools/list_changed', () => { listChanged = true; });
|
|
14
16
|
return client.callTool({ name, arguments: args }, { signal, timeout: 180_000 });
|
|
15
17
|
});
|
|
16
18
|
const client = new Client(serverInfo);
|
|
17
19
|
const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();
|
|
18
20
|
try {
|
|
19
21
|
await Promise.all([mcp.connect(serverTransport), client.connect(clientTransport)]);
|
|
20
|
-
|
|
22
|
+
const result = await action(client);
|
|
23
|
+
return { ...result, _meta: { ...result._meta, 'comfyui/discovery': { cli: serverInfo, runtime: backend?.identity, listChanged } } };
|
|
21
24
|
} finally {
|
|
22
25
|
await Promise.allSettled([client.close(), mcp.close(), backend?.close()]);
|
|
23
26
|
}
|
|
@@ -29,7 +32,10 @@ try {
|
|
|
29
32
|
if (!args.length || args[0] === 'mcp' || args[0] === '--local') {
|
|
30
33
|
await import('./stdio.js');
|
|
31
34
|
} else if (args[0] === '--tool-manifest' && args.length === 1) {
|
|
32
|
-
console.log(JSON.stringify(await withTools(client =>
|
|
35
|
+
console.log(JSON.stringify(await withTools(async client => ({
|
|
36
|
+
...await client.listTools(), serverInfo: client.getServerVersion(), capabilities: client.getServerCapabilities(),
|
|
37
|
+
protocolVersion,
|
|
38
|
+
}))));
|
|
33
39
|
} else if (args[0] === '--execute-tool' && args.length === 2) {
|
|
34
40
|
let result;
|
|
35
41
|
try {
|
package/src/daemon.js
CHANGED
|
@@ -11,7 +11,7 @@ import { serverInfo, protocolVersion } from './settings.js';
|
|
|
11
11
|
/** @param {number} port */
|
|
12
12
|
export const daemonLogPath = (port) => join(tmpdir(), 'comfyui-mcp-runtime', `http-${port}.log`);
|
|
13
13
|
|
|
14
|
-
/** @param {number} port @returns {Promise<number | undefined>} */
|
|
14
|
+
/** @param {number} port @returns {Promise<{name: string, version: string, protocol_version: number, pid: number} | undefined>} */
|
|
15
15
|
async function health(port) {
|
|
16
16
|
let response;
|
|
17
17
|
try { response = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(1000) }); }
|
|
@@ -23,7 +23,7 @@ async function health(port) {
|
|
|
23
23
|
if (!response.ok || data?.name !== serverInfo.name || data.protocol_version !== protocolVersion || !Number.isInteger(data.pid)) {
|
|
24
24
|
throw new Error('HTTP_SERVER_INCOMPATIBLE');
|
|
25
25
|
}
|
|
26
|
-
return data
|
|
26
|
+
return data;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/** @param {number} port */
|
|
@@ -61,7 +61,9 @@ export class HttpBackend {
|
|
|
61
61
|
/** @param {number} port */
|
|
62
62
|
constructor(port) { this.port = port; }
|
|
63
63
|
async connect() {
|
|
64
|
-
const
|
|
64
|
+
const info = await ensureHttp(this.port);
|
|
65
|
+
this.identity = { name: info.name, version: info.version, pid: info.pid, protocol_version: info.protocol_version };
|
|
66
|
+
const pid = info.pid;
|
|
65
67
|
if (this.connection?.pid === pid) return this.connection.client;
|
|
66
68
|
await this.closeConnection();
|
|
67
69
|
const client = new Client(serverInfo);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, open, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
|
+
import { ListToolsResultSchema, ImplementationSchema, ServerCapabilitiesSchema } from '@modelcontextprotocol/core';
|
|
7
|
+
import * as z from 'zod/v4';
|
|
8
|
+
|
|
9
|
+
const catalogSchema = z.object({
|
|
10
|
+
tools: ListToolsResultSchema.shape.tools,
|
|
11
|
+
serverInfo: ImplementationSchema.optional(),
|
|
12
|
+
capabilities: ServerCapabilitiesSchema.optional(),
|
|
13
|
+
protocolVersion: z.number().int().optional(),
|
|
14
|
+
});
|
|
15
|
+
const recordSchema = z.strictObject({
|
|
16
|
+
format: z.literal(1), key: z.string(), savedAt: z.number().finite(), expiresAt: z.number().finite(), catalog: catalogSchema,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export function validateCatalog(value) {
|
|
20
|
+
const catalog = catalogSchema.parse(value);
|
|
21
|
+
if (new Set(catalog.tools.map(tool => tool.name)).size !== catalog.tools.length) throw new Error('DUPLICATE_TOOL_NAME');
|
|
22
|
+
return catalog;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Hash only the actual target invocation. Environment values never leave this function.
|
|
26
|
+
export function discoveryKey({ command, args, cwd, env }, ignored = [], platform = process.platform) {
|
|
27
|
+
const normalize = name => platform === 'win32' ? name.toUpperCase() : name;
|
|
28
|
+
const excluded = new Set(['CODEX_TOOL_CALL_ID', ...ignored].map(normalize));
|
|
29
|
+
const entries = new Map();
|
|
30
|
+
for (const name of Object.keys(env).sort()) {
|
|
31
|
+
const key = normalize(name);
|
|
32
|
+
if (!excluded.has(key) && env[name] !== undefined && !entries.has(key)) entries.set(key, String(env[name]));
|
|
33
|
+
}
|
|
34
|
+
return createHash('sha256').update(JSON.stringify([command, args, cwd, [...entries].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)])).digest('hex');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class DiscoveryCache {
|
|
38
|
+
constructor(target, {
|
|
39
|
+
directory = process.env.COMFY_MCP_DISCOVERY_CACHE_DIR ?? join(tmpdir(), 'comfyui-mcp-runtime', 'discovery'),
|
|
40
|
+
ttlMs = Number(process.env.COMFY_MCP_DISCOVERY_TTL_MS ?? 600_000),
|
|
41
|
+
ignoredEnv = (process.env.COMFY_MCP_CACHE_IGNORE_ENV ?? '').split(',').map(name => name.trim()).filter(Boolean),
|
|
42
|
+
now = Date.now,
|
|
43
|
+
} = {}) {
|
|
44
|
+
this.target = target; this.directory = directory; this.ignoredEnv = ignoredEnv;
|
|
45
|
+
this.ttlMs = Number.isFinite(ttlMs) && ttlMs >= 0 ? ttlMs : 600_000;
|
|
46
|
+
this.now = now;
|
|
47
|
+
}
|
|
48
|
+
location() {
|
|
49
|
+
const key = discoveryKey(this.target(), this.ignoredEnv);
|
|
50
|
+
return { key, file: join(this.directory, `${key}.json`) };
|
|
51
|
+
}
|
|
52
|
+
async read({ key, file } = this.location()) {
|
|
53
|
+
try {
|
|
54
|
+
if ((await stat(file)).size > 8 * 1024 * 1024) return undefined;
|
|
55
|
+
const record = recordSchema.parse(JSON.parse(await readFile(file, 'utf8')));
|
|
56
|
+
const age = this.now() - record.savedAt;
|
|
57
|
+
if (record.key !== key || age < 0 || age >= this.ttlMs || this.now() >= record.expiresAt) return undefined;
|
|
58
|
+
return validateCatalog(record.catalog);
|
|
59
|
+
} catch { return undefined; }
|
|
60
|
+
}
|
|
61
|
+
async lock(file, signal) {
|
|
62
|
+
await mkdir(this.directory, { recursive: true, mode: 0o700 });
|
|
63
|
+
const deadline = Date.now() + 5000, lockPath = file + '.lock';
|
|
64
|
+
while (true) {
|
|
65
|
+
signal?.throwIfAborted();
|
|
66
|
+
try {
|
|
67
|
+
const handle = await open(lockPath, 'wx', 0o600);
|
|
68
|
+
return async () => { await handle.close(); await rm(lockPath, { force: true }); };
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error.code !== 'EEXIST') throw error;
|
|
71
|
+
// CLI subprocesses have a 180-second deadline; recover locks left by a crashed writer.
|
|
72
|
+
const info = await stat(lockPath).catch(() => undefined);
|
|
73
|
+
if (info && Date.now() - info.mtimeMs > 200_000) await rm(lockPath, { force: true });
|
|
74
|
+
if (Date.now() >= deadline) throw new Error('DISCOVERY_CACHE_BUSY');
|
|
75
|
+
await delay(25, undefined, { signal });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async get(load, signal) {
|
|
80
|
+
const location = this.location();
|
|
81
|
+
const hit = await this.read(location);
|
|
82
|
+
signal?.throwIfAborted();
|
|
83
|
+
if (hit) return hit;
|
|
84
|
+
let unlock;
|
|
85
|
+
try { unlock = await this.lock(location.file, signal); }
|
|
86
|
+
catch (error) {
|
|
87
|
+
signal?.throwIfAborted();
|
|
88
|
+
// Cache availability must not prevent discovery. An unlocked reader never writes.
|
|
89
|
+
return validateCatalog(await load());
|
|
90
|
+
}
|
|
91
|
+
const temporary = `${location.file}.${randomUUID()}.tmp`;
|
|
92
|
+
try {
|
|
93
|
+
const shared = await this.read(location);
|
|
94
|
+
if (shared) return shared;
|
|
95
|
+
const catalog = validateCatalog(await load());
|
|
96
|
+
signal?.throwIfAborted();
|
|
97
|
+
try {
|
|
98
|
+
const savedAt = this.now();
|
|
99
|
+
await writeFile(temporary, JSON.stringify({ format: 1, key: location.key, savedAt, expiresAt: savedAt + this.ttlMs, catalog }), { flag: 'wx', mode: 0o600 });
|
|
100
|
+
await rename(temporary, location.file);
|
|
101
|
+
} catch { /* Discovery still succeeds if the optional cache is unwritable. */ }
|
|
102
|
+
return catalog;
|
|
103
|
+
} finally {
|
|
104
|
+
await rm(temporary, { force: true }).catch(() => {});
|
|
105
|
+
await unlock();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async clear() {
|
|
109
|
+
const { file } = this.location();
|
|
110
|
+
const unlock = await this.lock(file);
|
|
111
|
+
try { await rm(file, { force: true }); }
|
|
112
|
+
finally { await unlock(); }
|
|
113
|
+
}
|
|
114
|
+
}
|
package/src/mcp.js
CHANGED
|
@@ -5,7 +5,7 @@ import { workflowResultSchema, runResultSchema, summary, readWorkflow, writeWork
|
|
|
5
5
|
import { createToolServer } from './tools.js';
|
|
6
6
|
import { serverInfo, protocolVersion } from './settings.js';
|
|
7
7
|
|
|
8
|
-
/** @param {Sessions} sessions @param {() => void} [activity] */
|
|
8
|
+
/** @param {Sessions} sessions @param {(delta?: number) => void} [activity] */
|
|
9
9
|
export function createMcp(sessions, activity = () => {}) {
|
|
10
10
|
const result = async (action) => {
|
|
11
11
|
try {
|
|
@@ -45,24 +45,27 @@ export function createMcp(sessions, activity = () => {}) {
|
|
|
45
45
|
}),
|
|
46
46
|
};
|
|
47
47
|
return createToolServer(async (name, args) => {
|
|
48
|
-
activity();
|
|
48
|
+
activity(1);
|
|
49
49
|
try { return await handlers[name](args); }
|
|
50
|
-
finally { activity(); }
|
|
50
|
+
finally { activity(-1); }
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/** @param {number} [port] @param {Sessions} [sessions] @param {number} [idleMs] */
|
|
55
|
-
export async function startMcp(port = 37861, sessions = new Sessions(), idleMs = 30 * 60 * 1000) {
|
|
54
|
+
/** @param {number} [port] @param {Sessions} [sessions] @param {number} [idleMs] @param {number} [discoveryMs] */
|
|
55
|
+
export async function startMcp(port = 37861, sessions = new Sessions(), idleMs = 30 * 60 * 1000, discoveryMs = Math.min(idleMs, 60_000)) {
|
|
56
56
|
let timer;
|
|
57
57
|
let closing;
|
|
58
58
|
let finish;
|
|
59
|
+
let active = 0;
|
|
59
60
|
const closed = new Promise(resolve => { finish = resolve; });
|
|
60
|
-
const
|
|
61
|
+
const arm = (ms) => {
|
|
61
62
|
if (closing) return;
|
|
62
63
|
clearTimeout(timer);
|
|
63
|
-
|
|
64
|
+
if (active) return;
|
|
65
|
+
timer = setTimeout(() => { void close().catch(error => console.error('Idle shutdown failed:', error)); }, ms);
|
|
64
66
|
timer.unref();
|
|
65
67
|
};
|
|
68
|
+
const activity = (delta = 0) => { active += delta; arm(idleMs); };
|
|
66
69
|
sessions.onActivity = activity;
|
|
67
70
|
const validateHost = localhostHostValidation();
|
|
68
71
|
const validateOrigin = localhostOriginValidation();
|
|
@@ -92,6 +95,6 @@ export async function startMcp(port = 37861, sessions = new Sessions(), idleMs =
|
|
|
92
95
|
finish();
|
|
93
96
|
})();
|
|
94
97
|
}
|
|
95
|
-
|
|
98
|
+
arm(discoveryMs);
|
|
96
99
|
return { url: `http://127.0.0.1:${address.port}/mcp`, close, closed };
|
|
97
100
|
}
|
package/src/stdio.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
3
3
|
import { createAdapter } from './adapter.js';
|
|
4
4
|
import { createCliRunner } from './cli-runner.js';
|
|
5
|
+
import { DiscoveryCache } from './discovery-cache.js';
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
+
const run = createCliRunner({ local: process.argv.includes('--local') });
|
|
8
|
+
const mcp = await createAdapter(run, new DiscoveryCache(() => run.target(['--tool-manifest'])));
|
|
7
9
|
await mcp.connect(new StdioServerTransport());
|
|
8
10
|
let closing = false;
|
|
9
11
|
function close() {
|