@ultimat3/mcp 31.49.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.
- package/CLAUDE.md +5 -5
- package/README.md +132 -14
- package/package.json +11 -11
- package/src/app-tool.ts +10 -3
- package/src/app-tools.ts +29 -7
- package/src/audit.ts +2 -0
- package/src/catalog-errors.ts +11 -5
- package/src/errors.ts +6 -1
- package/src/from-action.ts +33 -3
- package/src/index.ts +11 -1
- package/src/meta-call.ts +2 -2
- package/src/meta-errors.ts +27 -3
- package/src/meta-split-call.ts +45 -6
- package/src/meta-split-options.ts +180 -0
- package/src/meta-split.ts +3 -2
- package/src/meta-surface.ts +17 -1
- package/src/protocol-era.ts +2 -1
- package/src/recipe-errors.ts +19 -7
- package/src/recipe-markdown.ts +64 -12
- package/src/recipe-replay.ts +12 -5
- package/src/recipe-search.ts +14 -7
- package/src/recipes-surface.ts +19 -6
- package/src/recipes-tool.ts +67 -14
- package/src/recipes.ts +99 -24
- package/src/registry.ts +30 -0
- package/src/remote-client.ts +21 -2
- package/src/remote-tools.ts +4 -0
- package/src/runtime-tool.ts +10 -4
- package/src/server-catalog.ts +6 -0
- package/src/server-input.ts +61 -0
- package/src/server-voice.ts +17 -0
- package/src/server.ts +40 -78
- package/src/tenant-discover.ts +167 -0
- package/src/tenant.ts +94 -21
- package/src/url-elicitation.ts +153 -0
- package/src/wire.ts +2 -0
package/CLAUDE.md
CHANGED
|
@@ -18,7 +18,7 @@ import. The CLI wires it.
|
|
|
18
18
|
| `audit.ts` | one structured line per `tools/call` and per `resources/read`, outcome → level |
|
|
19
19
|
| `validate-args.ts` | JSON-Schema-subset arg validation, applies defaults |
|
|
20
20
|
| `server.ts` | JSON-RPC dispatch; `classify` delegates to `protocol-era.ts` |
|
|
21
|
-
| `protocol-era.ts` | one request's era (`_meta` version), `METHODS
|
|
21
|
+
| `protocol-era.ts` | one request's era (`_meta` version), `METHODS`, `classifyBody`, `initialize`, `server/discover`, the modern stamp, the HTTP header check, each answer's status |
|
|
22
22
|
| `server-resources.ts` | `resources/read`'s three outcomes, audited, provider in a `try` |
|
|
23
23
|
| `from-action.ts` | action/query → tool; the "one authz system" projection; `toolsFrom` (sweep, skips) vs `toolsListed` (written out, refuses) |
|
|
24
24
|
| `resources.ts` | resources + prompts, stable `ultimate://` URIs |
|
|
@@ -30,10 +30,9 @@ import. The CLI wires it.
|
|
|
30
30
|
| `confirmations.ts` · `confirmation-*.ts` | `mcpConfirmations`: a factory over `action` (view/decide) · the gate on `handle` · stores · DDL · codes. `confirmation-installed.ts` is the `mcpConfirmationStore` slot a declaration with no `store` reads; `adapter.ts` (`./adapter`) its interface, error and installer |
|
|
31
31
|
| `oauth-metadata.ts` | RFC 9728 protected-resource metadata + the 401 `resource_metadata` challenge (`defineAppMcp({ oauth })`) |
|
|
32
32
|
| `oauth-server.ts` | `mcpAuthorizationServer`: `@ultimat3/auth`'s `authorizationServer` bound to one endpoint's `resource` (default and required by `resolveToken`), its `oauth` block, `mcp.auth.<event>` lines. No protocol rule lives here |
|
|
33
|
-
| `transport-stdio.ts` | NDJSON on stdin/stdout for `x mcp serve`: ≤ 16 calls run, ≤ 64 queued; the reader keeps reading at the cap, so `notifications/cancelled` and `ping` are always heard |
|
|
34
|
-
| `stdio-lines.ts` | raw chunks → lines, the cap in bytes |
|
|
33
|
+
| `transport-stdio.ts` · `stdio-lines.ts` | NDJSON on stdin/stdout for `x mcp serve`: ≤ 16 calls run, ≤ 64 queued; the reader keeps reading at the cap, so `notifications/cancelled` and `ping` are always heard |
|
|
35
34
|
| `app-tools.ts` | `defineAppMcp` — a generated app's own MCP surface, one call |
|
|
36
|
-
| `runtime-*` · `*-catalog.ts` · `tenant
|
|
35
|
+
| `runtime-*` · `*-catalog.ts` · `tenant*.ts` | `catalog:` (`runtimeTool()`, checked, merged per request) · `tenant:` (`list_tenants`); codes in `catalog-errors.ts` |
|
|
37
36
|
| `app-tool.ts` | the authored `tools: { name: {...} }` record → `ProjectablePrimitive` |
|
|
38
37
|
| `projectable.ts` | a real `action`/`query` → `ProjectablePrimitive`; the ONE adapter both the sweep and the written-out list use |
|
|
39
38
|
| `exposed.ts` | `include: 'exposed'` — the action/query registries → primitives |
|
|
@@ -41,9 +40,10 @@ import. The CLI wires it.
|
|
|
41
40
|
| `scopes.ts` | the `scopes:` map — outcome 2's declaration surface and its three boot refusals |
|
|
42
41
|
| `readonly-sql.ts` · `readonly-sql-calls.ts` · `explain-sql.ts` | layer 3 of `db.query` — the single-read parse — and `db.migrate`'s branch check · the banned call families · `db.explain`'s screen |
|
|
43
42
|
| `query-page.ts` | a list query tool's ONE bounded page, `_after` cursor |
|
|
43
|
+
| `url-elicitation.ts` | `withUrlElicitation`, `input_required` |
|
|
44
44
|
| `query-limits.ts` | layer 4 of `db.query` — the row, byte and timeout ceilings, and what truncation reports |
|
|
45
45
|
| `meta-surface.ts` · `meta-catalog-render.ts` | `surface: 'meta'` catalog, `groups:` boot checks (dispatch: `server.ts`) · its text, `catalogDetail` |
|
|
46
|
-
| `meta-split
|
|
46
|
+
| `meta-split*.ts` · `meta-host.ts` | `'meta-split'`: dispatchers, effect boot check · `split:` (fields, `stricter`) · dispatch (wrong tool, stricter door, preview) · the server half both meta doors call |
|
|
47
47
|
| `list-params.ts` | `listParams` whitelist → the schema `manage_resource` enforces (flat keys: `status_eq`) |
|
|
48
48
|
| `meta-errors.ts` · `framework-error.ts` | meta boot refusals · a thrown value read and rendered (split from `server.ts`) |
|
|
49
49
|
| `server-voice.ts` · `surface-budget.ts` | `instructions`, `errorAudience`, the invalid-args RESULT · `tools/list`/`list_resources` size, measured and budgeted |
|
package/README.md
CHANGED
|
@@ -282,7 +282,7 @@ serves the same catalog pair plus three dispatchers, each running only its own e
|
|
|
282
282
|
|---|---|---|---|
|
|
283
283
|
| `read_resource` | every query (`destructive: false`) | `{ resource, action, params? }` | `readOnlyHint: true` |
|
|
284
284
|
| `write_resource` | actions declaring `mcp: { effect: 'write' }` | `{ resource, action, params? }` | `readOnlyHint: false`, `destructiveHint: true` |
|
|
285
|
-
| `delete_resource` | actions declaring `mcp: { effect: 'delete' }` — archive, cancel, delete, an external send, a spend | `{ resource, action, params?, live?, confirmed_by_user }` | `readOnlyHint: false`, `destructiveHint: true` |
|
|
285
|
+
| `delete_resource` | actions declaring `mcp: { effect: 'delete' }` — archive, cancel, delete, an external send, a spend; and, as the stricter door, any `write` sent to it and a read the app's `stricter` hook demands | `{ resource, action, params?, live?, confirmed_by_user }` | `readOnlyHint: false`, `destructiveHint: true` |
|
|
286
286
|
|
|
287
287
|
```ts
|
|
288
288
|
import { action } from '@ultimat3/action';
|
|
@@ -322,7 +322,46 @@ defineAppMcp({
|
|
|
322
322
|
Neither is `required` by the schema — the dispatcher is the one gate, so a call carrying both only
|
|
323
323
|
inside `params` is read, not refused as `X_INPUT_INVALID` (#798).
|
|
324
324
|
- Order: visibility (absent answer) → effect (`X_MCP_WRONG_TOOL`) → scope → arguments → the policy's
|
|
325
|
-
actor half → preview / confirmation → `dispatch`, the flat path — same
|
|
325
|
+
actor half → the `stricter` hook → preview / confirmation → `dispatch`, the flat path — same
|
|
326
|
+
audit line, same bucket.
|
|
327
|
+
- **The stricter door** (`As of 2026-11`). `delete_resource` also runs a `write` action sent to it:
|
|
328
|
+
the same preview, the same `confirmed_by_user`. `write_resource` and `read_resource` are never
|
|
329
|
+
widened — a delete through `write_resource` stays `X_MCP_WRONG_TOOL`. A read through
|
|
330
|
+
`delete_resource` stays `X_MCP_WRONG_TOOL` unless the app demanded it for that call (below).
|
|
331
|
+
- **The door is on the call.** `caller.door` is `{ tool, fields }` for a call that came through a
|
|
332
|
+
dispatcher: the audit line carries `door: '<dispatcher>'`, `onAudit` reads `event.caller.door`,
|
|
333
|
+
and a hand-written tool or a `runtimeTool` is handed `door` beside `input` and `ctx`.
|
|
334
|
+
|
|
335
|
+
#### `split:` — envelope fields and the `stricter` hook
|
|
336
|
+
|
|
337
|
+
`As of 2026-11`. Two things an app adds to the dispatchers, checked at boot (`X_MCP_SPLIT_INVALID`:
|
|
338
|
+
a surface that is never `'meta-split'`, a field name the envelope owns, a `stricter` that is not a
|
|
339
|
+
function):
|
|
340
|
+
|
|
341
|
+
| `split.` | What it is | Refusal |
|
|
342
|
+
|---|---|---|
|
|
343
|
+
| `fields: { <name>: { description, tools?, required?, maxLength? } }` | a string field of the app's own on the envelope of the named dispatchers (default: all three): a `reason`, a change ticket. Published by `tools/list`, validated on the envelope, handed on as `door.fields`. **Never part of the action input** | undeclared, mistyped, too long, or a required one missing: invalid arguments, as for any other |
|
|
344
|
+
| `stricter: (call) => boolean` | whether THIS call must come through `delete_resource`, decided from `{ caller, tool, resource, action, effect, params, fields }` — `params` already validated, the caller already in scope and admitted | demanded on `read_resource` / `write_resource`: `X_MCP_WRONG_TOOL` naming `delete_resource`, nothing ran. On `delete_resource` it is what lets a read run there, behind preview and `confirmed_by_user` |
|
|
345
|
+
|
|
346
|
+
`stricter` fails closed: anything but the literal `false` demands the stricter door, and a throw
|
|
347
|
+
fails the call. It is not asked for a `delete` action, nor for a `write` already on
|
|
348
|
+
`delete_resource`.
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
import { defineAppMcp } from '@ultimat3/mcp';
|
|
352
|
+
|
|
353
|
+
defineAppMcp({
|
|
354
|
+
include: 'exposed',
|
|
355
|
+
surface: 'meta-split',
|
|
356
|
+
groups: { payments: { description: 'Payments', tools: ['refundPayment', 'paymentById'] } },
|
|
357
|
+
split: {
|
|
358
|
+
fields: { reason: { description: 'Why this call is made, in one sentence.', maxLength: 500 } },
|
|
359
|
+
// A large refund is confirmed by the user, a small one is not.
|
|
360
|
+
stricter: ({ action, params }) =>
|
|
361
|
+
action === 'refundPayment' && Number(params['amountMinor']) > 10_000,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
```
|
|
326
365
|
- Ungrouped tools (`docs`, `whoami`) stay flat beside the five, exactly as on `'meta'`.
|
|
327
366
|
|
|
328
367
|
### Per-caller tools: `catalog:` and `runtimeTool()`
|
|
@@ -376,7 +415,7 @@ defineAppMcp({
|
|
|
376
415
|
tenant it acts in under `tenant.arg`. The step runs first on a call:
|
|
377
416
|
|
|
378
417
|
1. the arg is read and **stripped** — no tool's schema or handler ever sees it (`X_MCP_TENANT_INVALID`
|
|
379
|
-
at boot for a tool declaring it). Missing or empty: `X_MCP_TENANT_REQUIRED`, whose fix is `list_tenants({})
|
|
418
|
+
at boot for a tool declaring it). Missing or empty: `X_MCP_TENANT_REQUIRED`, whose fix is `list_tenants({})` (or the `discover` tool).
|
|
380
419
|
2. `resolve({ person, value })` answers the call's actor, a `kind: 'agent'` — or `null`, which is
|
|
381
420
|
**byte-for-byte the hidden-tool answer**: no 403, no echo of the value. A throw (or a non-agent
|
|
382
421
|
actor) is `X_MCP_TENANT_UNRESOLVED`, never "not a member".
|
|
@@ -386,6 +425,20 @@ tenant it acts in under `tenant.arg`. The step runs first on a call:
|
|
|
386
425
|
`list_tenants` (no arg, no scope) serves `list({ person })`; `tools/list` publishes the arg as a
|
|
387
426
|
required string on every other tool.
|
|
388
427
|
|
|
428
|
+
**Which calls may name no tenant** (`tenant-discover.ts`, `As of 2026-11`). By default one tool,
|
|
429
|
+
`list_tenants`. Two options change that, both checked at boot (`X_MCP_TENANT_INVALID`):
|
|
430
|
+
|
|
431
|
+
| option | names | a call with no `tenant.arg` | a call with one |
|
|
432
|
+
|---|---|---|---|
|
|
433
|
+
| `discover: '<tool>'` | `list_resources` (with `surface: 'meta'` or `'meta-split'`, never a function), or an ungrouped tool of `tools:` with no `visibleTo` | answers `{ tenants, next }` as the person, behind the tool's own scope, whatever else it sends | the tool itself, in that tenant |
|
|
434
|
+
| `optional: ['<tool>', …]` | ungrouped tools of `tools:` (`docs`), never the `discover` tool | runs as the person: no `orgId`, `caller.tenant` absent | runs as the tenant actor |
|
|
435
|
+
|
|
436
|
+
With `discover`, `list_tenants` is not registered — the tool list keeps its size — and
|
|
437
|
+
`X_MCP_TENANT_REQUIRED` points at the discover tool. `tools/list` publishes the arg on those tools
|
|
438
|
+
too, but not as required. Only an ABSENT arg opens either door: a present, unusable one (`''`,
|
|
439
|
+
`null`, a number) is `X_MCP_TENANT_REQUIRED`, and a tenant the person is not in is the hidden-tool
|
|
440
|
+
answer on these tools as on every other. A per-caller `catalog` tool can be named by neither.
|
|
441
|
+
|
|
389
442
|
**`tools/list` is person-scoped, and not a promise.** It names no tenant (MCP's `tools/list` takes
|
|
390
443
|
only a `cursor`), so `visibleTo`, `can()` and `catalog` run there as the PERSON. `tools/call` runs
|
|
391
444
|
them as the tenant actor, and the call is authoritative:
|
|
@@ -502,12 +555,73 @@ did not.
|
|
|
502
555
|
**Dual-era, `As of 2026-11`** (`protocol-era.ts`). A request whose
|
|
503
556
|
`params._meta["io.modelcontextprotocol/protocolVersion"]` is in `MCP_MODERN_VERSIONS` (`2026-07-28`)
|
|
504
557
|
is served statelessly: `server/discover`, no `initialize` or `ping`, every result stamped
|
|
505
|
-
`resultType: 'complete'` + `_meta` `serverInfo
|
|
558
|
+
`resultType: 'complete'` + `_meta` `serverInfo` — except a `tools/call` answered
|
|
559
|
+
`resultType: 'input_required'` (the URL prompt below), so a client branches on `resultType` before
|
|
560
|
+
reading `content` — lists and reads `ttlMs: 0`, `cacheScope: 'private'`.
|
|
506
561
|
No `_meta` version, or one in `MCP_LEGACY_VERSIONS` (`2025-11-25`, `2025-06-18`, `2025-03-26`), is
|
|
507
562
|
today's legacy dispatch; `initialize` echoes an offered legacy revision, else `2025-11-25`. Any
|
|
508
563
|
other version is `-32022` `X_MCP_PROTOCOL_UNSUPPORTED` with `data: { supported, requested }`.
|
|
509
564
|
There is no `MCP_PROTOCOL_VERSION`: name the era, `MCP_MODERN_VERSIONS[0]` or `MCP_LEGACY_VERSIONS`.
|
|
510
565
|
|
|
566
|
+
**URL-mode elicitation, `As of 2026-11`** (`url-elicitation.ts`; MCP 2026-07-28 `client/elicitation`,
|
|
567
|
+
`basic/patterns/mrtr`). A handler that needs the person to open a page returns
|
|
568
|
+
`withUrlElicitation(output, { url, message })`. `output` is unchanged and is the whole answer for
|
|
569
|
+
every client that cannot show a prompt, so it says the same in its own fields.
|
|
570
|
+
|
|
571
|
+
```ts
|
|
572
|
+
import { withUrlElicitation } from '@ultimat3/mcp';
|
|
573
|
+
|
|
574
|
+
declare const appOrigin: string;
|
|
575
|
+
|
|
576
|
+
// What a projected handler (an action's or a query's) returns when the person has a page to open.
|
|
577
|
+
export function notConnected() {
|
|
578
|
+
const link = new URL('/connect', appOrigin).href;
|
|
579
|
+
return withUrlElicitation(
|
|
580
|
+
{ status: 'not_connected', open: link },
|
|
581
|
+
{ url: link, message: 'Open this page to finish connecting.' },
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
| `tools/call` | Answer |
|
|
587
|
+
|---|---|
|
|
588
|
+
| modern, `_meta["io.modelcontextprotocol/clientCapabilities"].elicitation.url` an object | `{ resultType: 'input_required', inputRequests: { url_elicitation: { method: 'elicitation/create', params: { mode: 'url', url, message } } } }` — no `content`, no `requestState`. `url` is the checked URL in its parsed spelling (`new URL(url).href`) |
|
|
589
|
+
| the retry, `params.inputResponses.url_elicitation.action` `accept`, `decline` or `cancel` | the tool runs again and its result is the answer: asked once per call. `accept` is consent to open the page, not proof it was finished. Any other `action` is no answer: the tool runs again, and an ask it makes is sent, not suppressed; a rerun that no longer asks answers its result |
|
|
590
|
+
| the tool failed (`isError`, a result that is not JSON) | the failure, to every caller: a prompt never hides it, and an ask beside it is not checked |
|
|
591
|
+
| modern without the capability (`elicitation: {}` is form mode only) | the tool's result |
|
|
592
|
+
| legacy | the tool's result. `-32042` is not sent: its capability is declared on `initialize`, and no handshake is kept |
|
|
593
|
+
| the ask is not an absolute `https:` URL (`http:` on `localhost`, `127.0.0.1`, `[::1]`), carries `user:password@`, or has an empty message | `isError`, `X_MCP_ELICITATION_URL_INVALID` — for every caller, capable or not |
|
|
594
|
+
|
|
595
|
+
The ask belongs to the call whose handler made it — an output object returned again by a later
|
|
596
|
+
call carries nothing — and an action's `output` parse does not drop it.
|
|
597
|
+
|
|
598
|
+
The handler runs again on the retry whatever the person answered (`decline` and `cancel`
|
|
599
|
+
included), so it must be replay-safe: a write before the ask runs twice. Keep the write behind a
|
|
600
|
+
completion check the handler makes itself — read whether the page was finished, and ask only when
|
|
601
|
+
it was not. Asked once per call: a rerun that asks again inside the retry (a second page, a fresh
|
|
602
|
+
nonce in the URL) is answered with its content, which says what is still needed, and the next call
|
|
603
|
+
asks. An action with an `idempotencyKey` replays its first result to a retry under the same key, so
|
|
604
|
+
it can never see the page finished: the completion check goes in a call without that key.
|
|
605
|
+
|
|
606
|
+
The spec's rules a
|
|
607
|
+
value cannot show stay the app's: nothing about the person and no pre-authenticated link in the
|
|
608
|
+
URL, and the page verifies that whoever opened it is the caller the ask was made for (its
|
|
609
|
+
session against the MCP caller's subject) before it accepts anything.
|
|
610
|
+
|
|
611
|
+
A hand-built `McpTool` sets the field on its `McpToolResult` instead, beside its `content`:
|
|
612
|
+
|
|
613
|
+
```ts
|
|
614
|
+
import type { McpToolResult } from '@ultimat3/mcp';
|
|
615
|
+
import { textResult } from '@ultimat3/mcp';
|
|
616
|
+
|
|
617
|
+
declare const link: string;
|
|
618
|
+
|
|
619
|
+
const answer: McpToolResult = {
|
|
620
|
+
...textResult(`Not connected yet. Open ${link} to finish.`),
|
|
621
|
+
urlElicitation: { url: link, message: 'Open this page to finish connecting.' },
|
|
622
|
+
};
|
|
623
|
+
```
|
|
624
|
+
|
|
511
625
|
| HTTP refusal | Status | Code |
|
|
512
626
|
|---|---|---|
|
|
513
627
|
| `Origin` present and core's `proveSameOrigin` cannot show it is this app — not `seen.origin` (else the request URL's), not `seen.listed` (`http.cors.origins` on a mounted app) — before `resolveToken`. A DNS-rebound name passes it (Host and Origin agree) | 403 | `X_MCP_ORIGIN_REFUSED` |
|
|
@@ -778,18 +892,22 @@ A driver without `introspect` is `X_MCP_JOB_TOOL_INVALID`.
|
|
|
778
892
|
| Declare | What it does |
|
|
779
893
|
|---|---|
|
|
780
894
|
| `recipes: [{ name, title, description, steps: [{ tool, why, example? }], notes? }]` | each served as `docs://recipes/<name>` (`text/markdown`) and through a read-only `docs` tool. Every step's tool must be in the catalog (`X_MCP_RECIPE_TOOL_UNKNOWN`), every example must pass its input (`X_MCP_RECIPE_EXAMPLE_INVALID`), at boot, all offenders at once |
|
|
781
|
-
| `recipes:
|
|
782
|
-
| `
|
|
783
|
-
|
|
784
|
-
`docs({})`
|
|
785
|
-
|
|
786
|
-
|
|
895
|
+
| `recipes: [{ ..., section: 'ref', aliases: ['refusals'] }]` | served as `docs://ref/<name>` instead of `docs://recipes/<name>`; `section`, like a name, is lowercase letters and digits in groups joined by single `-` (`ref-v2`; never `-ref`, `ref-` or `ref--v2`) (`X_MCP_RECIPE_URI_RESERVED`), one URI per recipe, and every section a recipe uses is owned by `recipes:` — a `resources:` URI under it is refused. `aliases` score in `docs({ q })` like the title |
|
|
896
|
+
| `recipes: await markdownRecipes({ dir })` | one `*.md` per recipe, body served as written (line ends normalised to LF, outer blank lines trimmed). Name = file name; a sub-folder one level down is its section (`ref/errors.md` → `docs://ref/errors`; `recipes/<name>.md` is `<name>.md`). `---` `title:` / `description:` / `aliases: a, b` frontmatter, else the first `# ` heading and paragraph. A ```` ```call ```` fence — `tool {"arg": "value"}` — is a step, checked like one; a whole `"<name>"` value is a placeholder, any value at boot. A `docs://<section>/` link into a section this server serves that names no recipe is `X_MCP_RECIPE_LINK_DANGLING`, the link's whole path checked (`docs://ref/errors/old` is not `docs://ref/errors`); another `docs://` prefix is not judged |
|
|
897
|
+
| `extraRecipes: (caller) => recipes` | the caller's own (a tenant's runbooks), asked per request: on `docs` as `source: 'caller'`, on `resources/list` and `resources/read` to that caller alone (a throw is `-32603` on all three, audited `failed`). Not boot-checked; one naming a tool the caller cannot call is not shown. May add a section of its own; a section outside that grammar is `X_MCP_RECIPE_URI_RESERVED` |
|
|
898
|
+
| `docsTool: { description?, index?: 'json' \| 'map' }` | `description` replaces the `docs` tool's own. `index: 'map'` makes `docs({})` plain text: a `# <section>` line per section, then `<uri> <title>` per recipe (` (yours)` for a caller's own). Default `'json'`: `{ recipes: [{ name, title, description, uri, source }] }`; `name` is bare, so outside `recipes` read by `uri` (or `<section>/<name>`) |
|
|
899
|
+
|
|
900
|
+
`docs({})` lists what this caller can follow; `docs({ name })` / `docs({ uri })` reads one —
|
|
901
|
+
`name` is the bare name in `recipes`, `<section>/<name>` elsewhere;
|
|
902
|
+
`docs({ q })` inlines the best match (3 points a word in name, title or aliases, 2 in description,
|
|
903
|
+
1 in the body) and names the nearest names on a miss — never an empty answer while a recipe is visible. `q`
|
|
787
904
|
is at most 1000 characters (`X_INPUT_INVALID` beyond); a miss compares its first 16 words. A
|
|
788
905
|
recipe is visible only when every step's tool is visible to the caller and its scope is on the
|
|
789
906
|
token; hidden and unknown are the same not-found. An `UltimateError`'s `docs://recipes/<name>` is
|
|
790
907
|
checked at load (`X_MCP_RECIPE_UNKNOWN`). In a contract test, `replayRecipes(server, recipes, {
|
|
791
|
-
caller, placeholders })` CALLS every fenced example through the server and reads every
|
|
792
|
-
|
|
908
|
+
caller, placeholders, sections? })` CALLS every fenced example through the server and reads every
|
|
909
|
+
link into a section `recipes` uses or `sections` names — replaying a subset, name the server's
|
|
910
|
+
other sections. No such tool, refused arguments, a refusing policy or a dangling link fails it.
|
|
793
911
|
|
|
794
912
|
`McpResource.read(caller)` takes the caller the gates admitted, and `mcpServer({ resourceSources })`
|
|
795
913
|
lists resources per caller — what `extraRecipes` is built on.
|
|
@@ -804,7 +922,7 @@ lists resources per caller — what `extraRecipes` is built on.
|
|
|
804
922
|
| output | `{ untrusted, isError }`: the remote's text inside `<untrusted source="mcp:<name>/<tool>">`, middle cut past `maxResultChars`; invisible format characters (`\p{Cf}`) stripped, then every `<` (and full-width `<`, small `﹤`) written `<` — no tag-shaped pattern left to bypass |
|
|
805
923
|
| `expose` | default `false`: the actions are this app's, not its `/mcp`'s — `include: 'exposed'` leaves them out, while an in-app `agent()` is still offered them (`agents: true`). `expose: true` opts one remote server in, making this app's `/mcp` answer for a third party's tools |
|
|
806
924
|
| `reverifyMs` | default 3,600,000: one verdict against the live server stands this long (read on `clock`, default `systemClock`), then the next call re-lists and holds it to the lock again — a remote that changes and announces nothing is caught within the hour |
|
|
807
|
-
| `mcpClient({ name, url, dial, deadlineMs, auth })` | over core's `outbound()`; modern era first, the legacy handshake when the server refuses it for its era (a 400/404/405, an unknown-version/method/request JSON-RPC code, a body that is no answer — never a 429, 408 or 403; one handshake shared by concurrent first calls, and a failed one decides nothing). A `tools/list` whose cursor outlasts 50 pages is `malformed`, never a truncated list. A text-only result is a success. `X_MCP_REMOTE_REFUSED`'s `meta.failure` tells `transport` / `status` / `rpc` / `malformed` apart; a tool's own `isError` is a result. A 401 is `X_MCP_REMOTE_AUTH_REQUIRED` with `meta.resourceMetadata` |
|
|
925
|
+
| `mcpClient({ name, url, dial, deadlineMs, auth, maxBytes?, fetch? })` | over core's `outbound()`; `maxBytes` caps one answer (default 16 MiB, `X_MCP_REMOTE_REFUSED` `transport` past it); `fetch` is the transport under `outbound()`, so the screen, deadline, cap and redirect refusal stay the client's; modern era first, the legacy handshake when the server refuses it for its era (a 400/404/405, an unknown-version/method/request JSON-RPC code, a body that is no answer — never a 429, 408 or 403; one handshake shared by concurrent first calls, and a failed one decides nothing). A `tools/list` whose cursor outlasts 50 pages is `malformed`, never a truncated list. A text-only result is a success. `X_MCP_REMOTE_REFUSED`'s `meta.failure` tells `transport` / `status` / `rpc` / `malformed` apart; a tool's own `isError` is a result. A 401 is `X_MCP_REMOTE_AUTH_REQUIRED` with `meta.resourceMetadata` |
|
|
808
926
|
| `mcpOAuthClient({ clientId, clientName, redirectUri, scopes? })` | the upstream's OAuth: `begin(serverUrl)` reads RFC 9728 then RFC 8414 metadata and answers `{ authorizeUrl, handshake }` (PKCE S256 from `@ultimat3/auth`, `resource` per RFC 8707); `exchange(handshake, { code, state })` and `refresh(handshake, token)` answer `{ accessToken, refreshToken, expiresIn }`. When the server's refresh answer carries no `refresh_token`, `refresh` answers the one it was passed (RFC 6749 §6: the old one stays valid), so storing the answer never loses it; `null` only from `exchange`. `begin` refuses a server URL or an issuer that is not `https:` (loopback `http:` aside), before fetching its metadata. `clientId` is the HTTPS URL this app serves `metadata()` at (a client ID metadata document). Keep the handshake server-side; return the token from `auth` |
|
|
809
927
|
|
|
810
928
|
## Errors
|
|
@@ -821,7 +939,7 @@ lists resources per caller — what `extraRecipes` is built on.
|
|
|
821
939
|
| `X_MCP_SURFACE_OVER_BUDGET` | `assertMcpSurfaceBudget` measured a surface over its declared ceiling |
|
|
822
940
|
| `X_MCP_TENANT_REQUIRED` | a call on a `tenant:` server names no tenant (missing or empty `tenant.arg`); refused before dispatch, `list_tenants({})` names the values — `refused`, at `warn` |
|
|
823
941
|
| `X_MCP_TENANT_UNRESOLVED` | `tenant.resolve` threw or answered a non-agent actor — never "not a member", which is the hidden-tool answer |
|
|
824
|
-
| `X_MCP_TENANT_INVALID` | `tenant.arg` is not a plain name, or a tool's own input already declares it — at boot |
|
|
942
|
+
| `X_MCP_TENANT_INVALID` | `tenant.arg` is not a plain name, or a tool's own input already declares it; or `tenant.discover` / `tenant.optional` names a tool some caller cannot reach by that name — at boot |
|
|
825
943
|
| `X_MCP_IDEMPOTENCY_KEY_SHADOWED` | an idempotent action's input declares `idempotencyKey`, the reserved retry-key argument |
|
|
826
944
|
| `X_MCP_PROTOCOL` | malformed envelope, unknown method, bad auth header |
|
|
827
945
|
| `X_MCP_PROTOCOL_UNSUPPORTED` | the request names a protocol version this server does not serve (`-32022`, 400) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/mcp",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.50.0",
|
|
4
4
|
"description": "MCP server, dev tools, and the action-to-tool projection \u2014 one authz system, two surfaces",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"test": "bun test"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@ultimat3/action": "31.
|
|
48
|
-
"@ultimat3/auth": "31.
|
|
49
|
-
"@ultimat3/core": "31.
|
|
50
|
-
"@ultimat3/db": "31.
|
|
51
|
-
"@ultimat3/entity": "31.
|
|
52
|
-
"@ultimat3/http": "31.
|
|
53
|
-
"@ultimat3/jobs": "31.
|
|
54
|
-
"@ultimat3/policy": "31.
|
|
55
|
-
"@ultimat3/query": "31.
|
|
56
|
-
"@ultimat3/schema": "31.
|
|
47
|
+
"@ultimat3/action": "31.50.0",
|
|
48
|
+
"@ultimat3/auth": "31.50.0",
|
|
49
|
+
"@ultimat3/core": "31.50.0",
|
|
50
|
+
"@ultimat3/db": "31.50.0",
|
|
51
|
+
"@ultimat3/entity": "31.50.0",
|
|
52
|
+
"@ultimat3/http": "31.50.0",
|
|
53
|
+
"@ultimat3/jobs": "31.50.0",
|
|
54
|
+
"@ultimat3/policy": "31.50.0",
|
|
55
|
+
"@ultimat3/query": "31.50.0",
|
|
56
|
+
"@ultimat3/schema": "31.50.0"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/src/app-tool.ts
CHANGED
|
@@ -24,12 +24,18 @@ import type { InferOutput, StandardSchemaV1 } from '@ultimat3/schema';
|
|
|
24
24
|
import { formatIssues, toValidationIssues, toWireSchema, validateAsync } from '@ultimat3/schema';
|
|
25
25
|
import { McpToolUnsafeError } from './errors';
|
|
26
26
|
import type { ProjectablePrimitive } from './from-action';
|
|
27
|
-
import
|
|
27
|
+
import { throughDoor } from './from-action';
|
|
28
|
+
import type { McpDoor, McpRole, McpToolAnnotations } from './registry';
|
|
28
29
|
|
|
29
30
|
export interface AppToolArgs<TInput extends StandardSchemaV1> {
|
|
30
31
|
readonly input: InferOutput<TInput>;
|
|
31
32
|
/** The ambient request context, with `actor` set to the MCP caller. */
|
|
32
33
|
readonly ctx: Ctx;
|
|
34
|
+
/**
|
|
35
|
+
* The `'meta-split'` dispatcher this call came through, and the `split.fields` its envelope
|
|
36
|
+
* carried. Absent on every other path.
|
|
37
|
+
*/
|
|
38
|
+
readonly door?: McpDoor;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
export interface AppToolDefinition<TInput extends StandardSchemaV1 = StandardSchemaV1> {
|
|
@@ -118,7 +124,7 @@ export function appToolPrimitive(name: string, def: AnyAppToolDefinition): Proje
|
|
|
118
124
|
const ctx = useContext();
|
|
119
125
|
guardActionBeforeInput(policy, { actor: actorOf(ctx), ctx, action: name }, 'mcp');
|
|
120
126
|
}),
|
|
121
|
-
|
|
127
|
+
...throughDoor(({ input, actor, door }) =>
|
|
122
128
|
// The caller is the actor for the WHOLE call. A child context is how the framework
|
|
123
129
|
// impersonates, so the policy subject and whatever `handle` reads off `ctx.actor` are
|
|
124
130
|
// the same identity by construction rather than by two call sites agreeing.
|
|
@@ -135,8 +141,9 @@ export function appToolPrimitive(name: string, def: AnyAppToolDefinition): Proje
|
|
|
135
141
|
// input by another name: one code, X_INPUT_INVALID, whichever surface the call came in on.
|
|
136
142
|
const parsed = await parseInput(def.input, input, name);
|
|
137
143
|
guardAction(policy, { actor: actorOf(ctx), input: parsed, ctx, action: name }, 'mcp');
|
|
138
|
-
return def.handle({ input: parsed, ctx });
|
|
144
|
+
return def.handle({ input: parsed, ctx, ...(door === undefined ? {} : { door }) });
|
|
139
145
|
}),
|
|
146
|
+
),
|
|
140
147
|
};
|
|
141
148
|
}
|
|
142
149
|
|
package/src/app-tools.ts
CHANGED
|
@@ -26,13 +26,14 @@ import { noteIncluded } from './include-early';
|
|
|
26
26
|
import { jobStatusPrimitive } from './job-status-tool';
|
|
27
27
|
import { jobToolBrand } from './job-tool';
|
|
28
28
|
import type { McpCatalogDetail } from './meta-catalog-render';
|
|
29
|
+
import type { McpSplitOptions } from './meta-split-options';
|
|
29
30
|
import type { McpResourceGroups, McpSurfaceOption } from './meta-surface';
|
|
30
31
|
import type { McpOAuth } from './oauth-metadata';
|
|
31
32
|
import type { ListedPrimitive } from './projectable';
|
|
32
33
|
import { asProjectable } from './projectable';
|
|
33
34
|
import type { McpRecipe } from './recipes';
|
|
34
35
|
import { withRecipes } from './recipes-surface';
|
|
35
|
-
import type { ExtraRecipes } from './recipes-tool';
|
|
36
|
+
import type { DocsToolOptions, ExtraRecipes } from './recipes-tool';
|
|
36
37
|
import type { AnyMcpTool } from './registry';
|
|
37
38
|
import type { McpPrompt, McpResource } from './resources';
|
|
38
39
|
import { toPrompts } from './resources';
|
|
@@ -71,10 +72,11 @@ export interface DefineAppMcpInput<TSchemas extends AppToolSchemas = AppToolSche
|
|
|
71
72
|
/** App-specific readable documents (a catalog export, a report). */
|
|
72
73
|
readonly resources?: readonly McpResource[];
|
|
73
74
|
/**
|
|
74
|
-
* How-to recipes, each served as `docs
|
|
75
|
-
* Every step names a tool of THIS server and its example must
|
|
76
|
-
* here, so a renamed tool fails the boot instead of sending an
|
|
77
|
-
* declared, `resources:` may not hold a
|
|
75
|
+
* How-to recipes, each served as `docs://<section>/<name>` (section `recipes` unless set) and
|
|
76
|
+
* through a read-only `docs` tool. Every step names a tool of THIS server and its example must
|
|
77
|
+
* pass that tool's input — checked here, so a renamed tool fails the boot instead of sending an
|
|
78
|
+
* agent to nothing. With recipes declared, `resources:` may not hold a URI under a section they
|
|
79
|
+
* use, `docs://recipes/` always included (`X_MCP_RECIPE_URI_RESERVED`).
|
|
78
80
|
*/
|
|
79
81
|
readonly recipes?: readonly McpRecipe[];
|
|
80
82
|
/**
|
|
@@ -83,6 +85,11 @@ export interface DefineAppMcpInput<TSchemas extends AppToolSchemas = AppToolSche
|
|
|
83
85
|
* boot (they do not exist yet): one naming a tool the caller cannot call is simply not shown.
|
|
84
86
|
*/
|
|
85
87
|
readonly extraRecipes?: ExtraRecipes;
|
|
88
|
+
/**
|
|
89
|
+
* The `docs` tool's presentation: `description` replaces its default one, `index: 'map'` makes
|
|
90
|
+
* `docs({})` answer a text map grouped by section instead of JSON. Only with recipes.
|
|
91
|
+
*/
|
|
92
|
+
readonly docsTool?: DocsToolOptions;
|
|
86
93
|
/** Prompts the app ships: a path to a versioned artifact, or the full descriptor. */
|
|
87
94
|
readonly prompts?: readonly (string | McpPrompt)[];
|
|
88
95
|
/**
|
|
@@ -111,9 +118,17 @@ export interface DefineAppMcpInput<TSchemas extends AppToolSchemas = AppToolSche
|
|
|
111
118
|
* One token across tenants: `resolveToken` answers the PERSON, and every `tools/call` names its
|
|
112
119
|
* tenant under `arg` — stripped before validation, checked by `resolve` (`null` answers as a
|
|
113
120
|
* hidden tool), and the actor `resolve` answers is the caller for every gate and the policy.
|
|
114
|
-
* `list_tenants` serves `list`; a call naming none is `X_MCP_TENANT_REQUIRED`.
|
|
121
|
+
* `list_tenants` serves `list`; a call naming none is `X_MCP_TENANT_REQUIRED`. `discover` names
|
|
122
|
+
* a tool that lists the tenants in its place, `optional` the tools a call may reach with none.
|
|
115
123
|
*/
|
|
116
124
|
readonly tenant?: McpTenant;
|
|
125
|
+
/**
|
|
126
|
+
* What this app adds to the `'meta-split'` dispatchers. `fields`: string fields of its own on
|
|
127
|
+
* their envelopes (a `reason`), validated there and handed to a tool as `door.fields`, never
|
|
128
|
+
* as input. `stricter`: sends one call to `delete_resource` by its arguments — preview, then
|
|
129
|
+
* `confirmed_by_user`. `X_MCP_SPLIT_INVALID` at boot on a surface that is never `'meta-split'`.
|
|
130
|
+
*/
|
|
131
|
+
readonly split?: McpSplitOptions;
|
|
117
132
|
/**
|
|
118
133
|
* Scope name → the tools that capability covers, by tool name. The connection gate, and the
|
|
119
134
|
* second of the three outcomes: a caller that may SEE a tool but whose token does not carry
|
|
@@ -307,7 +322,13 @@ export function defineAppMcp<TSchemas extends AppToolSchemas>(
|
|
|
307
322
|
tools: projected,
|
|
308
323
|
resources,
|
|
309
324
|
resourceSources,
|
|
310
|
-
} = withRecipes(
|
|
325
|
+
} = withRecipes(
|
|
326
|
+
confirmed,
|
|
327
|
+
input.resources ?? [],
|
|
328
|
+
input.recipes,
|
|
329
|
+
input.extraRecipes,
|
|
330
|
+
input.docsTool,
|
|
331
|
+
);
|
|
311
332
|
|
|
312
333
|
const config: McpServerInput = {
|
|
313
334
|
tools: projected,
|
|
@@ -325,6 +346,7 @@ export function defineAppMcp<TSchemas extends AppToolSchemas>(
|
|
|
325
346
|
? {}
|
|
326
347
|
: { catalog: appCatalogSource(input.catalog, input.scopes) }),
|
|
327
348
|
...(input.tenant === undefined ? {} : { tenant: input.tenant }),
|
|
349
|
+
...(input.split === undefined ? {} : { split: input.split }),
|
|
328
350
|
};
|
|
329
351
|
const server = mcpServer(config);
|
|
330
352
|
|
package/src/audit.ts
CHANGED
|
@@ -212,6 +212,8 @@ function callerFields(entry: McpResourceAuditEntry | McpAuditEntry): LogFields {
|
|
|
212
212
|
...(entry.caller.role === undefined ? {} : { role: entry.caller.role }),
|
|
213
213
|
// The tenant a `tenant` server resolved for this call — the decision's subject, not an argument.
|
|
214
214
|
...(entry.caller.tenant === undefined ? {} : { tenant: entry.caller.tenant }),
|
|
215
|
+
// The dispatcher a 'meta-split' call came through — its name alone: a field is an argument.
|
|
216
|
+
...(entry.caller.door === undefined ? {} : { door: entry.caller.door.tool }),
|
|
215
217
|
...(entry.scope === undefined ? {} : { scope: entry.scope }),
|
|
216
218
|
...(entry.code === undefined ? {} : { code: entry.code }),
|
|
217
219
|
};
|
package/src/catalog-errors.ts
CHANGED
|
@@ -61,11 +61,12 @@ export class McpCatalogUnresolvedError extends UltimateError {
|
|
|
61
61
|
|
|
62
62
|
/** A call on a `tenant` server whose arguments carry no tenant value. */
|
|
63
63
|
export class McpTenantRequiredError extends UltimateError {
|
|
64
|
-
|
|
64
|
+
/** `lister`: the tool that lists the tenants — `list_tenants`, or the server's `tenant.discover`. */
|
|
65
|
+
constructor(input: { readonly arg: string; readonly lister?: string }) {
|
|
65
66
|
super({
|
|
66
67
|
code: 'X_MCP_TENANT_REQUIRED',
|
|
67
68
|
cause: `this server acts every call in the tenant the call names, and this call's arguments carry no "${input.arg}"`,
|
|
68
|
-
fix: 'list_tenants({}) — then send one of its values as the tenant argument of every tools/call
|
|
69
|
+
fix: `${input.lister ?? 'list_tenants'}({}) — then send one of its values as the tenant argument of every tools/call`,
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
}
|
|
@@ -85,13 +86,18 @@ export class McpTenantUnresolvedError extends UltimateError {
|
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* The `tenant` option is unusable: `arg` is not a plain name or a tool's own input already declares
|
|
91
|
+
* it, or `discover` / `optional` names a tool some caller cannot reach by that name.
|
|
92
|
+
*/
|
|
89
93
|
export class McpTenantInvalidError extends UltimateError {
|
|
90
|
-
constructor(input: { readonly cause: string }) {
|
|
94
|
+
constructor(input: { readonly cause: string; readonly fix?: string }) {
|
|
91
95
|
super({
|
|
92
96
|
code: 'X_MCP_TENANT_INVALID',
|
|
93
97
|
cause: input.cause,
|
|
94
|
-
fix:
|
|
98
|
+
fix:
|
|
99
|
+
input.fix ??
|
|
100
|
+
"defineAppMcp({ tenant: { arg: 'tenant', resolve, list } }) — pick an argument name no tool's input declares",
|
|
95
101
|
});
|
|
96
102
|
}
|
|
97
103
|
}
|
package/src/errors.ts
CHANGED
|
@@ -62,6 +62,8 @@ export const MCP_ERROR_CODES = [
|
|
|
62
62
|
'X_MCP_TENANT_UNRESOLVED',
|
|
63
63
|
'X_MCP_TENANT_INVALID',
|
|
64
64
|
'X_MCP_INCLUDE_EARLY',
|
|
65
|
+
'X_MCP_SPLIT_INVALID',
|
|
66
|
+
'X_MCP_ELICITATION_URL_INVALID',
|
|
65
67
|
] as const;
|
|
66
68
|
|
|
67
69
|
export type McpErrorCode = (typeof MCP_ERROR_CODES)[number];
|
|
@@ -119,7 +121,8 @@ export const MCP_ERROR_TITLES: Readonly<Record<McpErrorCode, string>> = {
|
|
|
119
121
|
X_MCP_RECIPE_UNKNOWN: 'an error links to a docs://recipes/ URI no recipe serves',
|
|
120
122
|
X_MCP_RECIPE_URI_RESERVED: 'docs://recipes/ is owned by recipes:',
|
|
121
123
|
X_MCP_REMOTE_AUTH_REQUIRED: 'a remote MCP server needs authorization this app does not hold',
|
|
122
|
-
X_MCP_RECIPE_LINK_DANGLING:
|
|
124
|
+
X_MCP_RECIPE_LINK_DANGLING:
|
|
125
|
+
"a recipe links to a docs://<section>/ URI no recipe serves, or replay's caller cannot read",
|
|
123
126
|
X_MCP_CONFIRMATION_QUORUM_PENDING:
|
|
124
127
|
'an MCP confirmation needs more approvers before the call runs',
|
|
125
128
|
X_MCP_CONFIRMATION_EVIDENCE_INVALID:
|
|
@@ -133,6 +136,8 @@ export const MCP_ERROR_TITLES: Readonly<Record<McpErrorCode, string>> = {
|
|
|
133
136
|
X_MCP_TENANT_INVALID: 'defineAppMcp declares its tenant argument inconsistently',
|
|
134
137
|
X_MCP_INCLUDE_EARLY:
|
|
135
138
|
"include: 'exposed' projected before the scan registered every exposed primitive",
|
|
139
|
+
X_MCP_SPLIT_INVALID: 'defineAppMcp declares its meta-split options inconsistently',
|
|
140
|
+
X_MCP_ELICITATION_URL_INVALID: 'a tool asked for a URL prompt no client may be shown',
|
|
136
141
|
};
|
|
137
142
|
|
|
138
143
|
// Titles must be registered for `format()` to render the contract's first line. Every code above is
|
package/src/from-action.ts
CHANGED
|
@@ -35,11 +35,13 @@ import { pageFactsOf, truncatedResult } from './query-page';
|
|
|
35
35
|
import type {
|
|
36
36
|
AnyMcpTool,
|
|
37
37
|
McpCaller,
|
|
38
|
+
McpDoor,
|
|
38
39
|
McpToolAnnotations,
|
|
39
40
|
McpToolResult,
|
|
40
41
|
ToolArgs,
|
|
41
42
|
} from './registry';
|
|
42
43
|
import { jsonResult, structuredResult } from './registry';
|
|
44
|
+
import { withCallAsk } from './url-elicitation';
|
|
43
45
|
import type { JsonSchema } from './wire';
|
|
44
46
|
import { NO_ARGS } from './wire';
|
|
45
47
|
|
|
@@ -49,6 +51,20 @@ import { NO_ARGS } from './wire';
|
|
|
49
51
|
* (rather than imported as a generic) so the projection is testable with a fake and does
|
|
50
52
|
* not bind to either package's type parameters.
|
|
51
53
|
*/
|
|
54
|
+
/** What `runThrough` is handed: `run`'s arguments and the door, `undefined` off a dispatcher. */
|
|
55
|
+
export interface DoorRun {
|
|
56
|
+
readonly input: unknown;
|
|
57
|
+
readonly actor: Actor;
|
|
58
|
+
readonly door: McpDoor | undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** `run` and `runThrough` from ONE body, so the two cannot differ: `run` is the call through no door. */
|
|
62
|
+
export function throughDoor(
|
|
63
|
+
body: (args: DoorRun) => Promise<unknown>,
|
|
64
|
+
): Pick<ProjectablePrimitive, 'run'> & { runThrough(args: DoorRun): Promise<unknown> } {
|
|
65
|
+
return { run: (args) => body({ ...args, door: undefined }), runThrough: body };
|
|
66
|
+
}
|
|
67
|
+
|
|
52
68
|
export interface ProjectablePrimitive {
|
|
53
69
|
readonly name: string;
|
|
54
70
|
readonly description?: string;
|
|
@@ -72,6 +88,11 @@ export interface ProjectablePrimitive {
|
|
|
72
88
|
readonly outputWrap?: string;
|
|
73
89
|
/** The one server-authoritative entry point. Runs policy, then the handler. */
|
|
74
90
|
run(args: { input: unknown; actor: Actor }): Promise<unknown>;
|
|
91
|
+
/**
|
|
92
|
+
* `run`, also handed the `'meta-split'` dispatcher the call came through — for a tool that
|
|
93
|
+
* reads its envelope fields (`throughDoor`). Absent: the tool is run by `run`.
|
|
94
|
+
*/
|
|
95
|
+
runThrough?(args: DoorRun): Promise<unknown>;
|
|
75
96
|
/**
|
|
76
97
|
* The policy's actor half, alone: throws the denial `run` would raise for this actor whatever
|
|
77
98
|
* the input, returns otherwise. Becomes the tool's `admit`. Absent: no before-args gate.
|
|
@@ -129,14 +150,23 @@ export function toolFrom(listed: ListedPrimitive): AnyMcpTool {
|
|
|
129
150
|
// ONE authz system, TWO surfaces. This `run` IS `invoke`; the HTTP route reaches the
|
|
130
151
|
// same `invoke` with an actor of kind 'user', MCP arrives with kind 'agent'. Same
|
|
131
152
|
// policy, same decision.
|
|
132
|
-
const output = await
|
|
133
|
-
|
|
153
|
+
const { value: output, ask: urlElicitation } = await withCallAsk(async () =>
|
|
154
|
+
withSignal(signal, () =>
|
|
155
|
+
primitive.runThrough === undefined
|
|
156
|
+
? primitive.run({ input: args, actor: caller.actor })
|
|
157
|
+
: primitive.runThrough({ input: args, actor: caller.actor, door: caller.door }),
|
|
158
|
+
),
|
|
134
159
|
);
|
|
135
160
|
const result =
|
|
136
161
|
outputSchema === undefined ? jsonResult(output) : structuredResult(output, wrap);
|
|
137
162
|
// A list query's page that was cut says so, and where the next one starts (`query-page.ts`).
|
|
138
163
|
const page = pageFactsOf(output);
|
|
139
|
-
|
|
164
|
+
const answer = page === undefined ? result : truncatedResult(result, page);
|
|
165
|
+
// A handler that asked the person to open a page (`withUrlElicitation`) says so beside it —
|
|
166
|
+
// unless its answer could not be rendered: that failure is the answer.
|
|
167
|
+
return urlElicitation === undefined || answer.isError === true
|
|
168
|
+
? answer
|
|
169
|
+
: { ...answer, urlElicitation };
|
|
140
170
|
},
|
|
141
171
|
};
|
|
142
172
|
}
|
package/src/index.ts
CHANGED
|
@@ -138,9 +138,16 @@ export {
|
|
|
138
138
|
McpGroupConflictError,
|
|
139
139
|
McpGroupUnknownError,
|
|
140
140
|
McpListParamsInvalidError,
|
|
141
|
+
McpSplitInvalidError,
|
|
141
142
|
McpSurfaceInvalidError,
|
|
142
143
|
} from './meta-errors';
|
|
143
144
|
export type { McpEffectClass } from './meta-split';
|
|
145
|
+
export type {
|
|
146
|
+
McpSplitCall,
|
|
147
|
+
McpSplitDispatcher,
|
|
148
|
+
McpSplitField,
|
|
149
|
+
McpSplitOptions,
|
|
150
|
+
} from './meta-split-options';
|
|
144
151
|
export type {
|
|
145
152
|
McpResourceGroup,
|
|
146
153
|
McpResourceGroups,
|
|
@@ -165,15 +172,17 @@ export { markdownRecipes } from './recipe-markdown';
|
|
|
165
172
|
export type { ReplayOptions, ReplayReport } from './recipe-replay';
|
|
166
173
|
export { replayRecipes } from './recipe-replay';
|
|
167
174
|
export type { McpRecipe, McpRecipeStep } from './recipes';
|
|
168
|
-
export type { ExtraRecipes } from './recipes-tool';
|
|
175
|
+
export type { DocsToolOptions, ExtraRecipes } from './recipes-tool';
|
|
169
176
|
export type {
|
|
170
177
|
AnyMcpTool,
|
|
171
178
|
ContentBlock,
|
|
172
179
|
McpCaller,
|
|
180
|
+
McpDoor,
|
|
173
181
|
McpRole,
|
|
174
182
|
McpTool,
|
|
175
183
|
McpToolAnnotations,
|
|
176
184
|
McpToolResult,
|
|
185
|
+
McpUrlElicitation,
|
|
177
186
|
McpVerbClass,
|
|
178
187
|
McpVisibility,
|
|
179
188
|
ToolArgs,
|
|
@@ -248,6 +257,7 @@ export { MCP_RATE_LIMITS, MCP_UNAUTHENTICATED_LIMIT, mcpHttpRoute } from './tran
|
|
|
248
257
|
export { mcpHostRefused } from './transport-http-answers';
|
|
249
258
|
export type { StdioTransportInput } from './transport-stdio';
|
|
250
259
|
export { serveStdio } from './transport-stdio';
|
|
260
|
+
export { URL_ELICITATION_KEY, withUrlElicitation } from './url-elicitation';
|
|
251
261
|
export type { ArgIssue, ArgValidation } from './validate-args';
|
|
252
262
|
export { validateArgs } from './validate-args';
|
|
253
263
|
export type {
|