stitchkit 0.36.1 → 0.38.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.
Files changed (92) hide show
  1. package/README.md +4 -2
  2. package/dist/browser/client-url.d.ts +11 -0
  3. package/dist/browser/client-url.d.ts.map +1 -0
  4. package/dist/browser/client.d.ts +16 -4
  5. package/dist/browser/client.d.ts.map +1 -1
  6. package/dist/browser/http.d.ts +7 -3
  7. package/dist/browser/http.d.ts.map +1 -1
  8. package/dist/cli.js +3 -3
  9. package/dist/contract/define.d.ts +102 -2
  10. package/dist/contract/define.d.ts.map +1 -1
  11. package/dist/contract/errors.d.ts.map +1 -1
  12. package/dist/contract/index.d.ts +1 -1
  13. package/dist/contract/index.d.ts.map +1 -1
  14. package/dist/contract/index.js +1 -1
  15. package/dist/{index-bx49hskg.js → index-bgdd42pt.js} +1 -1
  16. package/dist/{index-0ed3bx43.js → index-frfyw9fa.js} +2 -2
  17. package/dist/{index-82gncajj.js → index-n5t4gnfz.js} +557 -337
  18. package/dist/{index-dvrn81q4.js → index-p3kwf73n.js} +165 -55
  19. package/dist/{index-pmftwk2a.js → index-x4wbc8sz.js} +54 -0
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +147 -114
  23. package/dist/node.d.ts +1 -1
  24. package/dist/node.d.ts.map +1 -1
  25. package/dist/node.js +7 -3
  26. package/dist/observability/index.js +3 -3
  27. package/dist/server/bun.d.ts +32 -0
  28. package/dist/server/bun.d.ts.map +1 -0
  29. package/dist/server/context.d.ts +1 -1
  30. package/dist/server/context.d.ts.map +1 -1
  31. package/dist/server/create.d.ts +2 -3
  32. package/dist/server/create.d.ts.map +1 -1
  33. package/dist/server/implement.d.ts.map +1 -1
  34. package/dist/server/index.d.ts +3 -2
  35. package/dist/server/index.d.ts.map +1 -1
  36. package/dist/server/index.js +41 -7
  37. package/dist/server/logger.d.ts +5 -5
  38. package/dist/server/logger.d.ts.map +1 -1
  39. package/dist/server/logging.d.ts +4 -1
  40. package/dist/server/logging.d.ts.map +1 -1
  41. package/dist/server/middleware/auth.d.ts +2 -2
  42. package/dist/server/middleware/auth.d.ts.map +1 -1
  43. package/dist/server/openapi.d.ts.map +1 -1
  44. package/dist/server/request-body.d.ts +4 -0
  45. package/dist/server/request-body.d.ts.map +1 -0
  46. package/dist/server/response-metadata.d.ts +9 -0
  47. package/dist/server/response-metadata.d.ts.map +1 -0
  48. package/dist/server/router.d.ts +3 -3
  49. package/dist/server/router.d.ts.map +1 -1
  50. package/dist/server/socket-io-config.d.ts +20 -0
  51. package/dist/server/socket-io-config.d.ts.map +1 -0
  52. package/dist/server/socket-io-node.d.ts +14 -0
  53. package/dist/server/socket-io-node.d.ts.map +1 -0
  54. package/dist/server/socket-io.d.ts +5 -32
  55. package/dist/server/socket-io.d.ts.map +1 -1
  56. package/dist/server/types.d.ts +63 -50
  57. package/dist/server/types.d.ts.map +1 -1
  58. package/dist/tools/agent.d.ts.map +1 -1
  59. package/dist/tools/execute.d.ts +46 -16
  60. package/dist/tools/execute.d.ts.map +1 -1
  61. package/dist/tools/flatten-join.d.ts +8 -0
  62. package/dist/tools/flatten-join.d.ts.map +1 -0
  63. package/dist/tools/flatten.d.ts +7 -44
  64. package/dist/tools/flatten.d.ts.map +1 -1
  65. package/dist/tools/json-schema.d.ts +1 -1
  66. package/dist/tools/json-schema.d.ts.map +1 -1
  67. package/dist/tools/manifest.d.ts.map +1 -1
  68. package/dist/tools/mcp-handler.d.ts +7 -13
  69. package/dist/tools/mcp-handler.d.ts.map +1 -1
  70. package/dist/tools/mcp.d.ts +61 -24
  71. package/dist/tools/mcp.d.ts.map +1 -1
  72. package/dist/tools/mount.d.ts +9 -6
  73. package/dist/tools/mount.d.ts.map +1 -1
  74. package/dist/tools/names.d.ts +1 -1
  75. package/dist/tools/native-mcp.d.ts +57 -0
  76. package/dist/tools/native-mcp.d.ts.map +1 -0
  77. package/dist/tools/portable-formats.d.ts +15 -0
  78. package/dist/tools/portable-formats.d.ts.map +1 -0
  79. package/dist/tools/presentation.d.ts +15 -0
  80. package/dist/tools/presentation.d.ts.map +1 -0
  81. package/dist/tools/remote.d.ts.map +1 -1
  82. package/dist/tools/schema.d.ts +3 -8
  83. package/dist/tools/schema.d.ts.map +1 -1
  84. package/dist/tools/tool-logger.d.ts.map +1 -1
  85. package/dist/tools/view-file.d.ts +5 -3
  86. package/dist/tools/view-file.d.ts.map +1 -1
  87. package/dist/tools.d.ts +7 -4
  88. package/dist/tools.d.ts.map +1 -1
  89. package/dist/tools.js +481 -205
  90. package/llms-full.txt +536 -87
  91. package/package.json +14 -11
  92. /package/dist/{index-17rdjw68.js → index-mzx0an0s.js} +0 -0
