stitchkit 0.123.7 → 0.124.1

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 (104) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/dist/entrypoints/agent-runtime/coding-tools.js +1 -1
  3. package/dist/entrypoints/agent-runtime/realtime.js +3 -3
  4. package/dist/entrypoints/agent-runtime/sandbox.js +1 -1
  5. package/dist/entrypoints/agent-runtime/sqlite/bun.js +3 -3
  6. package/dist/entrypoints/agent-runtime/sqlite/node.js +3 -3
  7. package/dist/entrypoints/agent-runtime/testing.js +3 -3
  8. package/dist/entrypoints/agent-runtime.js +3 -3
  9. package/dist/entrypoints/application/diagnostic-journal.js +3 -5
  10. package/dist/entrypoints/application/directory-inbox.js +9 -11
  11. package/dist/entrypoints/application.js +3 -3
  12. package/dist/entrypoints/cli/publish.js +6 -6
  13. package/dist/entrypoints/cli.js +7 -4
  14. package/dist/entrypoints/files.js +5 -5
  15. package/dist/entrypoints/index.js +3 -3
  16. package/dist/entrypoints/server.js +6 -6
  17. package/dist/entrypoints/telegram.js +2 -2
  18. package/dist/entrypoints/tools/connections.d.ts +2 -2
  19. package/dist/entrypoints/tools/connections.d.ts.map +1 -1
  20. package/dist/entrypoints/tools/connections.js +121 -29
  21. package/dist/entrypoints/tools/contract.d.ts +1 -1
  22. package/dist/entrypoints/tools/contract.d.ts.map +1 -1
  23. package/dist/entrypoints/tools/contract.js +3 -1
  24. package/dist/entrypoints/tools/mcp.d.ts +1 -1
  25. package/dist/entrypoints/tools/mcp.d.ts.map +1 -1
  26. package/dist/entrypoints/tools/mcp.js +8 -6
  27. package/dist/entrypoints/tools/toolkit.js +3 -3
  28. package/dist/entrypoints/tools.d.ts +1 -1
  29. package/dist/entrypoints/tools.d.ts.map +1 -1
  30. package/dist/entrypoints/tools.js +25 -30
  31. package/dist/{index-jswst0h3.js → index-03qrr49d.js} +49 -4
  32. package/dist/{index-8yky60kq.js → index-1szhrfsf.js} +5 -7
  33. package/dist/{index-mqttte96.js → index-3ymcmpa9.js} +3 -5
  34. package/dist/{index-v8xm2s9v.js → index-7177dxjn.js} +1 -1
  35. package/dist/{index-2x2ch0bt.js → index-782qtc24.js} +1 -1
  36. package/dist/{index-j8rda9n6.js → index-8pwwd6rp.js} +3 -3
  37. package/dist/{index-m616f0yz.js → index-8x0q6yfb.js} +134 -7
  38. package/dist/{index-1a741dpf.js → index-e1x6vze4.js} +10 -4
  39. package/dist/{index-ezwvsqx9.js → index-fvd6pvw3.js} +1 -1
  40. package/dist/{index-bknzva6n.js → index-gy9x38a2.js} +4 -3
  41. package/dist/{index-w0wy05gr.js → index-jkjh7zw4.js} +50 -40
  42. package/dist/{index-ac6vvm30.js → index-jp2qd9jb.js} +1 -1
  43. package/dist/index-mm89hd8v.js +39 -0
  44. package/dist/{index-jc5xgkpk.js → index-qsm899qp.js} +1 -1
  45. package/dist/index-wqzw3qg9.js +91 -0
  46. package/dist/{index-364k2zwa.js → index-wt6rw7rf.js} +5 -7
  47. package/dist/{index-tt3ej8r3.js → index-x0769xt9.js} +217 -24
  48. package/dist/internal/deadline.d.ts +30 -0
  49. package/dist/internal/deadline.d.ts.map +1 -1
  50. package/dist/internal/pinned-http.d.ts +1 -1
  51. package/dist/internal/pinned-http.d.ts.map +1 -1
  52. package/dist/internal/secure-fetch.d.ts +8 -0
  53. package/dist/internal/secure-fetch.d.ts.map +1 -1
  54. package/dist/tools/cli/inline-files.d.ts +5 -5
  55. package/dist/tools/cli/inline-files.d.ts.map +1 -1
  56. package/dist/tools/cli/resumable-download.d.ts +18 -0
  57. package/dist/tools/cli/resumable-download.d.ts.map +1 -0
  58. package/dist/tools/cli/update.d.ts +18 -0
  59. package/dist/tools/cli/update.d.ts.map +1 -1
  60. package/dist/tools/connections/catalog-cache.d.ts +9 -0
  61. package/dist/tools/connections/catalog-cache.d.ts.map +1 -0
  62. package/dist/tools/connections/errors.d.ts +10 -1
  63. package/dist/tools/connections/errors.d.ts.map +1 -1
  64. package/dist/tools/connections/limits.d.ts +16 -4
  65. package/dist/tools/connections/limits.d.ts.map +1 -1
  66. package/dist/tools/connections/mcp-client.d.ts +10 -2
  67. package/dist/tools/connections/mcp-client.d.ts.map +1 -1
  68. package/dist/tools/connections/mcp.d.ts.map +1 -1
  69. package/dist/tools/connections/operation-limits.d.ts +12 -1
  70. package/dist/tools/connections/operation-limits.d.ts.map +1 -1
  71. package/dist/tools/connections/sse-session.d.ts +2 -2
  72. package/dist/tools/connections/sse-session.d.ts.map +1 -1
  73. package/dist/tools/connections/types.d.ts +38 -2
  74. package/dist/tools/connections/types.d.ts.map +1 -1
  75. package/dist/tools/mcp/catalog-stamp.d.ts +47 -0
  76. package/dist/tools/mcp/catalog-stamp.d.ts.map +1 -0
  77. package/dist/tools/mcp/catalog.d.ts +1 -30
  78. package/dist/tools/mcp/catalog.d.ts.map +1 -1
  79. package/dist/tools/mcp/handler.d.ts.map +1 -1
  80. package/dist/tools/mcp/mount.d.ts +6 -1
  81. package/dist/tools/mcp/mount.d.ts.map +1 -1
  82. package/dist/tools/mcp/register.d.ts +1 -1
  83. package/dist/tools/mcp/register.d.ts.map +1 -1
  84. package/dist/tools/mcp/runtime-tools.d.ts +1 -1
  85. package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
  86. package/dist/tools/transfer/view-file-contract.d.ts +17 -6
  87. package/dist/tools/transfer/view-file-contract.d.ts.map +1 -1
  88. package/dist/tools/transfer/view-file.d.ts +1 -1
  89. package/dist/tools/transfer/view-file.d.ts.map +1 -1
  90. package/llms/cli.2.txt +60 -6
  91. package/llms/cli.txt +3 -2
  92. package/llms/stitchkit.txt +3 -3
  93. package/llms/tools-connections.txt +5 -3
  94. package/llms/tools-mcp.txt +5 -2
  95. package/llms/tools.2.txt +10 -4
  96. package/llms/tools.3.txt +2 -1
  97. package/llms/tools.txt +10 -3
  98. package/llms/{upgrading-0.106.0-0.123.0.txt → upgrading-0.106.0-0.124.0.txt} +39 -3
  99. package/llms/upgrading.txt +1 -1
  100. package/llms-full.txt +134 -24
  101. package/llms.txt +5 -5
  102. package/package.json +1 -1
  103. package/dist/index-9tqbxv5p.js +0 -44
  104. package/dist/index-b56nnscm.js +0 -132
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  raceAbort
3
3
  } from "./index-b0kddvzw.js";
