@ultimat3/mcp 30.9.0 → 31.1.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 +6 -10
- package/README.md +50 -14
- package/package.json +12 -11
- package/src/adapter.ts +18 -0
- package/src/app-tools.ts +9 -1
- package/src/audit.ts +20 -6
- package/src/catalog-errors.ts +1 -1
- package/src/confirmation-approvers.ts +18 -0
- package/src/confirmation-decide.ts +6 -0
- package/src/confirmation-gate.ts +6 -1
- package/src/confirmation-installed.ts +34 -0
- package/src/confirmation-quorum-errors.ts +8 -3
- package/src/confirmations.ts +18 -8
- package/src/index.ts +19 -120
- package/src/meta-call.ts +6 -2
- package/src/meta-catalog-render.ts +195 -0
- package/src/meta-host.ts +3 -0
- package/src/meta-surface.ts +1 -140
- package/src/oauth-metadata.ts +12 -5
- package/src/projectable.ts +2 -2
- package/src/registry.ts +62 -5
- package/src/remote-lock.ts +7 -19
- package/src/remote-tools.ts +72 -9
- package/src/server-resources.ts +7 -2
- package/src/server-voice.ts +29 -0
- package/src/server.ts +14 -2
- package/src/tenant.ts +12 -20
- package/src/transport-http.ts +1 -0
package/src/index.ts
CHANGED
|
@@ -7,28 +7,13 @@ export type { RequestFacts as McpRequestFacts } from '@ultimat3/http';
|
|
|
7
7
|
export type { Infer } from '@ultimat3/schema';
|
|
8
8
|
export { t } from '@ultimat3/schema';
|
|
9
9
|
export type { McpCatalog, McpRuntimeCatalog } from './app-catalog';
|
|
10
|
-
export type {
|
|
11
|
-
AnyAppToolDefinition,
|
|
12
|
-
AppToolArgs,
|
|
13
|
-
AppToolDefinition,
|
|
14
|
-
AppTools,
|
|
15
|
-
} from './app-tool';
|
|
10
|
+
export type { AnyAppToolDefinition, AppToolArgs, AppToolDefinition, AppTools } from './app-tool';
|
|
16
11
|
export type { AppMcp, AppToolSchemas, DefineAppMcpInput } from './app-tools';
|
|
17
12
|
export { defineAppMcp } from './app-tools';
|
|
18
13
|
export type { McpAuditEntry, McpOutcome, McpResourceAuditEntry } from './audit';
|
|
19
|
-
export { auditResourceRead
|
|
20
|
-
export type {
|
|
21
|
-
McpAuditEvent,
|
|
22
|
-
McpAuditHook,
|
|
23
|
-
McpAuditor,
|
|
24
|
-
McpAuditorInput,
|
|
25
|
-
McpAuthRefusal,
|
|
26
|
-
} from './audit-hook';
|
|
27
|
-
export { mcpAuditor } from './audit-hook';
|
|
28
|
-
export type { McpCatalogNameSource } from './catalog-errors';
|
|
14
|
+
export { auditResourceRead } from './audit';
|
|
15
|
+
export type { McpAuditEvent, McpAuditHook, McpAuditor, McpAuthRefusal } from './audit-hook';
|
|
29
16
|
export {
|
|
30
|
-
McpCatalogToolDuplicateError,
|
|
31
|
-
McpCatalogUnresolvedError,
|
|
32
17
|
McpTenantInvalidError,
|
|
33
18
|
McpTenantRequiredError,
|
|
34
19
|
McpTenantUnresolvedError,
|
|
@@ -41,7 +26,6 @@ export type {
|
|
|
41
26
|
} from './confirmation-approvers';
|
|
42
27
|
export {
|
|
43
28
|
McpConfirmationArgumentsMismatchError,
|
|
44
|
-
McpConfirmationContestedError,
|
|
45
29
|
McpConfirmationDecidedError,
|
|
46
30
|
McpConfirmationExpiredError,
|
|
47
31
|
McpConfirmationPendingError,
|
|
@@ -55,17 +39,8 @@ export type {
|
|
|
55
39
|
McpEvidenceCheck,
|
|
56
40
|
VerifyConfirmationOptions,
|
|
57
41
|
} from './confirmation-evidence';
|
|
58
|
-
export {
|
|
59
|
-
|
|
60
|
-
MCP_CONFIRMATION_SIGNING_PURPOSE,
|
|
61
|
-
verifyConfirmationEvidence,
|
|
62
|
-
} from './confirmation-evidence';
|
|
63
|
-
export {
|
|
64
|
-
inputDigest,
|
|
65
|
-
MCP_CONFIRMATION_ARGUMENTS_PURPOSE,
|
|
66
|
-
MCP_CONFIRMATION_DIGEST_PURPOSE,
|
|
67
|
-
withConfirmations,
|
|
68
|
-
} from './confirmation-gate';
|
|
42
|
+
export { verifyConfirmationEvidence } from './confirmation-evidence';
|
|
43
|
+
export { inputDigest } from './confirmation-gate';
|
|
69
44
|
export type { PostgresConfirmationStoreOptions } from './confirmation-postgres';
|
|
70
45
|
export { postgresConfirmationStore } from './confirmation-postgres';
|
|
71
46
|
export type { McpEvidenceFailure } from './confirmation-quorum-errors';
|
|
@@ -83,14 +58,9 @@ export type {
|
|
|
83
58
|
McpConfirmationStore,
|
|
84
59
|
} from './confirmation-store';
|
|
85
60
|
export { memoryConfirmationStore } from './confirmation-store';
|
|
86
|
-
export type {
|
|
87
|
-
|
|
88
|
-
McpConfirmations,
|
|
89
|
-
McpConfirmationsInput,
|
|
90
|
-
} from './confirmations';
|
|
91
|
-
export { DEFAULT_MCP_CONFIRMATION_TTL_MS, mcpConfirmations } from './confirmations';
|
|
61
|
+
export type { McpConfirmations, McpConfirmationsInput } from './confirmations';
|
|
62
|
+
export { mcpConfirmations } from './confirmations';
|
|
92
63
|
export type { DevGraphHost, DevGraphQuestion } from './dev-graph-tool';
|
|
93
|
-
export { graphQuestion } from './dev-graph-tool';
|
|
94
64
|
export type { DevMcpServerInput } from './dev-host';
|
|
95
65
|
export { devHost, devMcpServer, frameworkIntrospection } from './dev-host';
|
|
96
66
|
export type {
|
|
@@ -115,28 +85,18 @@ export type {
|
|
|
115
85
|
UiInteractInput,
|
|
116
86
|
UiInteractInspect,
|
|
117
87
|
UiInteractResult,
|
|
118
|
-
UiInteractStep,
|
|
119
88
|
UiInteractStepKind,
|
|
120
89
|
UiInteractStepResult,
|
|
121
90
|
UiIslandInput,
|
|
122
91
|
UiIslandResult,
|
|
123
|
-
UiScopes,
|
|
124
92
|
UiShotInput,
|
|
125
93
|
UiShotResult,
|
|
126
|
-
UiViewportName,
|
|
127
94
|
VerifyResult,
|
|
128
95
|
VerifyStep,
|
|
129
96
|
} from './dev-server';
|
|
130
|
-
export {
|
|
131
|
-
DEV_SCOPES,
|
|
132
|
-
devTools,
|
|
133
|
-
UI_INSPECT_LIMITS,
|
|
134
|
-
UI_INTERACT_LIMITS,
|
|
135
|
-
} from './dev-server';
|
|
97
|
+
export { DEV_SCOPES, devTools, UI_INSPECT_LIMITS, UI_INTERACT_LIMITS } from './dev-server';
|
|
136
98
|
export type { McpErrorCode } from './errors';
|
|
137
99
|
export {
|
|
138
|
-
MCP_ERROR_CODES,
|
|
139
|
-
MCP_ERROR_TITLES,
|
|
140
100
|
McpAppUnmountedError,
|
|
141
101
|
McpArgsInvalidError,
|
|
142
102
|
McpIdempotencyKeyShadowedError,
|
|
@@ -159,7 +119,6 @@ export {
|
|
|
159
119
|
McpBodyTooLargeError,
|
|
160
120
|
McpHeaderMismatchError,
|
|
161
121
|
McpHostRefusedError,
|
|
162
|
-
McpOAuthInvalidError,
|
|
163
122
|
McpOriginRefusedError,
|
|
164
123
|
McpProtocolUnsupportedError,
|
|
165
124
|
McpRateLimitedError,
|
|
@@ -170,32 +129,19 @@ export { deriveAnnotations, toolFrom, toolsFrom, toolsListed } from './from-acti
|
|
|
170
129
|
export { MCP_IDEMPOTENCY_KEY_ARG } from './idempotency-arg';
|
|
171
130
|
export { assertIncludeCurrent } from './include-early';
|
|
172
131
|
export type { JobToolAnswer, JobToolDef, JobToolWait } from './job-tool';
|
|
173
|
-
export {
|
|
174
|
-
export { McpJobToolInvalidError } from './job-tool-errors';
|
|
132
|
+
export { JOB_TOOL_INLINE_CEILING_MS, jobTool } from './job-tool';
|
|
175
133
|
export type { ListFilterOp, McpListParams } from './list-params';
|
|
176
134
|
export { DEFAULT_LIST_MAX_LIMIT, listParamsSchema } from './list-params';
|
|
135
|
+
export type { McpCatalogDetail } from './meta-catalog-render';
|
|
136
|
+
export { oneLineParams, renderCatalog } from './meta-catalog-render';
|
|
177
137
|
export {
|
|
178
|
-
McpEffectConflictError,
|
|
179
|
-
McpEffectUndeclaredError,
|
|
180
138
|
McpGroupConflictError,
|
|
181
139
|
McpGroupUnknownError,
|
|
182
140
|
McpListParamsInvalidError,
|
|
183
141
|
McpSurfaceInvalidError,
|
|
184
|
-
McpUserConfirmationRequiredError,
|
|
185
|
-
McpWrongToolError,
|
|
186
|
-
META_UNKNOWN_FIX,
|
|
187
142
|
} from './meta-errors';
|
|
188
143
|
export type { McpEffectClass } from './meta-split';
|
|
189
|
-
export {
|
|
190
|
-
DELETE_RESOURCE,
|
|
191
|
-
effectOf,
|
|
192
|
-
READ_RESOURCE,
|
|
193
|
-
SPLIT_DISPATCHERS,
|
|
194
|
-
toolForEffect,
|
|
195
|
-
WRITE_RESOURCE,
|
|
196
|
-
} from './meta-split';
|
|
197
144
|
export type {
|
|
198
|
-
DescribedAction,
|
|
199
145
|
McpResourceGroup,
|
|
200
146
|
McpResourceGroups,
|
|
201
147
|
McpSurface,
|
|
@@ -203,48 +149,23 @@ export type {
|
|
|
203
149
|
MetaAction,
|
|
204
150
|
MetaResource,
|
|
205
151
|
} from './meta-surface';
|
|
206
|
-
export {
|
|
207
|
-
DESCRIBE_RESOURCE,
|
|
208
|
-
LIST_RESOURCES,
|
|
209
|
-
MANAGE_RESOURCE,
|
|
210
|
-
META_TOOL_NAMES,
|
|
211
|
-
oneLineParams,
|
|
212
|
-
renderCatalog,
|
|
213
|
-
} from './meta-surface';
|
|
214
|
-
export { McpIncludeEarlyError, McpPathDuplicateError } from './mount-errors';
|
|
152
|
+
export { McpPathDuplicateError } from './mount-errors';
|
|
215
153
|
export type { McpOAuth } from './oauth-metadata';
|
|
216
|
-
export {
|
|
217
|
-
metadataPaths,
|
|
218
|
-
metadataUrlFor,
|
|
219
|
-
PROTECTED_RESOURCE_WELL_KNOWN,
|
|
220
|
-
protectedResourceMetadata,
|
|
221
|
-
} from './oauth-metadata';
|
|
154
|
+
export { PROTECTED_RESOURCE_WELL_KNOWN } from './oauth-metadata';
|
|
222
155
|
export type { McpAuthorizationServer, McpAuthorizationServerOptions } from './oauth-server';
|
|
223
156
|
export { mcpAuthorizationServer } from './oauth-server';
|
|
224
157
|
export type { ListedPrimitive } from './projectable';
|
|
225
158
|
export { asProjectable, toRowsOutputSchema } from './projectable';
|
|
226
159
|
export type { QueryLimits, QueryResult, QueryRows } from './query-limits';
|
|
227
|
-
export {
|
|
228
|
-
capQueryRows,
|
|
229
|
-
resolveQueryLimits,
|
|
230
|
-
} from './query-limits';
|
|
160
|
+
export { capQueryRows, resolveQueryLimits } from './query-limits';
|
|
231
161
|
export type { DatabaseTarget } from './readonly-sql';
|
|
232
162
|
export { assertBranchDatabase, assertReadOnlyQuery } from './readonly-sql';
|
|
233
|
-
export {
|
|
234
|
-
McpRecipeExampleInvalidError,
|
|
235
|
-
McpRecipeLinkDanglingError,
|
|
236
|
-
McpRecipeToolUnknownError,
|
|
237
|
-
McpRecipeUnknownError,
|
|
238
|
-
McpRecipeUriReservedError,
|
|
239
|
-
} from './recipe-errors';
|
|
240
163
|
export { assertRecipeLinks, servedRecipes } from './recipe-links';
|
|
241
|
-
export { markdownRecipes
|
|
164
|
+
export { markdownRecipes } from './recipe-markdown';
|
|
242
165
|
export type { ReplayOptions, ReplayReport } from './recipe-replay';
|
|
243
166
|
export { replayRecipes } from './recipe-replay';
|
|
244
167
|
export type { McpRecipe, McpRecipeStep } from './recipes';
|
|
245
|
-
export { RECIPE_URI_PREFIX, recipeUri, renderRecipe } from './recipes';
|
|
246
168
|
export type { ExtraRecipes } from './recipes-tool';
|
|
247
|
-
export { DOCS_TOOL } from './recipes-tool';
|
|
248
169
|
export type {
|
|
249
170
|
AnyMcpTool,
|
|
250
171
|
ContentBlock,
|
|
@@ -267,12 +188,7 @@ export {
|
|
|
267
188
|
toolListEntry,
|
|
268
189
|
visibleToCaller,
|
|
269
190
|
} from './registry';
|
|
270
|
-
export type {
|
|
271
|
-
McpClient,
|
|
272
|
-
McpClientOptions,
|
|
273
|
-
RemoteTool,
|
|
274
|
-
RemoteToolResult,
|
|
275
|
-
} from './remote-client';
|
|
191
|
+
export type { McpClient, McpClientOptions, RemoteTool, RemoteToolResult } from './remote-client';
|
|
276
192
|
export { mcpClient } from './remote-client';
|
|
277
193
|
export type { McpRemoteFailure } from './remote-errors';
|
|
278
194
|
export {
|
|
@@ -297,7 +213,7 @@ export type {
|
|
|
297
213
|
} from './remote-oauth';
|
|
298
214
|
export { mcpOAuthClient } from './remote-oauth';
|
|
299
215
|
export type { DeclaredMcpServer, McpTools, McpToolsDef, RemoteToolAction } from './remote-tools';
|
|
300
|
-
export { declaredMcpServers, mcpTools
|
|
216
|
+
export { declaredMcpServers, mcpTools } from './remote-tools';
|
|
301
217
|
export type {
|
|
302
218
|
FrameworkResourceProviders,
|
|
303
219
|
McpPrompt,
|
|
@@ -308,13 +224,7 @@ export type {
|
|
|
308
224
|
ResourceListEntry,
|
|
309
225
|
ResourceResolution,
|
|
310
226
|
} from './resources';
|
|
311
|
-
export {
|
|
312
|
-
frameworkResources,
|
|
313
|
-
promptFromPath,
|
|
314
|
-
RESOURCE_URIS,
|
|
315
|
-
ResourceRegistry,
|
|
316
|
-
toPrompts,
|
|
317
|
-
} from './resources';
|
|
227
|
+
export { frameworkResources, ResourceRegistry } from './resources';
|
|
318
228
|
export type { McpRuntimeTool, RuntimeToolArgs, RuntimeToolDefinition } from './runtime-tool';
|
|
319
229
|
export { runtimeTool } from './runtime-tool';
|
|
320
230
|
export type { McpScopes } from './scopes';
|
|
@@ -326,7 +236,6 @@ export type { McpInstructions, McpServerVoice } from './server-voice';
|
|
|
326
236
|
export type { McpSurfaceBudget, McpSurfaceSize } from './surface-budget';
|
|
327
237
|
export { assertMcpSurfaceBudget, measureMcpSurface } from './surface-budget';
|
|
328
238
|
export type { McpTenant, McpTenantEntry } from './tenant';
|
|
329
|
-
export { LIST_TENANTS } from './tenant';
|
|
330
239
|
export type {
|
|
331
240
|
McpHttpTransportInput,
|
|
332
241
|
McpProtectedResource,
|
|
@@ -335,12 +244,7 @@ export type {
|
|
|
335
244
|
McpRouteDescriptor,
|
|
336
245
|
ResolvedToken,
|
|
337
246
|
} from './transport-http';
|
|
338
|
-
export {
|
|
339
|
-
DEFAULT_MCP_BODY_LIMIT_BYTES,
|
|
340
|
-
MCP_RATE_LIMITS,
|
|
341
|
-
MCP_UNAUTHENTICATED_LIMIT,
|
|
342
|
-
mcpHttpRoute,
|
|
343
|
-
} from './transport-http';
|
|
247
|
+
export { MCP_RATE_LIMITS, MCP_UNAUTHENTICATED_LIMIT, mcpHttpRoute } from './transport-http';
|
|
344
248
|
export { mcpHostRefused } from './transport-http-answers';
|
|
345
249
|
export type { StdioTransportInput } from './transport-stdio';
|
|
346
250
|
export { serveStdio } from './transport-stdio';
|
|
@@ -359,13 +263,8 @@ export {
|
|
|
359
263
|
errorResponse,
|
|
360
264
|
HEADER_MISMATCH,
|
|
361
265
|
INTERNAL_ERROR,
|
|
362
|
-
INVALID_PARAMS,
|
|
363
|
-
INVALID_REQUEST,
|
|
364
|
-
isJsonRpcRequest,
|
|
365
266
|
MCP_LEGACY_VERSIONS,
|
|
366
267
|
MCP_MODERN_VERSIONS,
|
|
367
268
|
METHOD_NOT_FOUND,
|
|
368
|
-
PARSE_ERROR,
|
|
369
|
-
resultResponse,
|
|
370
269
|
UNSUPPORTED_PROTOCOL_VERSION,
|
|
371
270
|
} from './wire';
|
package/src/meta-call.ts
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
// `server.ts` for the size ceiling only — it holds no gate of its own: every call it runs goes back
|
|
4
4
|
// through the server's `resolve` → `dispatch`, the flat path.
|
|
5
5
|
|
|
6
|
+
import { renderCatalog } from './meta-catalog-render';
|
|
6
7
|
import { META_UNKNOWN_FIX } from './meta-errors';
|
|
7
8
|
import type { MetaHost } from './meta-host';
|
|
8
9
|
import { resolveAddressed } from './meta-host';
|
|
9
10
|
import { splitCall } from './meta-split-call';
|
|
10
|
-
import { DESCRIBE_RESOURCE, LIST_RESOURCES, MetaSurface
|
|
11
|
+
import { DESCRIBE_RESOURCE, LIST_RESOURCES, MetaSurface } from './meta-surface';
|
|
11
12
|
import type { McpCaller } from './registry';
|
|
12
13
|
import { jsonResult, textResult } from './registry';
|
|
13
14
|
import { validateArgs } from './validate-args';
|
|
@@ -41,7 +42,10 @@ export async function metaCall(
|
|
|
41
42
|
}
|
|
42
43
|
if (name === LIST_RESOURCES) {
|
|
43
44
|
host.audit.toolCall({ tool: name, outcome: 'ok', caller });
|
|
44
|
-
return resultResponse(
|
|
45
|
+
return resultResponse(
|
|
46
|
+
id,
|
|
47
|
+
textResult(renderCatalog(meta.listResources(caller), surface, host.catalogDetail)),
|
|
48
|
+
);
|
|
45
49
|
}
|
|
46
50
|
if (name === DESCRIBE_RESOURCE) {
|
|
47
51
|
const described = meta.describe(args.value['resources'] as readonly string[], caller);
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// `list_resources` as text: the full catalog (one line per action, with its parameter hint) or the
|
|
2
|
+
// compact one an app picks with `catalogDetail: 'compact'` (action names and tags, the rest in
|
|
3
|
+
// `describe_resource`). Split from ./meta-surface (the catalog's data and boot checks) at its
|
|
4
|
+
// line ceiling.
|
|
5
|
+
|
|
6
|
+
import type { MetaAction, MetaResource } from './meta-surface';
|
|
7
|
+
import type { JsonSchema } from './wire';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* How much of each action `list_resources` says. `'full'` (the default): description and a
|
|
11
|
+
* one-line parameter hint per action. `'compact'`: names and tags only — for a catalog whose full
|
|
12
|
+
* listing outgrows a model's turn; `describe_resource` answers the rest per resource.
|
|
13
|
+
*/
|
|
14
|
+
export type McpCatalogDetail = 'full' | 'compact';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* `list_resources` as the model reads it: PLAIN TEXT, one line per action under one line per
|
|
18
|
+
* resource. The JSON form it answered until 22.10 repeated every key on every action and escaped
|
|
19
|
+
* every quote — a staff catalog measured 32.5k characters — and `JSON.parse` was never its reader's
|
|
20
|
+
* job: the model's is. Same facts, same order; `describe_resource` stays JSON because a schema is.
|
|
21
|
+
*
|
|
22
|
+
* Every per-action tag costs once per action, so each is stated where it is cheapest and still
|
|
23
|
+
* exact (#590): a scope shared by every action of the resource — or of one kind — is said once on
|
|
24
|
+
* the resource line (`hoistScopes`); only `action` is tagged, because untagged means `query` and
|
|
25
|
+
* the header says so. The kind comes from `destructive` (`headOf`), never from the name.
|
|
26
|
+
*
|
|
27
|
+
* ```text
|
|
28
|
+
* cases (scope cases) — Court cases of the account.
|
|
29
|
+
* listCases {radicado?: string} — List the account's cases.
|
|
30
|
+
* closeCase (action; confirms) {id: string} — Close a case.
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* `'meta-split'` tags a write with the tool that runs it instead — `(write)` or `(delete)` — and
|
|
34
|
+
* its header names the three dispatchers; untagged still means a read.
|
|
35
|
+
*/
|
|
36
|
+
export function renderCatalog(
|
|
37
|
+
resources: readonly MetaResource[],
|
|
38
|
+
surface: 'meta' | 'meta-split' = 'meta',
|
|
39
|
+
detail: McpCatalogDetail = 'full',
|
|
40
|
+
): string {
|
|
41
|
+
if (resources.length === 0) return 'No resources are available to this caller.';
|
|
42
|
+
const header = surface === 'meta' ? metaHeader(resources.length) : splitHeader(resources.length);
|
|
43
|
+
const lines = [detail === 'compact' ? `${header} ${COMPACT_NOTE}` : header];
|
|
44
|
+
for (const resource of resources) {
|
|
45
|
+
const hoisted = hoistScopes(resource.actions);
|
|
46
|
+
const said = hoisted.line === '' ? '' : ` (${hoisted.line})`;
|
|
47
|
+
lines.push('', `${resource.name}${said} — ${oneLine(resource.description)}`);
|
|
48
|
+
const named = resource.actions.map((action) => {
|
|
49
|
+
const kind =
|
|
50
|
+
action.kind === 'action'
|
|
51
|
+
? surface === 'meta'
|
|
52
|
+
? 'action'
|
|
53
|
+
: (action.effect ?? 'action')
|
|
54
|
+
: '';
|
|
55
|
+
const rest = [
|
|
56
|
+
...(action.confirms === true ? ['confirms'] : []),
|
|
57
|
+
...(action.scope === undefined || hoisted.kinds.has(action.kind)
|
|
58
|
+
? []
|
|
59
|
+
: [`scope ${action.scope}`]),
|
|
60
|
+
];
|
|
61
|
+
return { action, kind, rest };
|
|
62
|
+
});
|
|
63
|
+
if (detail === 'compact') {
|
|
64
|
+
lines.push(` ${compactLine(named)}`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const { action, kind, rest } of named) {
|
|
68
|
+
const tags = [...(kind === '' ? [] : [kind]), ...rest];
|
|
69
|
+
const tagged = tags.length === 0 ? '' : ` (${tags.join('; ')})`;
|
|
70
|
+
lines.push(` ${action.name}${tagged} {${action.params}} — ${oneLine(action.description)}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return lines.join('\n');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* One resource's actions on one line, grouped by the kind tag each would carry — reads untagged,
|
|
78
|
+
* then `action:` (or `write:` / `delete:`) once per group — so a tag is said once per resource, not
|
|
79
|
+
* once per action. The tags that differ per action (`confirms`, an unhoisted scope) stay on it.
|
|
80
|
+
*/
|
|
81
|
+
function compactLine(
|
|
82
|
+
named: readonly {
|
|
83
|
+
readonly action: MetaAction;
|
|
84
|
+
readonly kind: string;
|
|
85
|
+
readonly rest: readonly string[];
|
|
86
|
+
}[],
|
|
87
|
+
): string {
|
|
88
|
+
const groups: string[] = [];
|
|
89
|
+
for (const kind of ['', 'action', 'write', 'delete']) {
|
|
90
|
+
const members = named
|
|
91
|
+
.filter((one) => one.kind === kind)
|
|
92
|
+
.map((one) =>
|
|
93
|
+
one.rest.length === 0 ? one.action.name : `${one.action.name} (${one.rest.join('; ')})`,
|
|
94
|
+
);
|
|
95
|
+
if (members.length === 0) continue;
|
|
96
|
+
groups.push(kind === '' ? members.join(', ') : `${kind}: ${members.join(', ')}`);
|
|
97
|
+
}
|
|
98
|
+
return groups.join('; ');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const COMPACT_NOTE =
|
|
102
|
+
'Names only: a tag before a colon (action: …) tags every name after it on that line. Each action\'s description and parameters are in describe_resource({resources:["<name>"]}) — read it before the first call to a resource.';
|
|
103
|
+
|
|
104
|
+
const metaHeader = (count: number): string =>
|
|
105
|
+
`${count} resource(s). Run one with manage_resource({resource, action, params}); describe_resource({resources:["<name>"]}) has the full input schemas. Untagged = read-only query; (action) may write; (confirms) waits for a human; … = more in describe_resource.`;
|
|
106
|
+
|
|
107
|
+
const splitHeader = (count: number): string =>
|
|
108
|
+
`${count} resource(s). Untagged = read-only, run with read_resource({resource, action, params}); (write) runs with write_resource({resource, action, params}); (delete) archives, sends or spends, run with delete_resource({resource, action, params, live, confirmed_by_user}) — live: false previews it. describe_resource({resources:["<name>"]}) has the full input schemas. (confirms) waits for a human; … = more in describe_resource.`;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The scopes said once on the resource line, and the kinds whose actions no longer repeat theirs.
|
|
112
|
+
* One scope for every action → `scope cases`. Otherwise per kind, because a token split into
|
|
113
|
+
* `cases:read` / `cases:write` is the common shape: `query scope cases:read; action scope
|
|
114
|
+
* cases:write`. A kind is hoisted only when EVERY action of it carries the SAME scope — one
|
|
115
|
+
* unscoped action among scoped ones must not inherit a gate the registry does not enforce.
|
|
116
|
+
* Computed over what THIS caller sees: the catalog is per caller.
|
|
117
|
+
*/
|
|
118
|
+
function hoistScopes(actions: readonly MetaAction[]): {
|
|
119
|
+
readonly line: string;
|
|
120
|
+
readonly kinds: ReadonlySet<MetaAction['kind']>;
|
|
121
|
+
} {
|
|
122
|
+
const all = sharedScope(actions);
|
|
123
|
+
if (all !== undefined) return { line: `scope ${all}`, kinds: new Set(['query', 'action']) };
|
|
124
|
+
const parts: string[] = [];
|
|
125
|
+
const kinds = new Set<MetaAction['kind']>();
|
|
126
|
+
for (const kind of ['query', 'action'] as const) {
|
|
127
|
+
const scope = sharedScope(actions.filter((action) => action.kind === kind));
|
|
128
|
+
if (scope === undefined) continue;
|
|
129
|
+
parts.push(`${kind} scope ${scope}`);
|
|
130
|
+
kinds.add(kind);
|
|
131
|
+
}
|
|
132
|
+
return { line: parts.join('; '), kinds };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The scope every action carries, or `undefined` when there is none, one lacks it or two differ. */
|
|
136
|
+
function sharedScope(actions: readonly MetaAction[]): string | undefined {
|
|
137
|
+
const first = actions[0]?.scope;
|
|
138
|
+
if (first === undefined) return undefined;
|
|
139
|
+
return actions.every((action) => action.scope === first) ? first : undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A description authored across lines is still one catalog line. */
|
|
143
|
+
const oneLine = (text: string): string => text.replace(/\s+/g, ' ').trim();
|
|
144
|
+
|
|
145
|
+
/** Fields a hint names before `…` — every required one is named regardless. */
|
|
146
|
+
const HINT_FIELDS = 4;
|
|
147
|
+
/** Optional fields stop being added once the hint is this long; required ones never stop. */
|
|
148
|
+
const HINT_MAX = 100;
|
|
149
|
+
/** Literals an enum hint names before `|…`. */
|
|
150
|
+
const HINT_LITERALS = 8;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* `name: type` per property, `?` when optional, an enum as its literals — the hint
|
|
154
|
+
* `list_resources` carries so a common call needs no `describe_resource` round-trip.
|
|
155
|
+
*
|
|
156
|
+
* Cut by FIELDS, never by characters (#590): a character cut sliced `limit?: integer` into
|
|
157
|
+
* `limit?: i…`. Every required field is named, in declared order, because a call without one
|
|
158
|
+
* fails; optional fields follow until `HINT_FIELDS` names or `HINT_MAX` characters, and a trailing
|
|
159
|
+
* `…` says some were left out. `describe_resource` always has the full schema.
|
|
160
|
+
*/
|
|
161
|
+
export function oneLineParams(schema: JsonSchema): string {
|
|
162
|
+
const required = new Set(schema.required ?? []);
|
|
163
|
+
const fields = Object.entries(schema.properties ?? {}).map(([key, child]) => ({
|
|
164
|
+
required: required.has(key),
|
|
165
|
+
text: `${key}${required.has(key) ? '' : '?'}: ${typeHint(child)}`,
|
|
166
|
+
}));
|
|
167
|
+
const named = new Set(fields.filter((field) => field.required));
|
|
168
|
+
let length = [...named].reduce((sum, field) => sum + field.text.length + 2, 0);
|
|
169
|
+
for (const field of fields) {
|
|
170
|
+
if (field.required) continue;
|
|
171
|
+
if (named.size >= HINT_FIELDS || length + field.text.length > HINT_MAX) break;
|
|
172
|
+
named.add(field);
|
|
173
|
+
length += field.text.length + 2;
|
|
174
|
+
}
|
|
175
|
+
const parts = fields.filter((field) => named.has(field)).map((field) => field.text);
|
|
176
|
+
return named.size < fields.length ? [...parts, '…'].join(', ') : parts.join(', ');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function typeHint(schema: JsonSchema): string {
|
|
180
|
+
if (schema.enum !== undefined) return literals(schema.enum.map((v) => JSON.stringify(v)));
|
|
181
|
+
if (schema.const !== undefined) return JSON.stringify(schema.const);
|
|
182
|
+
if (schema.anyOf !== undefined) return literals(schema.anyOf.map(typeHint));
|
|
183
|
+
if (schema.type === 'array') {
|
|
184
|
+
if (schema.items === undefined) return 'array';
|
|
185
|
+
const item = typeHint(schema.items);
|
|
186
|
+
return item.includes('|') ? `(${item})[]` : `${item}[]`;
|
|
187
|
+
}
|
|
188
|
+
return schema.type ?? 'any';
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A union cut at an alternative, never inside one. */
|
|
192
|
+
function literals(alternatives: readonly string[]): string {
|
|
193
|
+
if (alternatives.length <= HINT_LITERALS) return alternatives.join('|');
|
|
194
|
+
return [...alternatives.slice(0, HINT_LITERALS), '…'].join('|');
|
|
195
|
+
}
|
package/src/meta-host.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// can grow a second path: its `dispatch` IS the flat `tools/call`'s resolve → run → audit.
|
|
3
3
|
|
|
4
4
|
import type { McpAuditor } from './audit-hook';
|
|
5
|
+
import type { McpCatalogDetail } from './meta-catalog-render';
|
|
5
6
|
import { schemaOf } from './meta-surface';
|
|
6
7
|
import type { AnyMcpTool, McpCaller, ToolRegistry, ToolResolution } from './registry';
|
|
7
8
|
import { validateArgs } from './validate-args';
|
|
@@ -11,6 +12,8 @@ import type { JsonRpcId, JsonRpcResponse } from './wire';
|
|
|
11
12
|
export interface MetaHost {
|
|
12
13
|
readonly tools: ToolRegistry;
|
|
13
14
|
readonly audit: McpAuditor;
|
|
15
|
+
/** The app's one choice of `list_resources` density. */
|
|
16
|
+
readonly catalogDetail: McpCatalogDetail;
|
|
14
17
|
dispatch(
|
|
15
18
|
id: JsonRpcId,
|
|
16
19
|
name: string,
|
package/src/meta-surface.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import type { McpEffect } from '@ultimat3/core';
|
|
12
12
|
import { McpToolDuplicateError } from './errors';
|
|
13
13
|
import { assertListParams, listParamsSchema } from './list-params';
|
|
14
|
+
import { oneLineParams } from './meta-catalog-render';
|
|
14
15
|
import { McpGroupConflictError, McpGroupUnknownError, McpSurfaceInvalidError } from './meta-errors';
|
|
15
16
|
import { assertEffects, SPLIT_DISPATCHERS, SPLIT_TOOL_ENTRIES } from './meta-split';
|
|
16
17
|
import type { AnyMcpTool, McpCaller, ToolListEntry } from './registry';
|
|
@@ -313,94 +314,6 @@ export function schemaOf(tool: AnyMcpTool): JsonSchema {
|
|
|
313
314
|
: listParamsSchema(tool.listParams, tool.inputSchema);
|
|
314
315
|
}
|
|
315
316
|
|
|
316
|
-
/**
|
|
317
|
-
* `list_resources` as the model reads it: PLAIN TEXT, one line per action under one line per
|
|
318
|
-
* resource. The JSON form it answered until 22.10 repeated every key on every action and escaped
|
|
319
|
-
* every quote — a staff catalog measured 32.5k characters — and `JSON.parse` was never its reader's
|
|
320
|
-
* job: the model's is. Same facts, same order; `describe_resource` stays JSON because a schema is.
|
|
321
|
-
*
|
|
322
|
-
* Every per-action tag costs once per action, so each is stated where it is cheapest and still
|
|
323
|
-
* exact (#590): a scope shared by every action of the resource — or of one kind — is said once on
|
|
324
|
-
* the resource line (`hoistScopes`); only `action` is tagged, because untagged means `query` and
|
|
325
|
-
* the header says so. The kind comes from `destructive` (`headOf`), never from the name.
|
|
326
|
-
*
|
|
327
|
-
* ```text
|
|
328
|
-
* cases (scope cases) — Court cases of the account.
|
|
329
|
-
* listCases {radicado?: string} — List the account's cases.
|
|
330
|
-
* closeCase (action; confirms) {id: string} — Close a case.
|
|
331
|
-
* ```
|
|
332
|
-
*
|
|
333
|
-
* `'meta-split'` tags a write with the tool that runs it instead — `(write)` or `(delete)` — and
|
|
334
|
-
* its header names the three dispatchers; untagged still means a read.
|
|
335
|
-
*/
|
|
336
|
-
export function renderCatalog(
|
|
337
|
-
resources: readonly MetaResource[],
|
|
338
|
-
surface: 'meta' | 'meta-split' = 'meta',
|
|
339
|
-
): string {
|
|
340
|
-
if (resources.length === 0) return 'No resources are available to this caller.';
|
|
341
|
-
const lines = [surface === 'meta' ? metaHeader(resources.length) : splitHeader(resources.length)];
|
|
342
|
-
for (const resource of resources) {
|
|
343
|
-
const hoisted = hoistScopes(resource.actions);
|
|
344
|
-
const said = hoisted.line === '' ? '' : ` (${hoisted.line})`;
|
|
345
|
-
lines.push('', `${resource.name}${said} — ${oneLine(resource.description)}`);
|
|
346
|
-
for (const action of resource.actions) {
|
|
347
|
-
const tags = [
|
|
348
|
-
...(action.kind === 'action'
|
|
349
|
-
? [surface === 'meta' ? 'action' : (action.effect ?? 'action')]
|
|
350
|
-
: []),
|
|
351
|
-
...(action.confirms === true ? ['confirms'] : []),
|
|
352
|
-
...(action.scope === undefined || hoisted.kinds.has(action.kind)
|
|
353
|
-
? []
|
|
354
|
-
: [`scope ${action.scope}`]),
|
|
355
|
-
];
|
|
356
|
-
const tagged = tags.length === 0 ? '' : ` (${tags.join('; ')})`;
|
|
357
|
-
lines.push(` ${action.name}${tagged} {${action.params}} — ${oneLine(action.description)}`);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return lines.join('\n');
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const metaHeader = (count: number): string =>
|
|
364
|
-
`${count} resource(s). Run one with manage_resource({resource, action, params}); describe_resource({resources:["<name>"]}) has the full input schemas. Untagged = read-only query; (action) may write; (confirms) waits for a human; … = more in describe_resource.`;
|
|
365
|
-
|
|
366
|
-
const splitHeader = (count: number): string =>
|
|
367
|
-
`${count} resource(s). Untagged = read-only, run with read_resource({resource, action, params}); (write) runs with write_resource({resource, action, params}); (delete) archives, sends or spends, run with delete_resource({resource, action, params, live, confirmed_by_user}) — live: false previews it. describe_resource({resources:["<name>"]}) has the full input schemas. (confirms) waits for a human; … = more in describe_resource.`;
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* The scopes said once on the resource line, and the kinds whose actions no longer repeat theirs.
|
|
371
|
-
* One scope for every action → `scope cases`. Otherwise per kind, because a token split into
|
|
372
|
-
* `cases:read` / `cases:write` is the common shape: `query scope cases:read; action scope
|
|
373
|
-
* cases:write`. A kind is hoisted only when EVERY action of it carries the SAME scope — one
|
|
374
|
-
* unscoped action among scoped ones must not inherit a gate the registry does not enforce.
|
|
375
|
-
* Computed over what THIS caller sees: the catalog is per caller.
|
|
376
|
-
*/
|
|
377
|
-
function hoistScopes(actions: readonly MetaAction[]): {
|
|
378
|
-
readonly line: string;
|
|
379
|
-
readonly kinds: ReadonlySet<MetaAction['kind']>;
|
|
380
|
-
} {
|
|
381
|
-
const all = sharedScope(actions);
|
|
382
|
-
if (all !== undefined) return { line: `scope ${all}`, kinds: new Set(['query', 'action']) };
|
|
383
|
-
const parts: string[] = [];
|
|
384
|
-
const kinds = new Set<MetaAction['kind']>();
|
|
385
|
-
for (const kind of ['query', 'action'] as const) {
|
|
386
|
-
const scope = sharedScope(actions.filter((action) => action.kind === kind));
|
|
387
|
-
if (scope === undefined) continue;
|
|
388
|
-
parts.push(`${kind} scope ${scope}`);
|
|
389
|
-
kinds.add(kind);
|
|
390
|
-
}
|
|
391
|
-
return { line: parts.join('; '), kinds };
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/** The scope every action carries, or `undefined` when there is none, one lacks it or two differ. */
|
|
395
|
-
function sharedScope(actions: readonly MetaAction[]): string | undefined {
|
|
396
|
-
const first = actions[0]?.scope;
|
|
397
|
-
if (first === undefined) return undefined;
|
|
398
|
-
return actions.every((action) => action.scope === first) ? first : undefined;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/** A description authored across lines is still one catalog line. */
|
|
402
|
-
const oneLine = (text: string): string => text.replace(/\s+/g, ' ').trim();
|
|
403
|
-
|
|
404
317
|
function headOf(tool: AnyMcpTool): Omit<MetaAction, 'params'> {
|
|
405
318
|
const effect = tool.destructive === false ? undefined : tool.effect;
|
|
406
319
|
return {
|
|
@@ -418,55 +331,3 @@ function headOf(tool: AnyMcpTool): Omit<MetaAction, 'params'> {
|
|
|
418
331
|
function sorted<V>(map: ReadonlyMap<string, V>): readonly [string, V][] {
|
|
419
332
|
return [...map.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
420
333
|
}
|
|
421
|
-
|
|
422
|
-
/** Fields a hint names before `…` — every required one is named regardless. */
|
|
423
|
-
const HINT_FIELDS = 4;
|
|
424
|
-
/** Optional fields stop being added once the hint is this long; required ones never stop. */
|
|
425
|
-
const HINT_MAX = 100;
|
|
426
|
-
/** Literals an enum hint names before `|…`. */
|
|
427
|
-
const HINT_LITERALS = 8;
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* `name: type` per property, `?` when optional, an enum as its literals — the hint
|
|
431
|
-
* `list_resources` carries so a common call needs no `describe_resource` round-trip.
|
|
432
|
-
*
|
|
433
|
-
* Cut by FIELDS, never by characters (#590): a character cut sliced `limit?: integer` into
|
|
434
|
-
* `limit?: i…`. Every required field is named, in declared order, because a call without one
|
|
435
|
-
* fails; optional fields follow until `HINT_FIELDS` names or `HINT_MAX` characters, and a trailing
|
|
436
|
-
* `…` says some were left out. `describe_resource` always has the full schema.
|
|
437
|
-
*/
|
|
438
|
-
export function oneLineParams(schema: JsonSchema): string {
|
|
439
|
-
const required = new Set(schema.required ?? []);
|
|
440
|
-
const fields = Object.entries(schema.properties ?? {}).map(([key, child]) => ({
|
|
441
|
-
required: required.has(key),
|
|
442
|
-
text: `${key}${required.has(key) ? '' : '?'}: ${typeHint(child)}`,
|
|
443
|
-
}));
|
|
444
|
-
const named = new Set(fields.filter((field) => field.required));
|
|
445
|
-
let length = [...named].reduce((sum, field) => sum + field.text.length + 2, 0);
|
|
446
|
-
for (const field of fields) {
|
|
447
|
-
if (field.required) continue;
|
|
448
|
-
if (named.size >= HINT_FIELDS || length + field.text.length > HINT_MAX) break;
|
|
449
|
-
named.add(field);
|
|
450
|
-
length += field.text.length + 2;
|
|
451
|
-
}
|
|
452
|
-
const parts = fields.filter((field) => named.has(field)).map((field) => field.text);
|
|
453
|
-
return named.size < fields.length ? [...parts, '…'].join(', ') : parts.join(', ');
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
function typeHint(schema: JsonSchema): string {
|
|
457
|
-
if (schema.enum !== undefined) return literals(schema.enum.map((v) => JSON.stringify(v)));
|
|
458
|
-
if (schema.const !== undefined) return JSON.stringify(schema.const);
|
|
459
|
-
if (schema.anyOf !== undefined) return literals(schema.anyOf.map(typeHint));
|
|
460
|
-
if (schema.type === 'array') {
|
|
461
|
-
if (schema.items === undefined) return 'array';
|
|
462
|
-
const item = typeHint(schema.items);
|
|
463
|
-
return item.includes('|') ? `(${item})[]` : `${item}[]`;
|
|
464
|
-
}
|
|
465
|
-
return schema.type ?? 'any';
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/** A union cut at an alternative, never inside one. */
|
|
469
|
-
function literals(alternatives: readonly string[]): string {
|
|
470
|
-
if (alternatives.length <= HINT_LITERALS) return alternatives.join('|');
|
|
471
|
-
return [...alternatives.slice(0, HINT_LITERALS), '…'].join('|');
|
|
472
|
-
}
|