@@ -1,5 +1,6 @@
1
+ import type { ZodType, z } from 'zod';
1
2
  import type { RuntimeContext, TransportSource } from '../contract';
2
- import type { MethodDef } from '../server/types';
3
+ import type { OperationIdentity } from '../server/types';
3
4
  export type ToolResult = {
4
5
  ok: true;
5
6
  data: unknown;
@@ -13,8 +14,26 @@ export interface ToolCallContext {
13
14
  source: TransportSource;
14
15
  [key: string]: unknown;
15
16
  }
17
+ export interface BeforeToolCallOptions {
18
+ toolName: string;
19
+ args: Record<string, unknown>;
20
+ context: ToolCallContext;
21
+ endpoint: OperationIdentity;
22
+ }
23
+ export interface AfterToolCallOptions extends BeforeToolCallOptions {
24
+ result: ToolResult;
25
+ durationMs: number;
26
+ /** The value as thrown; absent for failures that did not throw. */
27
+ error?: unknown;
28
+ }
29
+ export interface ToolErrorOptions {
30
+ toolName: string;
31
+ error: unknown;
32
+ context: ToolCallContext;
33
+ endpoint: OperationIdentity;
34
+ }
16
35
  export interface ToolCallHooks {
17
- beforeToolCall?: (toolName: string, args: Record<string, unknown>, context: ToolCallContext, endpoint: MethodDef) => void | Promise<void>;
36
+ beforeToolCall?: (options: BeforeToolCallOptions) => void | Promise<void>;
18
37
  /**
19
38
  * Every finished call, success and failure alike — the record of the call.
20
39
  *
@@ -24,23 +43,22 @@ export interface ToolCallHooks {
24
43
  * It is the same value `onToolError` receives, handed here too so a single
25
44
  * hook can build one row that names the cause: the `result` alone cannot,
26
45
  * because an unexpected throw is scrubbed to a bare `INTERNAL_SERVER_ERROR`.
27
- * A six-parameter hook is unaffected.
28
46
  */
29
- afterToolCall?: (toolName: string, args: Record<string, unknown>, result: ToolResult, durationMs: number, context: ToolCallContext, endpoint: MethodDef, error?: unknown) => void | Promise<void>;
47
+ afterToolCall?: (options: AfterToolCallOptions) => void | Promise<void>;
30
48
  /**
31
- * The handler path threw — the value **as thrown**, before it is normalised
49
+ * The tool execution path threw — the value **as thrown**, before it is normalised
32
50
  * into a `ToolResult`. The tool-side answer to HTTP's `hooks.onError`, and the
33
51
  * only place the real cause of an unexpected failure is reachable: an error
34
52
  * that is not an `AppError` is scrubbed to a bare `INTERNAL_SERVER_ERROR` with
35
53
  * no details, so by the time `afterToolCall` sees the result, the stack, the
36
54
  * `cause` chain and the message are gone.
37
55
  *
38
- * Fires for a throw from `lifecycle.beforeHandle`, the handler, or
39
- * `lifecycle.afterHandle` the span where information is destroyed. It does
40
- * **not** fire for a `beforeToolCall` rejection, an argument-validation
41
- * failure or an output-schema mismatch: each of those is already described in
42
- * full by the `ToolResult` that `afterToolCall` receives, and a second path to
43
- * the same information only invites double-logging.
56
+ * Fires for a throw from executable input parsing (`ToolExtend`, params or
57
+ * input), extension resolution, `lifecycle.beforeHandle`, the handler, or
58
+ * `lifecycle.afterHandle` every span where the raw cause would otherwise be
59
+ * destroyed. It does **not** fire for a normal validation result, a
60
+ * `beforeToolCall` rejection or an output-schema mismatch: each is already
61
+ * described in full by the `ToolResult` that `afterToolCall` receives.
44
62
  *
45
63
  * This is observation, not an error handler — the tool envelope is always
46
64
  * `toolResultFromError`, so the return value is ignored and a throw from the
@@ -49,7 +67,7 @@ export interface ToolCallHooks {
49
67
  * records (a request-context error, say) is already in place when the audit
50
68
  * hook reads it.
51
69
  */
52
- onToolError?: (toolName: string, error: unknown, context: ToolCallContext, endpoint: MethodDef) => void | Promise<void>;
70
+ onToolError?: (options: ToolErrorOptions) => void | Promise<void>;
53
71
  }
54
72
  /**
55
73
  * A per-tool hint appended to a failed tool result — given the tool name and the
@@ -75,9 +93,21 @@ export type ErrorHintFn = (toolName: string, errorCode: string) => string | null
75
93
  */
76
94
  export interface ToolLifecycle {
77
95
  /** Auth / scope gate — throw to reject the call. */
78
- beforeHandle?: (ctx: RuntimeContext, endpoint: MethodDef) => void | Promise<void>;
96
+ beforeHandle?: (ctx: RuntimeContext, endpoint: OperationIdentity) => void | Promise<void>;
79
97
  /** Transform the handler result before it is returned. */
80
- afterHandle?: (ctx: RuntimeContext, result: unknown, endpoint: MethodDef) => unknown | Promise<unknown>;
98
+ afterHandle?: (ctx: RuntimeContext, result: unknown, endpoint: OperationIdentity) => unknown | Promise<unknown>;
99
+ }
100
+ /** Executable tool operation; contract methods and native tools share this runner shape. */
101
+ export interface ToolOperation extends OperationIdentity {
102
+ paramsSchema?: ZodType;
103
+ inputSchema?: ZodType;
104
+ outputSchema?: ZodType;
105
+ handler(ctx: RuntimeContext): unknown | Promise<unknown>;
106
+ }
107
+ /** Executable extension parsed once inside the shared runner before resolution. */
108
+ export interface ToolArgumentExtension {
109
+ schema: z.ZodObject;
110
+ resolve: (args: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>;
81
111
  }
82
112
  /**
83
113
  * Normalise any thrown value into a failed `ToolResult` — the one place an
@@ -87,7 +117,7 @@ export interface ToolLifecycle {
87
117
  export declare function toolResultFromError(err: unknown): Extract<ToolResult, {
88
118
  ok: false;
89
119
  }>;
90
- export declare function executeToolMethod(method: MethodDef<unknown, unknown, unknown>, toolName: string, rawArgs: Record<string, unknown>, context: ToolCallContext, hooks?: ToolCallHooks, lifecycle?: ToolLifecycle, coerceJson?: boolean, onOutputStrip?: (paths: string[]) => void): Promise<ToolResult>;
120
+ export declare function executeToolMethod(method: ToolOperation, toolName: string, rawArgs: Record<string, unknown>, context: ToolCallContext, hooks?: ToolCallHooks, lifecycle?: ToolLifecycle, coerceJson?: boolean, onOutputStrip?: (paths: string[]) => void, extension?: ToolArgumentExtension): Promise<ToolResult>;
91
121
  /**
92
122
  * Run `body` in a request context forked for one tool call — the shared rule,
93
123
  * so every entry point isolates the same way. A mount uses it around
@@ -101,6 +131,6 @@ export declare function executeToolMethod(method: MethodDef<unknown, unknown, un
101
131
  export declare function inToolCallContext<T>(call: {
102
132
  source: TransportSource;
103
133
  toolName: string;
104
- method: MethodDef<unknown, unknown, unknown>;
134
+ method: OperationIdentity;
105
135
  }, body: () => Promise<T>): Promise<T>;
106
136
  //# sourceMappingURL=execute.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/tools/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,MAAM,UAAU,GAClB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC3B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,eAAe,CAAC;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,cAAc,CAAC,EAAE,CACf,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,SAAS,KAChB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B;;;;;;;;;;OAUG;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MAAM,CAAC;IACjB,MAAM,EAAE,iBAAiB,CAAC;CAC3B,EACD,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,CAuBZ"}
@@ -0,0 +1,8 @@
1
+ import type { ToolPresentationSchema } from './flatten';
2
+ export interface VariantProperty {
3
+ schema: ToolPresentationSchema;
4
+ labels: string[];
5
+ required: boolean;
6
+ }
7
+ export declare function mergePropertySchemas(properties: VariantProperty[]): ToolPresentationSchema;
8
+ //# sourceMappingURL=flatten-join.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten-join.d.ts","sourceRoot":"","sources":["../../src/tools/flatten-join.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,sBAAsB,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAgID,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,eAAe,EAAE,GAAG,sBAAsB,CAuB1F"}
@@ -1,47 +1,10 @@
1
- import { z } from 'zod';
1
+ export type ToolPresentationSchema = Record<string, unknown>;
2
2
  /**
3
- * Flatten a `ZodDiscriminatedUnion` into a single `ZodObject` for LLM transports
4
- * that cannot represent `oneOf` (MCP / weaker models).
5
- *
6
- * The discriminator becomes a `z.enum(...)` of **all** variant values; each
7
- * variant's fields become optional with a `.describe()` hint naming the variants
8
- * that require them. When two variants declare the **same key with different
9
- * shapes**, the advertised field is widened so it accepts every variant's value —
10
- * never narrowed to one (which would make the losing variant unsatisfiable):
11
- *
12
- * - identical across variants → kept as-is.
13
- * - all string literal/enum → merged into one widened `z.enum`.
14
- * - otherwise (object vs array, differing object shapes) → `z.unknown()` (accepts
15
- * anything; the `.describe()` carries the per-variant shape).
16
- *
17
- * This keeps the advertised schema free of `oneOf` / `anyOf` at any depth (→ ADR
18
- * 0033) **and** a superset of the original union, so a model can always produce a
19
- * value that passes both the transport SDK and validation.
20
- *
21
- * **Key policy is merged, not dropped.** The flat object stands in for every
22
- * variant, so it takes the policy that cannot remove what any variant would have
23
- * kept: every variant `.strict()` → strict (sound, because the flat shape is the
24
- * union of all variant keys); any variant with a catchall → loose; otherwise
25
- * plain. A *typed* catchall is never copied onto the flat object — it would
26
- * reject a sibling variant's differently-typed extra key.
27
- *
28
- * **Still lossy:** per-variant strictness (a key legal in variant A and illegal
29
- * in B) is unrepresentable in one flat object, as are object-level refinements.
30
- * Those stay enforced only by the original union in `executeToolMethod`. What is
31
- * *not* lossy any more is deletion — the advertised schema can no longer drop a
32
- * key the contract would have seen. → ADR 0034.
3
+ * Rebuild a JSON Schema and replace every structurally identifiable
4
+ * discriminated object `oneOf` with one conservative object-shaped join.
5
+ * Plain unions remain unions. The source document is never mutated.
33
6
  */
34
- export declare function flattenDiscriminatedUnion(union: z.ZodDiscriminatedUnion): z.ZodObject<z.ZodRawShape>;
35
- /**
36
- * Recursively flatten **every** flattenable `ZodDiscriminatedUnion` in a schema —
37
- * top level and nested inside object fields, array items, plain unions, records,
38
- * and `optional` / `nullable` / `default` / intersection wrappers — so the
39
- * advertised JSON Schema carries no `oneOf` / `anyOf` at any depth. A union that
40
- * cannot be flattened (non-string discriminator, non-object variant) is left
41
- * untouched rather than crashing the mount (→ ADR 0033).
42
- *
43
- * Every object is rebuilt **with its key policy** (`rebuildObject`) — the walk
44
- * changes union shape, never what an object does with an undeclared key. → ADR 0034.
45
- */
46
- export declare function flattenUnionsDeep(schema: z.core.$ZodType): z.ZodType;
7
+ export declare function flattenToolJsonSchema(schema: ToolPresentationSchema): ToolPresentationSchema;
8
+ /** Freeze every JSON object/array in a prepared presentation document. */
9
+ export declare function freezeToolJsonSchema(schema: ToolPresentationSchema): ToolPresentationSchema;
47
10
  //# sourceMappingURL=flatten.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/tools/flatten.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,CAAC,CAAC,qBAAqB,GAC7B,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAiD5B;AA6TD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,OAAO,CAqDpE"}
1
+ {"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/tools/flatten.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA6J7D;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,sBAAsB,GAAG,sBAAsB,CAG5F;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,sBAAsB,GAAG,sBAAsB,CAG3F"}
@@ -21,7 +21,7 @@ export type JsonSchemaIo = 'input' | 'output';
21
21
  * The OpenAPI generator wants this: one `z.date()` field must not collapse a
22
22
  * whole endpoint's schema to `{}`.
23
23
  */
24
- export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo, unrepresentable?: 'throw' | 'any'): Record<string, unknown>;
24
+ export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo, unrepresentable?: 'throw' | 'any', target?: 'draft-07' | 'draft-2020-12'): Record<string, unknown>;
25
25
  /** One top-level property of an object JSON Schema. */
