@ultimat3/mcp 31.48.0 → 31.50.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.
@@ -9,6 +9,7 @@ import { fixFor, isJsonObject, logger, stringField } from '@ultimat3/core';
9
9
  import type { McpCatalogNameSource } from './catalog-errors';
10
10
  import { McpCatalogToolDuplicateError, McpCatalogUnresolvedError } from './catalog-errors';
11
11
  import { asFrameworkError, forAudience } from './framework-error';
12
+ import type { McpSplitOptions } from './meta-split-options';
12
13
  import type { McpResourceGroups, McpSurfaceOption } from './meta-surface';
13
14
  import { META_TOOL_NAMES, MetaSurface } from './meta-surface';
14
15
  import type { AnyMcpTool, McpCaller } from './registry';
@@ -49,6 +50,7 @@ export interface PerCall {
49
50
  readonly tools: readonly AnyMcpTool[];
50
51
  readonly surface?: McpSurfaceOption | undefined;
51
52
  readonly groups?: McpResourceGroups | undefined;
53
+ readonly split?: McpSplitOptions | undefined;
52
54
  }
53
55
 
54
56
  export interface CatalogRefused {
@@ -67,6 +69,7 @@ export async function viewOf(
67
69
  tools: perCall.tools,
68
70
  surface: perCall.surface,
69
71
  groups: perCall.groups,
72
+ split: perCall.split,
70
73
  source: perCall.catalog,
71
74
  tenantArg: perCall.tenant?.arg,
72
75
  },
@@ -107,6 +110,8 @@ export interface CatalogBoot {
107
110
  readonly tools: readonly AnyMcpTool[];
108
111
  readonly surface: McpSurfaceOption | undefined;
109
112
  readonly groups: McpResourceGroups | undefined;
113
+ /** The app's `split:`, so a resolved view's dispatchers are the boot ones. */
114
+ readonly split?: McpSplitOptions | undefined;
110
115
  readonly source: McpCatalogSource;
111
116
  /** `tenant.arg`, which no runtime tool may declare either. */
112
117
  readonly tenantArg: string | undefined;
@@ -154,7 +159,10 @@ function merge(boot: CatalogBoot, resolved: McpResolvedCatalog): CatalogView {
154
159
  if (boot.tenantArg !== undefined) refused(() => assertArgFree(boot.tenantArg ?? '', tool));
155
160
  }
156
161
  const all = [...boot.tools, ...resolved.tools];
157
- return { tools: new ToolRegistry().registerAll(all), meta: metaOf(boot, resolved, all) };
162
+ // Built with the reserved name, as the boot registry is: `params` reaches `resolve` through the
163
+ // meta dispatchers without passing `tenantStep`.
164
+ const tools = new ToolRegistry(boot.tenantArg).registerAll(all);
165
+ return { tools, meta: metaOf(boot, resolved, all) };
158
166
  }
159
167
 
160
168
  /** The boot groups plus the resolved ones, held to every boot check `MetaSurface.build` makes. */
@@ -176,6 +184,7 @@ function metaOf(
176
184
  surface: boot.surface,
177
185
  groups: groups.size === 0 ? undefined : Object.fromEntries(groups),
178
186
  tools,
187
+ split: boot.split,
179
188
  }),
180
189
  );
181
190
  }