4
+ import {
5
+ startIdleTimer
6
+ } from "./index-wqzw3qg9.js";
4
7
  import {
5
8
  readBoundedChunks
6
9
  } from "./index-5efrpfmj.js";
@@ -25,7 +28,7 @@ async function requestPinned(url, resolved, signal, headers = {}) {
25
28
  method: "GET",
26
29
  signal,
27
30
  ...url.protocol === "https:" ? { servername: url.hostname } : {},
28
- headers: { host: url.host, accept: "*/*", ...headers }
31
+ headers: { accept: "*/*", ...headers, host: url.host }
29
32
  }, (response) => {
30
33
  answered = true;
31
34
  resolve(response);
@@ -200,6 +203,7 @@ async function fetchGuarded(start, allowPrivate, options = {}) {
200
203
  controller.abort(new Error(`fetch did not produce response headers within ${timeoutMs}ms`));
201
204
  }, timeoutMs);
202
205
  headerTimer.unref?.();
206
+ const idle = options.idleTimeoutMs === undefined ? undefined : startIdleTimer(options.idleTimeoutMs, () => controller.abort(new Error(`fetch received nothing for ${options.idleTimeoutMs}ms`)), { unref: true });
203
207
  const transport = options.transport ?? requestPinned;
204
208
  let settled = false;
