@ultimat3/mcp 29.4.0 → 30.0.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 +54 -59
- package/README.md +259 -2
- package/package.json +21 -10
- package/src/app-catalog.ts +84 -0
- package/src/app-tool.ts +6 -2
- package/src/app-tools.ts +80 -5
- package/src/audit-hook.ts +7 -1
- package/src/audit.ts +12 -1
- package/src/catalog-errors.ts +97 -0
- package/src/confirmation-approvers.ts +85 -0
- package/src/confirmation-decide.ts +78 -8
- package/src/confirmation-evidence.ts +118 -0
- package/src/confirmation-gate.ts +147 -44
- package/src/confirmation-postgres.ts +88 -7
- package/src/confirmation-quorum-errors.ts +102 -0
- package/src/confirmation-schema.ts +13 -2
- package/src/confirmation-store.ts +54 -19
- package/src/confirmations.ts +77 -8
- package/src/dev-graph-tool.ts +62 -0
- package/src/dev-server.ts +10 -2
- package/src/errors-transport.ts +84 -3
- package/src/errors.ts +46 -0
- package/src/exposed.ts +13 -3
- package/src/framework-error.ts +8 -1
- package/src/from-action.ts +2 -3
- package/src/index.ts +102 -1
- package/src/job-status-tool.ts +66 -0
- package/src/job-tool-errors.ts +15 -0
- package/src/job-tool.ts +167 -0
- package/src/oauth-metadata.ts +2 -2
- package/src/oauth-server.ts +80 -0
- package/src/projectable.ts +15 -10
- package/src/protocol-era.ts +270 -0
- package/src/recipe-errors.ts +75 -0
- package/src/recipe-links.ts +49 -0
- package/src/recipe-markdown.ts +143 -0
- package/src/recipe-replay.ts +101 -0
- package/src/recipe-search.ts +82 -0
- package/src/recipes-surface.ts +55 -0
- package/src/recipes-tool.ts +123 -0
- package/src/recipes.ts +167 -0
- package/src/registry.ts +5 -0
- package/src/remote-client.ts +378 -0
- package/src/remote-errors.ts +76 -0
- package/src/remote-listen.ts +108 -0
- package/src/remote-lock.ts +139 -0
- package/src/remote-oauth.ts +258 -0
- package/src/remote-schema.ts +51 -0
- package/src/remote-tools.ts +157 -0
- package/src/remote-wire.ts +121 -0
- package/src/resources.ts +84 -13
- package/src/runtime-schema.ts +132 -0
- package/src/runtime-tool.ts +115 -0
- package/src/scopes.ts +8 -1
- package/src/server-catalog.ts +200 -0
- package/src/server-resources.ts +117 -0
- package/src/server-voice.ts +10 -5
- package/src/server.ts +149 -168
- package/src/tenant.ts +189 -0
- package/src/transport-http-answers.ts +124 -0
- package/src/transport-http.ts +50 -94
- package/src/wire.ts +18 -4
- package/src/caller-context.ts +0 -22
package/CLAUDE.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# @ultimat3/mcp — boundary
|
|
2
2
|
|
|
3
|
-
Tier 4. May import tier 0–3: `core schema i18n money time cache seo entity policy http
|
|
4
|
-
query jobs realtime`. **Never** `render manifest ai pwa ui admin testing cli`.
|
|
3
|
+
Tier 4. May import tier 0–3: `core schema i18n money time cache seo entity policy http auth
|
|
4
|
+
action query jobs realtime`. **Never** `render manifest ai pwa ui admin testing cli`.
|
|
5
5
|
|
|
6
|
-
`@ultimat3/http` is a DIRECT dependency (`transport-http.ts`, the rate limiter).
|
|
6
|
+
`@ultimat3/http` is a DIRECT dependency (`transport-http.ts`, the rate limiter). So is
|
|
7
|
+
`@ultimat3/auth` (`oauth-server.ts`): the authorization server is auth's; this package binds it.
|
|
7
8
|
|
|
8
9
|
Same-tier data (routes, manifest, policy catalog) arrives as an **injected thunk**, never an
|
|
9
10
|
import. The CLI wires it.
|
|
@@ -12,21 +13,26 @@ import. The CLI wires it.
|
|
|
12
13
|
|
|
13
14
|
| File | Job |
|
|
14
15
|
|---|---|
|
|
15
|
-
| `wire.ts` | JSON-RPC types, error codes,
|
|
16
|
+
| `wire.ts` | JSON-RPC types, error codes (incl. `-32020`/`-32022`), `MCP_MODERN_VERSIONS` / `MCP_LEGACY_VERSIONS` (no `MCP_PROTOCOL_VERSION`: name the era), `JsonSchema` subset |
|
|
16
17
|
| `registry.ts` | catalog + the first two security outcomes (visibility, scope) |
|
|
17
18
|
| `audit.ts` | one structured line per `tools/call` and per `resources/read`, outcome → level |
|
|
18
19
|
| `validate-args.ts` | JSON-Schema-subset arg validation, applies defaults |
|
|
19
|
-
| `server.ts` | JSON-RPC dispatch
|
|
20
|
+
| `server.ts` | JSON-RPC dispatch; `classify` delegates to `protocol-era.ts` |
|
|
21
|
+
| `protocol-era.ts` | one request's era (`_meta` version), `METHODS` per era, `classifyBody`, `initialize` negotiation, `server/discover`, the modern stamp, the HTTP mirrored-header check and each answer's status |
|
|
22
|
+
| `server-resources.ts` | `resources/read`'s three outcomes, audited, provider in a `try` |
|
|
20
23
|
| `from-action.ts` | action/query → tool; the "one authz system" projection; `toolsFrom` (sweep, skips) vs `toolsListed` (written out, refuses) |
|
|
21
24
|
| `resources.ts` | resources + prompts, stable `ultimate://` URIs |
|
|
22
|
-
| `dev-server.ts` | the
|
|
25
|
+
| `dev-server.ts` | 13 of the 19 dev tools (`routes.list` … `logs.tail`); `ui.shot`, `ui.island`, `ui.inspect`, `ui.diff` are `dev-ui-tools.ts`, `ui.interact` `dev-ui-interact.ts`, `graph.query` `dev-graph-tool.ts`. Depends only on an injected `DevHost` |
|
|
23
26
|
| `dev-host.ts` | wires `describe*` from entity/action/query/jobs into a `DevHost` |
|
|
24
|
-
| `transport-http.ts` | `POST /mcp` route descriptor, bearer → agent actor, and the per-caller rate limit it enforces itself |
|
|
27
|
+
| `transport-http.ts` | `POST /mcp` route descriptor, bearer → agent actor, and the per-caller rate limit it enforces itself; it keeps the order |
|
|
28
|
+
| `transport-http-answers.ts` | the pre-dispatch answers (401, 403 not-an-agent / origin, 421, 429) and the per-address failure meter |
|
|
25
29
|
| `audit-hook.ts` | `onAudit`; `resolveToken`'s 2nd arg is http's `RequestFacts` (`seen.address` only, never `x-forwarded-for`), re-exported as `McpRequestFacts` |
|
|
26
30
|
| `confirmations.ts` · `confirmation-*.ts` | `mcpConfirmations`: a factory over `action` (view/decide) · the gate on `handle` · stores · DDL · codes |
|
|
27
|
-
| `oauth-metadata.ts` | RFC 9728 protected-resource metadata + the 401 `resource_metadata` challenge (`defineAppMcp({ oauth })`)
|
|
31
|
+
| `oauth-metadata.ts` | RFC 9728 protected-resource metadata + the 401 `resource_metadata` challenge (`defineAppMcp({ oauth })`) |
|
|
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 |
|
|
28
33
|
| `transport-stdio.ts` | NDJSON on stdin/stdout for `x mcp serve` |
|
|
29
34
|
| `app-tools.ts` | `defineAppMcp` — a generated app's own MCP surface, one call |
|
|
35
|
+
| `runtime-*` · `*-catalog.ts` · `tenant.ts` | `catalog:` (`runtimeTool()`, checked, merged per request) · `tenant:` (`list_tenants`); codes in `catalog-errors.ts` |
|
|
30
36
|
| `app-tool.ts` | the authored `tools: { name: {...} }` record → `ProjectablePrimitive` |
|
|
31
37
|
| `projectable.ts` | a real `action`/`query` → `ProjectablePrimitive`; the ONE adapter both the sweep and the written-out list use |
|
|
32
38
|
| `exposed.ts` | `include: 'exposed'` — the action/query registries → primitives |
|
|
@@ -38,9 +44,22 @@ import. The CLI wires it.
|
|
|
38
44
|
| `list-params.ts` | `listParams` whitelist → the schema `manage_resource` enforces (flat keys: `status_eq`) |
|
|
39
45
|
| `meta-errors.ts` · `framework-error.ts` | meta boot refusals · a thrown value read and rendered (split from `server.ts`) |
|
|
40
46
|
| `server-voice.ts` · `surface-budget.ts` | `instructions`, `errorAudience`, the invalid-args RESULT · `tools/list`/`list_resources` size, measured and budgeted |
|
|
47
|
+
| `job-*` · `recipe*` · `remote-*` | `jobTool`/`job_status` · `recipes:`/`docs` · `mcpTools`/`mcpClient`/`tools.lock.json` — [history](../../docs/history/mcp.md) |
|
|
41
48
|
|
|
42
49
|
## Invariants
|
|
43
50
|
|
|
51
|
+
- **Dual-era, per request** (`As of 2026-11`, MCP 2026-07-28). A `_meta` version in
|
|
52
|
+
`MCP_MODERN_VERSIONS` → modern: stateless, `server/discover`, no `initialize`/`ping`, every result
|
|
53
|
+
stamped (`resultType`, `_meta` `serverInfo`; lists/reads `ttlMs: 0`, `cacheScope: 'private'`).
|
|
54
|
+
None, or one in `MCP_LEGACY_VERSIONS` → legacy. Else `-32022`. Resource not found is one answer
|
|
55
|
+
per era (`-32602` modern, `-32601` legacy, never `data`). A modern HTTP request's mirrored
|
|
56
|
+
headers equal its body (`headerRefusal`): absent or unequal → 400 `-32020`.
|
|
57
|
+
- **`Origin` is core's `proveSameOrigin`, at the transport, before the token is read** (403
|
|
58
|
+
`X_MCP_ORIGIN_REFUSED`, audited `origin-refused`): self = `seen.origin`, allowance = `seen.listed`
|
|
59
|
+
(`http.cors.origins`), never a second origin rule. It cannot refuse a DNS-rebound name: `x mcp
|
|
60
|
+
serve` refuses a non-loopback Host first (421 `X_MCP_HOST_REFUSED`). `GET`/`DELETE` is
|
|
61
|
+
`@ultimat3/http`'s one `X_METHOD_NOT_ALLOWED` 405, mount and `x mcp serve` alike.
|
|
62
|
+
|
|
44
63
|
- **`manage_resource` is a second DOOR, never a second PATH** (`As of 2026-09-26`): locate (visibility,
|
|
45
64
|
else the absent answer) → the shared `resolve` (scope → args; a list whitelist's issues win) → `dispatch`,
|
|
46
65
|
audited under the inner tool. `tools/list` shows what `tools/call` answers PER CALLER: a meta caller
|
|
@@ -76,66 +95,42 @@ import. The CLI wires it.
|
|
|
76
95
|
`exposureOf` to the projected tool — outcome 1's only declaration surface for a projected
|
|
77
96
|
primitive. Dropping it there silently disables outcome 1 for every projected tool: nothing
|
|
78
97
|
fails, every caller simply sees every tool.
|
|
79
|
-
- **A thrown value is a framework error only when its `code` matches core's `FRAMEWORK_CODE
|
|
80
|
-
never `code.startsWith('X_')
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
the
|
|
84
|
-
because `@ultimat3/core`'s `client-wire.ts` already had to answer the same question for a
|
|
85
|
-
problem document off the wire.
|
|
98
|
+
- **A thrown value is a framework error only when its `code` matches core's `FRAMEWORK_CODE`**,
|
|
99
|
+
never `code.startsWith('X_')` (`asFrameworkError` puts the code in a command). Full rule: `docs/history/mcp.md`.
|
|
100
|
+
- **`catalog(caller)` runs per `tools/list`/`tools/call`**, never cached; a duplicate or a throw fails
|
|
101
|
+
the REQUEST (`X_MCP_CATALOG_*`), never a smaller list. **`tenant` runs first on a call**: `null` =
|
|
102
|
+
the hidden-tool answer, a throw `X_MCP_TENANT_UNRESOLVED`; its actor is the caller from there on.
|
|
86
103
|
- Resolve order is visibility → scope → args → policy. Validating first leaks a schema;
|
|
87
104
|
running the policy first decides a refusal from attacker-supplied input.
|
|
88
|
-
- **A key's membership of a declared schema is `Object.hasOwn(properties, key)
|
|
89
|
-
`
|
|
90
|
-
|
|
91
|
-
`__proto__` on every plain object — so the index read answered "declared" for four names no
|
|
92
|
-
schema declares, and `validate-args.ts` accepted them past an `additionalProperties: false` that
|
|
93
|
-
forbids them and then dropped them. Its twin: a validated key
|
|
94
|
-
lands on the result through `Object.defineProperty`, because `out[key] = v` for `__proto__` runs
|
|
95
|
-
the setter on `Object.prototype` and re-prototypes the record instead of adding a key.
|
|
105
|
+
- **A key's membership of a declared schema is `Object.hasOwn(properties, key)`**, never an index
|
|
106
|
+
read (`Object.prototype` answers four names); a validated key lands through `Object.defineProperty`.
|
|
107
|
+
Full rule: `docs/history/mcp.md`.
|
|
96
108
|
- **The RESOURCE surface owes the same three outcomes as the tool surface.** `resources/list` and
|
|
97
109
|
`resources/read` take the `McpCaller`; `McpResource` carries `visibleTo` and `scope`, applied by
|
|
98
110
|
`ResourceRegistry.resolve` in `ToolRegistry.resolve`'s order through the same `visibleToCaller`.
|
|
99
111
|
The not-found branch carries no `data` (a catalog there enumerates it). `resource-security.test.ts`
|
|
100
112
|
is the contract, for hand-built resources AND `defineAppMcp({ resources })`.
|
|
101
|
-
- **Every provider call is inside a `try
|
|
102
|
-
|
|
103
|
-
`x.manifest.json` throws ENOENT. Outside the try it escaped `handle()`: `serveStdio` REJECTED with
|
|
104
|
-
the raw error, zero frames written, the request unanswered and every later request on that buffer
|
|
105
|
-
never processed. Same shape `toolsCall` uses — a framework error keeps its code/cause/fix, anything
|
|
106
|
-
else is `-32603` with no internals.
|
|
113
|
+
- **Every provider call is inside a `try`** (an injected `read` thunk can throw ENOENT): a framework
|
|
114
|
+
error keeps its code/cause/fix, anything else is `-32603`. Full rule: `docs/history/mcp.md`.
|
|
107
115
|
- **A declared `pattern` is compiled once per schema NODE, never per `tools/call`** — a `WeakMap`
|
|
108
116
|
keyed on the node (never on the pattern string, which grows forever), caching an uncompilable
|
|
109
117
|
pattern's `null` too. `compiledPatternCount()` is the test-only probe; `validate-args.test.ts`
|
|
110
118
|
asserts it does not climb over 100 calls. Compiled WITH `x-ultimate-pattern-flags` (schema's),
|
|
111
119
|
`lastIndex` reset.
|
|
112
|
-
- **`format` is NOT in the wire subset
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
only drift from the action's own parse. `tools/list` published it and `validate-args.ts` ignored
|
|
116
|
-
it, so a tool declaring `t.uuid` accepted `"not-a-uuid"` with `ok: true`. `pattern` is the
|
|
117
|
-
opposite case and is kept: the rule travels with the schema. The narrowing is `@ultimat3/schema`'s
|
|
118
|
-
`toWireSchema` (tier 0, so OpenAPI-adjacent readers reach the same document) and the
|
|
119
|
-
type is its `WireJsonSchema`, which `wire.ts` names `JsonSchema`; `validate-args-subset.test.ts`
|
|
120
|
-
asserts every published keyword is one this server enforces, at any depth.
|
|
120
|
+
- **`format` is NOT in the wire subset** (`wire.ts` types it `never`): its meaning is
|
|
121
|
+
`@ultimat3/schema`'s; `pattern` is kept. `validate-args-subset.test.ts` asserts every published
|
|
122
|
+
keyword is enforced. Full rule: `docs/history/mcp.md`.
|
|
121
123
|
- **A hand-written app tool parses its own input**, in the slot `invoke` puts it: parse, then
|
|
122
124
|
`guardAction()`, then `handle`. A projected action re-parses inside `invoke`; `app-tool.ts` had no second
|
|
123
125
|
parse, so `handle` was handed whatever the wire subset let through — typed `InferOutput<TInput>`,
|
|
124
126
|
past the policy. One code either way, `X_INPUT_INVALID`, built from `@ultimat3/action`'s own
|
|
125
127
|
`InputInvalidError`.
|
|
126
|
-
- **Anything a tool RETURNS is rendered totally
|
|
127
|
-
|
|
128
|
-
`
|
|
129
|
-
a `toJSON` the value carries. Unreadable is an ordinary `isError` result, never an escape past
|
|
130
|
-
`server.ts`'s catch, which would report a bug in the tool for a fault in the rendering.
|
|
131
|
-
`query-limits.ts`' `rowBytes` holds the same line one layer earlier: a row the driver decoded
|
|
132
|
-
into a bigint costs `Infinity` and is cut by the byte ceiling, rather than raising inside the cap
|
|
133
|
-
that exists to protect the answer.
|
|
128
|
+
- **Anything a tool RETURNS is rendered totally** (`jsonResult`: nothing, a bigint, a cycle, a
|
|
129
|
+
throwing `toJSON`) — unreadable is an `isError` result, never an escape past `server.ts`'s catch;
|
|
130
|
+
`query-limits.ts`' `rowBytes` prices a bigint row `Infinity` rather than raising in the cap.
|
|
134
131
|
- **A thrown value is read with `stringField` from `@ultimat3/core`, never `typeof e.code ===
|
|
135
|
-
'string'
|
|
136
|
-
|
|
137
|
-
a probe that raises there leaves the JSON-RPC request with no answer at all, not even the
|
|
138
|
-
`-32603` the transport promises for a genuine bug.
|
|
132
|
+
'string'`**: each read is a getter or `Proxy` trap in the catch that owes an answer, and a probe
|
|
133
|
+
that raises there leaves the request with none, not even `-32603`.
|
|
139
134
|
- A framework error rendered into a tool result is **byte-identical to
|
|
140
135
|
`UltimateError.format()`** — one denial must not read one way over MCP and another in the
|
|
141
136
|
terminal. `server.ts` renders it; the test pins it against `format()`, never a literal. Except a
|
|
@@ -156,8 +151,7 @@ import. The CLI wires it.
|
|
|
156
151
|
the line is written, then the decision handed on, unawaited; a throwing hook changes no answer
|
|
157
152
|
(`mcp.audit-hook.failed`). Core's `AuditSink` = what a primitive DID; `onAudit` = what the gate
|
|
158
153
|
decided, refused tokens included (`mcp.auth.<reason>`). The route reads `server.audit`.
|
|
159
|
-
- **A `--` comment ends at the first CR *or* LF
|
|
160
|
-
`endOfLineComment`). A scanner stopping at LF alone read `select 1;--\rupdate …` as one read.
|
|
154
|
+
- **A `--` comment ends at the first CR *or* LF** (`readonly-sql.ts`): why in `docs/history/mcp.md`.
|
|
161
155
|
- `security.test.ts` and `app-security.test.ts` are the executable contract for all of the
|
|
162
156
|
above — the first over hand-built tools (each gate in isolation), the second over what an app
|
|
163
157
|
actually declares (`defineAppMcp` projecting real actions and queries). Extend them, never
|
|
@@ -245,11 +239,15 @@ import. The CLI wires it.
|
|
|
245
239
|
SAME rejected token, which is precisely the oracle the pre-parse 401 exists to remove. The parse
|
|
246
240
|
error still exists — it is what an authenticated agent gets. Failures spend a per-ADDRESS bucket
|
|
247
241
|
(`seen.address`), and an exhausted address is `429` BEFORE `resolveToken` — a valid guess too.
|
|
248
|
-
- **Confirmation order: visibility → scope → args → `admit` → confirmation
|
|
242
|
+
- **Confirmation order: visibility → scope → args → `admit` → confirmation (quorum + signed
|
|
243
|
+
evidence when declared) → policy.** An approval
|
|
249
244
|
binds actor + tool + `keyedFingerprint(args)` (rotation ⇒ new row); `consume` (CAS) makes one approval run one
|
|
250
245
|
call; rejected/expired is told once, then the call asks again. Args sealed; `approve` carries
|
|
251
246
|
viewed args (digest must match); default `check`: same org. An agent never decides (in the
|
|
252
247
|
policy). Statuses < 500, or `forAudience` hides the id.
|
|
248
|
+
- **`mcpConfirmations` also registers its gate by name** (`@ultimat3/ai`'s adapter reads it). Invalid
|
|
249
|
+
args REFUSE (`X_INPUT_INVALID`), never `run()`: an action's parse drops unknown keys. First
|
|
250
|
+
registered answers in-app; any server without its own asks it. Proof: `scripts/ai-tool-confirmation.test.ts`.
|
|
253
251
|
- **`transport-stdio.ts`'s default `write` is AWAITED** — fd 1 is a pipe, and an unawaited
|
|
254
252
|
`Bun.stdout.write` lost the tail of a 4 MB frame at exit. It is also the loop's only
|
|
255
253
|
back-pressure; only a child-process test can see it.
|
|
@@ -258,12 +256,9 @@ import. The CLI wires it.
|
|
|
258
256
|
a property named `__proto__` runs `Object.prototype`'s setter and re-prototypes the published
|
|
259
257
|
`properties` record instead of adding a key, so a field the tool author declared vanishes from
|
|
260
258
|
`tools/list` and from what the arg validator reads back.
|
|
261
|
-
- `transport-stdio.ts` never writes stdout except the wire
|
|
262
|
-
message
|
|
263
|
-
|
|
264
|
-
stream with no newline grew the buffer until the process died. Over-long is one `-32600` frame
|
|
265
|
-
carrying a `fix`, then the rest of that line is DISCARDED to the next newline: what follows an
|
|
266
|
-
over-long message on the same line is its tail, never a message of its own.
|
|
259
|
+
- `transport-stdio.ts` never writes stdout except the wire (diagnostics → stderr) and caps one
|
|
260
|
+
message at `DEFAULT_STDIO_LINE_LIMIT` (1 MiB): one `-32600` frame, the rest of that line discarded.
|
|
261
|
+
Full rule: `docs/history/mcp.md`.
|
|
267
262
|
- New mutating tool ⇒ set `destructive: true`, or it is metered as cheap read chatter.
|
|
268
263
|
- **Invalid arguments are an `isError` RESULT (`X_INPUT_INVALID`), `As of 22.10`** — clients hide a
|
|
269
264
|
`-32602` from the model. Audit outcome stays `invalid-args`. `-32602` only for a call that is not
|
package/README.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
The MCP surface. An agent that can reach this package needs no framework documentation — it
|
|
4
4
|
asks instead of guessing.
|
|
5
5
|
|
|
6
|
+
`bun add @ultimat3/mcp` · guide: [MCP And AI](https://github.com/developerz-ai/ultimate/wiki/MCP-And-AI)
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { defineAppMcp } from '@ultimat3/mcp';
|
|
10
|
+
|
|
11
|
+
// every action declaring `mcp: { expose: true }` becomes a tool, under its own policy
|
|
12
|
+
defineAppMcp({ include: 'exposed' });
|
|
13
|
+
```
|
|
14
|
+
|
|
6
15
|
## The dev server: `x mcp serve`
|
|
7
16
|
|
|
8
17
|
| Tool | Scope | Answers |
|
|
@@ -15,6 +24,7 @@ asks instead of guessing.
|
|
|
15
24
|
| `queue.depth` | `dev:read` | pending / running / failed per queue |
|
|
16
25
|
| `manifest.read` | `dev:read` | `x.manifest.json` verbatim |
|
|
17
26
|
| `errors.explain` | `dev:read` | stable `X_*` code → cause + exact fix command + docs |
|
|
27
|
+
| `graph.query` | `dev:read` | `{ node }` → what a change to a file or primitive reaches (`x impact`'s answer); `{ from, to }` → the chain of edges linking two nodes (`x graph --from --to`). The CLI answers through `DevCapabilities.queryGraph`: the graph is `@ultimat3/manifest`'s |
|
|
18
28
|
| `db.query` | `db:read` | **read-only, enforced four ways** — SELECT-only role, `BEGIN READ ONLY`, one-statement parse, 5s/1000-row/256 KiB caps |
|
|
19
29
|
| `db.migrate` | `db:migrate` | **branch DB only** — refuses production and any non-branch target |
|
|
20
30
|
| `tests.run` | `dev:test` | runs the suite (executes project code) |
|
|
@@ -135,7 +145,9 @@ in its summary). The http pipeline does not pre-judge the route (`auth: 'public'
|
|
|
135
145
|
and decides per tool through the policy every other surface evaluates. `expose: true` with nothing
|
|
136
146
|
to mount — no file exports `mcp`, or the export was built without `resolveToken` and so carries no
|
|
137
147
|
`route` — logs `X_MCP_APP_UNMOUNTED` once, with the file to write; `expose: false` mounts nothing
|
|
138
|
-
and says nothing.
|
|
148
|
+
and says nothing. `x new` writes that file, so a new app boots `app mcp mounted`: `apps/web/mcp.ts`
|
|
149
|
+
over its `@<app>/mcp` catalog, with `resolveToken` taking an `@ultimat3/auth` API key everywhere and
|
|
150
|
+
`dev-agent.<role>` under `x dev` alone — and a 401 for anything else.
|
|
139
151
|
|
|
140
152
|
**Several endpoints, one per population (Unreleased).** `mcp` may be a non-empty array of
|
|
141
153
|
`defineAppMcp` values: every endpoint mounts at its own `defineAppMcp({ path })`; endpoint #0 owns
|
|
@@ -303,6 +315,99 @@ defineAppMcp({
|
|
|
303
315
|
actor half → preview / confirmation → `dispatch`, the flat path — same audit line, same bucket.
|
|
304
316
|
- Ungrouped tools (`docs`, `whoami`) stay flat beside the five, exactly as on `'meta'`.
|
|
305
317
|
|
|
318
|
+
### Per-caller tools: `catalog:` and `runtimeTool()`
|
|
319
|
+
|
|
320
|
+
`As of 2026-11`. A tool that exists per tenant — a connector row, a project's integration — is a
|
|
321
|
+
`runtimeTool()` answered by `catalog(caller)`, resolved for **every** `tools/list` and `tools/call`
|
|
322
|
+
(never cached) and merged with the static tools into one per-request registry, so visibility →
|
|
323
|
+
scope → args → admit → confirmation → policy run on it unchanged.
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
import { defineAppMcp, runtimeTool } from '@ultimat3/mcp';
|
|
327
|
+
|
|
328
|
+
interface ConnectorRow {
|
|
329
|
+
readonly name: string;
|
|
330
|
+
readonly description: string;
|
|
331
|
+
readonly schema: unknown;
|
|
332
|
+
}
|
|
333
|
+
declare function connectorsOf(orgId: string | undefined): Promise<readonly ConnectorRow[]>;
|
|
334
|
+
|
|
335
|
+
defineAppMcp({
|
|
336
|
+
catalog: async (caller) => ({
|
|
337
|
+
tools: (await connectorsOf(caller.actor.orgId)).map((row) =>
|
|
338
|
+
runtimeTool({
|
|
339
|
+
name: row.name,
|
|
340
|
+
description: row.description,
|
|
341
|
+
inputSchema: row.schema, // the wire subset, root `type: 'object'` — else refused
|
|
342
|
+
permission: 'connector:call', // a DECLARED permission, borrowed: never its own authz
|
|
343
|
+
destructive: false,
|
|
344
|
+
run: ({ input }) => ({ called: row.name, input }),
|
|
345
|
+
}),
|
|
346
|
+
),
|
|
347
|
+
}),
|
|
348
|
+
});
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
| Rule | Answer |
|
|
352
|
+
|---|---|
|
|
353
|
+
| only `runtimeTool()` values are served | anything else is `X_MCP_CATALOG_UNRESOLVED` — a hand-built tool would skip the permission |
|
|
354
|
+
| `permission` | `can(permission)`: an undeclared one is `X_PERMISSION_UNKNOWN`, an empty one `X_MCP_TOOL_UNSAFE` |
|
|
355
|
+
| `inputSchema` | copied into the wire subset or refused whole (`format`, `$ref`, `oneOf`…): published = enforced |
|
|
356
|
+
| a name a static tool, a meta tool, `list_tenants` or another runtime tool holds | `X_MCP_CATALOG_TOOL_DUPLICATE` |
|
|
357
|
+
| outcome 2 | with `scopes:` declared, `scope` must be one of its keys (else `X_MCP_CATALOG_UNRESOLVED`); without, none |
|
|
358
|
+
| visibility | the resolver already answers per caller: no `visibleTo`. Another caller's tool is an absent tool |
|
|
359
|
+
| meta surface | `groups` beside `tools` adds resources to `list_resources`; a boot group's name is a duplicate |
|
|
360
|
+
| the resolver throws | the request fails: `tools/list` `-32603` + `{ code, fix }`, `tools/call` an `isError` result — every name alike, so no name is an oracle. Never a smaller catalog |
|
|
361
|
+
| rate limit | a runtime name is unknown to the pre-dispatch classifier, so it bills the `write` bucket (fail closed) |
|
|
362
|
+
|
|
363
|
+
### One token across tenants: `tenant:`
|
|
364
|
+
|
|
365
|
+
`As of 2026-11`. `resolveToken` answers the PERSON (unchanged shape); every `tools/call` names the
|
|
366
|
+
tenant it acts in under `tenant.arg`. The step runs first on a call:
|
|
367
|
+
|
|
368
|
+
1. the arg is read and **stripped** — no tool's schema or handler ever sees it (`X_MCP_TENANT_INVALID`
|
|
369
|
+
at boot for a tool declaring it). Missing or empty: `X_MCP_TENANT_REQUIRED`, whose fix is `list_tenants({})`.
|
|
370
|
+
2. `resolve({ person, value })` answers the call's actor, a `kind: 'agent'` — or `null`, which is
|
|
371
|
+
**byte-for-byte the hidden-tool answer**: no 403, no echo of the value. A throw (or a non-agent
|
|
372
|
+
actor) is `X_MCP_TENANT_UNRESOLVED`, never "not a member".
|
|
373
|
+
3. that actor IS the caller for every gate, the confirmation, the policy and `ctx.actor.orgId` — so
|
|
374
|
+
the tenancy guards see one org per call — and the audit line carries `tenant`.
|
|
375
|
+
|
|
376
|
+
`list_tenants` (no arg, no scope) serves `list({ person })`; `tools/list` publishes the arg as a
|
|
377
|
+
required string on every other tool.
|
|
378
|
+
|
|
379
|
+
**`tools/list` is person-scoped, and not a promise.** It names no tenant (MCP's `tools/list` takes
|
|
380
|
+
only a `cursor`), so `visibleTo`, `can()` and `catalog` run there as the PERSON. `tools/call` runs
|
|
381
|
+
them as the tenant actor, and the call is authoritative:
|
|
382
|
+
|
|
383
|
+
| a tool | `tools/list` | `tools/call` |
|
|
384
|
+
|---|---|---|
|
|
385
|
+
| visible to the person, not to the tenant actor | listed | the hidden-tool answer |
|
|
386
|
+
| visible only through a tenant role or a tenant's `catalog` row | not listed | runs, when called by name |
|
|
387
|
+
|
|
388
|
+
A role or a runtime tool an agent must discover per tenant belongs on the person's actor, or in a
|
|
389
|
+
tool the agent reads after `list_tenants` (`docs`, `list_resources`).
|
|
390
|
+
|
|
391
|
+
```ts
|
|
392
|
+
import { agentActor } from '@ultimat3/core';
|
|
393
|
+
import { defineAppMcp } from '@ultimat3/mcp';
|
|
394
|
+
|
|
395
|
+
declare function roleIn(personId: string, project: string): Promise<string | undefined>;
|
|
396
|
+
declare function projectsOf(personId: string): Promise<readonly string[]>;
|
|
397
|
+
|
|
398
|
+
defineAppMcp({
|
|
399
|
+
include: 'exposed',
|
|
400
|
+
tenant: {
|
|
401
|
+
arg: 'project',
|
|
402
|
+
resolve: async ({ person, value }) => {
|
|
403
|
+
const role = await roleIn(person.id, value);
|
|
404
|
+
return role === undefined ? null : agentActor({ id: person.id, orgId: value, roles: [role] });
|
|
405
|
+
},
|
|
406
|
+
list: async ({ person }) => (await projectsOf(person.id)).map((value) => ({ value })),
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
```
|
|
410
|
+
|
|
306
411
|
### What a client is told beyond the schema
|
|
307
412
|
|
|
308
413
|
`As of 22.10`, MCP 2025-06-18. The projection derives each from the declaration; the primitive's
|
|
@@ -360,6 +465,24 @@ an over-long line with the same code. A JSON-RPC batch (an array) is refused `-3
|
|
|
360
465
|
this surface carries its instruction, `As of 2026-09-07` — the 413 and the batch were the two that
|
|
361
466
|
did not.
|
|
362
467
|
|
|
468
|
+
**Dual-era, `As of 2026-11`** (`protocol-era.ts`). A request whose
|
|
469
|
+
`params._meta["io.modelcontextprotocol/protocolVersion"]` is in `MCP_MODERN_VERSIONS` (`2026-07-28`)
|
|
470
|
+
is served statelessly: `server/discover`, no `initialize` or `ping`, every result stamped
|
|
471
|
+
`resultType: 'complete'` + `_meta` `serverInfo`, lists and reads `ttlMs: 0`, `cacheScope: 'private'`.
|
|
472
|
+
No `_meta` version, or one in `MCP_LEGACY_VERSIONS` (`2025-11-25`, `2025-06-18`, `2025-03-26`), is
|
|
473
|
+
today's legacy dispatch; `initialize` echoes an offered legacy revision, else `2025-11-25`. Any
|
|
474
|
+
other version is `-32022` `X_MCP_PROTOCOL_UNSUPPORTED` with `data: { supported, requested }`.
|
|
475
|
+
There is no `MCP_PROTOCOL_VERSION`: name the era, `MCP_MODERN_VERSIONS[0]` or `MCP_LEGACY_VERSIONS`.
|
|
476
|
+
|
|
477
|
+
| HTTP refusal | Status | Code |
|
|
478
|
+
|---|---|---|
|
|
479
|
+
| `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` |
|
|
480
|
+
| a Host the host does not serve — `x mcp serve` checks loopback and renders `mcpHostRefused(endpoint)` before `handle` | 421 | `X_MCP_HOST_REFUSED` |
|
|
481
|
+
| modern request whose `MCP-Protocol-Version`, `Mcp-Method` or `Mcp-Name` is absent or unequal to the body (base64 sentinel decoded) | 400, `-32020` | `X_MCP_HEADER_MISMATCH` |
|
|
482
|
+
| a version (header or `_meta`) this server does not serve | 400, `-32022` | `X_MCP_PROTOCOL_UNSUPPORTED` |
|
|
483
|
+
| a modern request naming a method not served | 404, `-32601` | — |
|
|
484
|
+
| `GET`/`DELETE` on the endpoint (a legacy stream or session) | 405, `Allow: POST` | `@ultimat3/http`'s `X_METHOD_NOT_ALLOWED` — the pipeline's on a mounted app, rendered the same by `x mcp serve` |
|
|
485
|
+
|
|
363
486
|
| Knob | Where | Default |
|
|
364
487
|
|---|---|---|
|
|
365
488
|
| the body cap | `mcpHttpRoute({ bodyLimitBytes })` · `defineAppMcp({ bodyLimitBytes })` | `DEFAULT_MCP_BODY_LIMIT_BYTES`, 1 MiB |
|
|
@@ -409,7 +532,7 @@ handed on. What an action or query DID still reaches core's `setAuditSink` (`sur
|
|
|
409
532
|
|---|---|---|
|
|
410
533
|
| `tool-call` | every `tools/call` outcome (`ok`, `hidden`, `scope-denied`, `policy-denied`, `invalid-args`, `unconfirmed`, `failed`) | `tool`, `outcome`, `caller`, `scope?`, `code?` |
|
|
411
534
|
| `resource-read` | every `resources/read` outcome | `uri`, `outcome`, `caller`, `scope?`, `code?` |
|
|
412
|
-
| `auth-refused` | a missing or rejected token, a non-agent actor, an address past its failure allowance — also logged `mcp.auth.<reason>` at `warn` | `reason`, `status` (401/403/429), `facts` |
|
|
535
|
+
| `auth-refused` | a missing or rejected token, a non-agent actor, an address past its failure allowance, a cross-origin `Origin` (`origin-refused`, before the token is read) — also logged `mcp.auth.<reason>` at `warn` | `reason`, `status` (401/403/429), `facts` |
|
|
413
536
|
|
|
414
537
|
Every event has `at` from the server's `clock`. Never the token, never the arguments. The hook is
|
|
415
538
|
not awaited and cannot change an answer: one that throws or rejects is logged once as
|
|
@@ -428,6 +551,15 @@ PUBLIC origin (`handle(request, { origin })`, which the boot fills from `ctx.htt
|
|
|
428
551
|
path; `scopes_supported` to the `scopes` map's keys. Issuers must be https (http on loopback):
|
|
429
552
|
`X_MCP_OAUTH_INVALID`. The authorization server is the app's own routes.
|
|
430
553
|
|
|
554
|
+
## OAuth: `mcpAuthorizationServer`
|
|
555
|
+
|
|
556
|
+
`As of 2026-11`. `mcpAuthorizationServer({ issuer, resource, store, consentPath, lifetimes, scopes,
|
|
557
|
+
actor, … })` is `@ultimat3/auth`'s `authorizationServer` bound to one endpoint: every grant binds to
|
|
558
|
+
`resource` (a request naming none included), `resolveToken` refuses any other, `oauth` is the block
|
|
559
|
+
`defineAppMcp({ oauth })` advertises, and each server decision is an `mcp.auth.<event>` line.
|
|
560
|
+
Spread `routes` into `runtime.routes`; write one consent page. Every protocol rule is auth's — see
|
|
561
|
+
[wiki MCP and AI](https://github.com/developerz-ai/ultimate/wiki/MCP-And-AI#oauth-discovery-for-remote-connectors).
|
|
562
|
+
|
|
431
563
|
## Human confirmation: `mcpConfirmations`
|
|
432
564
|
|
|
433
565
|
A factory over `action`, never a ninth primitive: what it returns IS the decision action
|
|
@@ -460,6 +592,26 @@ export const mcp = defineAppMcp({ include: 'exposed', confirmations: confirmRefu
|
|
|
460
592
|
| who may view and decide | policy `can(permission, check)`. An agent never may, whatever it holds (`X_FORBIDDEN`). The default `check` is the asking org: `row !== null && row.orgId === (actor.orgId ?? null)` — another tenant's row and an unknown id are one `X_FORBIDDEN`. Crossing tenants is an explicit `check`; with one that admits a missing row, an unknown id is `X_MCP_CONFIRMATION_UNKNOWN` |
|
|
461
593
|
| agent repeats the SAME call | approved: it runs once, through the tool's own `handle` — the action's full policy still decides it. Rejected: `X_MCP_CONFIRMATION_REJECTED`, audited as a denial. Past expiry: `X_MCP_CONFIRMATION_EXPIRED`. Each outcome is delivered once; the next identical call asks again |
|
|
462
594
|
|
|
595
|
+
**One list, both surfaces.** Calling `mcpConfirmations` also registers its gate by tool name
|
|
596
|
+
(`registerToolGate`, `@ultimat3/action`), so the same tool waits for a person from
|
|
597
|
+
`agent({ tools })` in `@ultimat3/ai`, with no option on the agent to forget. Its arguments are
|
|
598
|
+
validated against the tool's published schema first, so one digest covers both; what the schema
|
|
599
|
+
refuses is `X_INPUT_INVALID` and opens no row. An approval binds actor, tool and digest, not
|
|
600
|
+
surface. Two `mcpConfirmations` on one tool stay legal: each server keeps its own, and **in-app the
|
|
601
|
+
first registered answers** (a later one for that name is a no-op). A server handed no
|
|
602
|
+
`confirmations`, or handed one for other tools, asks the registered gate per call on every tool it
|
|
603
|
+
serves, so forgetting the option is no way around the list. A gated name no exposed action, exposed
|
|
604
|
+
query, MCP tool or in-process tool answers to holds nothing, so it is
|
|
605
|
+
`X_MCP_CONFIRMATION_TOOL_UNKNOWN` at the `manifest` step. A worker holds a gate only if it
|
|
606
|
+
imports the module declaring it, which is `X_ROLE_LOAD_INCOMPLETE` at the `manifest` step otherwise.
|
|
607
|
+
|
|
608
|
+
The gate binds a tool's **name**, never what it reaches: `inProcessTool({ name: 'refundNow', execute:
|
|
609
|
+
() => invoke(refundOrder, …) })` is not gated by `refundOrder`'s row, so list `refundNow` in `tools`.
|
|
610
|
+
|
|
611
|
+
**Never set `mcp: { expose: true }` on the decision action.** It declares none, which is what makes
|
|
612
|
+
`agent({ tools: [decide] })` `X_AGENT_TOOL_UNEXPOSED`. The policy's agent refusal does not reach an
|
|
613
|
+
in-app agent, whose actor is the user: exposing the decision action hands that agent its own approval.
|
|
614
|
+
|
|
463
615
|
Bound to the asking actor, the tool and the input digest: other arguments, or another agent, ride
|
|
464
616
|
no one's approval. The digest is keyed because the row stores it — an unkeyed hash of `{ accountNumber }` is
|
|
465
617
|
brute-forced from a database read. The open row is found by equality on it, key id included, so
|
|
@@ -472,6 +624,50 @@ another. `sealKeys` points at the key in a test. `SQL_MCP_CONFIRMATIONS_TABLE` i
|
|
|
472
624
|
`X_MCP_CONFIRMATION_TOOL_UNKNOWN` at boot. The gated tool carries `confirms: true`, which the meta
|
|
473
625
|
catalog shows as `(confirms)`.
|
|
474
626
|
|
|
627
|
+
### Quorum and signed decisions
|
|
628
|
+
|
|
629
|
+
Two more options on the same factory, `As of 2026-11`: `approvers` (N of M) and `evidence` (every
|
|
630
|
+
vote signed). Same gate, same order, same single-use `consume`.
|
|
631
|
+
|
|
632
|
+
```ts
|
|
633
|
+
import type { PgExecutor } from '@ultimat3/core';
|
|
634
|
+
import type { McpEvidenceCheck } from '@ultimat3/mcp';
|
|
635
|
+
import { mcpConfirmations, postgresConfirmationStore } from '@ultimat3/mcp';
|
|
636
|
+
|
|
637
|
+
declare const executor: PgExecutor;
|
|
638
|
+
// The app's key registry: true only when `signature` verifies over `payload` under a key
|
|
639
|
+
// registered to `approver` (a device key — the private half never reaches the server).
|
|
640
|
+
declare function verifyDeviceKey(check: McpEvidenceCheck): Promise<boolean>;
|
|
641
|
+
|
|
642
|
+
export const confirmRefunds = mcpConfirmations({
|
|
643
|
+
tools: ['refundOrder'],
|
|
644
|
+
store: postgresConfirmationStore({ executor }),
|
|
645
|
+
permission: 'order:refund',
|
|
646
|
+
approvers: ({ args }) => ({ quorum: Number(args['amount']) > 1000 ? 2 : 1, from: ['role:finance'] }),
|
|
647
|
+
evidence: { verify: verifyDeviceKey },
|
|
648
|
+
ttlMs: 4 * 3_600_000,
|
|
649
|
+
});
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
| Rule | Mechanism |
|
|
653
|
+
|---|---|
|
|
654
|
+
| the bar | `approvers({ tool, args, actor })` over the VALIDATED arguments, at the call, before a row opens; `quorum` and `from` are stored on the row, so a later declaration cannot lower an open one (the gate re-checks with the higher of the two) |
|
|
655
|
+
| `from` | `'role:<name>'` (an application role on the decider) or `'actor:<id>'`, a closed template type. Matched by the decision action's policy — the one authz path — for `approve` and `reject`; `view` stays `permission` + `check` |
|
|
656
|
+
| the requester never counts | a decider whose id is the row's `actorId` is `X_FORBIDDEN` (`mcp-confirmation.requester`), and so is an impersonated one (`onBehalfOf`). Only when `approvers` is declared: without it, the original single decision by anyone the policy admits holds |
|
|
657
|
+
| one approver, one vote | the store's conditional write refuses a second vote by the same id; the decision answers `X_MCP_CONFIRMATION_QUORUM_PENDING` naming it |
|
|
658
|
+
| partial | the row stays `pending` until `quorum` distinct votes; the agent's repeat answers `X_MCP_CONFIRMATION_QUORUM_PENDING` (`n of m`), nothing runs. One rejection rejects. `ttlMs` expires a partial row like any other |
|
|
659
|
+
| refused at the call | a quorum that is not a whole number ≥ 1, an empty or malformed `from`, or more named `actor:` approvers than exist without the requester: `X_MCP_CONFIRMATION_QUORUM_INVALID`, no row. `evidence` with no `verify`: the same code at declaration |
|
|
660
|
+
| what is signed | `signingPayload` — `confirmationSigningPayload(row)`, canonical JSON of purpose, confirmation id, tool and the keyed argument digest — returned by `view`. The id makes a signature good for one row (a replay onto the next identical call binds another id); the digest for one set of arguments |
|
|
661
|
+
| at the decision | `approve` carries `signature`; missing or not `true` from `verify` is `X_MCP_CONFIRMATION_EVIDENCE_INVALID` and stores no vote. A `verify` that throws propagates: an outage, never a verdict |
|
|
662
|
+
| at the call | before the CAS `consume`, the gate runs `verifyConfirmationEvidence` over the STORED row: approved, bound to these arguments, every signature verifying, `quorum` distinct eligible approvers. Any failure consumes the row and answers `X_MCP_CONFIRMATION_EVIDENCE_INVALID` (a denial); a throwing verifier leaves it for a retry |
|
|
663
|
+
| a separate process | `verifyConfirmationEvidence(row, { evidence, quorum, from, arguments })` is exported: an executor that trusts nothing the app server wrote re-checks the row with public keys alone. `from` checks `actor:` selectors here; a `role:` standing is the registry's, so `verify` is handed `from` |
|
|
664
|
+
|
|
665
|
+
The row carries `quorum`, `approvers` and `approvals` (`{ approver, at, signature }[]`, one per
|
|
666
|
+
distinct approver, in order); `decidedBy`/`decidedAt` are the vote that met the quorum. The view
|
|
667
|
+
answers `quorum`, `approvedBy` and `signingPayload` too. `McpConfirmationStore.decide` takes the
|
|
668
|
+
signature as a fifth argument. Three columns are added by the boot (`alter table … add column if
|
|
669
|
+
not exists`): a row opened before them reads as one approval, no selectors.
|
|
670
|
+
|
|
475
671
|
## Resources
|
|
476
672
|
|
|
477
673
|
| URI | Contents |
|
|
@@ -516,6 +712,53 @@ it (`X_INPUT_INVALID`, as an `isError` result). An argument, not `params._meta`:
|
|
|
516
712
|
model-driven client cannot set it. An idempotent action whose input already names `idempotencyKey`
|
|
517
713
|
is `X_MCP_IDEMPOTENCY_KEY_SHADOWED` at boot.
|
|
518
714
|
|
|
715
|
+
## Long tools: `jobTool()` and `job_status`
|
|
716
|
+
|
|
717
|
+
`tools: { exportPosts: jobTool({ job, policy, description, result, input?, jobInput?, inlineMs? }) }`
|
|
718
|
+
enqueues at once under the caller — `jobInput(input, ctx)` builds the job's input from the tool's
|
|
719
|
+
and the caller's (a member id off the request, never an argument) — waits up to `inlineMs`
|
|
720
|
+
(default 5,000, ceiling 25,000; also a count of 250 ms polls, so a clock that never moves still
|
|
721
|
+
ends it), then answers
|
|
722
|
+
`{ status: 'done', result }` — the app's `result` query, run AS the caller — or
|
|
723
|
+
`{ status: 'running', jobId, poll: { tool: 'job_status', arguments: { jobId } } }`. One
|
|
724
|
+
`job_status` is projected beside any job tool; another actor's, another org's and an unknown id
|
|
725
|
+
read the same not-found. A failed job crosses as its code — the code it was THROWN with, read from
|
|
726
|
+
the head of the row's `lastError` by `@ultimat3/jobs`' `callerFailure`, `X_INTERNAL` for an uncoded
|
|
727
|
+
throw — plus the error's declared `callerFix` when it has one; never the developer `fix` or the row's
|
|
728
|
+
text.
|
|
729
|
+
A driver without `introspect` is `X_MCP_JOB_TOOL_INVALID`.
|
|
730
|
+
|
|
731
|
+
## Recipes and the `docs` tool
|
|
732
|
+
|
|
733
|
+
| Declare | What it does |
|
|
734
|
+
|---|---|
|
|
735
|
+
| `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 |
|
|
736
|
+
| `recipes: await markdownRecipes({ dir })` | one `*.md` per recipe, body served verbatim. Name = file name; `---` `title:` / `description:` 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://recipes/` link in the text that names no recipe is `X_MCP_RECIPE_LINK_DANGLING` |
|
|
737
|
+
| `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. Not boot-checked; one naming a tool the caller cannot call is not shown |
|
|
738
|
+
|
|
739
|
+
`docs({})` lists what this caller can follow; `docs({ name })` / `docs({ uri })` reads one;
|
|
740
|
+
`docs({ q })` inlines the best match (3 points a word in name or title, 2 in description, 1 in the
|
|
741
|
+
body) and names the nearest names on a miss — never an empty answer while a recipe is visible. A
|
|
742
|
+
recipe is visible only when every step's tool is visible to the caller and its scope is on the
|
|
743
|
+
token; hidden and unknown are the same not-found. An `UltimateError`'s `docs://recipes/<name>` is
|
|
744
|
+
checked at load (`X_MCP_RECIPE_UNKNOWN`). In a contract test, `replayRecipes(server, recipes, {
|
|
745
|
+
caller, placeholders })` CALLS every fenced example through the server and reads every link: no
|
|
746
|
+
such tool, refused arguments, a refusing policy or a dangling link fails it.
|
|
747
|
+
|
|
748
|
+
`McpResource.read(caller)` takes the caller the gates admitted, and `mcpServer({ resourceSources })`
|
|
749
|
+
lists resources per caller — what `extraRecipes` is built on.
|
|
750
|
+
|
|
751
|
+
## Consuming another server: `mcpTools()` and `mcpClient()`
|
|
752
|
+
|
|
753
|
+
| Piece | Rule |
|
|
754
|
+
|---|---|
|
|
755
|
+
| `mcpTools({ name, url, auth, allow, policy, lock })` | one `action` per allowed remote tool, named `<name>_<tool>`, under the APP's `resource:verb` permission (`policy: 'docs:search'` — a predicate over the remote's input would read nothing), rate limit and confirmation gate. `allow` is required; nothing is discovered at run time |
|
|
756
|
+
| `tools.lock.json` | what a person reviewed: per tool, the description, input schema and `readOnly` (a person sets it; `false` keeps the gate binding). `x mcp lock <name>` writes it; `--check` compares. An allowed tool the lock lacks refuses at declaration; a live drift is `X_MCP_REMOTE_TOOL_CHANGED` before the first call, and the `manifest` step of `x verify` runs the check for every declared server (an unreachable server is a warning) |
|
|
757
|
+
| `notifications/tools/list_changed` | heard on any response stream, and — for a legacy session — on the `GET` stream the client holds open for the server's own messages (one per session, detached from the request, `listenMs` long, default 5 min, re-opened by the next call; a `405` is a server without one, never asked again; `client.close()` ends it). The next call re-lists and is held to the lock again — a changed tool is refused, never trusted silently |
|
|
758
|
+
| output | `{ untrusted, isError }`: the remote's text inside `<untrusted source="mcp:<name>/<tool>">`, middle cut past `maxResultChars` |
|
|
759
|
+
| `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 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` |
|
|
760
|
+
| `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 }`. `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` |
|
|
761
|
+
|
|
519
762
|
## Errors
|
|
520
763
|
|
|
521
764
|
| Code | Meaning |
|
|
@@ -530,6 +773,10 @@ is `X_MCP_IDEMPOTENCY_KEY_SHADOWED` at boot.
|
|
|
530
773
|
| `X_MCP_SURFACE_OVER_BUDGET` | `assertMcpSurfaceBudget` measured a surface over its declared ceiling |
|
|
531
774
|
| `X_MCP_IDEMPOTENCY_KEY_SHADOWED` | an idempotent action's input declares `idempotencyKey`, the reserved retry-key argument |
|
|
532
775
|
| `X_MCP_PROTOCOL` | malformed envelope, unknown method, bad auth header |
|
|
776
|
+
| `X_MCP_PROTOCOL_UNSUPPORTED` | the request names a protocol version this server does not serve (`-32022`, 400) |
|
|
777
|
+
| `X_MCP_HEADER_MISMATCH` | a modern HTTP request's mirrored header is absent or disagrees with the body (`-32020`, 400) |
|
|
778
|
+
| `X_MCP_ORIGIN_REFUSED` | `Origin` that `proveSameOrigin` cannot show is this app's (nor listed in `http.cors.origins`), refused 403 before the token is read |
|
|
779
|
+
| `X_MCP_HOST_REFUSED` | `x mcp serve` was reached on a Host that is not loopback — a DNS-rebound name — 421 |
|
|
533
780
|
| `X_MCP_QUERY_REJECTED` | `db.query` given anything but one read-only statement |
|
|
534
781
|
| `X_MCP_NOT_BRANCH_DB` | `db.migrate` aimed at a production or otherwise non-branch database |
|
|
535
782
|
| `X_MCP_RESOURCE_DUPLICATE` | two resources claim one `ultimate://` URI — refused at registration, as a duplicate tool name is |
|
|
@@ -544,6 +791,9 @@ is `X_MCP_IDEMPOTENCY_KEY_SHADOWED` at boot.
|
|
|
544
791
|
| `X_MCP_CONFIRMATION_TOOL_UNKNOWN` | `mcpConfirmations({ tools })` names a tool this server does not project, or none |
|
|
545
792
|
| `X_MCP_CONFIRMATION_CONTESTED` | identical concurrent calls kept racing one confirmation; retry |
|
|
546
793
|
| `X_MCP_CONFIRMATION_ARGUMENTS_MISMATCH` | an approval did not carry the arguments the agent sent (missing, different, or keyed before a rotation) |
|
|
794
|
+
| `X_MCP_CONFIRMATION_QUORUM_PENDING` | some distinct approvers approved and the quorum needs more; also a repeat vote by one who already counted |
|
|
795
|
+
| `X_MCP_CONFIRMATION_EVIDENCE_INVALID` | under `evidence`, a vote's signature is missing or does not verify, or the stored row no longer proves its approval |
|
|
796
|
+
| `X_MCP_CONFIRMATION_QUORUM_INVALID` | `approvers` answered a bar nobody can meet, or `evidence` declares no `verify` |
|
|
547
797
|
| `X_MCP_RATE_LIMITED` | the caller spent its per-minute allowance for this request's class. Its own code rather than `@ultimat3/http`'s `X_RATE_LIMITED` because the KNOB differs — `rateLimits` on the route, never `rateLimit.buckets` in `app.config.ts` |
|
|
548
798
|
|
|
549
799
|
### Error classes
|
|
@@ -560,11 +810,18 @@ a job boundary the class is gone and the `code` is what survives — match on th
|
|
|
560
810
|
| `McpConfirmationArgumentsMismatchError` | `X_MCP_CONFIRMATION_ARGUMENTS_MISMATCH` | `src/confirmation-errors.ts` |
|
|
561
811
|
| `McpConfirmationContestedError` | `X_MCP_CONFIRMATION_CONTESTED` | `src/confirmation-errors.ts` |
|
|
562
812
|
| `McpConfirmationDecidedError` | `X_MCP_CONFIRMATION_DECIDED` | `src/confirmation-errors.ts` |
|
|
813
|
+
| `McpConfirmationEvidenceInvalidError` | `X_MCP_CONFIRMATION_EVIDENCE_INVALID` | `src/confirmation-quorum-errors.ts` |
|
|
563
814
|
| `McpConfirmationExpiredError` | `X_MCP_CONFIRMATION_EXPIRED` | `src/confirmation-errors.ts` |
|
|
564
815
|
| `McpConfirmationPendingError` | `X_MCP_CONFIRMATION_PENDING` | `src/confirmation-errors.ts` |
|
|
816
|
+
| `McpConfirmationQuorumInvalidError` | `X_MCP_CONFIRMATION_QUORUM_INVALID` | `src/confirmation-quorum-errors.ts` |
|
|
817
|
+
| `McpConfirmationQuorumPendingError` | `X_MCP_CONFIRMATION_QUORUM_PENDING` | `src/confirmation-quorum-errors.ts` |
|
|
565
818
|
| `McpConfirmationRejectedError` | `X_MCP_CONFIRMATION_REJECTED` | `src/confirmation-errors.ts` |
|
|
566
819
|
| `McpConfirmationToolUnknownError` | `X_MCP_CONFIRMATION_TOOL_UNKNOWN` | `src/confirmation-errors.ts` |
|
|
567
820
|
| `McpConfirmationUnknownError` | `X_MCP_CONFIRMATION_UNKNOWN` | `src/confirmation-errors.ts` |
|
|
821
|
+
| `McpHeaderMismatchError` | `X_MCP_HEADER_MISMATCH` | `src/errors-transport.ts` |
|
|
822
|
+
| `McpHostRefusedError` | `X_MCP_HOST_REFUSED` | `src/errors-transport.ts` |
|
|
823
|
+
| `McpOriginRefusedError` | `X_MCP_ORIGIN_REFUSED` | `src/errors-transport.ts` |
|
|
824
|
+
| `McpProtocolUnsupportedError` | `X_MCP_PROTOCOL_UNSUPPORTED` | `src/errors-transport.ts` |
|
|
568
825
|
| `McpGroupConflictError` | `X_MCP_GROUP_CONFLICT` | `src/meta-errors.ts` |
|
|
569
826
|
| `McpGroupUnknownError` | `X_MCP_GROUP_UNKNOWN` | `src/meta-errors.ts` |
|
|
570
827
|
| `McpListParamsInvalidError` | `X_MCP_LIST_PARAMS_INVALID` | `src/meta-errors.ts` |
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "30.0.0",
|
|
4
4
|
"description": "MCP server, dev tools, and the action-to-tool projection \u2014 one authz system, two surfaces",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ultimate",
|
|
7
|
+
"bun",
|
|
8
|
+
"framework",
|
|
9
|
+
"mcp",
|
|
10
|
+
"model-context-protocol",
|
|
11
|
+
"agents",
|
|
12
|
+
"ai"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/developerz-ai/ultimate/wiki/MCP-And-AI",
|
|
5
15
|
"license": "MIT",
|
|
6
16
|
"type": "module",
|
|
7
17
|
"repository": {
|
|
@@ -33,14 +43,15 @@
|
|
|
33
43
|
"test": "bun test"
|
|
34
44
|
},
|
|
35
45
|
"dependencies": {
|
|
36
|
-
"@ultimat3/action": "
|
|
37
|
-
"@ultimat3/
|
|
38
|
-
"@ultimat3/
|
|
39
|
-
"@ultimat3/
|
|
40
|
-
"@ultimat3/
|
|
41
|
-
"@ultimat3/
|
|
42
|
-
"@ultimat3/
|
|
43
|
-
"@ultimat3/
|
|
44
|
-
"@ultimat3/
|
|
46
|
+
"@ultimat3/action": "30.0.0",
|
|
47
|
+
"@ultimat3/auth": "30.0.0",
|
|
48
|
+
"@ultimat3/core": "30.0.0",
|
|
49
|
+
"@ultimat3/db": "30.0.0",
|
|
50
|
+
"@ultimat3/entity": "30.0.0",
|
|
51
|
+
"@ultimat3/http": "30.0.0",
|
|
52
|
+
"@ultimat3/jobs": "30.0.0",
|
|
53
|
+
"@ultimat3/policy": "30.0.0",
|
|
54
|
+
"@ultimat3/query": "30.0.0",
|
|
55
|
+
"@ultimat3/schema": "30.0.0"
|
|
45
56
|
}
|
|
46
57
|
}
|