@@ -0,0 +1,61 @@
1
+ // What `mcpServer(input)` takes. Split from `server.ts` for the size ceiling only: it declares,
2
+ // and decides nothing.
3
+
4
+ import type { Clock, ErrorAudience } from '@ultimat3/core';
5
+ import type { McpAuditHook } from './audit-hook';
6
+ import type { McpCatalogDetail } from './meta-catalog-render';
7
+ import type { McpSplitOptions } from './meta-split-options';
8
+ import type { McpResourceGroups, McpSurfaceOption } from './meta-surface';
9
+ import type { AnyMcpTool } from './registry';
10
+ import type { McpPrompt, McpResource, McpResourceSource } from './resources';
11
+ import type { McpCatalogSource } from './server-catalog';
12
+ import type { McpInstructions } from './server-voice';
13
+ import type { McpTenant } from './tenant';
14
+ import type { ServerInfo } from './wire';
15
+
16
+ export interface McpServerInput {
17
+ readonly tools?: readonly AnyMcpTool[];
18
+ readonly resources?: readonly McpResource[];
19
+ /** Resources listed per caller (a tenant's own docs), after the fixed ones. */
20
+ readonly resourceSources?: readonly McpResourceSource[];
21
+ readonly prompts?: readonly McpPrompt[];
22
+ readonly serverInfo?: ServerInfo;
23
+ /** `'flat'` (the default): one tool per primitive. See `McpSurfaceOption`. */
24
+ readonly surface?: McpSurfaceOption | undefined;
25
+ /** The meta catalog's resources. Required with a surface that can be `'meta'`. */
26
+ readonly groups?: McpResourceGroups | undefined;
27
+ /**
28
+ * How much of each action `list_resources` says: `'full'` (the default) or `'compact'` — names
29
+ * and tags, the rest in `describe_resource`. Needs a surface that can be `'meta'`.
30
+ */
31
+ readonly catalogDetail?: McpCatalogDetail | undefined;
32
+ /**
33
+ * `initialize`'s `instructions`: how to use this server, for a client that injects it into the
34
+ * model's context (Claude Code does; many clients do not — never load-bear on it). A function
35
+ * answers per caller population — a staff surface and a customer one read different advice —
36
+ * and a function that throws or answers anything but a non-empty string sends none.
37
+ */
38
+ readonly instructions?: McpInstructions | undefined;
39
+ /**
40
+ * Whose `fix:` line a refusal carries. `'developer'` (the default, and the dev server's): the
41
+ * fix the author wrote — `x policy explain …`, a declaration to edit. `'caller'`: the error's
42
+ * `callerFix` where it declares one — what a REMOTE agent can do about it. `defineAppMcp`
43
+ * serves `'caller'`.
44
+ */
45
+ readonly errorAudience?: ErrorAudience | undefined;
46
+ /** Every gate decision as data, after its log line — see `audit-hook.ts`. The route reads it too. */
47
+ readonly onAudit?: McpAuditHook | undefined;
48
+ /** Stamps each `onAudit` event's `at`. */
49
+ readonly clock?: Clock | undefined;
50
+ /**
51
+ * The per-caller catalog, resolved per request for `tools/list` and every `tools/call` and merged
52
+ * with `tools`/`groups` (`server-catalog.ts`). `defineAppMcp({ catalog })` builds it.
53
+ */
54
+ readonly catalog?: McpCatalogSource | undefined;
55
+ /** One token across tenants, the tenant named per call — see `tenant.ts`. */
56
+ readonly tenant?: McpTenant | undefined /**
57
+ * What the app adds to the `'meta-split'` dispatchers: envelope fields of its own, and the
58
+ * `stricter` hook — see `meta-split-options.ts`. Needs a surface that can be `'meta-split'`.
59
+ */;
60
+ readonly split?: McpSplitOptions | undefined;
61
+ }
@@ -1,6 +1,6 @@
1
- // `resources/read` — the document surface's three outcomes (hidden = absent, scope, read), every
2
- // one audited, and every provider call inside a `try`. Split from `server.ts` for the size ceiling;
3
- // the server passes what it owns, so this stays a function and never a second dispatcher.
1
+ // `resources/read` and `resources/list` — the document surface's three outcomes (hidden = absent,
2
+ // scope, read), every one audited, and every provider or source call inside a `try`. Split from
3
+ // `server.ts` for the size ceiling; the server passes what it owns, so these stay functions.
4
4
 
5
5
  import { asCallerContext } from '@ultimat3/action';
6
6
  import type { ErrorAudience } from '@ultimat3/core';
@@ -11,9 +11,9 @@ import { asFrameworkError, forAudience } from './framework-error';
11
11
  import type { McpEra } from './protocol-era';
12
12
  import { resourceNotFoundCode } from './protocol-era';
13
13
  import type { McpCaller } from './registry';
14
- import type { ResourceRegistry } from './resources';
14
+ import type { ResourceRegistry, ResourceResolution } from './resources';
15
15
  import { readResource } from './resources';
