@ultimat3/mcp 31.35.0 → 31.36.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/mcp",
3
- "version": "31.35.0",
3
+ "version": "31.36.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.35.0",
48
- "@ultimat3/auth": "31.35.0",
49
- "@ultimat3/core": "31.35.0",
50
- "@ultimat3/db": "31.35.0",
51
- "@ultimat3/entity": "31.35.0",
52
- "@ultimat3/http": "31.35.0",
53
- "@ultimat3/jobs": "31.35.0",
54
- "@ultimat3/policy": "31.35.0",
55
- "@ultimat3/query": "31.35.0",
56
- "@ultimat3/schema": "31.35.0"
47
+ "@ultimat3/action": "31.36.0",
48
+ "@ultimat3/auth": "31.36.0",
49
+ "@ultimat3/core": "31.36.0",
50
+ "@ultimat3/db": "31.36.0",
51
+ "@ultimat3/entity": "31.36.0",
52
+ "@ultimat3/http": "31.36.0",
53
+ "@ultimat3/jobs": "31.36.0",
54
+ "@ultimat3/policy": "31.36.0",
55
+ "@ultimat3/query": "31.36.0",
56
+ "@ultimat3/schema": "31.36.0"
57
57
  }
58
58
  }
@@ -40,8 +40,8 @@ export class McpBodyTooLargeError extends UltimateError {
40
40
  ? `request body is at least ${input.over ?? input.limit} bytes, limit is ${input.limit}`
41
41
  : `one message exceeded ${input.limit} bytes and was dropped`,
42
42
  fix: http
43
- ? `send less in one request — page a large read, split a long prompt across calls — or raise the cap where the route is built: mcpHttpRoute({ bodyLimitBytes: ${raised} }) or defineAppMcp({ bodyLimitBytes: ${raised} })`
44
- : `send one JSON-RPC message per line, each under the cap — split a large tool result into paged calls — or raise it where the transport is started: serveStdio({ lineLimitBytes: ${raised} })`,
43
+ ? `defineAppMcp({ bodyLimitBytes: ${raised} }) // or mcpHttpRoute({ bodyLimitBytes: ${raised} }), where the route is built — or send less in one request: page a large read, split a long prompt across calls`
44
+ : `serveStdio({ lineLimitBytes: ${raised} }) // where the transport is started — or send one JSON-RPC message per line, each under the cap: split a large tool result into paged calls`,
45
45
  // The numbers as FIELDS, not only prose: a `--json` reader and the wire's `data` both want
46
46
  // the limit without re-parsing a sentence.
47
47
  meta: {
@@ -72,7 +72,7 @@ export class McpRateLimitedError extends UltimateError {
72
72
  super({
73
73
  code: 'X_MCP_RATE_LIMITED',
74
74
  cause: `this caller has spent its ${input.limit} ${input.verbClass} requests per minute; the bucket refills in ${input.retryAfterSeconds}s`,
75
- fix: `wait ${input.retryAfterSeconds}s — the Retry-After header carries the same number — or raise it where the route is built: mcpHttpRoute({ rateLimits: { ${input.verbClass}: <n> } }), or defineAppMcp({ rateLimits })`,
75
+ fix: `defineAppMcp({ rateLimits: { ...MCP_RATE_LIMITS, ${input.verbClass}: ${2 * input.limit} } }) // or mcpHttpRoute({ rateLimits }), where the route is built — or wait ${input.retryAfterSeconds}s: the Retry-After header carries the same number`,
76
76
  // why `meta` and not only the sentence: `transport-http.ts` writes `Retry-After` by hand, so
77
77
  // this route is correct today. `@ultimat3/http`'s `retryAfterOf` reads the header off
78
78
  // `meta.retryAfterSeconds` — so the day an MCP host is mounted inside that pipeline, an error
package/src/errors.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // The X_* codes owned by @ultimat3/mcp. Each carries the exact next command, because the
2
2
  // caller reading it is usually an agent with no human to ask.
3
3
 
4
- import { registerErrorCodes, UltimateError } from '@ultimat3/core';
4
+ import { registerErrorCodes, renderFixShellArg, UltimateError } from '@ultimat3/core';
5
5
 
6
6
  export const MCP_ERROR_CODES = [
7
7
  'X_MCP_TOOL_UNKNOWN',
@@ -195,8 +195,8 @@ export class McpScopeDeniedError extends UltimateError {
195
195
  cause: `${subject} "${input.name}" requires scope "${input.scope}", which this connection's token does not carry`,
196
196
  fix:
197
197
  subject === 'tool'
198
- ? `reconnect with a token whose scopes include "${input.scope}" — the app's resolveToken(token) is what returns them — or drop "${input.scope}" from defineAppMcp({ scopes }); scopes are fixed for the life of a connection`
199
- : `reconnect with a token whose scopes include "${input.scope}" — the app's resolveToken(token) is what returns them — or drop scope: '${input.scope}' from the resource declaring "${input.name}"; scopes are fixed for the life of a connection`,
198
+ ? `{ actor, scopes: new Set(['${input.scope}']) } // what the app's resolveToken(token) returns, then reconnect: scopes are fixed for the life of a connection — or drop "${input.scope}" from defineAppMcp({ scopes })`
199
+ : `{ actor, scopes: new Set(['${input.scope}']) } // what the app's resolveToken(token) returns, then reconnect: scopes are fixed for the life of a connection — or drop scope: '${input.scope}' from the resource declaring "${input.name}"`,
200
200
  // The agent's half: it cannot edit `defineAppMcp`, and its token is what it can change.
201
201
  callerFix: `this token was not granted scope "${input.scope}": ask the account owner for a token that includes it, then reconnect — scopes are fixed for the life of a connection, so retrying on this one is refused the same way`,
202
202
  });
@@ -210,7 +210,7 @@ export class McpArgsInvalidError extends UltimateError {
210
210
  super({
211
211
  code: 'X_MCP_ARGS_INVALID',
212
212
  cause: `arguments for "${input.name}" are invalid: ${input.issues.join('; ')}`,
213
- fix: `re-read the tool's inputSchema from tools/list and resend`,
213
+ fix: `{ jsonrpc: '2.0', id, method: 'tools/list' } // re-read the inputSchema of "${input.name}", then resend tools/call with arguments it accepts`,
214
214
  });
215
215
  }
216
216
  }
@@ -225,7 +225,7 @@ export class McpToolUnsafeError extends UltimateError {
225
225
  super({
226
226
  code: 'X_MCP_TOOL_UNSAFE',
227
227
  cause: `tool "${input.name}" declares no policy; an unguarded tool is a second door into the data`,
228
- fix: `add policy: '<resource>:<verb>' to the tool, reusing the permission its action uses`,
228
+ fix: `policy: '<resource>:<verb>' // on the tool, reusing the permission its action uses`,
229
229
  });
230
230
  }
231
231
  }
@@ -249,9 +249,7 @@ export class McpToolUndeclaredError extends UltimateError {
249
249
  super({
250
250
  code: 'X_MCP_TOOL_UNDECLARED',
251
251
  cause: `listed in defineAppMcp but never declared mcp.expose: ${names}`,
252
- fix:
253
- "add mcp: { expose: true, description: '<what it does>' } beside the policy on each — " +
254
- "or drop it from the list and let include: 'exposed' project what opted in",
252
+ fix: "mcp: { expose: true, description: '<what it does>' } // beside the policy on each — or drop it from the list and let include: 'exposed' project what opted in",
255
253
  });
256
254
  this.names = input.names;
257
255
  }
@@ -286,8 +284,8 @@ export class McpAppUnmountedError extends UltimateError {
286
284
  : `${where} exports mcp with no route — defineAppMcp was given no resolveToken — so ${route} answers 404`,
287
285
  fix:
288
286
  input.reason === 'missing'
289
- ? `write ${input.file}: export const mcp = defineAppMcp({ include: 'exposed', resolveToken: (token) => resolveAgentToken(token) }) — or set ai: { mcp: { expose: false } } in app.config.ts`
290
- : `add resolveToken: (token) => resolveAgentToken(token) to the defineAppMcp({ ... }) at ${where} — the route is only built with one`,
287
+ ? `export const mcp = defineAppMcp({ include: 'exposed', resolveToken: (token) => resolveAgentToken(token) }) // in ${input.file} — or ai: { mcp: { expose: false } } in app.config.ts`
288
+ : `resolveToken: (token) => resolveAgentToken(token) // in the defineAppMcp({ ... }) at ${where} — the route is only built with one`,
291
289
  });
292
290
  this.reason = input.reason;
293
291
  }
@@ -333,7 +331,7 @@ export class McpResourceDuplicateError extends UltimateError {
333
331
  super({
334
332
  code: 'X_MCP_RESOURCE_DUPLICATE',
335
333
  cause: `two resources are registered at "${input.uri}"; a URI addresses one document`,
336
- fix: `give one of them its own URI — register({ uri: '${input.uri}-<what-it-is>', … }) — or drop the duplicate registration`,
334
+ fix: `register({ uri: '${input.uri}-<what-it-is>', … }) // one of the two at its own URI — or drop the duplicate registration`,
337
335
  });
338
336
  }
339
337
  }
