toolcraft 0.0.231 → 0.0.233

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 (180) hide show
  1. package/composition.json +3 -3
  2. package/dist/applied-default.d.ts +3 -0
  3. package/dist/applied-default.js +16 -0
  4. package/dist/cli.js +508 -204
  5. package/dist/composition.json +3 -3
  6. package/dist/discriminator.d.ts +9 -0
  7. package/dist/discriminator.js +32 -0
  8. package/dist/error-report.d.ts +2 -18
  9. package/dist/error-report.js +12 -14
  10. package/dist/http.js +8 -1
  11. package/dist/human-in-loop/gate.js +6 -0
  12. package/dist/index.compile-check.js +22 -5
  13. package/dist/index.d.ts +12 -5
  14. package/dist/index.js +50 -0
  15. package/dist/json-schema-converter.d.ts +14 -6
  16. package/dist/json-schema-converter.js +150 -20
  17. package/dist/mcp-proxy-metadata.d.ts +2 -0
  18. package/dist/mcp-proxy-metadata.js +13 -0
  19. package/dist/mcp-proxy.d.ts +1 -0
  20. package/dist/mcp-proxy.js +65 -47
  21. package/dist/mcp-result.d.ts +3 -0
  22. package/dist/mcp-result.js +10 -0
  23. package/dist/mcp.js +211 -153
  24. package/dist/redaction.js +26 -17
  25. package/dist/renderer.js +40 -29
  26. package/dist/schema-member-names.d.ts +2 -0
  27. package/dist/schema-member-names.js +39 -0
  28. package/dist/schema-scope.d.ts +1 -0
  29. package/dist/schema-scope.js +29 -16
  30. package/dist/schema.d.ts +1 -1
  31. package/dist/sdk.d.ts +2 -1
  32. package/dist/sdk.js +164 -50
  33. package/dist/stream.js +24 -23
  34. package/dist/testing/diagnostic-value.d.ts +1 -0
  35. package/dist/testing/diagnostic-value.js +57 -0
  36. package/dist/testing/fakes.js +2 -1
  37. package/dist/testing/harness.js +1 -0
  38. package/dist/testing/memory-fs.js +42 -1
  39. package/dist/testing/parity.js +50 -6
  40. package/dist/union-validation.d.ts +5 -0
  41. package/dist/union-validation.js +36 -0
  42. package/node_modules/@poe-code/process-runner/dist/types.d.ts +2 -0
  43. package/node_modules/mcp-oauth-server/dist/index.js +47 -6
  44. package/node_modules/tiny-http-mcp-server/dist/cli.js +14 -2
  45. package/node_modules/tiny-http-mcp-server/dist/composition.json +1 -1
  46. package/node_modules/tiny-http-mcp-server/dist/http-server.d.ts +7 -5
  47. package/node_modules/tiny-http-mcp-server/dist/http-server.js +3 -11
  48. package/node_modules/tiny-http-mcp-server/dist/http-transport.d.ts +6 -1
  49. package/node_modules/tiny-http-mcp-server/dist/http-transport.js +196 -15
  50. package/node_modules/tiny-http-mcp-server/dist/index.d.ts +2 -2
  51. package/node_modules/tiny-http-mcp-server/dist/modern-headers.d.ts +3 -0
  52. package/node_modules/tiny-http-mcp-server/dist/modern-headers.js +35 -0
  53. package/node_modules/tiny-http-mcp-server/dist/parse-body.d.ts +1 -0
  54. package/node_modules/tiny-http-mcp-server/dist/parse-body.js +9 -5
  55. package/node_modules/tiny-http-mcp-server/dist/test-support.js +17 -0
  56. package/node_modules/tiny-http-mcp-server/dist/testing.d.ts +1 -1
  57. package/node_modules/tiny-http-mcp-server/dist/testing.js +3 -2
  58. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +21 -4
  59. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.d.ts +1 -1
  60. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +14 -6
  61. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-fetch.d.ts +1 -0
  62. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-fetch.js +8 -0
  63. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-response.d.ts +1 -0
  64. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-response.js +50 -0
  65. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +2 -0
  66. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +2 -0
  67. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/server/jwks-token-verifier.js +21 -3
  68. package/node_modules/tiny-http-mcp-server/package.json +1 -1
  69. package/node_modules/tiny-mcp-client/README.md +1 -0
  70. package/node_modules/tiny-mcp-client/dist/index.d.ts +178 -101
  71. package/node_modules/tiny-mcp-client/dist/index.js +4696 -291
  72. package/node_modules/tiny-mcp-client/package.json +2 -1
  73. package/node_modules/tiny-stdio-mcp-server/dist/base64.d.ts +1 -0
  74. package/node_modules/tiny-stdio-mcp-server/dist/base64.js +5 -0
  75. package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
  76. package/node_modules/tiny-stdio-mcp-server/dist/content/audio.d.ts +3 -0
  77. package/node_modules/tiny-stdio-mcp-server/dist/content/convert.d.ts +5 -1
  78. package/node_modules/tiny-stdio-mcp-server/dist/content/convert.js +41 -6
  79. package/node_modules/tiny-stdio-mcp-server/dist/content/file.d.ts +5 -0
  80. package/node_modules/tiny-stdio-mcp-server/dist/content/image.d.ts +3 -0
  81. package/node_modules/tiny-stdio-mcp-server/dist/headers.d.ts +10 -0
  82. package/node_modules/tiny-stdio-mcp-server/dist/headers.js +180 -0
  83. package/node_modules/tiny-stdio-mcp-server/dist/index.d.ts +5 -5
  84. package/node_modules/tiny-stdio-mcp-server/dist/index.js +1 -1
  85. package/node_modules/tiny-stdio-mcp-server/dist/input-request-schema.d.ts +220 -0
  86. package/node_modules/tiny-stdio-mcp-server/dist/input-request-schema.js +1995 -0
  87. package/node_modules/tiny-stdio-mcp-server/dist/jsonrpc.d.ts +1 -0
  88. package/node_modules/tiny-stdio-mcp-server/dist/jsonrpc.js +38 -25
  89. package/node_modules/tiny-stdio-mcp-server/dist/metadata.d.ts +2 -0
  90. package/node_modules/tiny-stdio-mcp-server/dist/metadata.js +37 -0
  91. package/node_modules/tiny-stdio-mcp-server/dist/protocol-validation.d.ts +4 -0
  92. package/node_modules/tiny-stdio-mcp-server/dist/protocol-validation.js +53 -0
  93. package/node_modules/tiny-stdio-mcp-server/dist/protocol.d.ts +17 -0
  94. package/node_modules/tiny-stdio-mcp-server/dist/protocol.js +228 -0
  95. package/node_modules/tiny-stdio-mcp-server/dist/request-cancellation.d.ts +1 -0
  96. package/node_modules/tiny-stdio-mcp-server/dist/request-cancellation.js +18 -0
  97. package/node_modules/tiny-stdio-mcp-server/dist/sampling-messages.d.ts +18 -0
  98. package/node_modules/tiny-stdio-mcp-server/dist/sampling-messages.js +34 -0
  99. package/node_modules/tiny-stdio-mcp-server/dist/schema.d.ts +4 -1
  100. package/node_modules/tiny-stdio-mcp-server/dist/server.d.ts +9 -4
  101. package/node_modules/tiny-stdio-mcp-server/dist/server.js +334 -135
  102. package/node_modules/tiny-stdio-mcp-server/dist/stdio-input.d.ts +3 -0
  103. package/node_modules/tiny-stdio-mcp-server/dist/stdio-input.js +50 -28
  104. package/node_modules/tiny-stdio-mcp-server/dist/subscriptions.d.ts +11 -0
  105. package/node_modules/tiny-stdio-mcp-server/dist/subscriptions.js +128 -0
  106. package/node_modules/tiny-stdio-mcp-server/dist/types.d.ts +58 -18
  107. package/node_modules/tiny-stdio-mcp-server/dist/types.js +2 -1
  108. package/node_modules/tiny-stdio-mcp-server/dist/uri.d.ts +1 -0
  109. package/node_modules/tiny-stdio-mcp-server/dist/uri.js +41 -0
  110. package/node_modules/tiny-stdio-mcp-server/package.json +8 -0
  111. package/node_modules/toolcraft-design/dist/command-registry.d.ts +11 -0
  112. package/node_modules/toolcraft-design/dist/command-registry.js +24 -0
  113. package/node_modules/toolcraft-design/dist/dashboard/ansi.d.ts +2 -0
  114. package/node_modules/toolcraft-design/dist/dashboard/ansi.js +81 -27
  115. package/node_modules/toolcraft-design/dist/dashboard/buffer.js +39 -25
  116. package/node_modules/toolcraft-design/dist/dashboard/components/border.js +6 -5
  117. package/node_modules/toolcraft-design/dist/dashboard/components/footer.js +26 -21
  118. package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.d.ts +1 -1
  119. package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.js +12 -6
  120. package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.d.ts +2 -1
  121. package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.js +51 -10
  122. package/node_modules/toolcraft-design/dist/dashboard/dashboard.d.ts +4 -0
  123. package/node_modules/toolcraft-design/dist/dashboard/dashboard.js +77 -4
  124. package/node_modules/toolcraft-design/dist/dashboard/index.d.ts +2 -0
  125. package/node_modules/toolcraft-design/dist/dashboard/index.js +2 -0
  126. package/node_modules/toolcraft-design/dist/dashboard/keymap.js +26 -6
  127. package/node_modules/toolcraft-design/dist/dashboard/layout.d.ts +1 -0
  128. package/node_modules/toolcraft-design/dist/dashboard/layout.js +19 -3
  129. package/node_modules/toolcraft-design/dist/dashboard/line-buffer.d.ts +9 -0
  130. package/node_modules/toolcraft-design/dist/dashboard/line-buffer.js +63 -0
  131. package/node_modules/toolcraft-design/dist/dashboard/output-preview.d.ts +9 -0
  132. package/node_modules/toolcraft-design/dist/dashboard/output-preview.js +70 -0
  133. package/node_modules/toolcraft-design/dist/dashboard/snapshot.js +3 -1
  134. package/node_modules/toolcraft-design/dist/dashboard/store.js +9 -3
  135. package/node_modules/toolcraft-design/dist/dashboard/terminal-strings.d.ts +6 -0
  136. package/node_modules/toolcraft-design/dist/dashboard/terminal-strings.js +108 -0
  137. package/node_modules/toolcraft-design/dist/dashboard/terminal-width.js +3 -1
  138. package/node_modules/toolcraft-design/dist/dashboard/terminal.js +11 -1
  139. package/node_modules/toolcraft-design/dist/dashboard/testing/pipeline-scenario.d.ts +1 -0
  140. package/node_modules/toolcraft-design/dist/dashboard/testing/pipeline-scenario.js +126 -0
  141. package/node_modules/toolcraft-design/dist/dashboard/types.d.ts +3 -1
  142. package/node_modules/toolcraft-design/dist/event-groups.d.ts +19 -0
  143. package/node_modules/toolcraft-design/dist/event-groups.js +49 -0
  144. package/node_modules/toolcraft-design/dist/index.d.ts +6 -1
  145. package/node_modules/toolcraft-design/dist/index.js +5 -1
  146. package/node_modules/toolcraft-design/dist/inline-notice.d.ts +14 -0
  147. package/node_modules/toolcraft-design/dist/inline-notice.js +28 -0
  148. package/node_modules/toolcraft-design/dist/metric.d.ts +8 -0
  149. package/node_modules/toolcraft-design/dist/metric.js +21 -0
  150. package/node_modules/toolcraft-design/dist/overlay-manager.d.ts +6 -0
  151. package/node_modules/toolcraft-design/dist/overlay-manager.js +10 -0
  152. package/node_modules/toolcraft-design/dist/primitives.d.ts +12 -0
  153. package/node_modules/toolcraft-design/dist/primitives.js +7 -0
  154. package/node_modules/toolcraft-design/dist/progress-group.d.ts +7 -0
  155. package/node_modules/toolcraft-design/dist/progress-group.js +10 -0
  156. package/node_modules/toolcraft-design/dist/render-performance.d.ts +33 -0
  157. package/node_modules/toolcraft-design/dist/render-performance.js +71 -0
  158. package/node_modules/toolcraft-design/dist/task-tree.d.ts +22 -0
  159. package/node_modules/toolcraft-design/dist/task-tree.js +79 -0
  160. package/node_modules/toolcraft-design/dist/viewport.d.ts +18 -0
  161. package/node_modules/toolcraft-design/dist/viewport.js +56 -0
  162. package/node_modules/toolcraft-schema/dist/clone-default.d.ts +1 -0
  163. package/node_modules/toolcraft-schema/dist/clone-default.js +26 -0
  164. package/node_modules/toolcraft-schema/dist/index.compile-check.js +1 -0
  165. package/node_modules/toolcraft-schema/dist/index.d.ts +18 -9
  166. package/node_modules/toolcraft-schema/dist/index.js +46 -8
  167. package/node_modules/toolcraft-schema/dist/json-schema/compiler.d.ts +1 -0
  168. package/node_modules/toolcraft-schema/dist/json-schema/compiler.js +6 -0
  169. package/node_modules/toolcraft-schema/dist/json-schema/evaluate.js +6 -3
  170. package/node_modules/toolcraft-schema/dist/json-schema/normalize-nullability.d.ts +1 -0
  171. package/node_modules/toolcraft-schema/dist/json-schema/normalize-nullability.js +69 -0
  172. package/node_modules/toolcraft-schema/dist/json-schema/types.d.ts +1 -0
  173. package/node_modules/toolcraft-schema/dist/json.d.ts +4 -1
  174. package/node_modules/toolcraft-schema/dist/json.js +57 -1
  175. package/node_modules/toolcraft-schema/dist/native-json-schema.d.ts +10 -0
  176. package/node_modules/toolcraft-schema/dist/native-json-schema.js +11 -0
  177. package/node_modules/toolcraft-schema/dist/validate.d.ts +5 -1
  178. package/node_modules/toolcraft-schema/dist/validate.js +61 -47
  179. package/node_modules/toolcraft-schema/package.json +1 -1
  180. package/package.json +6 -3
