stitchkit 0.2.0 → 0.4.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 (136) hide show
  1. package/README.md +11 -10
  2. package/dist/browser/client.d.ts.map +1 -1
  3. package/dist/browser/http.d.ts +5 -0
  4. package/dist/browser/http.d.ts.map +1 -1
  5. package/dist/browser/socket-io.d.ts +17 -0
  6. package/dist/browser/socket-io.d.ts.map +1 -1
  7. package/dist/cli.d.ts +23 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +21 -0
  10. package/dist/contract/define.d.ts +35 -2
  11. package/dist/contract/define.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 +2 -1
  15. package/dist/index-0ed3bx43.js +33 -0
  16. package/dist/index-0ma1eqv4.js +1007 -0
  17. package/dist/index-1cf8jkhf.js +219 -0
  18. package/dist/index-37x76zdn.js +4 -0
  19. package/dist/{index-v2z2v3mq.js → index-3qmtdfpa.js} +304 -62
  20. package/dist/index-48ffdxgk.js +6 -0
  21. package/dist/{index-5sxnvwb1.js → index-78q1qm7v.js} +6 -3
  22. package/dist/{index-kckky6zw.js → index-afzt3nmx.js} +1 -1
  23. package/dist/{index-n7bmdwmz.js → index-d4rwrjbc.js} +8 -4
  24. package/dist/index-kzfs85xp.js +9 -0
  25. package/dist/index-mwmpw6j1.js +60 -0
  26. package/dist/{index-a35v22fh.js → index-vhdvv00d.js} +13 -5
  27. package/dist/index-x3fcszf8.js +8 -0
  28. package/dist/index.js +17 -4
  29. package/dist/internal/errors.d.ts +13 -1
  30. package/dist/internal/errors.d.ts.map +1 -1
  31. package/dist/internal/http-input.d.ts +13 -0
  32. package/dist/internal/http-input.d.ts.map +1 -0
  33. package/dist/internal/safe-json.d.ts +19 -0
  34. package/dist/internal/safe-json.d.ts.map +1 -0
  35. package/dist/internal/secure-fetch.d.ts +27 -0
  36. package/dist/internal/secure-fetch.d.ts.map +1 -0
  37. package/dist/internal/within-dir.d.ts +7 -0
  38. package/dist/internal/within-dir.d.ts.map +1 -0
  39. package/dist/node.d.ts +10 -1
  40. package/dist/node.d.ts.map +1 -1
  41. package/dist/node.js +41 -7
  42. package/dist/observability/audit.d.ts.map +1 -1
  43. package/dist/observability/context.d.ts +9 -1
  44. package/dist/observability/context.d.ts.map +1 -1
  45. package/dist/observability/event.d.ts +4 -0
  46. package/dist/observability/event.d.ts.map +1 -1
  47. package/dist/observability/index.js +38 -15
  48. package/dist/observability/sanitize.d.ts.map +1 -1
  49. package/dist/react.js +2 -0
  50. package/dist/server/context.d.ts +3 -2
  51. package/dist/server/context.d.ts.map +1 -1
  52. package/dist/server/create.d.ts.map +1 -1
  53. package/dist/server/event-bus.d.ts +10 -1
  54. package/dist/server/event-bus.d.ts.map +1 -1
  55. package/dist/server/implement.d.ts.map +1 -1
  56. package/dist/server/index.d.ts +6 -3
  57. package/dist/server/index.d.ts.map +1 -1
  58. package/dist/server/index.js +203 -193
  59. package/dist/server/logger.d.ts +5 -4
  60. package/dist/server/logger.d.ts.map +1 -1
  61. package/dist/server/middleware/auth.d.ts +41 -1
  62. package/dist/server/middleware/auth.d.ts.map +1 -1
  63. package/dist/server/middleware/cookies.d.ts.map +1 -1
  64. package/dist/server/middleware/cors.d.ts +7 -0
  65. package/dist/server/middleware/cors.d.ts.map +1 -1
  66. package/dist/server/middleware/pkce.d.ts +17 -0
  67. package/dist/server/middleware/pkce.d.ts.map +1 -0
  68. package/dist/server/multipart.d.ts +2 -1
  69. package/dist/server/multipart.d.ts.map +1 -1
  70. package/dist/server/node.d.ts +9 -0
  71. package/dist/server/node.d.ts.map +1 -1
  72. package/dist/server/openapi.d.ts +52 -0
  73. package/dist/server/openapi.d.ts.map +1 -0
  74. package/dist/server/rate-limit.d.ts +7 -2
  75. package/dist/server/rate-limit.d.ts.map +1 -1
  76. package/dist/server/request.d.ts +27 -4
  77. package/dist/server/request.d.ts.map +1 -1
  78. package/dist/server/router.d.ts +4 -2
  79. package/dist/server/router.d.ts.map +1 -1
  80. package/dist/server/socket-io.d.ts +60 -15
  81. package/dist/server/socket-io.d.ts.map +1 -1
  82. package/dist/server/stream.d.ts +3 -1
  83. package/dist/server/stream.d.ts.map +1 -1
  84. package/dist/server/types.d.ts +17 -1
  85. package/dist/server/types.d.ts.map +1 -1
  86. package/dist/server/websocket.d.ts +73 -0
  87. package/dist/server/websocket.d.ts.map +1 -0
  88. package/dist/tools/cli-args.d.ts +68 -0
  89. package/dist/tools/cli-args.d.ts.map +1 -0
  90. package/dist/tools/cli-format.d.ts +39 -0
  91. package/dist/tools/cli-format.d.ts.map +1 -0
  92. package/dist/tools/cli-wait.d.ts +45 -0
  93. package/dist/tools/cli-wait.d.ts.map +1 -0
  94. package/dist/tools/cli.d.ts +77 -0
  95. package/dist/tools/cli.d.ts.map +1 -0
  96. package/dist/tools/coerce.d.ts +8 -4
  97. package/dist/tools/coerce.d.ts.map +1 -1
  98. package/dist/tools/execute.d.ts +1 -1
  99. package/dist/tools/execute.d.ts.map +1 -1
  100. package/dist/tools/json-schema.d.ts +29 -4
  101. package/dist/tools/json-schema.d.ts.map +1 -1
  102. package/dist/tools/manifest.d.ts +4 -0
  103. package/dist/tools/manifest.d.ts.map +1 -1
  104. package/dist/tools/mcp-app.d.ts +59 -0
  105. package/dist/tools/mcp-app.d.ts.map +1 -0
  106. package/dist/tools/mcp-handler.d.ts +18 -0
  107. package/dist/tools/mcp-handler.d.ts.map +1 -1
  108. package/dist/tools/mcp.d.ts +9 -0
  109. package/dist/tools/mcp.d.ts.map +1 -1
  110. package/dist/tools/mount-download.d.ts +30 -0
  111. package/dist/tools/mount-download.d.ts.map +1 -0
  112. package/dist/tools/mount-upload.d.ts +19 -0
  113. package/dist/tools/mount-upload.d.ts.map +1 -0
  114. package/dist/tools/mount-wait.d.ts +36 -0
  115. package/dist/tools/mount-wait.d.ts.map +1 -0
  116. package/dist/tools/mount.d.ts +8 -4
  117. package/dist/tools/mount.d.ts.map +1 -1
  118. package/dist/tools/native-result.d.ts +17 -0
  119. package/dist/tools/native-result.d.ts.map +1 -0
  120. package/dist/tools/oauth-metadata.d.ts +28 -0
  121. package/dist/tools/oauth-metadata.d.ts.map +1 -0
  122. package/dist/tools/oauth-provider.d.ts +85 -0
  123. package/dist/tools/oauth-provider.d.ts.map +1 -0
  124. package/dist/tools/remote.d.ts +2 -2
  125. package/dist/tools/remote.d.ts.map +1 -1
  126. package/dist/tools/toolkit.d.ts +51 -0
  127. package/dist/tools/toolkit.d.ts.map +1 -0
  128. package/dist/tools/view-file.d.ts +12 -0
  129. package/dist/tools/view-file.d.ts.map +1 -1
  130. package/dist/tools/wait-core.d.ts +33 -0
  131. package/dist/tools/wait-core.d.ts.map +1 -0
  132. package/dist/tools.d.ts +13 -2
  133. package/dist/tools.d.ts.map +1 -1
  134. package/dist/tools.js +637 -424
  135. package/package.json +22 -9
  136. package/dist/index-ke4mx4ea.js +0 -38