16
- import type { JsonRpcRequest, JsonRpcResponse } from './wire';
16
+ import type { JsonRpcId, JsonRpcRequest, JsonRpcResponse } from './wire';
17
17
  import {
18
18
  errorResponse,
19
19
  INTERNAL_ERROR,
@@ -52,7 +52,15 @@ export async function resourcesRead(
52
52
  return errorResponse(id, INVALID_PARAMS, 'resources/read params.uri must be a string');
53
53
  }
54
54
 
55
- const resolved = await on.resources.resolveFor(uri, caller);
55
+ // A per-caller SOURCE is an injected thunk too (`extraRecipes` is a tenant-runbook lookup), and
56
+ // `resolveFor` asks it for any URI the fixed list does not hold: it gets the same `try` the read
57
+ // below has, or its throw is the unanswered request that comment describes.
58
+ let resolved: ResourceResolution;
59
+ try {
60
+ resolved = await on.resources.resolveFor(uri, caller);
61
+ } catch (error) {
62
+ return failed(on, id, uri, `resource "${uri}" could not be read`, error, caller);
63
+ }
56
64
  switch (resolved.kind) {
57
65
  // OUTCOME 1. Absent AND hidden collapse to one answer with no `data`: this branch used to
58
66
  // return `available: [...every uri]`, so one wrong guess enumerated the whole catalog. No
@@ -103,20 +111,50 @@ export async function resourcesRead(
103
111
  on.audit.resourceRead({ uri, outcome: 'ok', caller });
104
112
  return resultResponse(id, { contents: [contents] });
105
113
  } catch (error) {
106
- const thrown = asFrameworkError(error);
107
- if (thrown !== undefined) {
108
- const framework = forAudience(thrown, on.audience);
109
- on.audit.resourceRead({ uri, outcome: 'failed', caller, code: framework.code });
110
- return errorResponse(id, INTERNAL_ERROR, `resource "${uri}" could not be read`, {
111
- code: framework.code,
112
- cause: framework.cause,
113
- fix: fixFor(framework, on.audience),
114
- ...(framework.docs === undefined ? {} : { docs: framework.docs }),
115
- });
116
- }
117
- // No internals: a provider's own message names a path, a query or a host the caller has no
118
- // business seeing, exactly as a failing tool's does.
119
- on.audit.resourceRead({ uri, outcome: 'failed', caller });
120
- return errorResponse(id, INTERNAL_ERROR, `resource "${uri}" could not be read`);
114
+ return failed(on, id, uri, `resource "${uri}" could not be read`, error, caller);
115
+ }
116
+ }
117
+
118
+ /**
119
+ * `resources/list`: the fixed list plus every per-caller source, each source call inside the `try`.
120
+ * Silent when it answers (pre-filtered, as `tools/list` is); a source that throws is one audited
121
+ * `failed` under the method's own name, there being no URI to file it under.
122
+ */
123
+ export async function resourcesList(
124
+ on: ResourceReadDeps,
125
+ req: JsonRpcRequest,
126
+ caller: McpCaller,
127
+ ): Promise<JsonRpcResponse> {
128
+ const id = req.id ?? null;
129
+ try {
130
+ return resultResponse(id, { resources: await on.resources.listFor(caller) });
131
+ } catch (error) {
132
+ return failed(on, id, 'resources/list', 'resources could not be listed', error, caller);
133
+ }
134
+ }
135
+
136
+ /** A provider's throw as `-32603`: a framework error keeps its code, cause and fix. */
137
+ function failed(
138
+ on: ResourceReadDeps,
139
+ id: JsonRpcId,
140
+ uri: string,
141
+ message: string,
142
+ error: unknown,
143
+ caller: McpCaller,
144
+ ): JsonRpcResponse {
145
+ const thrown = asFrameworkError(error);
146
+ if (thrown !== undefined) {
147
+ const framework = forAudience(thrown, on.audience);
148
+ on.audit.resourceRead({ uri, outcome: 'failed', caller, code: framework.code });
149
+ return errorResponse(id, INTERNAL_ERROR, message, {
150
+ code: framework.code,
151
+ cause: framework.cause,
152
+ fix: fixFor(framework, on.audience),
153
+ ...(framework.docs === undefined ? {} : { docs: framework.docs }),
154
+ });
121
155
  }
156
+ // No internals: a provider's own message names a path, a query or a host the caller has no
157
+ // business seeing, exactly as a failing tool's does.
158
+ on.audit.resourceRead({ uri, outcome: 'failed', caller });
159
+ return errorResponse(id, INTERNAL_ERROR, message);
122
160
  }
@@ -6,11 +6,14 @@ import { InputInvalidError } from '@ultimat3/action';
6
6
  import type { ErrorAudience } from '@ultimat3/core';
7
7
  import { renderCauseValue } from '@ultimat3/core';
8
8
  import { formatIssues } from '@ultimat3/schema';
9
+ import type { McpProtocolError } from './errors';
9
10
  import type { McpCatalogDetail } from './meta-catalog-render';
10
11
  import { McpSurfaceInvalidError } from './meta-errors';
11
12
  import type { McpSurfaceOption } from './meta-surface';
12
13
  import type { McpCaller, McpToolResult } from './registry';
13
14
  import type { ArgIssue } from './validate-args';
15
+ import type { JsonRpcResponse } from './wire';
16
+ import { errorResponse, INVALID_REQUEST } from './wire';
14
17
 
15
18
  /** See `McpServerInput.instructions`. */
16
19
  export type McpInstructions = string | ((caller: McpCaller) => string | undefined);
@@ -96,3 +99,17 @@ export function screenCatalogDetail(
96
99
  }
97
100
  return detail;
98
101
  }