@@ -0,0 +1,36 @@
1
+ import { isPlainRecord } from "toolcraft-schema";
2
+ export function validateUnionSchema(schema, value, label, errors, validateBranch) {
3
+ if (!isPlainRecord(value)) {
4
+ errors.push({
5
+ path: label,
6
+ message: `Invalid value for "${label}". Expected an object${typeof value === "object" && value !== null && !Array.isArray(value) ? ", got non-plain object" : ""}.`
7
+ });
8
+ return value;
9
+ }
10
+ const matches = [];
11
+ const branchFailures = [];
12
+ for (const [index, branch] of schema.branches.entries()) {
13
+ const branchErrors = [];
14
+ const normalized = validateBranch(branch, branchErrors);
15
+ if (branchErrors.length === 0) {
16
+ matches.push(normalized);
17
+ }
18
+ else {
19
+ const firstError = branchErrors[0];
20
+ branchFailures.push({ ...firstError, message: `Branch ${index + 1}: ${firstError.message}` });
21
+ }
22
+ }
23
+ if (matches.length === 1) {
24
+ return matches[0];
25
+ }
26
+ if (matches.length === 0) {
27
+ errors.push({ path: label, message: `No union branch matched for "${label}".` }, ...branchFailures);
28
+ }
29
+ else {
30
+ errors.push({
31
+ path: label,
32
+ message: `Invalid value for "${label}". Expected exactly one union branch, but matched ${matches.length}.`
33
+ });
34
+ }
35
+ return value;
36
+ }
@@ -61,6 +61,8 @@ export interface OpenSpec {
61
61
  tty?: boolean;
62
62
  input?: string | Buffer;
63
63
  captureOutput?: boolean;
64
+ /** Keep stdout callbacks and draining, without retaining its full text when false. */
65
+ captureStdout?: boolean;
64
66
  activityTimeoutMs?: number;
65
67
  onStdout?(chunk: string): void;
66
68
  onStderr?(chunk: string): void;
@@ -1,4 +1,5 @@
1
1
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
2
+ import { isIP } from "node:net";
2
3
  import { importJWK, jwtVerify, SignJWT } from "jose";
3
4
  class OAuthProtocolError extends Error {
4
5
  error;
@@ -69,11 +70,15 @@ function parseAbsoluteUrl(value, label) {
69
70
  }
70
71
  function validateIssuer(value) {
71
72
  const issuer = new URL(parseAbsoluteUrl(value, "issuer"));
73
+ const loopback = issuer.hostname === "localhost" || issuer.hostname === "[::1]" ||
74
+ (isIP(issuer.hostname) === 4 && issuer.hostname.startsWith("127."));
72
75
  if (issuer.protocol !== "https:" &&
73
- issuer.hostname !== "localhost" &&
74
- issuer.hostname !== "127.0.0.1") {
76
+ !(issuer.protocol === "http:" && loopback)) {
75
77
  throw new Error("issuer must use HTTPS unless it is loopback.");
76
78
  }
79
+ if (issuer.username.length > 0 || issuer.password.length > 0) {
80
+ throw new Error("issuer must not contain credentials.");
81
+ }
77
82
  if (issuer.pathname !== "/" || issuer.search.length > 0) {
78
83
  throw new Error("issuer must be an origin URL without a path or query.");
79
84
  }
@@ -272,6 +277,12 @@ export function createOAuthAuthorizationServer(options) {
272
277
  if (grant !== undefined)
273
278
  await options.onGrantRevoked?.(grant);
274
279
  }
280
+ for (const key of ["accessTokenTtlSeconds", "authorizationCodeTtlSeconds", "authorizationTransactionTtlSeconds", "refreshTokenTtlSeconds"]) {
281
+ const seconds = options[key];
282
+ if (seconds !== undefined && (!Number.isSafeInteger(seconds) || seconds <= 0 || !Number.isSafeInteger(seconds * 1000))) {
283
+ throw new Error(`${key} must be a positive safe integer with a safe millisecond duration.`);
284
+ }
285
+ }
275
286
  const accessTokenTtlMs = (options.accessTokenTtlSeconds ?? 300) * 1000;
276
287
  const authorizationCodeTtlMs = (options.authorizationCodeTtlSeconds ?? 60) * 1000;
277
288
  const authorizationTransactionTtlMs = (options.authorizationTransactionTtlSeconds ?? 600) * 1000;
@@ -306,14 +317,44 @@ export function createOAuthAuthorizationServer(options) {
306
317
  if (declaredLength !== null) {
307
318
  const parsedLength = Number(declaredLength);
308
319
  if (Number.isFinite(parsedLength) && parsedLength > maxRequestBodyBytes) {
320
+ await request.body?.cancel().catch(() => undefined);
309
321
  throw new OAuthProtocolError("invalid_request", "Request body is too large.", 413);
310
322
  }
311
323
  }
312
- const body = new Uint8Array(await request.arrayBuffer());
313
- if (body.byteLength > maxRequestBodyBytes) {
314
- throw new OAuthProtocolError("invalid_request", "Request body is too large.", 413);
324
+ if (request.body === null)
325
+ return "";
326
+ const reader = request.body.getReader();
327
+ const abort = () => { void reader.cancel().catch(() => undefined); };
328
+ request.signal.addEventListener("abort", abort, { once: true });
329
+ if (request.signal.aborted)
330
+ abort();
331
+ const decoder = new TextDecoder("utf-8", { fatal: true });
332
+ let bytes = 0;
333
+ let text = "";
334
+ try {
335
+ while (true) {
336
+ const chunk = await reader.read();
337
+ request.signal.throwIfAborted();
338
+ if (chunk.done)
339
+ return text + decoder.decode();
340
+ bytes += chunk.value.byteLength;
341
+ if (bytes > maxRequestBodyBytes) {
342
+ throw new OAuthProtocolError("invalid_request", "Request body is too large.", 413);
343
+ }
344
+ text += decoder.decode(chunk.value, { stream: true });
345
+ }
346
+ }
347
+ catch (error) {
348
+ await reader.cancel().catch(() => undefined);
349
+ if (error instanceof TypeError) {
350
+ throw new OAuthProtocolError("invalid_request", "Request body must use valid UTF-8.");
351
+ }
352
+ throw error;
353
+ }
354
+ finally {
355
+ request.signal.removeEventListener("abort", abort);
356
+ reader.releaseLock();
315
357
  }
316
- return new TextDecoder().decode(body);
317
358
  }
318
359
  async function handleRegister(request) {
319
360
  requireJsonContentType(request);
@@ -29,6 +29,8 @@ const HELP_TEXT = [
29
29
  " --allowed-origin <url> Allowed CORS Origin value (repeatable)",
30
30
  " --max-request-bytes <bytes>",
31
31
  " Maximum JSON request body size",
32
+ " --max-response-bytes <bytes>",
33
+ " Maximum JSON body or SSE frame size (default: 16777216)",
32
34
  " --max-batch-size <count>",
33
35
  " Maximum JSON-RPC batch member count",
34
36
  " --max-sessions <count> Maximum active sessions (default: 128)",
@@ -38,13 +40,15 @@ const HELP_TEXT = [
38
40
  " --max-streams-per-session <count>",
39
41
  " Maximum concurrent GET SSE streams per session",
40
42
  " --max-stream-buffer-bytes <bytes>",
41
- " Maximum buffered bytes per GET SSE stream (default: 1048576)",
43
+ " Maximum buffered bytes per SSE stream (default: 1048576)",
42
44
  " --max-sse-event-history <count>",
43
45
  " Number of SSE events retained for Last-Event-ID replay",
44
46
  " --sse-keep-alive-ms <ms>",
45
- " GET SSE keepalive interval (default: 30000; 0 disables)",
47
+ " SSE keepalive interval (default: 30000; 0 disables)",
46
48
  " --max-concurrent-tool-calls <count>",
47
49
  " Maximum concurrent tool calls across sessions (default: 4)",
50
+ " --max-active-requests <count>",
51
+ " Maximum active requests across connections (default: 128)",
48
52
  " --max-queued-tool-calls <count>",
49
53
  " Maximum waiting tool calls (default: 64; 0 disables waiting)",
50
54
  " --trusted-proxy Trust X-Forwarded-Proto and X-Forwarded-Host",
@@ -194,6 +198,7 @@ function parseCliOptions(args) {
194
198
  "allowed-host": { type: "string", multiple: true },
195
199
  "allowed-origin": { type: "string", multiple: true },
196
200
  "max-request-bytes": { type: "string" },
201
+ "max-response-bytes": { type: "string" },
197
202
  "max-batch-size": { type: "string" },
198
203
  "max-sessions": { type: "string" },
199
204
  "max-sessions-per-subject": { type: "string" },
@@ -203,6 +208,7 @@ function parseCliOptions(args) {
203
208
  "max-sse-event-history": { type: "string" },
204
209
  "sse-keep-alive-ms": { type: "string" },
205
210
  "max-concurrent-tool-calls": { type: "string" },
211
+ "max-active-requests": { type: "string" },
206
212
  "max-queued-tool-calls": { type: "string" },
207
213
  "trusted-proxy": { type: "boolean" },
208
214
  "request-timeout-ms": { type: "string" },
@@ -222,6 +228,7 @@ function parseCliOptions(args) {
222
228
  });
223
229
  const maxRequestBytes = parseOptionalInteger(values["max-request-bytes"], "--max-request-bytes", 1);
224
230
  const maxBatchSize = parseOptionalInteger(values["max-batch-size"], "--max-batch-size", 1);
231
+ const maxResponseBytes = parseOptionalInteger(values["max-response-bytes"], "--max-response-bytes", 1);
225
232
  const maxSessions = parseOptionalInteger(values["max-sessions"], "--max-sessions", 1);
226
233
  const maxSessionsPerSubject = parseOptionalInteger(values["max-sessions-per-subject"], "--max-sessions-per-subject", 1);
227
234
  const sessionTtlMs = parseOptionalInteger(values["session-ttl-ms"], "--session-ttl-ms", 1);
@@ -231,6 +238,7 @@ function parseCliOptions(args) {
231
238
  const sseKeepAliveMs = parseOptionalInteger(values["sse-keep-alive-ms"], "--sse-keep-alive-ms", 0);
232
239
  const maxConcurrentToolCalls = parseOptionalInteger(values["max-concurrent-tool-calls"], "--max-concurrent-tool-calls", 1);
233
240
  const maxQueuedToolCalls = parseOptionalInteger(values["max-queued-tool-calls"], "--max-queued-tool-calls", 0);
241
+ const maxActiveRequests = parseOptionalInteger(values["max-active-requests"], "--max-active-requests", 1);
234
242
  const requestTimeoutMs = parseOptionalInteger(values["request-timeout-ms"], "--request-timeout-ms", 0);
235
243
  const headersTimeoutMs = parseOptionalInteger(values["headers-timeout-ms"], "--headers-timeout-ms", 0);
236
244
  const keepAliveTimeoutMs = parseOptionalInteger(values["keep-alive-timeout-ms"], "--keep-alive-timeout-ms", 0);
@@ -252,6 +260,7 @@ function parseCliOptions(args) {
252
260
  }
253
261
  : {}),
254
262
  ...(maxRequestBytes === undefined ? {} : { maxRequestBytes }),
263
+ ...(maxResponseBytes === undefined ? {} : { maxResponseBytes }),
255
264
  ...(maxBatchSize === undefined ? {} : { maxBatchSize }),
256
265
  ...(maxSessions === undefined ? {} : { maxSessions }),
257
266
  ...(maxSessionsPerSubject === undefined ? {} : { maxSessionsPerSubject }),
@@ -261,6 +270,7 @@ function parseCliOptions(args) {
261
270
  ...(maxSseEventHistory === undefined ? {} : { maxSseEventHistory }),
262
271
  ...(sseKeepAliveMs === undefined ? {} : { sseKeepAliveMs }),
263
272
  ...(maxConcurrentToolCalls === undefined ? {} : { maxConcurrentToolCalls }),
273
+ ...(maxActiveRequests === undefined ? {} : { maxActiveRequests }),
264
274
  ...(maxQueuedToolCalls === undefined ? {} : { maxQueuedToolCalls }),
265
275
  trustedProxy: values["trusted-proxy"] ?? false,
266
276
  ...(requestTimeoutMs === undefined ? {} : { requestTimeoutMs }),
@@ -400,6 +410,7 @@ export async function runCli(args = process.argv.slice(2), dependencies = {}) {
400
410
  ...(options.maxRequestBytes === undefined
401
411
  ? {}
402
412
  : { maxRequestBytes: options.maxRequestBytes }),
413
+ ...(options.maxResponseBytes === undefined ? {} : { maxResponseBytes: options.maxResponseBytes }),
403
414
  ...(options.maxBatchSize === undefined ? {} : { maxBatchSize: options.maxBatchSize }),
404
415
  ...(options.maxSessions === undefined ? {} : { maxSessions: options.maxSessions }),
405
416
  ...(options.maxSessionsPerSubject === undefined ? {} : { maxSessionsPerSubject: options.maxSessionsPerSubject }),
@@ -418,6 +429,7 @@ export async function runCli(args = process.argv.slice(2), dependencies = {}) {
418
429
  ? {}
419
430
  : { maxConcurrentToolCalls: options.maxConcurrentToolCalls }),
420
431
  ...(options.maxQueuedToolCalls === undefined ? {} : { maxQueuedToolCalls: options.maxQueuedToolCalls }),
432
+ ...(options.maxActiveRequests === undefined ? {} : { maxActiveRequests: options.maxActiveRequests }),
421
433
  ...(options.trustedProxy ? { trustedProxy: true } : {}),
422
434
  ...(oauth === undefined ? {} : { oauth })
423
435
  });
@@ -18,7 +18,7 @@
18
18
  },
19
19
  {
20
20
  "name": "tiny-http-mcp-server",
21
- "version": "0.1.17",
21
+ "version": "0.1.18",
22
22
  "license": "MIT"
23
23
  },
24
24
  {
@@ -1,5 +1,5 @@
1
1
  import { type IncomingMessage, type ServerResponse } from "node:http";
2
- import { type Server, type ServerOptions, type ToolDefinition, type CallToolResult, type ToolReturn, type TypedSchema } from "tiny-stdio-mcp-server";
2
+ import { type Server, type ServerOptions, type ToolDefinition, type CallToolResult, type InputRequiredResult, type HandlerRequestContext, type ToolReturn, type TypedSchema, type TypedOutputSchema } from "tiny-stdio-mcp-server";
3
3
  import { type AuthenticatedIncomingMessage, type TokenVerifier, type VerifiedAccessToken, type RequestAuthInfo } from "./auth.js";
4
4
  import { type HttpObservabilityEvent, type StreamableHttpTransportOptions } from "./http-transport.js";
5
5
  export interface ProtectedResourceMetadataOptions {
@@ -33,18 +33,20 @@ export interface HttpServerHandle {
33
33
  closeAllConnections(): void;
34
34
  }
35
35
  export interface HttpServer extends Omit<Server, "tool" | "registerTool"> {
36
- tool<TIn, TOut = never>(name: string, description: string, inputSchema: TypedSchema<TIn>, handler: HttpToolHandler<TIn, TOut>, outputSchema?: TypedSchema<TOut>): HttpServer;
36
+ tool<TIn, TOut = never>(name: string, description: string, inputSchema: TypedSchema<TIn>, handler: HttpToolHandler<TIn, TOut>, outputSchema?: TypedOutputSchema<TOut>): HttpServer;
37
37
  registerTool<TIn, TOut = never>(definition: Omit<ToolDefinition<TIn, TOut>, "handler">, handler: HttpToolHandler<TIn, TOut>): HttpServer;
38
38
  listenHttp(options?: HttpListenOptions): Promise<HttpServerHandle>;
39
39
  handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void>;
40
- getRequestContext(): HttpToolContext | undefined;
40
+ getRequestContext(): HttpRequestContext | undefined;
41
41
  }
42
- export interface HttpToolContext {
42
+ export interface HttpRequestContext {
43
43
  request: AuthenticatedIncomingMessage;
44
44
  sessionId?: string;
45
45
  auth?: RequestAuthInfo;
46
46
  }
47
- export type HttpToolHandler<T = Record<string, unknown>, TOut = ToolReturn> = (args: T, context: HttpToolContext) => Promise<TOut | CallToolResult> | TOut | CallToolResult;
47
+ export interface HttpToolContext extends HttpRequestContext, HandlerRequestContext {
48
+ }
49
+ export type HttpToolHandler<T = Record<string, unknown>, TOut = ToolReturn> = (args: T, context: HttpToolContext) => Promise<TOut | CallToolResult | InputRequiredResult> | TOut | CallToolResult | InputRequiredResult;
48
50
  export declare function createProtectedResourceMetadataDocument(options: ProtectedResourceMetadataOptions): Record<string, unknown>;
49
51
  export declare function createHttpServer(options: HttpTransportOptions): HttpServer;
50
52
  export type { RequestAuthInfo, TokenVerifier, VerifiedAccessToken };
@@ -87,12 +87,7 @@ export function createProtectedResourceMetadataDocument(options) {
87
87
  }
88
88
  export function createHttpServer(options) {
89
89
  const requestContextStorage = new AsyncLocalStorage();
90
- const supportsSessions = !hasOwnProperty(options, "sessionIdGenerator") || options.sessionIdGenerator !== undefined;
91
- const server = createServer({
92
- ...options,
93
- supportNotifications: supportsSessions,
94
- supportResourceSubscriptions: supportsSessions
95
- });
90
+ const server = createServer(options);
96
91
  const transport = new StreamableHttpTransport(server, options, async (req, callback) => requestContextStorage.run({
97
92
  request: req,
98
93
  sessionId: Array.isArray(req.headers["mcp-session-id"])
@@ -144,11 +139,11 @@ export function createHttpServer(options) {
144
139
  return true;
145
140
  };
146
141
  httpServer.tool = (name, description, inputSchema, handler, outputSchema) => {
147
- registerTool(name, description, inputSchema, (args) => handler(args, requestContextStorage.getStore() ?? defaultContext), outputSchema);
142
+ registerTool(name, description, inputSchema, (args, context) => handler(args, { ...(requestContextStorage.getStore() ?? defaultContext), ...context }), outputSchema);
148
143
  return httpServer;
149
144
  };
150
145
  httpServer.registerTool = (definition, handler) => {
151
- registerRichTool(definition, (args) => handler(args, requestContextStorage.getStore() ?? defaultContext));
146
+ registerRichTool(definition, (args, context) => handler(args, { ...(requestContextStorage.getStore() ?? defaultContext), ...context }));
152
147
  return httpServer;
153
148
  };
154
149
  httpServer.listenHttp = async (listenOptions = {}) => {
@@ -265,6 +260,3 @@ export function createHttpServer(options) {
265
260
  httpServer.getRequestContext = () => requestContextStorage.getStore();
266
261
  return httpServer;
267
262
  }
268
- function hasOwnProperty(value, key) {
269
- return Object.prototype.hasOwnProperty.call(value, key);
270
- }
@@ -64,6 +64,7 @@ export interface StreamableHttpTransportOptions {
64
64
  allowedOrigins?: readonly string[];
65
65
  allowedHosts?: readonly string[];
66
66
  maxRequestBytes?: number;
67
+ maxResponseBytes?: number;
67
68
  maxBatchSize?: number;
68
69
  maxSessions?: number;
69
70
  /** Maximum sessions per authenticated subject or client ID; defaults to 16. */
@@ -88,6 +89,7 @@ export declare class StreamableHttpTransport {
88
89
  private readonly allowedOrigins;
89
90
  private readonly allowedHosts;
90
91
  private readonly maxRequestBytes;
92
+ private readonly maxResponseBytes;
91
93
  private readonly maxBatchSize;
92
94
  private readonly maxSessions;
93
95
  private readonly maxSessionsPerSubject;
@@ -108,6 +110,8 @@ export declare class StreamableHttpTransport {
108
110
  private readonly responseRequestIds;
109
111
  private readonly responseOrigins;
110
112
  private readonly responseRejectionReasons;
113
+ private readonly modernRequests;
114
+ private readonly modernStreams;
111
115
  private nextNotificationEventId;
112
116
  private nextRequestId;
113
117
  private activeToolCalls;
@@ -118,6 +122,7 @@ export declare class StreamableHttpTransport {
118
122
  handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void>;
119
123
  close(): Promise<void>;
120
124
  private handlePost;
125
+ private handleModernPost;
121
126
  private handleGet;
122
127
  private handleDelete;
123
128
  private handleOptions;
@@ -143,7 +148,7 @@ export declare class StreamableHttpTransport {
143
148
  private stopSseKeepAliveIfIdle;
144
149
  private stopSseKeepAlive;
145
150
  private sendNotificationToSession;
146
- private writeToLiveGetStream;
151
+ private writeToLiveStream;
147
152
  private recordSseEvent;
148
153
  private replaySseEvents;
149
154
  private isJsonRequest;