@@ -0,0 +1,45 @@
1
+ /**
2
+ * `--wait` polling — block on an async tool result until it reaches a terminal
3
+ * state. The headline CLI feature (a `Bash(run_in_background)` generation that
4
+ * notifies when done), kept strictly generic per ADR 0002: the core knows
5
+ * nothing about generations or statuses. The consumer supplies how to read the
6
+ * poll target from the first result (`poll`), which tool to re-call (`tool`)
7
+ * and when it is done (`done`).
8
+ */
9
+ import type { ToolResult } from './execute';
10
+ export interface CliWaitConfig {
11
+ /**
12
+ * Extract the poll-tool arguments from the initial result (e.g. `{ id }` from
13
+ * a `generate` response). Return `null` when there is nothing to wait on.
14
+ */
15
+ poll: (result: unknown) => Record<string, unknown> | null;
16
+ /** The tool/command name to call on each poll tick (e.g. `get_generation`). */
17
+ tool: string;
18
+ /** Done when this returns `true` for a poll result. */
19
+ done: (result: unknown) => boolean;
20
+ /** Backoff schedule in seconds; the last entry repeats. Default `[2,3,5,5,8,10]`. */
21
+ backoff?: number[];
22
+ /** Max seconds before giving up. Default `600`. */
23
+ timeout?: number;
24
+ }
25
+ export interface PollParams {
26
+ /** The result of the initial (non-poll) call. */
27
+ initial: ToolResult;
28
+ wait: CliWaitConfig;
29
+ /** Run a tool by name — the CLI binds this to its tool map + runner. */
30
+ call: (toolName: string, args: Record<string, unknown>) => Promise<ToolResult>;
31
+ /** Override `wait.timeout` (from `--wait-timeout`). */
32
+ timeoutSec?: number;
33
+ /** Progress callback — the CLI logs ticks to stderr unless `--quiet`. */
34
+ onTick?: (attempt: number, elapsedSec: number) => void;
35
+ /** Injectable sleep for tests. */
36
+ sleepFn?: (ms: number) => Promise<void>;
37
+ }
38
+ /**
39
+ * Poll `wait.tool` until `wait.done` or the timeout. Returns the last poll
40
+ * result; returns the initial result untouched when the initial call failed,
41
+ * already satisfies `done`, or yields no poll target. A timeout produces a
42
+ * `TIMEOUT` failed `ToolResult`.
43
+ */
44
+ export declare function pollUntilDone(params: PollParams): Promise<ToolResult>;
45
+ //# sourceMappingURL=cli-wait.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-wait.d.ts","sourceRoot":"","sources":["../../src/tools/cli-wait.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1D,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;IACnC,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID,MAAM,WAAW,UAAU;IACzB,iDAAiD;IACjD,OAAO,EAAE,UAAU,CAAC;IACpB,IAAI,EAAE,aAAa,CAAC;IACpB,wEAAwE;IACxE,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/E,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CA0B3E"}
@@ -0,0 +1,77 @@
1
+ import type { ServiceDef, StitchLogger } from '../server/types';
2
+ import { type ExitCodeMap } from './cli-format';
3
+ import { type CliWaitConfig } from './cli-wait';
4
+ import { type ToolCallHooks, type ToolLifecycle } from './execute';
5
+ export interface CliConfig<TAuth = unknown, TContext extends Record<string, unknown> = Record<string, unknown>> {
6
+ /** Program name — shown in help and unknown-command messages. */
7
+ name: string;
8
+ /** Program version — printed by `--version`. */
9
+ version: string;
10
+ /** Contract services exposed as commands — may depend on the resolved identity. */
11
+ services: ServiceDef[] | ((auth: Awaited<TAuth> | undefined) => ServiceDef[]);
12
+ /**
13
+ * Identity for the single CLI invocation — resolved ONCE at startup (from an
14
+ * env var / token file), like a stdio MCP server, not per call. A value or a
15
+ * promise of one.
16
+ */
17
+ auth?: TAuth | Promise<TAuth>;
18
+ /**
19
+ * Context merged into every handler. Typed against the app's context shape
20
+ * when the CLI is built via `createToolkit<AppContext>()`.
21
+ */
22
+ context?: (auth: Awaited<TAuth> | undefined) => TContext;
23
+ /** Tool-call observability hooks — `afterToolCall` fires for every result. */
24
+ hooks?: ToolCallHooks;
25
+ /**
26
+ * Auth / scope gate — pass the same `createAuthHook` result used for the HTTP
27
+ * server's `beforeHandle` so a CLI command is guarded identically. Without it
28
+ * a scoped command bypasses the gate.
29
+ */
30
+ lifecycle?: ToolLifecycle;
31
+ /** Logger for diagnostics — defaults to stderr-safe `console.error`. */
32
+ logger?: StitchLogger;
33
+ /** Coerce JSON-stringified arrays/objects in arguments. Default: true. */
34
+ coerceJsonArgs?: boolean;
35
+ /** Global error hint appended to every failed command's error. */
36
+ errorHint?: (toolName: string, errorCode: string) => string | null;
37
+ /** Override exit codes per `ToolResult.code`, merged over the defaults. */
38
+ exitCodes?: ExitCodeMap;
39
+ /**
40
+ * Route a command's unknown `--flags` into a freeform object field, keyed by
41
+ * command name → field. Lets `generate <model> --prompt … --aspect_ratio 16:9`
42
+ * fill the model's `parameters` directly, instead of a `--parameters '{json}'`
43
+ * blob. Values are loosely coerced (`"30"` → `30`, `"true"` → `true`).
44
+ */
45
+ passthrough?: Record<string, string>;
46
+ /** Per-command `--wait` polling behaviour, keyed by command name. */
47
+ wait?: Record<string, CliWaitConfig>;
48
+ /** Extract downloadable media URLs from a result for `--output-dir`. */
49
+ download?: (result: unknown) => Array<{
50
+ url: string;
51
+ name: string;
52
+ }>;
53
+ /**
54
+ * Allow `--output-dir` downloads from private / internal / loopback hosts.
55
+ * Default `false` — the SSRF guard, since the URLs come from handler output.
56
+ */
57
+ allowPrivateDownloadHosts?: boolean;
58
+ /** Max bytes per `--output-dir` download before aborting. Default 100 MB. */
59
+ maxDownloadBytes?: number;
60
+ /** argv to parse — default `process.argv.slice(2)`; injectable for tests. */
61
+ argv?: string[];
62
+ /** stdout sink — default `process.stdout`; injectable for tests. */
63
+ stdout?: (text: string) => void;
64
+ /** stderr sink — default `process.stderr`; injectable for tests. */
65
+ stderr?: (text: string) => void;
66
+ /** Exit hook — default `process.exit`; injectable for tests. */
67
+ exit?: (code: number) => void;
68
+ /** Read piped stdin — default reads when not a TTY; injectable for tests. */
69
+ stdin?: () => Promise<string | null>;
70
+ }
71
+ /**
72
+ * Build and run a CLI from contract services, then exit. Parses `process.argv`
73
+ * (or `config.argv`), routes to a command, executes it through the shared tool
74
+ * pipeline and writes the result. Resolves identity once up front.
75
+ */
76
+ export declare function createCli<TAuth = unknown, TContext extends Record<string, unknown> = Record<string, unknown>>(config: CliConfig<TAuth, TContext>): Promise<void>;
77
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/tools/cli.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEhE,OAAO,EAAsB,KAAK,WAAW,EAAc,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAGnB,MAAM,WAAW,CAAC;AAKnB,MAAM,WAAW,SAAS,CACxB,KAAK,GAAG,OAAO,EACf,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAElE,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,QAAQ,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,KAAK,UAAU,EAAE,CAAC,CAAC;IAC9E;;;;OAIG;IACH,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,KAAK,QAAQ,CAAC;IACzD,8EAA8E;IAC9E,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;;;OAIG;IACH,SA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O,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkInD"}
@@ -1,8 +1,12 @@
1
1
  import { z } from 'zod';