102
+
103
+ /**
104
+ * The envelope refusals — no id to answer on, so `null` — rendered the way the scope refusal
105
+ * already is: a `message` a client library surfaces verbatim, and `data: { code, fix, docs }`
106
+ * built by the error class that owns the wording. Every other refusal on this surface carried its
107
+ * instruction; these two answered a bare `-32600` and left the caller to guess.
108
+ */
109
+ export function protocolRefusal(message: string, error: McpProtocolError): JsonRpcResponse {
110
+ return errorResponse(null, INVALID_REQUEST, message, {
111
+ code: error.code,
112
+ fix: error.fix,
113
+ docs: error.docs,
114
+ });
115
+ }
package/src/server.ts CHANGED
@@ -3,16 +3,14 @@
3
3
  // and an already-resolved caller, and returns a response or `null` for a notification.
4
4
  // Both transports (http, stdio) and every test drive this one function.
5
5
 
6
- import type { Clock, ErrorAudience } from '@ultimat3/core';
7
6
  import { fixFor } from '@ultimat3/core';
8
7
  import { outcomeForResult } from './audit';
9
- import type { McpAuditHook, McpAuditor } from './audit-hook';
8
+ import type { McpAuditor } from './audit-hook';
10
9
  import { LOG_ONLY_AUDITOR, mcpAuditor } from './audit-hook';
11
10
  import { McpProtocolError, McpScopeDeniedError, TOOL_UNKNOWN_FIX } from './errors';
12
11
  import { metaCall } from './meta-call';
13
- import type { McpCatalogDetail } from './meta-catalog-render';
14
12
  import { META_UNKNOWN_FIX } from './meta-errors';
15
- import type { McpResourceGroups, McpSurfaceOption, MetaResource } from './meta-surface';
13
+ import type { MetaResource } from './meta-surface';
16
14
  import { MetaSurface } from './meta-surface';
17
15
  import { promptListEntry, promptsGet, visiblePrompts } from './prompts-get';
18
16
  import type { McpEra } from './protocol-era';
@@ -26,7 +24,6 @@ import {
26
24
  unsupportedVersion,
27
25
  } from './protocol-era';
