@cubicecho/agent-router-worker 0.13.0 → 0.14.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.
@@ -23,6 +23,7 @@ A worker's runs reach its built-in `workdir` server and each MCP server the `WOR
23
23
 
24
24
  - A server has either `command`, with optional `args`, `env` and `cwd`, or `url`, with optional `headers`. Any other key refuses the file.
25
25
  - A `command` server is started over stdio, as the worker's user, with no shell. A `url` server is reached over streamable HTTP.
26
+ - A `url` server is asked for MCP 2026-07-28 first, and one that doesn't speak it is reached with the 2025 handshake. A `command` server is started with the 2025 handshake, which every stdio server answers.
26
27
  - A server's name holds lowercase letters, digits, `.`, `-` and `_`, starts with a letter or digit, and is at most 64 characters. `workdir` is taken.
27
28
  - Servers start once, with the worker. Restart the worker after editing the file.
28
29
 
@@ -5,13 +5,9 @@ import { z } from "zod";
5
5
  import { RunEventKind, ToolDiscovery, failedRun, runAgentLoop, stamp } from "@cubicecho/agent-core";
6
6
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
7
7
  import { EventSourceParserStream } from "eventsource-parser/stream";
8
- import { CallToolResultSchema, ElicitRequestSchema, ElicitResultSchema, ToolListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js";
9
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
10
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
11
- import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
8
+ import { Client, InMemoryTransport, ReadBuffer, StreamableHTTPClientTransport, serializeMessage, specTypeSchemas } from "@modelcontextprotocol/client";
12
9
  import { spawn } from "node:child_process";
13
- import { ReadBuffer, serializeMessage } from "@modelcontextprotocol/sdk/shared/stdio.js";
14
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
10
+ import { McpServer } from "@cubicecho/mcp-host";
15
11
  import { lstat, mkdir, readdir, realpath, stat } from "node:fs/promises";
16
12
  // server/core/error-message.ts
17
13
  /**
@@ -222,6 +218,7 @@ Object.freeze({
222
218
  waitTimeoutHours: 24,
223
219
  expireEveryMinutes: 5,
224
220
  taskPollIntervalMs: 2e3,
221
+ inputWaitMinutes: 30,
225
222
  maxAgentDepth: 3
226
223
  });
227
224
  const WORKER_DEFAULTS = Object.freeze({
@@ -870,8 +867,8 @@ function createRunHost(options, overrides = {}) {
870
867
  call,
871
868
  params
872
869
  }, AbortSignal.any([signal, runSignal])));
873
- const answer = response.ok ? ElicitResultSchema.safeParse(await response.json()) : null;
874
- return answer?.success ? answer.data : DECLINED$1;
870
+ const answer = response.ok ? specTypeSchemas.ElicitResult["~standard"].validate(await response.json()) : null;
871
+ return answer !== null && answer.issues === void 0 ? answer.value : DECLINED$1;
875
872
  } catch (error) {
876
873
  console.warn(`[worker] could not ask run ${runId}'s question: ${errorMessage(error)}`);
877
874
  return DECLINED$1;
@@ -1151,7 +1148,7 @@ path.resolve(import.meta.dirname, "..", "..");
1151
1148
  * A bundle can't read the repo's package.json the way `version()` does, because it isn't there.
1152
1149
  */
1153
1150
  function workerVersion() {
1154
- return "0.13.0";
1151
+ return "0.14.0";
1155
1152
  }
1156
1153
  // worker/workdir/git.ts
1157
1154
  /** The git program, found on PATH. */
@@ -1551,7 +1548,7 @@ function createWorkdirServer(options, overrides = {}) {
1551
1548
  const opening = /* @__PURE__ */ new Map();
1552
1549
  server.registerTool("open_repo", {
1553
1550
  description: "Returns a work directory holding a checkout of a git repo, cloning it the first time. Answers JSON: { path, cloned, branch, head }.",
1554
- inputSchema: { repo: z.string().describe("`owner/name` on GitHub, an https clone URL, or an ssh one like `git@host:owner/name.git`.") }
1551
+ inputSchema: z.object({ repo: z.string().describe("`owner/name` on GitHub, an https clone URL, or an ssh one like `git@host:owner/name.git`.") })
1555
1552
  }, ({ repo }) => answer(async () => {
1556
1553
  const ref = parseRepo(repo);
1557
1554
  const rootPath = await realRoot(root);
@@ -1566,10 +1563,10 @@ function createWorkdirServer(options, overrides = {}) {
1566
1563
  }));
1567
1564
  server.registerTool("list_dir", {
1568
1565
  description: `Lists a directory under the work root: each entry with its type (file, dir, symlink, other) and size. Symlinks are not followed, and .git is never listed inside. Answers JSON with \`truncated\` when it held more than ${settings.maxEntries} entries.`,
1569
- inputSchema: {
1566
+ inputSchema: z.object({
1570
1567
  path: z.string().describe("Relative to the work root, or absolute inside it."),
1571
1568
  depth: z.number().int().min(1).optional().describe(`Levels to list; 1 lists the directory's own entries. At most ${settings.maxDepth}.`)
1572
- }
1569
+ })
1573
1570
  }, ({ path, depth = DEFAULT_LIST_DEPTH }) => answer(async () => listDir(await realRoot(root), path, depth, settings)));
1574
1571
  return server;
1575
1572
  }
@@ -1609,6 +1606,12 @@ const LOCAL_ENV_ALLOWLIST = Object.freeze([
1609
1606
  const CLIENT_NAME = "agent-router-worker";
1610
1607
  /** What the worker's servers are told it can do: answer a question in form mode, through the router. */
1611
1608
  const CLIENT_CAPABILITIES = { elicitation: { form: {} } };
1609
+ /**
1610
+ * How a `url` server's protocol era is settled: it is asked for 2026-07-28 first, and a 2025-era one falls back to
1611
+ * the `initialize` handshake. A `command` server, and `workdir` in process, get the 2025 handshake straight away: a
1612
+ * stdio server may never answer a request it doesn't know before `initialize`, which would stall its start.
1613
+ */
1614
+ const HTTP_NEGOTIATION = { mode: "auto" };
1612
1615
  /** The longest delay `setTimeout` keeps; past it, a timer fires at once. */
1613
1616
  const LONGEST_TIMER_MS = 0x7fffffff;
1614
1617
  /** What a question gets when no one can answer it. */
@@ -1725,54 +1728,62 @@ async function startLocalServers(options, overrides = {}) {
1725
1728
  ...WORKER_PROGRAM_DEFAULTS,
1726
1729
  ...overrides
1727
1730
  };
1728
- const started = /* @__PURE__ */ new Map();
1729
- const connect = async (name, transport) => {
1731
+ const running = /* @__PURE__ */ new Map();
1732
+ const connect = async (name, transport, isHttp) => {
1733
+ const refresh = async () => {
1734
+ try {
1735
+ started.tools = await listTools(started.client, settings.localStartTimeoutMs);
1736
+ onChange();
1737
+ } catch (error) {
1738
+ console.warn(`[worker] could not list "${name}"'s tools again: ${errorMessage(error)}`);
1739
+ }
1740
+ };
1730
1741
  const client = new Client({
1731
1742
  name: CLIENT_NAME,
1732
1743
  version: workerVersion()
1733
- }, { capabilities: CLIENT_CAPABILITIES });
1734
- const entry = {
1744
+ }, {
1745
+ capabilities: CLIENT_CAPABILITIES,
1746
+ ...isHttp ? { versionNegotiation: HTTP_NEGOTIATION } : {},
1747
+ listChanged: { tools: {
1748
+ autoRefresh: false,
1749
+ debounceMs: 0,
1750
+ onChanged: () => void refresh()
1751
+ } }
1752
+ });
1753
+ const started = {
1735
1754
  client,
1736
1755
  tools: [],
1737
1756
  calls: /* @__PURE__ */ new Set()
1738
1757
  };
1739
- client.setRequestHandler(ElicitRequestSchema, async (question, extra) => {
1740
- const [only, ...others] = [...entry.calls];
1758
+ client.setRequestHandler("elicitation/create", async (question, ctx) => {
1759
+ const [only, ...others] = [...started.calls];
1741
1760
  const onElicit = others.length === 0 ? only?.onElicit : void 0;
1742
1761
  if (only === void 0 || onElicit === void 0) return DECLINED;
1743
1762
  only.deadline.pause();
1744
1763
  try {
1745
- return await onElicit(question.params, { signal: extra.signal });
1764
+ return await onElicit(question.params, { signal: ctx.mcpReq.signal });
1746
1765
  } catch {
1747
1766
  return DECLINED;
1748
1767
  } finally {
1749
1768
  only.deadline.resume();
1750
1769
  }
1751
1770
  });
1752
- client.setNotificationHandler(ToolListChangedNotificationSchema, async () => {
1753
- try {
1754
- entry.tools = await listTools(client, settings.localStartTimeoutMs);
1755
- onChange();
1756
- } catch (error) {
1757
- console.warn(`[worker] could not list "${name}"'s tools again: ${errorMessage(error)}`);
1758
- }
1759
- });
1760
1771
  try {
1761
1772
  await client.connect(transport, { timeout: settings.localStartTimeoutMs });
1762
- entry.tools = await listTools(client, settings.localStartTimeoutMs);
1773
+ started.tools = await listTools(client, settings.localStartTimeoutMs);
1763
1774
  } catch (error) {
1764
1775
  console.error(`[worker] leaving out the local server "${name}": it did not start: ${errorMessage(error)}`);
1765
1776
  await client.close().catch(() => void 0);
1766
1777
  return;
1767
1778
  }
1768
- started.set(name, entry);
1779
+ running.set(name, started);
1769
1780
  };
1770
1781
  const [workdirSide, clientSide] = InMemoryTransport.createLinkedPair();
1771
1782
  await createWorkdirServer({
1772
1783
  root,
1773
1784
  ...git === void 0 ? {} : { git }
1774
1785
  }, workdir).connect(workdirSide);
1775
- await connect(WORKDIR_SERVER_NAME, clientSide);
1786
+ await connect(WORKDIR_SERVER_NAME, clientSide, false);
1776
1787
  const configured = Object.entries(servers).filter(([name]) => {
1777
1788
  if (name === "workdir") {
1778
1789
  console.error(`[worker] leaving out the local server "${name}": the built-in server has that name.`);
@@ -1786,14 +1797,14 @@ async function startLocalServers(options, overrides = {}) {
1786
1797
  }
1787
1798
  return true;
1788
1799
  });
1789
- await Promise.all(configured.map(([name, config]) => connect(name, transportFor(name, config, baseEnv, settings.localCloseGraceMs))));
1800
+ await Promise.all(configured.map(([name, config]) => connect(name, transportFor(name, config, baseEnv, settings.localCloseGraceMs), "url" in config)));
1790
1801
  return {
1791
- listing: () => [...started].map(([name, { tools }]) => ({
1802
+ listing: () => [...running].map(([name, { tools }]) => ({
1792
1803
  name,
1793
1804
  tools
1794
1805
  })),
1795
1806
  callTool: async (server, tool, args, signal, onElicit) => {
1796
- const entry = started.get(server);
1807
+ const entry = running.get(server);
1797
1808
  if (entry === void 0) throw new Error(`This worker has no local server named "${server}".`);
1798
1809
  const limitMs = settings.localToolTimeoutMs;
1799
1810
  const deadline = pausableDeadline(limitMs, () => /* @__PURE__ */ new Error(`"${tool}" on the local server "${server}" took longer than ${limitMs} ms.`));
@@ -1802,13 +1813,10 @@ async function startLocalServers(options, overrides = {}) {
1802
1813
  deadline
1803
1814
  };
1804
1815
  entry.calls.add(call);
1805
- const result = await entry.client.request({
1806
- method: "tools/call",
1807
- params: {
1808
- name: tool,
1809
- arguments: args
1810
- }
1811
- }, CallToolResultSchema, {
1816
+ const result = await entry.client.callTool({
1817
+ name: tool,
1818
+ arguments: args
1819
+ }, {
1812
1820
  signal: AbortSignal.any([signal, deadline.signal]),
1813
1821
  timeout: LONGEST_TIMER_MS
1814
1822
  }).finally(() => {
@@ -1819,8 +1827,8 @@ async function startLocalServers(options, overrides = {}) {
1819
1827
  return toolResultContent(result);
1820
1828
  },
1821
1829
  close: async () => {
1822
- const clients = [...started.values()].map(({ client }) => client);
1823
- started.clear();
1830
+ const clients = [...running.values()].map(({ client }) => client);
1831
+ running.clear();
1824
1832
  await Promise.all(clients.map((client) => client.close().catch(() => void 0)));
1825
1833
  }
1826
1834
  };
package/lib.js CHANGED
@@ -1 +1 @@
1
- export { r as TOOL_ORIGIN_LOCAL, i as TOOL_ORIGIN_ROUTER, a as WorkerConfigError, n as executeRun, o as readWorkerConfig, t as startWorker } from "./chunks/worker-DjXaG4tH.js";
1
+ export { r as TOOL_ORIGIN_LOCAL, i as TOOL_ORIGIN_ROUTER, a as WorkerConfigError, n as executeRun, o as readWorkerConfig, t as startWorker } from "./chunks/worker-DcCmGig3.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubicecho/agent-router-worker",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "agent-router's worker program: runs a workspace's agent loops on another machine.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -38,7 +38,8 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@modelcontextprotocol/sdk": "^1.30.0",
41
+ "@cubicecho/mcp-host": "^1.0.0",
42
+ "@modelcontextprotocol/client": "^2.4.0",
42
43
  "eventsource-parser": "^3.1.1",
43
44
  "zod": "^4.6.7"
44
45
  },
@@ -68,6 +68,11 @@ export interface RunSettings {
68
68
  expireEveryMinutes: number;
69
69
  /** How often `/mcp` asks a client to check a task, the run it started, when it polls rather than waits. */
70
70
  taskPollIntervalMs: number;
71
+ /**
72
+ * How long a run `/mcp` asked a 2026-07-28 client a question for waits for the client to call again with its
73
+ * answer. Past it the run is cancelled, since no request is left to end it.
74
+ */
75
+ inputWaitMinutes: number;
71
76
  /**
72
77
  * How deep agents may call agents through `/mcp`: a run an app started is 0, and each call to an agent one more.
73
78
  * A call past it is refused, so agents calling each other can't run on forever.
@@ -52,6 +52,11 @@ export declare const AGENT_DEPTH_META_KEY = "cubicecho.com/agent-depth";
52
52
  * they passed through. agent-core exports the same key as `SESSION_META_KEY`. A label only.
53
53
  */
54
54
  export declare const SESSION_META_KEY = "com.cubicecho/session";
55
+ /**
56
+ * The `_meta` key that ties a message to the task it is about, in MCP's 2025-11-25 tasks. SDK 2 keeps parsing task
57
+ * vocabulary but no longer serves it, so `/mcp` names the key itself.
58
+ */
59
+ export declare const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
55
60
  /** The `_meta` key a task's progress notification carries the run's `RunEvent` under. */
56
61
  export declare const RUN_EVENT_META_KEY = "cubicecho.com/run-event";
57
62
  /**
@@ -1,6 +1,5 @@
1
1
  import { type ChildProcessWithoutNullStreams } from 'node:child_process';
2
- import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
3
- import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type JSONRPCMessage, type Transport } from '@modelcontextprotocol/client';
4
3
  /** The signals a stopping program gets, in order, after its stdin closes. */
5
4
  export declare const STOP_SIGNALS: readonly ['SIGTERM', 'SIGKILL'];
6
5
  /** One of the signals a stopping program gets. */
@@ -1,4 +1,4 @@
1
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
1
+ import type { CallToolResult } from '@cubicecho/mcp-host';
2
2
  /**
3
3
  * Whether a tool call that answered is in fact the tool reporting a failure.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { type ElicitRequest, type ElicitResult } from '@modelcontextprotocol/sdk/types.js';
1
+ import { type ElicitRequest, type ElicitResult } from '@modelcontextprotocol/client';
2
2
  import type { LocalServer } from '../server/runner/protocol.ts';
3
3
  import type { CommandServerConfig, LocalServerConfig } from './config.ts';
4
4
  import { type WorkdirSettings, type WorkerProgramSettings } from './defaults.ts';
@@ -1,4 +1,4 @@
1
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
1
+ import { McpServer } from '@cubicecho/mcp-host';
2
2
  import { type WorkdirSettings } from '../defaults.ts';
3
3
  import { type GitRunner } from './git.ts';
4
4
  /** What the workdir server is built from. */
package/worker.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { o as readWorkerConfig, s as errorMessage, t as startWorker } from "./chunks/worker-DjXaG4tH.js";
2
+ import { o as readWorkerConfig, s as errorMessage, t as startWorker } from "./chunks/worker-DcCmGig3.js";
3
3
  // worker/index.ts
4
4
  /** Exits with this when the worker can't start, or is stopped twice. */
5
5
  const EXIT_FAILED = 1;