2
2
  /**
3
- * Wrap array/object fields with `z.preprocess(jsonCoerce)` — tolerant of
4
- * LLM double-serialization (sending `"[1,2]"` instead of `[1,2]`).
5
- * Preserves optional/nullable wrappers so the emitted JSON Schema is identical.
3
+ * Coerce JSON-stringified array/object arguments — an LLM sometimes
4
+ * double-serializes a nested value (sends `"[1,2]"` instead of `[1,2]`).
5
+ *
6
+ * Only fields the schema declares as an array/object are touched, and only
7
+ * when the incoming value is a string. The transform operates on the
8
+ * **arguments**, never the schema — so the advertised tool schema stays
9
+ * exactly the contract schema (correct types, correct `required`).
6
10
  */
7
- export declare function withJsonCoercion(schema: z.ZodObject<z.ZodRawShape>): z.ZodObject<z.ZodRawShape>;
11
+ export declare function coerceJsonArgs(args: Record<string, unknown>, schema: z.ZodType | undefined): Record<string, unknown>;
8
12
  //# sourceMappingURL=coerce.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../../src/tools/coerce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBxB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GACjC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAyB5B"}
1
+ {"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../../src/tools/coerce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAsBxB;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBzB"}
@@ -41,5 +41,5 @@ export interface ToolLifecycle {
41
41
  export declare function toolResultFromError(err: unknown): Extract<ToolResult, {
42
42
  ok: false;
43
43
  }>;
44
- export declare function executeToolMethod(method: MethodDef<unknown, unknown, unknown>, toolName: string, rawArgs: Record<string, unknown>, context: ToolCallContext, hooks?: ToolCallHooks, lifecycle?: ToolLifecycle): Promise<ToolResult>;
44
+ export declare function executeToolMethod(method: MethodDef<unknown, unknown, unknown>, toolName: string, rawArgs: Record<string, unknown>, context: ToolCallContext, hooks?: ToolCallHooks, lifecycle?: ToolLifecycle, coerceJson?: boolean): Promise<ToolResult>;
45
45
  //# 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;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,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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GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,CAQpF;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAC5C,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,eAAe,EACxB,KAAK,CAAC,EAAE,aAAa,EACrB,SAAS,CAAC,EAAE,aAAa,EACzB,UAAU,UAAQ,GACjB,OAAO,CAAC,UAAU,CAAC,CA8GrB"}
@@ -10,9 +10,34 @@ import { z } from 'zod';
10
10
  /** Conversion direction — `input` for tool arguments, `output` for results. */
11
11
  export type JsonSchemaIo = 'input' | 'output';
12
12
  /**
13
- * Convert a Zod schema to JSON Schema. Throws on a construct JSON Schema cannot
14
- * represent (`z.date()`, `z.bigint()`, `z.map()`, …). The caller decides what
15
- * to do with that failure — see `onIncompatibleSchema`.
13
+ * Convert a Zod schema to JSON Schema (draft-2020-12, the dialect OpenAPI 3.1
14
+ * uses). `unrepresentable` controls a construct JSON Schema cannot represent
15
+ * (`z.date()`, `z.bigint()`, `z.map()`, …):
16
+ *
17
+ * - `'throw'` (default) — throws for the whole schema. The tools layer wants
18
+ * this: it mirrors what the MCP SDK does, so a build-time probe catches an
19
+ * incompatible schema instead of shipping a tool the SDK would later reject.
20
+ * - `'any'` — degrades only the offending field to `{}` and keeps the rest.
21
+ * The OpenAPI generator wants this: one `z.date()` field must not collapse a
22
+ * whole endpoint's schema to `{}`.
23
+ */
24
+ export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo, unrepresentable?: 'throw' | 'any'): Record<string, unknown>;
25
+ /** One top-level property of an object JSON Schema. */
26
+ export interface JsonSchemaField {
27
+ /** Property name. */
28
+ name: string;
29
+ /** The property's own JSON Schema sub-document. */
30
+ schema: Record<string, unknown>;
31
+ /** Whether the property is in the schema's `required` list. */
32
+ required: boolean;
33
+ /** `description` (a Zod `.describe()`), when present. */
34
+ description?: string;
35
+ }
36
+ /**
37
+ * Extract the top-level object properties of a JSON Schema as a flat field list
38
+ * — the shared traversal behind CLI `--help` flag tables and OpenAPI
39
+ * `parameters`. Returns `[]` for a non-object schema (a union, a scalar); the
40
+ * caller decides how to degrade.
16
41
  */