@@ -353,7 +351,7 @@ export class McpScopeUnknownError extends UltimateError {
353
351
  super({
354
352
  code: 'X_MCP_SCOPE_UNKNOWN',
355
353
  cause: `scopes["${input.scope}"] names "${input.name}", which this server does not project (projected: ${projected})`,
356
- fix: `in defineAppMcp, spell it as one of the projected names above — or drop "${input.name}" from scopes["${input.scope}"]`,
354
+ fix: `scopes: { '${input.scope}': ['<a projected name>'] } // in defineAppMcp: spell "${input.name}" as one of the projected names above — or drop it`,
357
355
  });
358
356
  this.projected = input.projected;
359
357
  }
@@ -376,7 +374,7 @@ export class McpScopeConflictError extends UltimateError {
376
374
  super({
377
375
  code: 'X_MCP_SCOPE_CONFLICT',
378
376
  cause: `tool "${input.name}" is claimed by two scopes ("${input.scopes[0]}" and "${input.scopes[1]}"); a tool carries one`,
379
- fix: `in defineAppMcp, keep "${input.name}" under the single scope a token must hold for it, and remove the other entry`,
377
+ fix: `scopes: { '${input.scopes[0]}': ['${input.name}'] } // in defineAppMcp: the single scope a token must hold for "${input.name}" — remove it from '${input.scopes[1]}', or keep it there and remove this entry`,
380
378
  });
381
379
  this.scopes = input.scopes;
382
380
  }
