@ultimat3/mcp 30.3.0 → 30.5.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 CHANGED
@@ -22,7 +22,7 @@ import. The CLI wires it.
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 |
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` |
25
+ | `dev-server.ts` · `dev-ui-*.ts` · `dev-graph-tool.ts` | the 19 dev tools: 13 here (`routes.list` … `logs.tail`), the five `ui.*`, `graph.query`. Depends only on an injected `DevHost` |
26
26
  | `dev-host.ts` | wires `describe*` from entity/action/query/jobs into a `DevHost` |
27
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
28
  | `transport-http-answers.ts` | the pre-dispatch answers (401, 403 not-an-agent / origin, 421, 429) and the per-address failure meter |
@@ -36,6 +36,7 @@ import. The CLI wires it.
36
36
  | `app-tool.ts` | the authored `tools: { name: {...} }` record → `ProjectablePrimitive` |
37
37
  | `projectable.ts` | a real `action`/`query` → `ProjectablePrimitive`; the ONE adapter both the sweep and the written-out list use |
38
38
  | `exposed.ts` | `include: 'exposed'` — the action/query registries → primitives |
39
+ | `include-early.ts` | `assertIncludeCurrent`, the mount's after-scan check (`X_MCP_INCLUDE_EARLY`) — [history](../../docs/history/mcp.md) |
39
40
  | `scopes.ts` | the `scopes:` map — outcome 2's declaration surface and its three boot refusals |
40
41
  | `readonly-sql.ts` · `readonly-sql-calls.ts` | layer 3 of `db.query` — the single-read parse — and `db.migrate`'s branch check · the banned call families |
41
42
  | `query-limits.ts` | layer 4 of `db.query` — the row, byte and timeout ceilings, and what truncation reports |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/mcp",
3
- "version": "30.3.0",
3
+ "version": "30.5.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",
@@ -43,15 +43,15 @@
43
43
  "test": "bun test"
44
44
  },
45
45
  "dependencies": {
46
- "@ultimat3/action": "30.3.0",
47
- "@ultimat3/auth": "30.3.0",
48
- "@ultimat3/core": "30.3.0",
49
- "@ultimat3/db": "30.3.0",
50
- "@ultimat3/entity": "30.3.0",
51
- "@ultimat3/http": "30.3.0",
52
- "@ultimat3/jobs": "30.3.0",
53
- "@ultimat3/policy": "30.3.0",
54
- "@ultimat3/query": "30.3.0",
55
- "@ultimat3/schema": "30.3.0"
46
+ "@ultimat3/action": "30.5.0",
47
+ "@ultimat3/auth": "30.5.0",
48
+ "@ultimat3/core": "30.5.0",
49
+ "@ultimat3/db": "30.5.0",
50
+ "@ultimat3/entity": "30.5.0",
51
+ "@ultimat3/http": "30.5.0",
52
+ "@ultimat3/jobs": "30.5.0",
53
+ "@ultimat3/policy": "30.5.0",
54
+ "@ultimat3/query": "30.5.0",
55
+ "@ultimat3/schema": "30.5.0"
56
56
  }
57
57
  }
package/src/app-tools.ts CHANGED
@@ -22,6 +22,7 @@ import type { McpConfirmations } from './confirmations';
22
22
  import { McpToolDuplicateError } from './errors';
23
23
  import { exposedPrimitives } from './exposed';
24
24
  import { toolsFrom, toolsListed } from './from-action';
25
+ import { noteIncluded } from './include-early';
25
26
  import { jobStatusPrimitive } from './job-status-tool';
26
27
  import { jobToolBrand } from './job-tool';
27
28
  import type { McpResourceGroups, McpSurfaceOption } from './meta-surface';
@@ -238,9 +239,10 @@ export interface AppMcp {
238
239
  * Project an app's primitives into a ready MCP server.
239
240
  *
240
241
  * ```ts