205
209
  try {
@@ -209,7 +213,9 @@ async function fetchGuarded(start, allowPrivate, options = {}) {
209
213
  throw new Error("refusing to fetch a URL that carries credentials");
210
214
  }
211
215
  const resolved = await resolveAddress(url, allowPrivate, signal, options.dns);
212
- const res = await transport(url, resolved, signal);
216
+ const headers = url.origin === start.origin ? options.headers : undefined;
217
+ const res = await transport(url, resolved, signal, headers);
218
+ idle?.touch();
213
219
  const location = res.status >= 300 && res.status < 400 ? res.headers.get("location") : null;
214
220
  if (location === null) {
215
221
  settled = true;
@@ -218,16 +224,55 @@ async function fetchGuarded(start, allowPrivate, options = {}) {
218
224
  controller.abort(new Error(`fetch body was not consumed within ${bodyTimeoutMs}ms`));
219
225
  }, bodyTimeoutMs);
220
226
  bodyTimer.unref?.();
221
- return res;
227
+ return observeBody(res, signal, idle, bodyTimer);
222
228
  }
223
229
  await res.body?.cancel();
224
230
  url = new URL(location, url);
225
231
  }
226
232
  throw new Error("too many redirects");
227
233
  } finally {
228
- if (!settled)
234
+ if (!settled) {
229
235
  clearTimeout(headerTimer);
236
+ idle?.stop();
237
+ }
238
+ }
239
+ }
240
+ function observeBody(res, signal, idle, bodyTimer) {
241
+ const end = () => {
242
+ idle?.stop();
243
+ clearTimeout(bodyTimer);
244
+ };
245
+ if (!res.body) {
246
+ end();
247
+ return res;
230
248
  }
249
+ const reader = res.body.getReader();
250
+ const body = new ReadableStream({
251
+ async pull(controller) {
252
+ try {
253
+ const { done, value } = await reader.read();
254
+ if (done) {
255
+ end();
256
+ controller.close();
257
+ return;
258
+ }
259
+ idle?.touch();
260
+ controller.enqueue(value);
261
+ } catch (error) {
262
+ end();
263
+ controller.error(signal.aborted ? signal.reason : error);
264
+ }
265
+ },
266
+ cancel(reason) {
267
+ end();
268
+ return reader.cancel(reason);
269
+ }
270
+ });
271
+ return new Response(body, {
272
+ status: res.status,
273
+ statusText: res.statusText,
274
+ headers: res.headers
275
+ });
231
276
  }
232
277
  async function resolveAddress(url, allowPrivate, signal, dns) {
233
278
  if (!allowPrivate)
@@ -1,15 +1,13 @@
1
1
  import {
2
2
  withExclusiveLock2
3
- } from "./index-ezwvsqx9.js";
4
- import {
5
- readBoundedFile
6
- } from "./index-m616f0yz.js";
3
+ } from "./index-fvd6pvw3.js";
7
4
  import {
8
5
  writeAtomicFileData
9
- } from "./index-ac6vvm30.js";
6
+ } from "./index-jp2qd9jb.js";
10
7
  import {
11
- publishAtomicFile
12
- } from "./index-b56nnscm.js";
8
+ publishAtomicFile,
9
+ readBoundedFile
10
+ } from "./index-8x0q6yfb.js";
13
11
  import {
14
12
  errnoOf
15
13
  } from "./index-jj9228tt.js";
@@ -5,13 +5,11 @@ import {
5
5
  probeProcessOwner2
6
6
  } from "./index-bqzgaj57.js";
7
7
  import {
8
+ AtomicFilePublicationError2,
9
+ publishAtomicFile,
8
10
  BoundedFileReadError,
9
11
  readBoundedFile
10
- } from "./index-m616f0yz.js";
11
- import {
12
- AtomicFilePublicationError2,
13
- publishAtomicFile
14
- } from "./index-b56nnscm.js";
12
+ } from "./index-8x0q6yfb.js";
15
13
  import {
16
14
  isRecord
17
15
  } from "./index-hkxgennw.js";