@@ -403,7 +401,7 @@ export class McpProtocolError extends UltimateError {
403
401
  super({
404
402
  code: 'X_MCP_PROTOCOL',
405
403
  cause: input.cause,
406
- fix: input.fix ?? `send a JSON-RPC 2.0 body: { jsonrpc: '2.0', id, method, params }`,
404
+ fix: input.fix ?? `{ jsonrpc: '2.0', id, method, params } // a JSON-RPC 2.0 body`,
407
405
  });
408
406
  }
409
407
  }
@@ -459,7 +457,7 @@ export class McpIdempotencyKeyShadowedError extends UltimateError {
459
457
  super({
460
458
  code: 'X_MCP_IDEMPOTENCY_KEY_SHADOWED',
461
459
  cause: `${input.name} is idempotent and its input declares "${input.argument}", the MCP argument reserved for the idempotency key`,
462
- fix: `rename ${input.name}'s "${input.argument}" input field — MCP clients send the Idempotency-Key as the reserved "${input.argument}" argument, and the action receives the rest`,
460
+ fix: `x actions show ${renderFixShellArg(input.name, '<action>')} --json # rename its "${input.argument}" input field — MCP clients send the Idempotency-Key as the reserved "${input.argument}" argument, and the action receives the rest`,
463
461
  meta: { action: input.name, argument: input.argument },
464
462
  });
465
463
  }
@@ -480,7 +478,7 @@ export class McpSurfaceOverBudgetError extends UltimateError {
480
478
  super({
481
479
  code: 'X_MCP_SURFACE_OVER_BUDGET',
482
480
  cause: `over budget: ${input.over.map((o) => `${o.surface} is ${o.size} characters, budget ${o.budget}`).join('; ')}`,
483
- fix: "shorten the tool descriptions or instructions it names, group tools behind surface: 'meta', or raise the budget with the measured size and the reason in the same diff",
481
+ fix: "surface: 'meta' // in defineAppMcp: group tools behind it — or shorten the tool descriptions or instructions it names, or raise the budget with the measured size and the reason in the same diff",
484
482
  meta: { over: input.over },
485
483
  });
486
484
  }