241
- * // apps/admin/app/admin/mcp.ts
242
+ * // apps/admin/mcp.ts, at module scope — built earlier, the mount says X_MCP_INCLUDE_EARLY
242
243
  * export const mcp = defineAppMcp({
243
244
  * name: 'acme-admin',
245
+ * path: '/admin/mcp',
244
246
  * include: 'exposed',
245
247
  * prompts: ['apps/web/app/posts/prompts/summarize.v3.md'],
246
248
  * tools: {
@@ -270,8 +272,8 @@ export function defineAppMcp<TSchemas extends AppToolSchemas>(
270
272
  );
271
273
  // An explicitly listed primitive is a refinement of the registry's entry, not a rival to it,
272
274
  // so `include` fills the gaps rather than colliding with what the caller already spelled out.
273
- const included =
274
- input.include === 'exposed' ? notNamed(toolsFrom(exposedPrimitives()), listed) : [];
275
+ const exposed = input.include === 'exposed' ? exposedPrimitives() : [];
276
+ const included = notNamed(toolsFrom(exposed), listed);
275
277
  const written = handWritten(input.tools);
276
278
  // One `job_status` for every `jobTool()` here, projected beside them; an app tool already named
277
279
  // that is a duplicate below, never a silent shadow.
@@ -334,7 +336,16 @@ export function defineAppMcp<TSchemas extends AppToolSchemas>(
334
336
  : { oauth: input.oauth, scopes: Object.keys(input.scopes ?? {}) }),
335
337
  });
336
338
 
337
- return { server, tools: projected, route };
339
+ const app: AppMcp = { server, tools: projected, route };
340
+ // What `include` saw, so the mount can tell a catalog built before the scan finished
341
+ // (`X_MCP_INCLUDE_EARLY`) from one built after it.
342
+ if (input.include === 'exposed') {
343
+ noteIncluded(
344
+ app,
345
+ exposed.map((primitive) => primitive.name),
346
+ );
347
+ }
348
+ return app;
338
349
  }
339
350
 
340
351
  /**
package/src/errors.ts CHANGED
@@ -61,6 +61,7 @@ export const MCP_ERROR_CODES = [
61
61
  'X_MCP_TENANT_REQUIRED',
62
62
  'X_MCP_TENANT_UNRESOLVED',
63
63
  'X_MCP_TENANT_INVALID',
64
+ 'X_MCP_INCLUDE_EARLY',
64
65
  ] as const;
65
66
 
66
67
  export type McpErrorCode = (typeof MCP_ERROR_CODES)[number];
@@ -130,6 +131,8 @@ export const MCP_ERROR_TITLES: Readonly<Record<McpErrorCode, string>> = {
130
131
  X_MCP_TENANT_REQUIRED: 'an MCP call names no tenant',
131
132
  X_MCP_TENANT_UNRESOLVED: 'the tenant of an MCP call could not be resolved',
132
133
  X_MCP_TENANT_INVALID: 'defineAppMcp declares its tenant argument inconsistently',
134
+ X_MCP_INCLUDE_EARLY:
135
+ "include: 'exposed' projected before the scan registered every exposed primitive",
133
136
  };
134
137
 
135
138
  // Titles must be registered for `format()` to render the contract's first line. Every code above is
package/src/exposed.ts CHANGED
@@ -21,7 +21,8 @@ import { primitiveFromAction, primitiveFromQuery } from './projectable';
21
21
  * reserves the `idempotencyKey` argument and builds the wire schema, so an action no surface
22
22
  * serves could refuse the boot (`X_MCP_IDEMPOTENCY_KEY_SHADOWED`) of every tool that is served.
23
23
  *
24
- * Read eagerly, at the moment `defineAppMcp` runs — register the app's primitives first.
24
+ * Read eagerly, at the moment `defineAppMcp` runs — register the app's primitives first. The mount
25
+ * asks again after the boot scan (`include-early.ts`), so a catalog built too early is refused.
25
26
  */