17
- export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo): Record<string, unknown>;
42
+ export declare function jsonSchemaFields(jsonSchema: Record<string, unknown>): JsonSchemaField[];
18
43
  //# sourceMappingURL=json-schema.d.ts.map
@@ -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,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzF"}
1
+ {"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/tools/json-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,CAAC,CAAC,OAAO,EACjB,EAAE,EAAE,YAAY,EAChB,eAAe,GAAE,OAAO,GAAG,KAAe,GACzC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzB;AAED,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC9B,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC,MAAM,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"}
@@ -8,6 +8,10 @@ export interface ToolManifestEntry {
8
8
  * Build a searchable manifest from collected tools — name, description and
9
9
  * JSON Schema for each. Use it to power a `tool_search` native tool: the app
10
10
  * decides the search algorithm and the unlock mechanism.
11
+ *
12
+ * A tool whose schema cannot be represented as JSON Schema still appears —
13
+ * with an empty `inputSchema` — so it stays discoverable by name / description
14
+ * rather than crashing the whole manifest.
11
15
  */
12
16
  export declare function buildToolManifest(tools: MountableTool[]): ToolManifestEntry[];
13
17
  //# sourceMappingURL=manifest.d.ts.map
@@ -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;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,iBAAiB,EAAE,CAM7E"}
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"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * MIME type a host uses to recognise an MCP Apps UI resource — it renders the
3
+ * HTML as an interactive sandboxed iframe rather than displaying the source.
4
+ */
5
+ export declare const RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
6
+ /** Placeholder a widget HTML file carries where the ext-apps runtime is inlined. */
7
+ export declare const EXT_APPS_BUNDLE_PLACEHOLDER = "/*__EXT_APPS_BUNDLE__*/";
8
+ /**
9
+ * Content-Security-Policy allowlists a widget declares so the host's iframe can
10
+ * reach external origins (maps to the host's CSP directives). Default is
11
+ * block-all, so any external image / fetch origin must be listed.
12
+ */
13
+ export interface McpAppCsp {
14
+ /** `connect-src` — fetch / XHR / WebSocket origins. */
15
+ connectDomains?: string[];
16
+ /** `img-src` / `script-src` / `style-src` / `font-src` / `media-src` origins. */
17
+ resourceDomains?: string[];
18
+ /** `frame-src` — nested iframe origins (currently restricted in some hosts). */
19
+ frameDomains?: string[];
20
+ /** `base-uri` origins. */
21
+ baseUriDomains?: string[];
22
+ }
23
+ /** UI metadata attached to a served resource's content (`_meta.ui`). */
24
+ export interface McpAppResourceMeta {
25
+ csp?: McpAppCsp;
26
+ /** Drop the host's outer card border (mobile). */
27
+ prefersBorder?: boolean;
28
+ /** Stable origin for external-API CORS allowlists. */
29
+ domain?: string;
30
+ }
31
+ /**
32
+ * A UI resource served over MCP. `read` returns the widget HTML (already
33
+ * bundle-inlined). The default `mimeType` is the apps MIME type, so a plain
34
+ * widget needs only `uri`, `name` and `read`.
35
+ */
36
+ export interface McpResourceDef {
37
+ /** `ui://…` uri — must match a tool's `ui.resourceUri`. */
38
+ uri: string;
39
+ /** Human-readable name (shown in `resources/list`). */
40
+ name: string;
41
+ /** MIME type — defaults to `RESOURCE_MIME_TYPE`. */
42
+ mimeType?: string;
43
+ /** Optional UI metadata (CSP, border, domain) applied to the content. */
44
+ ui?: McpAppResourceMeta;
45
+ /** Return the resource body — the widget HTML for an apps resource. */
46
+ read: () => string | Promise<string>;
47
+ }
48
+ /**
49
+ * Inline the `@modelcontextprotocol/ext-apps` browser runtime into a widget's
50
+ * HTML, replacing `EXT_APPS_BUNDLE_PLACEHOLDER`. The iframe CSP blocks CDN
51
+ * script fetches, so the runtime must be inlined at startup rather than
52
+ * imported. `ext-apps` is an optional peer — a clear error is thrown if the
53
+ * widget needs the bundle but the peer is not installed.
54
+ *
55
+ * The bundle's trailing `export{…}` is rewritten to `globalThis.ExtApps = {…}`
56
+ * so an inline `<script type="module">` can read `globalThis.ExtApps`.
57
+ */
58
+ export declare function inlineMcpAppBundle(html: string): string;
59
+ //# sourceMappingURL=mcp-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-app.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-app.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,8BAA8B,CAAC;AAE9D,oFAAoF;AACpF,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gFAAgF;IAChF,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,0BAA0B;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,kDAAkD;IAClD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACxB,uEAAuE;IACvE,IAAI,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtC;AAID;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA4BvD"}
@@ -1,7 +1,25 @@
1
1
  import { type McpServerBuildConfig } from './mcp';
2
+ import { type ProtectedResourceConfig } from './oauth-metadata';
2
3
  export interface McpHandlerConfig<TAuth> extends McpServerBuildConfig<TAuth> {
3
4
  /** Resolve an incoming request to an identity. Return `null` → 401. */
4
5
  auth: (req: Request) => TAuth | null | Promise<TAuth | null>;
6
+ /**
7
+ * OAuth 2.0 Protected Resource metadata (RFC 9728). When set, a `401` carries
8
+ * a `WWW-Authenticate: Bearer resource_metadata="…"` header so an MCP client
9
+ * can discover the authorization server. Serve the matching metadata document
10
+ * with `oauthProtectedResourceRoute(protectedResource)`.
11
+ */
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;
5
23
  }
6
24
  /**
7
25
  * Build a Streamable-HTTP MCP request handler (`Request → Response`).
@@ -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;AAyDtF,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;CAC9D;AAYD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EACpC,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAC9B,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA+DrC"}
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,CAkHrC"}
@@ -1,6 +1,7 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { ServiceDef, StitchLogger } from '../server/types';
3
3
  import { type ToolCallHooks, type ToolLifecycle } from './execute';
4
+ import { type McpResourceDef } from './mcp-app';
4
5
  import { type ToolExtend } from './mount';
5
6
  /**
6
7
  * What to do when a tool's schema cannot be advertised on the MCP surface — a
@@ -74,6 +75,8 @@ export interface McpServerBuildConfig<TAuth> {
74
75
  /** Register native (non-contract) MCP tools — receives the `McpServer`
75
76
  * directly. For tools returning multimodal content, e.g. `mountViewFile`. */
76
77
  nativeTools?: (server: McpServer) => void;
78
+ /** MCP Apps UI resources (`ui://…`) served for tools that declare `ui`. */
79
+ resources?: McpResourceDef[];
77
80
  /** Server instructions — a short (≤2KB) hint to the host on when and how to
78
81
  * use these tools. Surfaced to MCP tool-search. */
79
82
  instructions?: string;
@@ -89,4 +92,10 @@ export interface McpServerBuildConfig<TAuth> {
89
92
  * Transport-agnostic — the shared core behind every MCP transport.
90
93
  */
91
94
  export declare function buildMcpServer<TAuth>(config: McpServerBuildConfig<TAuth>, auth: TAuth): McpServer;
95
+ /**
96
+ * Register one MCP Apps UI resource on an `McpServer`. The `read` callback's
97
+ * HTML is served under the resource `uri` with the apps MIME type; any `ui`
98
+ * metadata (CSP, border, domain) is attached to the content's `_meta.ui`.
99
+ */
100
+ export declare function mountMcpResource(server: McpServer, resource: McpResourceDef): void;
92
101
  //# 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;AAGpE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAGnB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GA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AE,OAAO,CAAC,CAAC;IACnD;+EAC2E;IAC3E,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;0CAEsC;IACtC,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,gFAAgF;IAChF,oBAAoB,CAAC,EAAE,wBAAwB,CAAC;IAChD,0EAA0E;IAC1E,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;kFAC8E;IAC9E,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,2EAA2E;IAC3E,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC;IAC7B;wDACoD;IACpD,YAAY,CAAC,EAAE,MAAM,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,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACpE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAClC,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC,EACnC,IAAI,EAAE,KAAK,GACV,SAAS,CAuBX;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI,CAgBlF"}
@@ -0,0 +1,30 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { z } from 'zod';
3
+ export interface DownloadToolConfig {
4
+ /** Tool name. Default `'download'`. */
5
+ name?: string;
6
+ description: string;
7
+ /** Tool input shape (e.g. `{ url: z.string().optional(), id: z.string().optional() }`). */
8
+ inputSchema: z.ZodRawShape;
9
+ /** Resolve the args to a media URL — `null` when there is nothing to download. */
10
+ resolveUrl: (args: Record<string, unknown>) => Promise<string | null> | string | null;
11
+ /** Directory to save into by default. */
12
+ defaultDir: string;
13
+ /** Read a per-call output directory from the args. */
14
+ dirFromArgs?: (args: Record<string, unknown>) => string | undefined;
15
+ /**
16
+ * Allow downloading from private / internal / loopback hosts. Default `false`
17
+ * — the SSRF guard, since the URL comes from model-controlled args. Enable
18
+ * only in a trusted network.
19
+ */
20
+ allowPrivateHosts?: boolean;
21
+ /** Max bytes to read before aborting (memory cap). Default 100 MB. */
22
+ maxBytes?: number;
23
+ }
24
+ /**
25
+ * Register a native "download" tool — resolves a URL from the args, fetches it
26
+ * and writes it to disk with a content-type / URL-derived extension. Returns
27
+ * the saved path / size / mime.
28
+ */
29
+ export declare function mountDownload(server: McpServer, config: DownloadToolConfig): void;
30
+ //# sourceMappingURL=mount-download.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount-download.d.ts","sourceRoot":"","sources":["../../src/tools/mount-download.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA0C7B,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,2FAA2F;IAC3F,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC;IAC3B,kFAAkF;IAClF,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;IACtF,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;IACpE;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAkDjF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * `mountUpload` — a generic native MCP tool that uploads a local file. The app
3
+ * injects how to read + send the file (`upload`); the tool wiring lives here.
4
+ * → ADR 0019.
5
+ */
6
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
7
+ export interface UploadToolConfig {
8
+ /** Tool name. Default `'upload'`. */
9
+ name?: string;
10
+ description: string;
11
+ /** Read a local `path` and upload it, returning whatever the upload yields. */
12
+ upload: (path: string) => Promise<unknown>;
13
+ }
14
+ /**
15
+ * Register a native "upload" tool — takes a local `path`, hands it to
16
+ * `config.upload` (which reads + sends it) and returns the result.
17
+ */
18
+ export declare function mountUpload(server: McpServer, config: UploadToolConfig): void;
19
+ //# sourceMappingURL=mount-upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount-upload.d.ts","sourceRoot":"","sources":["../../src/tools/mount-upload.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,MAAM,WAAW,gBAAgB;IAC/B,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAyB7E"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * `mountWait` — a generic native MCP tool that blocks until an async job
3
+ * reaches a terminal state. The poll loop is the shared `pollUntil`; the app
4
+ * injects only the domain bits (what to poll, when it's done). Owns the MCP
5
+ * wiring so the consumer never imports `@modelcontextprotocol/sdk`. → ADR 0019.
6
+ */
7
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
8
+ import type { z } from 'zod';
9
+ export interface WaitToolConfig {
10
+ /** Tool name. Default `'wait'`. */
11
+ name?: string;
12
+ description: string;
13
+ /** Tool input shape (e.g. `{ id: z.string() }`). */
14
+ inputSchema: z.ZodRawShape;
15
+ /** Fetch the current state for the call's args — one poll tick. */
16
+ poll: (args: Record<string, unknown>) => Promise<unknown>;
17
+ /** Terminal when this returns `true`. */
18
+ done: (state: unknown) => boolean;
19
+ /** Read a per-call timeout (seconds) from the args. */
20
+ timeoutFromArgs?: (args: Record<string, unknown>) => number | undefined;
21
+ /** Backoff schedule in seconds; the last entry repeats. */
22
+ backoff?: number[];
23
+ /** Default timeout in seconds. */
24
+ defaultTimeout?: number;
25
+ /** Render the final state. Default: pretty JSON, `isError` on timeout. */
26
+ render?: (state: unknown, timedOut: boolean) => {
27
+ text: string;
28
+ isError: boolean;
29
+ };
30
+ }
31
+ /**
32
+ * Register a native "wait" tool — polls `config.poll(args)` with backoff until
33
+ * `config.done` or the timeout, then returns the final state.
34
+ */
35
+ export declare function mountWait(server: McpServer, config: WaitToolConfig): void;
36
+ //# sourceMappingURL=mount-wait.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount-wait.d.ts","sourceRoot":"","sources":["../../src/tools/mount-wait.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAK7B,MAAM,WAAW,cAAc;IAC7B,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC;IAC3B,mEAAmE;IACnE,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1D,yCAAyC;IACzC,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAClC,uDAAuD;IACvD,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;IACxE,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,kCAAkC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,KAAK;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CACpF;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CA2BzE"}
@@ -10,12 +10,16 @@ import { type ToolCallHooks, type ToolLifecycle, type ToolResult } from './execu
10
10
  /**
11
11
  * Extra arguments folded into a mounted tool's schema — the host supplies them,
12
12
  * `resolve` turns them into handler context. Shared by `mountMcp` / `mountAgent`.
13
+ *
14
+ * `TContext` is the typed handler context the extension contributes — left as
15
+ * `Record<string, unknown>` for the untyped mounts, pinned by `createToolkit`
16
+ * so `resolve` is checked against the app's context shape.
13
17
  */
14
- export interface ToolExtend {
18
+ export interface ToolExtend<TContext extends Record<string, unknown> = Record<string, unknown>> {
15
19
  /** Extra Zod fields added to every (matching) tool's input schema. */
16
20
  schema: Record<string, z.ZodType>;
17
21
  /** Turn the extra arguments into context merged into the handler. */
18
- resolve: (args: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>;
22
+ resolve: (args: Record<string, unknown>) => Partial<TContext> | Promise<Partial<TContext>>;
19
23
  /** Limit the extension to specific methods — default: every method. */
20
24
  filter?: (service: ServiceDef, method: MethodDef) => boolean;
21
25
  }
@@ -32,8 +36,6 @@ export interface MountableTool {
32
36
  }
33
37
  export interface CollectToolsConfig {
34
38
  extend?: ToolExtend;
35
- /** Coerce JSON-stringified arrays/objects in tool arguments. Default: true. */
36
- coerceJsonArgs?: boolean;
37
39
  /** Flatten discriminated union inputs into a single object for MCP. Default: false. */
38
40
  flattenUnionInput?: boolean;
39
41
  }
@@ -56,6 +58,8 @@ export interface ToolRunnerConfig {
56
58
  lifecycle?: ToolLifecycle;
57
59
  /** Global error hint injected into every failed tool result. */
58
60
  errorHint?: (toolName: string, errorCode: string) => string | null;
61
+ /** Coerce JSON-stringified arrays/objects in tool arguments. Default: true. */
62
+ coerceJsonArgs?: boolean;
59
63
  }
60
64
  /**
61
65
  * Build the call executor for a mount — resolve the extend context, strip the
@@ -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;AAE7D,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAKnB;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;IAClC,qEAAqE;IACrE,OAAO,EAAE,CACP,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO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AE,OAAO,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAsBhF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,EAC1C,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GACjE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The MCP text-content result shape shared by the native tools (`mountWait`,
3
+ * `mountDownload`, `mountUpload`) — one place so each tool file does not
4
+ * re-spell the `{ content: [{ type: 'text' }], isError }` envelope.
5
+ */
6
+ export interface NativeTextResult {
7
+ content: Array<{
8
+ type: 'text';
9
+ text: string;
10
+ }>;
11
+ isError?: boolean;
12
+ /** MCP tool results carry an open `_meta` etc. — the SDK's result type is index-signed. */
13
+ [key: string]: unknown;
14
+ }
15
+ /** A single text block, optionally flagged as an error. */
16
+ export declare function textResult(text: string, isError?: boolean): NativeTextResult;
17
+ //# sourceMappingURL=native-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-result.d.ts","sourceRoot":"","sources":["../../src/tools/native-result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,2FAA2F;IAC3F,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,2DAA2D;AAC3D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,gBAAgB,CAG1E"}
@@ -0,0 +1,28 @@
1
+ import type { RawRoute } from '../server/types';
2
+ /**
3
+ * OAuth 2.0 Protected Resource Metadata (RFC 9728). An MCP server acting as a
4
+ * resource server publishes this so a client, after a `401`, can discover which
5
+ * authorization server(s) issue tokens for it.
6
+ */
7
+ export interface ProtectedResourceConfig {
8
+ /** Canonical resource identifier — the MCP server URL (RFC 8707 audience). */
9
+ resource: string;
10
+ /** Issuer URL(s) of the authorization server(s) that mint tokens for it. */
11
+ authorizationServers: string[];
12
+ /** Scopes the resource understands — advertised, not enforced here. */
13
+ scopesSupported?: string[];
14
+ }
15
+ /** Well-known prefix for the protected-resource metadata document (RFC 9728). */
16
+ export declare const PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource";
17
+ /** Absolute URL of the protected-resource metadata for a given resource. */
18
+ export declare function protectedResourceMetadataUrl(resource: string): string;
19
+ /** The `WWW-Authenticate` header value a protected `401` must carry (RFC 9728 §5.1). */
20
+ export declare function wwwAuthenticateHeader(resource: string): string;
21
+ /**
22
+ * A `RawRoute` serving the RFC 9728 protected-resource metadata at the path
23
+ * advertised by `protectedResourceMetadataUrl(config.resource)`. Mount it
24
+ * alongside the MCP handler; set the matching `protectedResource` on
25
+ * `createMcpHandler` so the `401` points here.
26
+ */
27
+ export declare function oauthProtectedResourceRoute(config: ProtectedResourceConfig): RawRoute;
28
+ //# sourceMappingURL=oauth-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-metadata.d.ts","sourceRoot":"","sources":["../../src/tools/oauth-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,uEAAuE;IACvE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,iFAAiF;AACjF,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAa/E,4EAA4E;AAC5E,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wFAAwF;AACxF,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE9D;AASD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,uBAAuB,GAAG,QAAQ,CAqBrF"}