@@ -21,7 +21,7 @@ export class McpGroupUnknownError extends UltimateError {
21
21
  super({
22
22
  code: 'X_MCP_GROUP_UNKNOWN',
23
23
  cause: `groups["${input.group}"] names "${input.name}", which this server does not project (projected: ${projected})`,
24
- fix: `in defineAppMcp, spell it as one of the projected names above — or drop "${input.name}" from groups["${input.group}"].tools`,
24
+ fix: `groups: { '${input.group}': { description, tools: ['<a projected name>'] } } // in defineAppMcp: spell "${input.name}" as one of the projected names above — or drop it`,
25
25
  });
26
26
  this.projected = input.projected;
27
27
  }
@@ -39,7 +39,7 @@ export class McpGroupConflictError extends UltimateError {
39
39
  super({
40
40
  code: 'X_MCP_GROUP_CONFLICT',
41
41
  cause: `tool "${input.name}" is listed in two groups ("${input.groups[0]}" and "${input.groups[1]}"); a tool belongs to one resource`,
42
- fix: `in defineAppMcp, keep "${input.name}" in the one group an agent should find it under, and remove the other entry`,
42
+ fix: `groups: { '${input.groups[0]}': { description, tools: ['${input.name}'] } } // in defineAppMcp: the one group an agent should find "${input.name}" under — remove it from '${input.groups[1]}', or keep it there and remove this entry`,
43
43
  });
44
44
  this.groups = input.groups;
45
45
  }
@@ -62,7 +62,7 @@ export class McpSurfaceInvalidError extends UltimateError {
62
62
  super({
63
63
  code: 'X_MCP_SURFACE_INVALID',
64
64
  cause: input.cause,
65
- fix: "in defineAppMcp, declare groups: { <resource>: { description, tools: [...] } } together with surface: 'meta' (or surface: (caller) => 'meta' | 'flat'), or drop both",
65
+ fix: "surface: 'meta', groups: { posts: { description, tools: [...] } } // together in defineAppMcp (or surface: (caller) => 'meta' | 'flat') — or drop both",
66
66
  });
67
67
  }
68
68
  }
@@ -29,7 +29,7 @@ export class McpPathDuplicateError extends UltimateError {
29
29
  cause: across
30
30
  ? `${input.firstFile} (mcp endpoint #${first}) and ${input.file} (mcp endpoint #${second}) both claim ${input.method} ${input.path}`
31
31
  : `${input.file} exports mcp endpoints #${first} and #${second}, and both claim ${input.method} ${input.path}`,
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)`,
32
+ fix: `defineAppMcp({ path: '/mcp/<population>', ... }) // endpoint #${second} in ${input.file}: every endpoint mounts at its own defineAppMcp path (default /mcp)`,
33
33
  });
34
34
  this.path = input.path;
35
35
  this.endpoints = input.endpoints;