26
27
  export function exposedPrimitives(): readonly ProjectablePrimitive[] {
27
28
  return [
@@ -0,0 +1,30 @@
1
+ // When `include: 'exposed'` was projected, and whether the registries have grown since. The boot
2
+ // scan registers each module's primitives as it reaches it, so an endpoint built at the top level
3
+ // of a module the scan evaluates early froze a catalog missing every primitive registered after —
4
+ // silently, and only in the process that booted. The mount asks here once the scan is done.
5
+
6
+ import { exposedPrimitives } from './exposed';
7
+ import { McpIncludeEarlyError } from './mount-errors';
8
+
9
+ /** Keyed on the `AppMcp` object: collected with it, and a hand-built look-alike has no entry. */
10
+ const projectedAt = new WeakMap<object, ReadonlySet<string>>();
11
+
12
+ /** `defineAppMcp`'s half: the exposed primitives `include: 'exposed'` saw, by name. */
13
+ export function noteIncluded(endpoint: object, names: readonly string[]): void {
14
+ projectedAt.set(endpoint, new Set(names));
15
+ }
16
+
17
+ /**
18
+ * The mount's half, after the scan: an endpoint built with `include: 'exposed'` must have seen
19
+ * every exposed primitive registered now, or it is `X_MCP_INCLUDE_EARLY` naming the ones it
20
+ * missed and `file`, the mount file that exported it. An endpoint without `include` is not asked.
21
+ */
22
+ export function assertIncludeCurrent(endpoint: object, file: string): void {
23
+ const seen = projectedAt.get(endpoint);
24
+ if (seen === undefined) return;
25
+ const missing = exposedPrimitives()
26
+ .map((primitive) => primitive.name)
27
+ .filter((name) => !seen.has(name))
28
+ .sort();
29
+ if (missing.length > 0) throw new McpIncludeEarlyError({ missing, file });
30
+ }
package/src/index.ts CHANGED
@@ -168,6 +168,7 @@ export { exposedPrimitives } from './exposed';
168
168
  export type { ProjectablePrimitive } from './from-action';
169
169
  export { deriveAnnotations, toolFrom, toolsFrom, toolsListed } from './from-action';
170
170
  export { MCP_IDEMPOTENCY_KEY_ARG } from './idempotency-arg';
171
+ export { assertIncludeCurrent } from './include-early';
171
172
  export type { JobToolAnswer, JobToolDef, JobToolWait } from './job-tool';
172
173
  export { JOB_STATUS_TOOL, JOB_TOOL_INLINE_CEILING_MS, jobTool } from './job-tool';
173
174
  export { McpJobToolInvalidError } from './job-tool-errors';
@@ -210,7 +211,7 @@ export {
210
211
  oneLineParams,
211
212
  renderCatalog,
212
213
  } from './meta-surface';
213
- export { McpPathDuplicateError } from './mount-errors';
214
+ export { McpIncludeEarlyError, McpPathDuplicateError } from './mount-errors';
214
215
  export type { McpOAuth } from './oauth-metadata';
215
216
  export {
216
217
  metadataPaths,
@@ -17,15 +17,39 @@ export class McpPathDuplicateError extends UltimateError {
17
17
  method: string;
18
18
  path: string;
19
19
  endpoints: readonly [number, number];
20
+ /** The file exporting endpoint `second` — and `first` too, unless `firstFile` says otherwise. */
20
21
  file: string;
22
+ /** The file exporting endpoint `first`, when two app directories' `mcp.ts` collide. */
23
+ firstFile?: string;
21
24
  }) {
22
25
  const [first, second] = input.endpoints;
26
+ const across = input.firstFile !== undefined && input.firstFile !== input.file;
23
27
  super({
24
28
  code: 'X_MCP_PATH_DUPLICATE',
25
- cause: `${input.file} exports mcp endpoints #${first} and #${second}, and both claim ${input.method} ${input.path}`,
29
+ cause: across
30
+ ? `${input.firstFile} (mcp endpoint #${first}) and ${input.file} (mcp endpoint #${second}) both claim ${input.method} ${input.path}`
31
+ : `${input.file} exports mcp endpoints #${first} and #${second}, and both claim ${input.method} ${input.path}`,
26
32
  fix: `give endpoint #${second} in ${input.file} its own path — defineAppMcp({ path: '/mcp/<population>', ... }); every endpoint mounts at its own defineAppMcp path (default /mcp)`,
27
33
  });
28
34
  this.path = input.path;
29
35
  this.endpoints = input.endpoints;
30
36
  }
31
37
  }
38
+
39
+ /**
40
+ * An endpoint's `include: 'exposed'` catalog was projected before the boot scan registered every
41
+ * exposed primitive. Thrown, never warned: served as is, the endpoint lists a smaller catalog than
42
+ * the app declared, and nothing else would ever say so.
43
+ */
44
+ export class McpIncludeEarlyError extends UltimateError {
45
+ readonly missing: readonly string[];
46
+
47
+ constructor(input: { missing: readonly string[]; file: string }) {
48
+ super({
49
+ code: 'X_MCP_INCLUDE_EARLY',
50
+ cause: `the mcp endpoint ${input.file} exports projected include: 'exposed' before ${input.missing.join(', ')} registered — it was built at the top level of a module the boot scan evaluates before the app's actions and queries — so its catalog lacks them`,
51
+ fix: `export const mcp = defineAppMcp({ include: 'exposed', resolveToken }) # at module scope in ${input.file} itself, not in a module it imports — the boot scan evaluates every apps/<app>/mcp.ts after all apps/*/{site,app,api,shared} modules have registered`,
52
+ });
53
+ this.missing = input.missing;
54
+ }
55
+ }