@@ -4,7 +4,7 @@ import {
4
4
  AgentSandboxRestrictionSchema2,
5
5
  AgentSandboxGradeSchema2,
6
6
  AGENT_CODING_TOOL_NAMES
7
- } from "./index-j8rda9n6.js";
7
+ } from "./index-8pwwd6rp.js";
8
8
  import {
9
9
  AgentRecordIdSchema2,
10
10
  AgentRecordVersionSchema2,
@@ -17,7 +17,7 @@ import {
17
17
  replaceMessage,
18
18
  ArchiveSpillSchema,
19
19
  createAgentRuntimeStore2
20
- } from "./index-v8xm2s9v.js";
20
+ } from "./index-7177dxjn.js";
21
21
 
22
22
  // src/agent-runtime/store-memory.ts
23
23
  import { z as z2 } from "zod";
@@ -28,15 +28,15 @@ import {
28
28
  containedEntryMetadata,
29
29
  openContainedParentFile
30
30
  } from "./index-ww3gss55.js";
31
- import {
32
- withSignalDeadline
33
- } from "./index-9tqbxv5p.js";
34
31
  import {
35
32
  defineRuntimeTool2
36
33
  } from "./index-6k47xdtt.js";
37
34
  import {
38
35
  errnoOf
39
36
  } from "./index-jj9228tt.js";
37
+ import {
38
+ withSignalDeadline
39
+ } from "./index-wqzw3qg9.js";
40
40
  import {
41
41
  MAX_TIMER_MS
42
42
  } from "./index-eemvahkc.js";
@@ -1,10 +1,137 @@
1
- import {
2
- closeAfter
3
- } from "./index-b56nnscm.js";
1
+ // src/internal/atomic-publication.ts
2
+ import { closeSync, fsyncSync, linkSync, openSync, renameSync, unlinkSync } from "node:fs";
3
+ import { link, open, rename, unlink } from "node:fs/promises";
4
+ import { dirname } from "node:path";
5
+
6
+ // src/internal/close-after.ts
7
+ async function closeAfter(handle, run) {
8
+ let result;
9
+ try {
10
+ result = await run();
11
+ } catch (error) {
12
+ await handle.close().catch(() => {
13
+ return;
14
+ });
15
+ throw error;
16
+ }
17
+ await handle.close();
18
+ return result;
19
+ }
20
+ function closeAfterSync(close, run) {
21
+ let result;
22
+ try {
23
+ result = run();
24
+ } catch (error) {
25
+ try {
26
+ close();
27
+ } catch {}
28
+ throw error;
29
+ }
30
+ close();
31
+ return result;
32
+ }
33
+
34
+ // src/internal/atomic-publication.ts
35
+ class AtomicFilePublicationError2 extends Error {
36
+ phase;
37
+ published = true;
38
+ constructor(phase, cause) {
39
+ super(`File published but ${phase} failed`, { cause });
40
+ this.phase = phase;
41
+ this.name = "AtomicFilePublicationError";
42
+ }
43
+ }
44
+ var native = { rename, link, unlink, open };
45
+ var nativeSync = {
46
+ rename: renameSync,
47
+ link: linkSync,
48
+ unlink: unlinkSync,
49
+ open(path, flags) {
50
+ const descriptor = openSync(path, flags);
51
+ return { sync: () => fsyncSync(descriptor), close: () => closeSync(descriptor) };
52
+ }
53
+ };
54
+ function assertDirectoryDurability() {
55
+ if (process.platform === "win32")
56
+ throw new Error("Directory durability is unsupported on Windows");
57
+ }
58
+ async function syncDirectory(path, io = native) {
59
+ assertDirectoryDurability();
60
+ const directory = await io.open(path, "r");
61
+ await closeAfter(directory, () => directory.sync());
62
+ }
63
+ async function publishAtomicFile(staged, target, { replace, durability }, io = native) {
64
+ const directorySync = durability === "directory";
65
+ if (directorySync)
66
+ assertDirectoryDurability();
67
+ const directory = directorySync ? await io.open(dirname(target), "r") : undefined;
68
+ const publish = async () => {
69
+ if (replace)
70
+ await io.rename(staged, target);
71
+ else {
72
+ await io.link(staged, target);
73
+ try {
74
+ await io.unlink(staged);
75
+ } catch (error) {
76
+ throw new AtomicFilePublicationError2("cleanup", error);
77
+ }
78
+ }
79
+ try {
80
+ await directory?.sync();
81
+ } catch (error) {
82
+ throw new AtomicFilePublicationError2("directory-sync", error);
83
+ }
84
+ };
85
+ if (directory === undefined)
86
+ return publish();
87
+ await closeAfter({
88
+ close: async () => {
89
+ try {
90
+ await directory.close();
91
+ } catch (error) {
92
+ throw new AtomicFilePublicationError2("directory-close", error);
93
+ }
94
+ }
95
+ }, publish);
96
+ }
97
+ function publishAtomicFileSync(staged, target, { replace, durability }, io = nativeSync) {
98
+ const directorySync = durability === "directory";
99
+ if (directorySync)
100
+ assertDirectoryDurability();
101
+ const directory = directorySync ? io.open(dirname(target), "r") : undefined;
102
+ const publish = () => {
103
+ if (replace)
104
+ io.rename(staged, target);
105
+ else {
106
+ io.link(staged, target);
107
+ try {
108
+ io.unlink(staged);
109
+ } catch (error) {
110
+ throw new AtomicFilePublicationError2("cleanup", error);
111
+ }
112
+ }
113
+ try {
114
+ directory?.sync();
115
+ } catch (error) {
116
+ throw new AtomicFilePublicationError2("directory-sync", error);
117
+ }
118
+ };
119
+ if (directory === undefined) {
120
+ publish();
121
+ return;
122
+ }
123
+ closeAfterSync(() => {
124
+ try {
125
+ directory.close();
126
+ } catch (error) {
127
+ throw new AtomicFilePublicationError2("directory-close", error);
128
+ }
129
+ }, publish);
130
+ }
4
131
 