@@ -85,12 +85,15 @@ export function assertReadOnlyQuery(sql: string): string {
85
85
  .filter((s) => s.length > 0);
86
86
 
87
87
  if (statements.length === 0) {
88
- throw rejected('the statement is empty', 'send one SELECT statement');
88
+ throw rejected(
89
+ 'the statement is empty',
90
+ 'SELECT * FROM <table> LIMIT 10 -- one SELECT statement',
91
+ );
89
92
  }
90
93
  if (statements.length > 1) {
91
94
  throw rejected(
92
95
  `${statements.length} statements were sent; batching hides a write behind a read`,
93
- 'send exactly one SELECT statement per db.query call',
96
+ 'SELECT * FROM <table> LIMIT 10 -- exactly one SELECT statement per db.query call',
94
97
  );
95
98
  }
96
99
 
@@ -102,7 +105,7 @@ export function assertReadOnlyQuery(sql: string): string {
102
105
  if (!READ_LEADERS.has(leader)) {
103
106
  throw rejected(
104
107
  `statement begins with "${leader}", which is not a read`,
105
- `begin with one of: ${[...READ_LEADERS].sort().join(', ')}`,
108
+ `SELECT * FROM <table> LIMIT 10 -- a read begins with one of: ${[...READ_LEADERS].sort().join(', ')}`,
106
109
  );
107
110
  }
108
111
  for (const word of words) {
@@ -130,7 +133,7 @@ export function assertReadOnlyQuery(sql: string): string {
130
133
  family === called
131
134
  ? `the statement calls ${called}(), which db.query may not call`
132
135
  : `the statement calls ${called}(), one of the ${family}* functions db.query may not call`,
133
- 'query tables only: no file access, no locks, no session settings, no sleeps',
136
+ 'SELECT * FROM <table> LIMIT 10 -- query tables only: no file access, no locks, no session settings, no sleeps',
134
137
  );
135
138
  }
136
139
  }
@@ -138,7 +141,7 @@ export function assertReadOnlyQuery(sql: string): string {
138
141
  if (/\bfor\s+(update|no\s+key\s+update|share|key\s+share)\b/i.test(statement)) {
139
142
  throw rejected(
140
143
  'the statement takes row locks (FOR UPDATE/SHARE)',
141
- 'drop the locking clause; db.query may not hold locks',
144
+ 'SELECT * FROM <table> LIMIT 10 -- the same read with no FOR UPDATE/SHARE clause: db.query may not hold locks',
142
145
  );
143
146
  }
144
147
  return verbatim(sql);
@@ -173,7 +176,7 @@ export function assertBranchDatabase(target: DatabaseTarget): string {
173
176
  if (target.production) {
174
177
  throw notBranch(
175
178
  `"${target.label}" is a production database`,
176
- 'run migrations in production through the migrate role: ROLE=migrate in your deploy hook',
179
+ 'ROLE=migrate bun apps/web/server.ts # in your deploy hook: production migrates through the migrate role, never from MCP',
177
180
  );
178
181
  }
179
182
  if (target.branch === null) {
@@ -253,7 +256,7 @@ function stripLiteralsAndComments(sql: string, identifiers: 'blank' | 'keep' = '
253
256
  throw rejected(
254
257
  'the statement quotes an identifier with Unicode escapes (U&"…"), which this check ' +
255
258
  'cannot read',
256
- 'spell the identifier plainly: select "column name" from posts',
259
+ 'SELECT "column name" FROM posts -- the identifier spelled plainly, no U&"…" escape',
257
260
  );
258
261
  }
259
262
  if (char === "'" || char === '"') {
package/src/server.ts CHANGED
@@ -192,7 +192,7 @@ export class McpServer {
192
192
  'a JSON-RPC batch (an array of requests) is not supported: send one request per message',
193
193
  new McpProtocolError({
194
194
  cause: 'the body is a JSON-RPC batch, and this server answers one request per message',
195
- fix: `send one request per ${messageUnitOf(wire)} — a batch is never walked, so its calls did not run`,
195
+ fix: `{ jsonrpc: '2.0', id, method, params } // one request per ${messageUnitOf(wire)} — a batch is never walked, so its calls did not run`,
196
196
  }),
197
197
  );
198
198
  }
@@ -108,7 +108,7 @@ export function notAnAgent(): Response {
108
108
  JSON.stringify({
109
109
  code: 'X_MCP_PROTOCOL',
110
110
  cause: 'resolveToken returned an actor whose kind is not "agent"',
111
- fix: 'return { kind: "agent", ... } from resolveToken; MCP callers are agents, not users',
111
+ fix: '{ actor: agentActor({ id }), scopes } // returned from resolveToken — MCP callers are agents, not users',
112
112
  }),
113
113
  { status: 403, headers: JSON_HEADERS },
114
114
  );
@@ -119,7 +119,7 @@ export function unauthorized(challenge: string): Response {
119
119
  JSON.stringify({
120
120
  code: 'X_MCP_PROTOCOL',
121
121
  cause: 'missing or unrecognised bearer token',
122
- fix: "send Authorization: Bearer <token> with a token the app's resolveToken(token) resolves to { actor, scopes } — it is the only issuer this route has",
122
+ fix: "authorization: 'Bearer <token>' // a header carrying a token the app's resolveToken(token) resolves to { actor, scopes } — it is the only issuer this route has",
123
123
  }),
124
124
  { status: 401, headers: { ...JSON_HEADERS, 'www-authenticate': challenge } },
125
125
  );