28
26
  import type {
29
- AnyMcpTool,
30
27
  McpCaller,
31
28
  McpToolResult,
32
29
  McpVerbClass,
@@ -34,16 +31,23 @@ import type {
34
31
  ToolResolution,
35
32
  } from './registry';
36
33
  import { ToolRegistry } from './registry';
37
- import type { McpPrompt, McpResource, McpResourceSource } from './resources';
34
+ import type { McpPrompt } from './resources';
38
35
  import { ResourceRegistry } from './resources';
39
- import type { CatalogRefused, CatalogView, McpCatalogSource, PerCall } from './server-catalog';
36
+ import type { CatalogRefused, CatalogView, PerCall } from './server-catalog';
40
37
  import { catalogRefusal, viewOf } from './server-catalog';
41
- import { resourcesRead } from './server-resources';
42
- import type { McpInstructions, McpServerVoice } from './server-voice';
43
- import { instructionsFor, invalidArgsResult, screenCatalogDetail } from './server-voice';
44
- import type { McpTenant } from './tenant';
45
- import { assertTenant, LIST_TENANTS, listTenantsTool, tenantStep, withTenantArg } from './tenant';
38
+ import type { McpServerInput } from './server-input';
39
+ import { resourcesList, resourcesRead } from './server-resources';
40
+ import type { McpServerVoice } from './server-voice';
41
+ import {
42
+ instructionsFor,
43
+ invalidArgsResult,
44
+ protocolRefusal,
45
+ screenCatalogDetail,
46
+ } from './server-voice';
47
+ import { assertTenant, listTenantsTool, tenantStep, withTenantArg } from './tenant';
48
+ import { tenantDoor, tenantsCall } from './tenant-discover';
46
49
  import { admitted, thrownResponse } from './tool-thrown';
50
+ import { inputRequiredFor } from './url-elicitation';
47
51
  import type { JsonRpcId, JsonRpcRequest, JsonRpcResponse, McpWire, ServerInfo } from './wire';
48
52
  import {
49
53
  defaultServerInfo,
@@ -58,63 +62,24 @@ import {
58
62
  resultResponse,
59
63
  } from './wire';
60
64
 
65
+ export type { McpServerInput } from './server-input';
61
66
  export type { McpWire } from './wire';
62
67
 
63
- export interface McpServerInput {
64
- readonly tools?: readonly AnyMcpTool[];
65
- readonly resources?: readonly McpResource[];
66
- /** Resources listed per caller (a tenant's own docs), after the fixed ones. */
67
- readonly resourceSources?: readonly McpResourceSource[];
68
- readonly prompts?: readonly McpPrompt[];
69
- readonly serverInfo?: ServerInfo;
70
- /** `'flat'` (the default): one tool per primitive. See `McpSurfaceOption`. */
71
- readonly surface?: McpSurfaceOption | undefined;
72
- /** The meta catalog's resources. Required with a surface that can be `'meta'`. */
73
- readonly groups?: McpResourceGroups | undefined;
74
- /**
75
- * How much of each action `list_resources` says: `'full'` (the default) or `'compact'` — names
76
- * and tags, the rest in `describe_resource`. Needs a surface that can be `'meta'`.
77
- */
78
- readonly catalogDetail?: McpCatalogDetail | undefined;
79
- /**
80
- * `initialize`'s `instructions`: how to use this server, for a client that injects it into the
81
- * model's context (Claude Code does; many clients do not — never load-bear on it). A function
82
- * answers per caller population — a staff surface and a customer one read different advice —
83
- * and a function that throws or answers anything but a non-empty string sends none.
84
- */
85
- readonly instructions?: McpInstructions | undefined;
86
- /**
87
- * Whose `fix:` line a refusal carries. `'developer'` (the default, and the dev server's): the
88
- * fix the author wrote — `x policy explain …`, a declaration to edit. `'caller'`: the error's
89
- * `callerFix` where it declares one — what a REMOTE agent can do about it. `defineAppMcp`
90
- * serves `'caller'`.
91
- */
92
- readonly errorAudience?: ErrorAudience | undefined;
93
- /** Every gate decision as data, after its log line — see `audit-hook.ts`. The route reads it too. */
94
- readonly onAudit?: McpAuditHook | undefined;
95
- /** Stamps each `onAudit` event's `at`. */
96
- readonly clock?: Clock | undefined;
97
- /**
98
- * The per-caller catalog, resolved per request for `tools/list` and every `tools/call` and merged
99
- * with `tools`/`groups` (`server-catalog.ts`). `defineAppMcp({ catalog })` builds it.
100
- */
101
- readonly catalog?: McpCatalogSource | undefined;
102
- /** One token across tenants, the tenant named per call — see `tenant.ts`. */
103
- readonly tenant?: McpTenant | undefined;
104
- }
105
-
106
68
  export function mcpServer(input: McpServerInput = {}): McpServer {
107
69
  const tenant = input.tenant;
108
- if (tenant !== undefined) assertTenant(tenant, input.tools ?? []);
70
+ if (tenant !== undefined) assertTenant(tenant, input.tools ?? [], input);
109
71
  // `list_tenants` is a boot tool like any other, so every surface lists it and nothing shadows it.
110
- const all = [...(input.tools ?? []), ...(tenant === undefined ? [] : [listTenantsTool(tenant)])];
111
- const tools = new ToolRegistry().registerAll(all);
72
+ // A `discover` tool takes its place, and it is then not registered.
73
+ const lists = tenant === undefined || tenant.discover !== undefined;
74
+ const all = [...(input.tools ?? []), ...(lists ? [] : [listTenantsTool(tenant)])];
75
+ const tools = new ToolRegistry(tenant?.arg).registerAll(all);
112
76
  const resources = new ResourceRegistry().registerAll(input.resources ?? []);
113
77
  for (const source of input.resourceSources ?? []) resources.addSource(source);
114
78
  const meta = MetaSurface.build({
115
79
  surface: input.surface,
116
80
  groups: input.groups,
117
81
  tools: all,
82
+ split: input.split,
118
83
  });
119
84
  const catalogDetail = screenCatalogDetail(input.catalogDetail, input.surface);
120
85
  return new McpServer(
@@ -137,6 +102,7 @@ export function mcpServer(input: McpServerInput = {}): McpServer {
137
102
  tools: all,
138
103
  surface: input.surface,
139
104
  groups: input.groups,
105
+ split: input.split,
140
106
  },
141
107
  );
142
108
  }
@@ -252,14 +218,16 @@ export class McpServer {
252
218
  case 'tools/call':
253
219
  return this.toolsCall(body, caller, signal);
254
220
  case 'resources/list':
255
- return resultResponse(id, { resources: await this.resources.listFor(caller) });
256
- case 'resources/read':
257
- return resourcesRead(
258
- { resources: this.resources, audit: this.audit, audience: this.voice.errorAudience },
259
- body,
260
- caller,
261
- era,
262
- );
221
+ case 'resources/read': {
222
+ const on = {
223
+ resources: this.resources,
224
+ audit: this.audit,
225
+ audience: this.voice.errorAudience,
226
+ };
227
+ return body.method === 'resources/list'
228
+ ? resourcesList(on, body, caller)
229
+ : resourcesRead(on, body, caller, era);
230
+ }
263
231
  // MCP's keep-alive: an empty result, which clients treat as "still here".
264
232
  case 'ping':
265
233
  return resultResponse(id, {});
@@ -285,14 +253,12 @@ export class McpServer {
285
253
  private listIn(view: CatalogView, caller: McpCaller): readonly ToolListEntry[] {
286
254
  const flat = view.tools.list(caller);
287
255
  const meta = metaServed(view.meta, caller);
288
- const arg = this.perCall?.tenant?.arg;
256
+ const tenant = this.perCall?.tenant;
289
257
  const withArg = (entries: readonly ToolListEntry[]) =>
290
- arg === undefined ? entries : withTenantArg(entries, arg);
258
+ tenant === undefined ? entries : withTenantArg(entries, tenant);
291
259
  if (meta === undefined) return withArg(flat);
292
260
  // Constant: the meta tools plus whatever the app left ungrouped (`docs`, `whoami`).
293
- const entries = MetaSurface.entriesFor(
294
- meta.surfaceFor(caller) === 'meta' ? 'meta' : 'meta-split',
295
- );
261
+ const entries = meta.entries(meta.surfaceFor(caller) === 'meta' ? 'meta' : 'meta-split');
296
262
  return withArg(
297
263
  [...flat.filter((tool) => !meta.isGrouped(tool.name)), ...entries].sort((a, b) =>
298
264
  a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
@@ -340,8 +306,14 @@ export class McpServer {
340
306
  // answers exactly as a hidden tool — `notFound`, the same call the dispatch below makes.
341
307
  let who = caller;
342
308
  let rawArgs: unknown = params['arguments'];
309
+ // A call naming none meets a door first (`tenant-discover.ts`): the tenant list, or the person.
343
310
  const tenant = this.perCall?.tenant;
344
- if (tenant !== undefined && name !== LIST_TENANTS) {
311
+ const door = tenant === undefined ? 'person' : tenantDoor(tenant, name, rawArgs);
312
+ if (tenant !== undefined && door === 'tenants') {
313
+ const resolved = tenantsCall(listTenantsTool(tenant), this.tools.get(name), name, caller);
314
+ return this.dispatch(id, name, resolved, caller, signal);
315
+ }
316
+ if (tenant !== undefined && door === 'step') {
345
317
  const step = await tenantStep(tenant, rawArgs, caller);
346
318
  if (step.kind === 'not-member') {
347
319
  return this.notFound(
@@ -368,7 +340,8 @@ export class McpServer {
368
340
  tools: view.tools,
369
341
  audit: this.audit,
370
342
  catalogDetail: this.voice.catalogDetail ?? 'full',
371
- dispatch: (at, tool, resolved, who) => this.dispatch(at, tool, resolved, who, signal),
343
+ dispatch: (at, tool, resolved, who) =>
344
+ this.dispatch(at, tool, resolved, who, signal, req),
372
345
  notFound: (at, tool, who, fix) => this.notFound(at, tool, who, fix),
373
346
  refuse: (at, tool, error, who) =>
374
347
  thrownResponse(at, tool, error, who, this.voice.errorAudience, this.audit),
@@ -378,7 +351,7 @@ export class McpServer {
378
351
  );
379
352
  if (answered !== undefined) return answered;
380
353
  }
381
- return this.dispatch(id, name, view.tools.resolve(name, rawArgs ?? {}, who), who, signal);
354
+ return this.dispatch(id, name, view.tools.resolve(name, rawArgs ?? {}, who), who, signal, req);
382
355
  }
383
356
 
384
357
  /** OUTCOME 1, the one answer for absent and hidden alike. See `dispatch`. */
@@ -397,6 +370,7 @@ export class McpServer {
397
370
  resolved: ToolResolution,
398
371
  caller: McpCaller,
399
372
  signal?: AbortSignal,
373
+ request?: JsonRpcRequest,
400
374
  ): Promise<JsonRpcResponse> {
401
375
  const audience = this.voice.errorAudience;
402
376
  // Three outcomes, deliberately different — and every one of them audited, including the
@@ -448,8 +422,11 @@ export class McpServer {
448
422
  }
449
423
 
450
424
  let result: McpToolResult;
425
+ // A page the tool asked the person to open, for a client that can show one (`url-elicitation.ts`).
426
+ let asked: Record<string, unknown> | undefined;
451
427
  try {
452
428
  result = await resolved.tool.handle(resolved.args, caller, signal);
429
+ asked = request === undefined ? undefined : inputRequiredFor(request, result);
453
430
  } catch (error) {
454
431
  return thrownResponse(id, name, error, caller, audience, this.audit);
455
432
  }
@@ -463,6 +440,7 @@ export class McpServer {
463
440
  caller,
464
441
  ...(result.code === undefined ? {} : { code: result.code }),
465
442
  });
443
+ if (asked !== undefined) return resultResponse(id, asked);
466
444
  // `code` is audit-only and never reaches the wire: it is already inside the rendered body.
467
445
  const payload: Record<string, unknown> = { content: result.content };
468
446
  // Through `manage_resource` too, byte for byte: the meta door answers what the flat one does,
@@ -475,20 +453,6 @@ export class McpServer {
475
453
  }
476
454
  }
477
455
 
478
- /**
479
- * The envelope refusals — no id to answer on, so `null` — rendered the way the scope refusal
480
- * already is: a `message` a client library surfaces verbatim, and `data: { code, fix, docs }`
481
- * built by the error class that owns the wording. Every other refusal on this surface carried its
482
- * instruction; these two answered a bare `-32600` and left the caller to guess.
483
- */
484
- function protocolRefusal(message: string, error: McpProtocolError): JsonRpcResponse {
485
- return errorResponse(null, INVALID_REQUEST, message, {
486
- code: error.code,
487
- fix: error.fix,
488
- docs: error.docs,
489
- });
490
- }
491
-
492
456
  /** `meta` when this caller is served it, else `undefined` — one rule for the boot and a resolved view. */
493
457
  function metaServed(meta: MetaSurface | undefined, caller: McpCaller): MetaSurface | undefined {
494
458
  return meta !== undefined && meta.surfaceFor(caller) !== 'flat' ? meta : undefined;