5
132
  // src/internal/bounded-file-read.ts
6
133
  import { constants } from "node:fs";
7
- import { open } from "node:fs/promises";
134
+ import { open as open2 } from "node:fs/promises";
8
135
  class BoundedFileReadError extends Error {
9
136
  code;
10
137
  observation;
@@ -53,10 +180,10 @@ async function openChecked(target, options, openDescriptor) {
53
180
  }
54
181
  }
55
182
  function openRegularFile(target, options = {}) {
56
- return openChecked(target, options, open);
183
+ return openChecked(target, options, open2);
57
184
  }
58
185
  var tooLarge = (maxBytes, observation) => new BoundedFileReadError("FILE_TOO_LARGE", `file exceeds the ${maxBytes}-byte cap`, observation);
59
- async function readBoundedFile(target, maxBytes, options = {}, openDescriptor = open) {
186
+ async function readBoundedFile(target, maxBytes, options = {}, openDescriptor = open2) {
60
187
  options.signal?.throwIfAborted();
61
188
  const { handle, before } = await openChecked(target, options, openDescriptor);
62
189
  return closeAfter(handle, async () => {
@@ -117,4 +244,4 @@ async function readHandle(handle, maxBytes, signal) {
117
244
  return bytes;
118
245
  }
119
246
 
120
- export { BoundedFileReadError, openRegularFile, readBoundedFile };
247
+ export { closeAfter, closeAfterSync, AtomicFilePublicationError2, assertDirectoryDurability, syncDirectory, publishAtomicFile, publishAtomicFileSync, BoundedFileReadError, openRegularFile, readBoundedFile };
@@ -31,9 +31,10 @@ import {
31
31
  isRepeatableRead
32
32
  } from "./index-332d0m9g.js";
33
33
  import {
34
+ MCP_FILE_NAME_META_KEY2,
34
35
  McpImageContentSchema,
35
36
  McpAudioContentSchema
36
- } from "./index-bknzva6n.js";
37
+ } from "./index-gy9x38a2.js";
37
38
  import {
38
39
  readContractStreamItems,
39
40
  contractStreamLifetimeExceeded
@@ -56,7 +57,7 @@ import {
56
57
  import {
57
58
  fetchGuarded,
58
59
  readCapped
59
- } from "./index-jswst0h3.js";
60
+ } from "./index-03qrr49d.js";
60
61
  import {
61
62
  errnoOf
62
63
  } from "./index-jj9228tt.js";
@@ -1021,9 +1022,14 @@ function uriFileName(uri) {
1021
1022
  function inlineFileMimeType(file) {
1022
1023
  return file.type === "resource" ? file.resource.mimeType : file.mimeType;
1023
1024
  }
1025
+ function ownFileName(file) {
1026
+ if (file.type === "resource")
1027
+ return uriFileName(file.resource.uri) || undefined;
1028
+ const name = file._meta?.[MCP_FILE_NAME_META_KEY2];
1029
+ return typeof name === "string" ? name : undefined;
1030
+ }
1024
1031
  function inlineFileName(file, digest) {
1025
- const own = file.type === "resource" ? uriFileName(file.resource.uri) || undefined : file.name;
1026
- return own ?? `${file.type}-${digest}${mediaExtension(inlineFileMimeType(file) ?? "") ?? ".bin"}`;
1032
+ return ownFileName(file) ?? `${file.type}-${digest}${mediaExtension(inlineFileMimeType(file) ?? "") ?? ".bin"}`;
1027
1033
  }
1028
1034
  function linkSavedFiles(data, blocks, saved) {
1029
1035
  if (!isRecord(data) || !Array.isArray(data.content))
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  attemptExclusiveLock
3
- } from "./index-mqttte96.js";
3
+ } from "./index-3ymcmpa9.js";
4
4
  import {
5
5
  sleep
6
6
  } from "./index-eemvahkc.js";
@@ -5,11 +5,12 @@ var McpAnnotationsSchema2 = z.object({
5
5
  audience: z.array(z.enum(["user", "assistant"])).optional(),
6
6
  priority: z.number().optional()
7
7
  });
8
+ var MCP_FILE_NAME_META_KEY2 = "stitchkit/fileName";
8
9
  var inlineMediaShape = {
9
10
  data: z.string(),
10
11
  mimeType: z.string(),
11
- name: z.string().optional(),
12
- annotations: McpAnnotationsSchema2.optional()
12
+ annotations: McpAnnotationsSchema2.optional(),
13
+ _meta: z.record(z.string(), z.unknown()).optional()
13
14
  };
14
15
  var McpImageContentSchema = z.object({
15
16
  type: z.literal("image"),
@@ -36,4 +37,4 @@ var ViewFileInputSchema2 = z.object({
36
37
  paths: z.union([z.string(), z.array(z.string()).max(MAX_VIEW_FILES)]).describe("One media URL or file path, or an array of them. Pass the array itself, not JSON written as text.")
37
38
  });
38
39
 
39
- export { McpAnnotationsSchema2, McpImageContentSchema, McpAudioContentSchema, McpMediaContentSchema2, ViewFileErrorSchema2, ViewFileOutputSchema2, ViewFileInputSchema2 };
40
+ export { McpAnnotationsSchema2, MCP_FILE_NAME_META_KEY2, McpImageContentSchema, McpAudioContentSchema, McpMediaContentSchema2, ViewFileErrorSchema2, ViewFileOutputSchema2, ViewFileInputSchema2 };
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  toJsonSchema
3
3
  } from "./index-ct75c3at.js";
4
- import {
5
- publishedToolAnnotations
6
- } from "./index-332d0m9g.js";
7
4
  import {
8
5
  toolSurfaceOutputSchema,
9
6
  staticInputRounds,
@@ -22,9 +19,17 @@ import {
22
19
  createToolRunner,
23
20
  formatToolError
24
21
  } from "./index-qc7tq0za.js";
22
+ import {
23
+ publishedToolAnnotations
24
+ } from "./index-332d0m9g.js";
25
25
  import {
26
26
  redact2
27
27
  } from "./index-fpwbskp2.js";
28
+ import {
29
+ MCP_CATALOG_HEADER,
30
+ mcpCatalogMeta2,
31
+ mcpCatalogHeaderValue
32
+ } from "./index-mm89hd8v.js";
28
33
  import {
29
34
  argumentsDigest
30
35
  } from "./index-mfntvj58.js";
@@ -78,9 +83,23 @@ function inlineMcpAppBundle2(html) {
78
83
  return html.replace(EXT_APPS_BUNDLE_PLACEHOLDER2, () => bundle);
79
84
  }
80
85
 
86
+ // src/tools/mcp/handler.ts
87
+ import {
88
+ createMcpHandler as createSdkMcpHandler,
89
+ hostHeaderValidationResponse,
90
+ localhostAllowedHostnames,
91
+ localhostAllowedOrigins,
92
+ originValidationResponse
93
+ } from "@modelcontextprotocol/server";
94
+
95
+ // src/tools/mcp/mount.ts
96
+ import {
97
+ createRequestStateCodec,
98
+ McpServer
99
+ } from "@modelcontextprotocol/server";
100
+
81
101
  // src/tools/mcp/catalog.ts
82
102
  import { createHash } from "node:crypto";
83
- var MCP_CATALOG_META_KEY2 = "stitchkit/catalog";
84
103
  var stampCache = new WeakMap;
85
104
  function toolFingerprint(descriptor) {
86
105
  const { mountable } = descriptor;
@@ -89,7 +108,8 @@ function toolFingerprint(descriptor) {
89
108
  description: mountable.method.desc,
90
109
  input: descriptor.inputSchema,
91
110
  output: descriptor.outputSchema ? toJsonSchema(descriptor.outputSchema, "output", "any") : null,
92
- annotations: publishedToolAnnotations(mountable.method) ?? null
111
+ annotations: publishedToolAnnotations(mountable.method) ?? null,
112
+ ui: mountable.method.ui ?? null
93
113
  };
94
114
  }
95
115
  function mcpCatalogStamp(surface) {
@@ -108,22 +128,6 @@ function mcpCatalogStamp(surface) {
108
128
  stampCache.set(surface, stamp);
109
129
  return stamp;
110
130
  }
111
- function mcpCatalogMeta2(stamp) {
112
- return { [MCP_CATALOG_META_KEY2]: { ...stamp } };
113
- }
114
- function readMcpCatalogStamp2(meta) {
115
- if (!isRecord(meta))
116
- return null;
117
- const value = meta[MCP_CATALOG_META_KEY2];
118
- if (!isRecord(value))
119
- return null;
120
- const { digest, tools } = value;
121
- if (typeof digest !== "string" || digest.length === 0)
122
- return null;
123
- if (typeof tools !== "number" || !Number.isInteger(tools) || tools < 0)
124
- return null;
125
- return { digest, tools };
126
- }
127
131
  function stampToolRegistration(config, stamp) {
128
132
  if (!stamp)
129
133
  return config;
@@ -135,21 +139,6 @@ function stampToolResult(result, stamp) {
135
139
  return { ...result, _meta: { ...result._meta, ...mcpCatalogMeta2(stamp) } };
136
140
  }
137
141
 
138
- // src/tools/mcp/handler.ts
139
- import {
140
- createMcpHandler as createSdkMcpHandler,
141
- hostHeaderValidationResponse,
142
- localhostAllowedHostnames,
143
- localhostAllowedOrigins,
144
- originValidationResponse
145
- } from "@modelcontextprotocol/server";
146
-
147
- // src/tools/mcp/mount.ts
148
- import {
149
- createRequestStateCodec,
150
- McpServer
151
- } from "@modelcontextprotocol/server";
152
-
153
142
  // src/tools/mcp/prepare.ts
154
143
  function textBlock(text) {
155
144
  return [{ type: "text", text }];
@@ -764,6 +753,10 @@ function buildMcpServer2(config, auth) {
764
753
  function isMcpServerBuildConfig(value) {
765
754
  return isRecord(value) && isRecord(value.serverInfo);
766
755
  }
756
+ var servedCatalogs = new WeakMap;
757
+ function servedMcpCatalog(server) {
758
+ return servedCatalogs.get(server);
759
+ }
767
760
  function buildMcpServerFromPrepared(config, auth, prepared) {
768
761
  let roundCodec;
769
762
  if (config.multiRound) {
@@ -790,6 +783,8 @@ function buildMcpServerFromPrepared(config, auth, prepared) {
790
783
  const server = new McpServer(config.serverInfo, serverOptions);
791
784
  const context = config.context?.(auth);
792
785
  const catalog = mcpCatalogStamp(prepared);
786
+ if (!config.rawTools)
787
+ servedCatalogs.set(server, catalog);
793
788
  mountPreparedMcp(server, prepared.contractTools, {
794
789
  catalog,
795
790
  context,
@@ -910,7 +905,9 @@ function createMcpHandler2(config) {
910
905
  throw new Error("[stitchkit] MCP request reached the SDK without resolved auth");
911
906
  }
912
907
  const auth = resolved.value;
913
- return buildPrepared ? buildPrepared(auth) : buildMcpServer2(config, auth);
908
+ const server = buildPrepared ? buildPrepared(auth) : buildMcpServer2(config, auth);
909
+ resolved.served = servedMcpCatalog(server);
910
+ return server;
914
911
  }, {
915
912
  legacy: config.legacy === "reject" ? "reject" : "stateless",
916
913
  maxSubscriptions: 0
@@ -955,9 +952,11 @@ function createMcpHandler2(config) {
955
952
  clientId: config.multiRound?.state.principal(auth) ?? "stitchkit",
956
953
  scopes: []
957
954
  };
958
- authByCarrier.set(authCarrier, { value: auth });
955
+ const resolved = { value: auth };
956
+ authByCarrier.set(authCarrier, resolved);
959
957
  try {
960
- return observeRejection(request, await sdkHandler.fetch(request, { authInfo: authCarrier }));
958
+ const response = await sdkHandler.fetch(request, { authInfo: authCarrier });
959
+ return observeRejection(request, withCatalogHeader(response, resolved.served));
961
960
  } finally {
962
961
  authByCarrier.delete(authCarrier);
963
962
  }
@@ -971,6 +970,17 @@ function createMcpHandler2(config) {
971
970
  }
972
971
  };
973
972
  }
973
+ function withCatalogHeader(response, served) {
974
+ if (!served)
975
+ return response;
976
+ const headers = new Headers(response.headers);
977
+ headers.set(MCP_CATALOG_HEADER, mcpCatalogHeaderValue(served));
978
+ return new Response(response.body, {
979
+ status: response.status,
980
+ statusText: response.statusText,
981
+ headers
982
+ });
983
+ }
974
984
  function createMcpHttpRoute2(config) {
975
985
  return {
976
986
  method: "ALL",
@@ -989,4 +999,4 @@ async function createStdioMcpServer2(config) {
989
999
  });
990
1000
  }
991
1001
 
992
- export { RESOURCE_MIME_TYPE2, EXT_APPS_BUNDLE_PLACEHOLDER2, inlineMcpAppBundle2, MCP_CATALOG_META_KEY2, mcpCatalogMeta2, readMcpCatalogStamp2, validateMcpSchemas2, mountMcp2, buildMcpServer2, mountMcpResource2, createMcpHandler2, createMcpHttpRoute2, createStdioMcpServer2 };
1002
+ export { RESOURCE_MIME_TYPE2, EXT_APPS_BUNDLE_PLACEHOLDER2, inlineMcpAppBundle2, validateMcpSchemas2, mountMcp2, buildMcpServer2, mountMcpResource2, createMcpHandler2, createMcpHttpRoute2, createStdioMcpServer2 };
@@ -3,7 +3,7 @@ import {
3
3
  closeAfterSync,
4
4
  publishAtomicFile,
5
5
  publishAtomicFileSync
6
- } from "./index-b56nnscm.js";
6
+ } from "./index-8x0q6yfb.js";
7
7
  import {
8
8
  stagingPath
9
9
  } from "./index-tt30h7mr.js";
@@ -0,0 +1,39 @@
1
+ import {
2
+ isRecord
3
+ } from "./index-hkxgennw.js";
4
+
5
+ // src/tools/mcp/catalog-stamp.ts
6
+ var MCP_CATALOG_META_KEY2 = "stitchkit/catalog";
7
+ var MCP_CATALOG_HEADER = "stitchkit-catalog";
8
+ function mcpCatalogMeta2(stamp) {
9
+ return { [MCP_CATALOG_META_KEY2]: { ...stamp } };
10
+ }
11
+ function mcpCatalogHeaderValue(stamp) {
12
+ return JSON.stringify({ digest: stamp.digest, tools: stamp.tools });
13
+ }
14
+ function readMcpCatalogStamp2(meta) {
15
+ if (!isRecord(meta))
16
+ return null;
17
+ return parseCatalogStamp(meta[MCP_CATALOG_META_KEY2]);
18
+ }
19
+ function readMcpCatalogHeader(value) {
20
+ if (value === null)
21
+ return null;
22
+ try {
23
+ return parseCatalogStamp(JSON.parse(value));
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ function parseCatalogStamp(value) {
29
+ if (!isRecord(value))
30
+ return null;
31
+ const { digest, tools } = value;
32
+ if (typeof digest !== "string" || digest.length === 0)
33
+ return null;
34
+ if (typeof tools !== "number" || !Number.isInteger(tools) || tools < 0)
35
+ return null;
36
+ return { digest, tools };
37
+ }
38
+
39
+ export { MCP_CATALOG_META_KEY2, MCP_CATALOG_HEADER, mcpCatalogMeta2, mcpCatalogHeaderValue, readMcpCatalogStamp2, readMcpCatalogHeader };
@@ -15,7 +15,7 @@ import {
15
15
  appendEventIn,
16
16
  ArchiveProjectionSchema,
17
17
  createAgentRuntimeStore2
18
- } from "./index-v8xm2s9v.js";
18
+ } from "./index-7177dxjn.js";
19
19
  import {
20
20
  AgentMessageSchema2,
21
21
  AgentRunSchema2