26
26
  export interface JsonSchemaField {
27
27
  /** Property name. */
@@ -1 +1 @@
1
- {"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/tools/json-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAA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M,EAAE,OAAO,CAAC,CAAC;IAChC,+DAA+D;IAC/D,QAAQ,EAAE,OAAO,CAAC;IAClB,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAOD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,eAAe,EAAE,CAqBvF"}
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/tools/manifest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,iBAAiB,EAAE,CAU7E"}
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/tools/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,iBAAiB,EAAE,CAM7E"}
@@ -10,23 +10,17 @@ export interface McpHandlerConfig<TAuth> extends McpServerBuildConfig<TAuth> {
10
10
  * with `oauthProtectedResourceRoute(protectedResource)`.
11
11
  */
12
12
  protectedResource?: ProtectedResourceConfig;
13
- /**
14
- * Stateless mode (default `false`). Each request builds a fresh transport +
15
- * server and is handled in isolation — no `Mcp-Session-Id`, no in-memory
16
- * session store. A restart / deploy / scale-out therefore never invalidates a
17
- * client (no `404 Session not found`), which is what most request/response
18
- * tool servers want. The trade-off is no server-initiated messages
19
- * (`notifications/progress`, standalone SSE) between requests — fine for
20
- * synchronous tools. Leave `false` only when you need that server push.
21
- */
22
- stateless?: boolean;
13
+ /** HTTP transport state. Default `'stateless'`; opt into `'stateful'` only
14
+ * for cross-request progress, server push or resumable SSE sessions. */
15
+ sessionMode?: McpSessionMode;
23
16
  }
17
+ export type McpSessionMode = 'stateful' | 'stateless';
24
18
  /**
25
19
  * Build a Streamable-HTTP MCP request handler (`Request → Response`).
26
20
  *
27
- * Owns the entire MCP server lifecycle — SSE event store, per-session
28
- * transports, the `McpServer` instances — so the consuming app never imports
29
- * `@modelcontextprotocol/sdk` itself. The app only declares WHAT to expose:
21
+ * Owns the MCP server/transport lifecycle — and, only in explicit stateful
22
+ * mode, the SSE event/session stores — so the consuming app never imports the
23
+ * SDK itself. The app only declares WHAT to expose:
30
24
  * how to authenticate and which contract services. MCP tools come from
31
25
  * contracts; native multimodal tools attach via `nativeTools`.
32
26
  *
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-handler.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-handler.ts"],"names":[],"mappings":"AASA,OAAO,EAAkB,KAAK,oBAAoB,EAAsB,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,KAAK,uBAAuB,EAAyB,MAAM,kBAAkB,CAAC;AAqEvF,MAAM,WAAW,gBAAgB,CAAC,KAAK,CAAE,SAAQ,oBAAoB,CAAC,KAAK,CAAC;IAC1E,uEAAuE;IACvE,IAAI,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC7D;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAC5C;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAoBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EACpC,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAC9B,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAqHrC"}
1
+ {"version":3,"file":"mcp-handler.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-handler.ts"],"names":[],"mappings":"AASA,OAAO,EAGL,KAAK,oBAAoB,EAE1B,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,uBAAuB,EAAyB,MAAM,kBAAkB,CAAC;AAqEvF,MAAM,WAAW,gBAAgB,CAAC,KAAK,CAAE,SAAQ,oBAAoB,CAAC,KAAK,CAAC;IAC1E,uEAAuE;IACvE,IAAI,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC7D;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAC5C;6EACyE;IACzE,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,WAAW,CAAC;AAoBtD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EACpC,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAC9B,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA2HrC"}
@@ -1,8 +1,11 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
2
3
  import type { ServiceDef, StitchLogger } from '../server/types';
3
4
  import { type ErrorHintFn, type ToolCallHooks, type ToolLifecycle } from './execute';
5
+ import type { ToolPresentationSchema } from './flatten';
4
6
  import { type McpResourceDef } from './mcp-app';
5
- import { type ToolExtend } from './mount';
7
+ import { type MountableTool, type ToolExtend } from './mount';
8
+ import { type NativeMcpRegistrar } from './native-mcp';
6
9
  /**
7
10
  * What to do when a tool's schema cannot be advertised on the MCP surface — a
8
11
  * union / discriminated-union input (MCP needs an object), or a construct
@@ -13,6 +16,49 @@ import { type ToolExtend } from './mount';
13
16
  * - `skip` — drop the tool silently.
14
17
  */
15
18
  export type IncompatibleSchemaPolicy = 'throw' | 'skip' | 'warn';
19
+ /** One schema policy shared by validation, mounting and every MCP transport. */
20
+ export interface McpSchemaValidationConfig {
21
+ /** What to do when a tool schema fails the profile. Default `'throw'`. */
22
+ policy?: IncompatibleSchemaPolicy;
23
+ /** Require every advertised input property to carry usable type information. */
24
+ requireTypedProperties?: boolean;
25
+ /** Dotted `tool.property` paths deliberately left unconstrained. */
26
+ allowUntyped?: readonly string[];
27
+ /** Reject formats outside the portable JSON Schema/AJV baseline. */
28
+ requirePortableFormats?: boolean;
29
+ /** Custom formats known to every client used by this server. */
30
+ allowFormats?: readonly string[];
31
+ }
32
+ /** Standalone schema-validation input, including the exact surface-shaping options. */
33
+ export interface ValidateMcpSchemasConfig extends McpSchemaValidationConfig {
34
+ services: ServiceDef[];
35
+ logger?: StitchLogger;
36
+ extend?: ToolExtend;
37
+ flattenUnionInput?: boolean;
38
+ }
39
+ /** How a tool's result maps to MCP `structuredContent`. */
40
+ type StructuredMode = 'none' | 'direct' | 'wrapped';
41
+ /** One immutable descriptor cleared to register on any fresh MCP server. */
42
+ export interface PreparedMcpTool {
43
+ mountable: MountableTool;
44
+ inputSchema: ToolPresentationSchema;
45
+ outputSchema?: z.ZodType;
46
+ outputMode: StructuredMode;
47
+ }
48
+ export type PreparedMcpSurface = readonly PreparedMcpTool[];
49
+ export interface McpSurfacePreparationConfig {
50
+ extend?: ToolExtend;
51
+ flattenUnionInput?: boolean;
52
+ schemaValidation?: McpSchemaValidationConfig;
53
+ logger?: StitchLogger;
54
+ }
55
+ /**
56
+ * Prepare the deterministic MCP surface once. No auth, context, hooks,
57
+ * lifecycle closures, server or transport enters this value.
58
+ */
59
+ export declare function prepareMcpSurface(services: ServiceDef | ServiceDef[], config?: McpSurfacePreparationConfig): PreparedMcpSurface;
60
+ /** Prepare already-resolved tool operations through the canonical MCP schema profile. */
61
+ export declare function prepareMcpTools(tools: readonly MountableTool[], config?: McpSurfacePreparationConfig): PreparedMcpSurface;
16
62
  export interface McpMountConfig {
17
63
  context?: Record<string, unknown>;
18
64
  /** Tool-call observability hooks. */
@@ -25,8 +71,8 @@ export interface McpMountConfig {
25
71
  */
26
72
  lifecycle?: ToolLifecycle;
27
73
  extend?: ToolExtend;
28
- /** What to do when a tool's schema is not MCP-compatible. Default `'throw'`. */
29
- onIncompatibleSchema?: IncompatibleSchemaPolicy;
74
+ /** Validation policy applied to the exact advertised MCP schemas. */
75
+ schemaValidation?: McpSchemaValidationConfig;
30
76
  /** Logger for the `'warn'` policy — defaults to `console`. */
31
77
  logger?: StitchLogger;
32
78
  /** Coerce JSON-stringified arrays/objects in tool arguments. Default: true. */
@@ -45,20 +91,10 @@ export interface McpMountConfig {
45
91
  * callable on its own (a startup assertion, a test) to fail a deploy before
46
92
  * the first request.
47
93
  */
48
- export declare function validateMcpSchemas(services: ServiceDef[], onIncompatibleSchema?: IncompatibleSchemaPolicy, logger?: StitchLogger, options?: {
49
- extend?: ToolExtend;
50
- flattenUnionInput?: boolean;
51
- /**
52
- * Also fail a tool whose advertised schema has a property with no type
53
- * information — nothing for a model to obey. Off by default because a
54
- * contract may legitimately declare `z.unknown()`; `allowUntyped` lists the
55
- * dotted paths that are deliberate, and anything else is a finding. → ADR 0044.
56
- */
57
- requireTypedProperties?: boolean;
58
- /** Dotted paths (`tool.property`) that are deliberately unconstrained. */
59
- allowUntyped?: readonly string[];
60
- }): void;
94
+ export declare function validateMcpSchemas(config: ValidateMcpSchemasConfig): void;
61
95
  export declare function mountMcp(mcpServer: McpServer, services: ServiceDef | ServiceDef[], config?: McpMountConfig): void;
96
+ /** Register a prepared immutable surface onto one fresh server/runtime. */
97
+ export declare function mountPreparedMcp(mcpServer: McpServer, prepared: PreparedMcpSurface, config?: McpMountConfig): void;
62
98
  /**
63
99
  * Transport-neutral build config for an MCP server — everything needed to turn
64
100
  * contract services into a live `McpServer`, minus how the identity is
@@ -88,16 +124,14 @@ export interface McpServerBuildConfig<TAuth> {
88
124
  * `mountMcp` — without this, the batteries-path (`createMcpHandler`) could not
89
125
  * reach it and a consumer had to hand-wrap every service. */
90
126
  extend?: ToolExtend;
91
- /** What to do when a tool's schema is not MCP-compatible. Default `'throw'`. */
92
- onIncompatibleSchema?: IncompatibleSchemaPolicy;
127
+ /** Validation policy applied to the exact advertised MCP schemas. */
128
+ schemaValidation?: McpSchemaValidationConfig;
93
129
  /** Logger for schema-incompatibility warnings — defaults to `console`. */
94
130
  logger?: StitchLogger;
95
- /** Register native (non-contract) MCP tools receives the `McpServer` and the
96
- * resolved identity, like `services` and `context` do, so a native tool can be
97
- * per-tenant. For tools returning multimodal content, e.g. `mountViewFile`.
98
- * Note this is **not** a scope gate: native tools are not contract methods and
99
- * `lifecycle` does not run for them. */
100
- nativeTools?: (server: McpServer, auth: TAuth) => void;
131
+ /** Register native multimodal MCP tools for the resolved identity. Use
132
+ * `registerTool` for stitchkit lifecycle/hooks; `rawServer` is an explicit
133
+ * unprotected SDK escape hatch. */
134
+ nativeTools?: (registrar: NativeMcpRegistrar, auth: TAuth) => void;
101
135
  /** MCP Apps UI resources (`ui://…`) served for tools that declare `ui`. */
102
136
  resources?: McpResourceDef[];
103
137
  /** Server instructions — a short (≤2KB) hint to the host on when and how to
@@ -117,10 +151,13 @@ export interface McpServerBuildConfig<TAuth> {
117
151
  * Transport-agnostic — the shared core behind every MCP transport.
118
152
  */
119
153
  export declare function buildMcpServer<TAuth>(config: McpServerBuildConfig<TAuth>, auth: TAuth): McpServer;
154
+ /** Build one fresh server from a deterministic surface prepared by its owner. */
155
+ export declare function buildMcpServerFromPrepared<TAuth>(config: McpServerBuildConfig<TAuth>, auth: TAuth, prepared: PreparedMcpSurface): McpServer;
120
156
  /**
121
157
  * Register one MCP Apps UI resource on an `McpServer`. The `read` callback's
122
158
  * HTML is served under the resource `uri` with the apps MIME type; any `ui`
123
159
  * metadata (CSP, border, domain) is attached to the content's `_meta.ui`.
124
160
  */
125
161
  export declare function mountMcpResource(server: McpServer, resource: McpResourceDef): void;
162
+ export {};
126
163
  //# sourceMappingURL=mcp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EAGnB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,KAAK,cAAc,EAAsB,MAAM,WAAW,CAAC;AACpE,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,SAAS,CAAC;AAIjB;;;;;;;;GAQG;AACH,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AA4JjE,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,qCAAqC;IACrC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,gFAAgF;IAChF,oBAAoB,CAAC,EAAE,wBAAwB,CAAC;IAChD,8DAA8D;IAC9D,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB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AC,KAAK,CAAC,EACnC,IAAI,EAAE,KAAK,GACV,SAAS,CAUX;AAED,iFAAiF;AACjF,wBAAgB,0BAA0B,CAAC,KAAK,EAC9C,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC,EACnC,IAAI,EAAE,KAAK,EACX,QAAQ,EAAE,kBAAkB,GAC3B,SAAS,CAuCX;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI,CAgBlF"}
@@ -6,7 +6,8 @@
6
6
  import { z } from 'zod';
7
7
  import type { Transport, TransportSource } from '../contract';
8
8
  import type { MethodDef, ServiceDef } from '../server/types';
9
- import { type ErrorHintFn, type ToolCallHooks, type ToolLifecycle, type ToolResult } from './execute';
9
+ import { type ErrorHintFn, type ToolCallHooks, type ToolLifecycle, type ToolOperation, type ToolResult } from './execute';
10
+ import type { ToolPresentationSchema } from './flatten';
10
11
  /**
11
12
  * Extra arguments folded into a mounted tool's schema — the host supplies them,
12
13
  * `resolve` turns them into handler context. Shared by `mountMcp` / `mountAgent`.
@@ -23,14 +24,16 @@ export interface ToolExtend<TContext extends Record<string, unknown> = Record<st
23
24
  /** Limit the extension to specific methods — default: every method. */
24
25
  filter?: (service: ServiceDef, method: MethodDef) => boolean;
25
26
  }
26
- /** One contract method resolved for mounting as a tool. */
27
+ /** One contract or framework-native operation resolved for mounting as a tool. */
27
28
  export interface MountableTool {
28
- /** The contract method behind the tool. */
29
- method: MethodDef<unknown, unknown, unknown>;
29
+ /** The executable operation identity and schemas behind the tool. */
30
+ method: ToolOperation;
30
31
  /** Tool name — the `toolName` override, else derived from service + method. */
31
32
  name: string;
32
- /** Merged params + input schema, with the extend fields folded in when they apply. */
33
- schema: z.ZodType;
33
+ /** Executable source schema used only by the CLI argument adapter. */
34
+ argumentSchema: z.ZodType;
35
+ /** Immutable model-facing JSON Schema; never used to execute validation effects. */
36
+ presentationSchema: ToolPresentationSchema;
34
37
  /** Whether `ToolExtend` applies to this method. */
35
38
  shouldExtend: boolean;
36
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/tools/mount.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EACL,KAAK,WAAW,EAGhB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAKnB;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU,CACzB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAElE,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;IAClC,qEAAqE;IACrE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3F,uEAAuE;IACvE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC;CAC9D;AAED,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC7C,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC;IAClB,mDAAmD;IACnD,YAAY,EAAE,OAAO,CAA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C,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,WAAW,GACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB"}
@@ -13,7 +13,7 @@ export declare function hasUsableChars(value: string): boolean;
13
13
  * that mount goes dark, not just the bad one. A tool name is an
14
14
  * *identity* defect like a duplicate name (which also throws unconditionally), not
15
15
  * a *representability* one like an unconvertible schema (which gets the
16
- * `onIncompatibleSchema` policy). → ADR 0035.
16
+ * schema-validation policy). → ADR 0035.
17
17
  */
18
18
  export declare function assertToolName(name: string, serviceName: string, key: string): void;
19
19
  export declare function toToolName(serviceName: string, methodName: string): string;
@@ -0,0 +1,57 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
3
+ import { z } from 'zod';
4
+ import type { EndpointToolAnnotations, EndpointUiMeta, HttpMethod, RuntimeContext } from '../contract';
5
+ import { executeToolMethod, type ToolCallHooks, type ToolLifecycle } from './execute';
6
+ import type { PreparedMcpSurface } from './mcp';
7
+ import type { MountableTool } from './mount';
8
+ export interface NativeMcpOperationIdentity {
9
+ serviceName: string;
10
+ action: string;
11
+ scope?: string;
12
+ /** Semantic operation verb for lifecycle and `RequestEvent.httpMethod`. */
13
+ method: HttpMethod;
14
+ /** Opaque project metadata exposed to lifecycle and tool hooks. */
15
+ meta?: Record<string, unknown>;
16
+ }
17
+ export type NativeMcpHandlerContext<TInput extends z.ZodObject> = RuntimeContext & {
18
+ params: undefined;
19
+ input: z.output<TInput>;
20
+ };
21
+ export type NativeMcpResult<TOutput extends z.ZodObject | undefined = undefined> = TOutput extends z.ZodObject ? Omit<CallToolResult, 'structuredContent'> & {
22
+ structuredContent: z.output<TOutput>;
23
+ } : CallToolResult;
24
+ export interface NativeMcpToolDefinition<TInput extends z.ZodObject, TOutput extends z.ZodObject | undefined = undefined> {
25
+ name: string;
26
+ description: string;
27
+ identity: NativeMcpOperationIdentity;
28
+ input: TInput;
29
+ output?: TOutput;
30
+ annotations?: EndpointToolAnnotations;
31
+ ui?: EndpointUiMeta;
32
+ handler: (context: NativeMcpHandlerContext<TInput>) => NativeMcpResult<TOutput> | Promise<NativeMcpResult<TOutput>>;
33
+ }
34
+ export interface NativeMcpRegistrar {
35
+ /** Register through stitchkit validation, lifecycle, context and tool hooks. */
36
+ registerTool<TInput extends z.ZodObject, TOutput extends z.ZodObject | undefined = undefined>(definition: NativeMcpToolDefinition<TInput, TOutput>): void;
37
+ /**
38
+ * Explicit SDK escape hatch. Registrations made here do not run stitchkit
39
+ * validation, lifecycle, per-call context or tool hooks.
40
+ */
41
+ readonly rawServer: McpServer;
42
+ }
43
+ interface NativeMcpRuntimeConfig {
44
+ context?: Record<string, unknown>;
45
+ hooks?: ToolCallHooks;
46
+ lifecycle?: ToolLifecycle;
47
+ coerceJsonArgs?: boolean;
48
+ onOutputStrip?: (toolName: string, paths: string[]) => void;
49
+ prepare: (tool: MountableTool) => PreparedMcpSurface;
50
+ formatError: (result: Extract<Awaited<ReturnType<typeof executeToolMethod>>, {
51
+ ok: false;
52
+ }>, toolName: string) => CallToolResult;
53
+ }
54
+ /** Build the protected registrar for one fresh MCP server/runtime. */
55
+ export declare function createNativeMcpRegistrar(server: McpServer, config: NativeMcpRuntimeConfig): NativeMcpRegistrar;
56
+ export {};
57
+ //# sourceMappingURL=native-mcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-mcp.d.ts","sourceRoot":"","sources":["../../src/tools/native-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,oCAAoC,CAAC;AAC/F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EACV,uBAAuB,EACvB,cAAc,EACd,UAAU,EACV,cAAc,EACf,MAAM,aAAa,CAAC;AAIrB,OAAO,EACL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;IACpB,OAAO,EAAE,CACP,OAAO,EAAE,uBAAuB,CAAC,MAAM,CAAC,KACrC,eAAe,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;CACnE;AAED,MAAM,WAAW,kBAAkB;IACjC,gFAAgF;IAChF,YAAY,CACV,MAAM,SAAS,CAAC,CAAC,SAAS,EAC1B,OAAO,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,EACnD,UAAU,EAAE,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC9D;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED,UAAU,sBAAsB;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC5D,OAAO,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,kBAAkB,CAAC;IACrD,WAAW,EAAE,CACX,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,EAAE;QAAE,EAAE,EAAE,KAAK,CAAA;KAAE,CAAC,EAC7E,QAAQ,EAAE,MAAM,KACb,cAAc,CAAC;CACrB;AAyCD,sEAAsE;AACtE,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,sBAAsB,GAC7B,kBAAkB,CA6EpB"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * JSON Schema formats implemented by the standard `ajv-formats` package and
3
+ * defined by JSON Schema itself. This deliberately excludes its OpenAPI-only,
4
+ * deprecated and AJV-specific aliases: the MCP surface must travel across
5
+ * clients, not only compile in one validator.
6
+ */
7
+ export declare const PORTABLE_JSON_SCHEMA_FORMATS: ReadonlySet<string>;
8
+ export interface NonPortableFormat {
9
+ /** Path inside the JSON Schema; `(root)` when the root itself has a format. */
10
+ path: string;
11
+ format: string;
12
+ }
13
+ /** Find every format outside the portable baseline and an explicit allowlist. */
14
+ export declare function findNonPortableFormats(schema: unknown, allowFormats?: readonly string[]): NonPortableFormat[];
15
+ //# sourceMappingURL=portable-formats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portable-formats.d.ts","sourceRoot":"","sources":["../../src/tools/portable-formats.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,EAAE,WAAW,CAAC,MAAM,CAgB3D,CAAC;AAEH,MAAM,WAAW,iBAAiB;IAChC,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAgBD,iFAAiF;AACjF,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,OAAO,EACf,YAAY,GAAE,SAAS,MAAM,EAAO,GACnC,iBAAiB,EAAE,CAiErB"}
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+ import { type ToolPresentationSchema } from './flatten';
3
+ export interface ToolPresentationConfig {
4
+ paramsSchema?: z.ZodType;
5
+ inputSchema?: z.ZodType;
6
+ extendSchema?: Record<string, z.ZodType>;
7
+ flattenUnionInput?: boolean;
8
+ unrepresentable?: 'throw' | 'any';
9
+ }
10
+ /** Build the one model-facing document shared by MCP, agents and manifests. */
11
+ export declare function buildToolPresentationSchema(config: ToolPresentationConfig): ToolPresentationSchema;
12
+ export declare function isObjectPresentationSchema(schema: ToolPresentationSchema): boolean;
13
+ /** Metadata passed to the Zod identity carrier; the SDK supplies its own dialect. */
14
+ export declare function presentationMetadata(schema: ToolPresentationSchema): ToolPresentationSchema;
15
+ //# sourceMappingURL=presentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation.d.ts","sourceRoot":"","sources":["../../src/tools/presentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,WAAW,CAAC;AAGnB,MAAM,WAAW,sBAAsB;IACrC,YAAY,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;IACzC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;CACnC;AA+FD,+EAA+E;AAC/E,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,sBAAsB,GAC7B,sBAAsB,CAgDxB;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAElF;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,sBAAsB,GAAG,sBAAsB,CAE3F"}
@@ -1 +1 @@
1
- {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/tools/remote.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAiB7D,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,CAAC,EAAE,CACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE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