agentfootprint 12.0.0 → 12.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/CAPABILITIES.md +1 -0
  2. package/dist/answer-account/templates.js +12 -6
  3. package/dist/answer-account/templates.js.map +1 -1
  4. package/dist/answer-validation/types.js.map +1 -1
  5. package/dist/core/agent/assessment/assess.js +94 -32
  6. package/dist/core/agent/assessment/assess.js.map +1 -1
  7. package/dist/core/agent/assessment/reasons.js +2 -2
  8. package/dist/core/agent/assessment/reasons.js.map +1 -1
  9. package/dist/core/agent/assessment/sources.js +61 -23
  10. package/dist/core/agent/assessment/sources.js.map +1 -1
  11. package/dist/core/agent/negativeClaims/delivery.js +10 -1
  12. package/dist/core/agent/negativeClaims/delivery.js.map +1 -1
  13. package/dist/esm/answer-account/templates.d.ts +1 -1
  14. package/dist/esm/answer-account/templates.js +12 -6
  15. package/dist/esm/answer-account/templates.js.map +1 -1
  16. package/dist/esm/answer-validation/types.d.ts +10 -0
  17. package/dist/esm/answer-validation/types.js.map +1 -1
  18. package/dist/esm/core/agent/assessment/assess.d.ts +6 -3
  19. package/dist/esm/core/agent/assessment/assess.js +95 -33
  20. package/dist/esm/core/agent/assessment/assess.js.map +1 -1
  21. package/dist/esm/core/agent/assessment/reasons.js +2 -2
  22. package/dist/esm/core/agent/assessment/reasons.js.map +1 -1
  23. package/dist/esm/core/agent/assessment/sources.d.ts +26 -1
  24. package/dist/esm/core/agent/assessment/sources.js +59 -22
  25. package/dist/esm/core/agent/assessment/sources.js.map +1 -1
  26. package/dist/esm/core/agent/assessment/types.d.ts +3 -1
  27. package/dist/esm/core/agent/negativeClaims/delivery.d.ts +9 -1
  28. package/dist/esm/core/agent/negativeClaims/delivery.js +10 -1
  29. package/dist/esm/core/agent/negativeClaims/delivery.js.map +1 -1
  30. package/dist/esm/identity/types.d.ts +12 -0
  31. package/dist/esm/identity/types.js.map +1 -1
  32. package/dist/esm/identity/withCredentialRetry.d.ts +5 -0
  33. package/dist/esm/identity/withCredentialRetry.js +16 -3
  34. package/dist/esm/identity/withCredentialRetry.js.map +1 -1
  35. package/dist/esm/lib/boundedJson.d.ts +27 -0
  36. package/dist/esm/lib/boundedJson.js +33 -0
  37. package/dist/esm/lib/boundedJson.js.map +1 -1
  38. package/dist/esm/mcp/callChecks.d.ts +160 -0
  39. package/dist/esm/mcp/callChecks.js +237 -0
  40. package/dist/esm/mcp/callChecks.js.map +1 -0
  41. package/dist/esm/mcp/gatewayTransport.d.ts +8 -0
  42. package/dist/esm/mcp/gatewayTransport.js +35 -2
  43. package/dist/esm/mcp/gatewayTransport.js.map +1 -1
  44. package/dist/esm/mcp/index.d.ts +3 -1
  45. package/dist/esm/mcp/index.js +7 -0
  46. package/dist/esm/mcp/index.js.map +1 -1
  47. package/dist/esm/mcp/listingGenerations.d.ts +54 -0
  48. package/dist/esm/mcp/listingGenerations.js +75 -0
  49. package/dist/esm/mcp/listingGenerations.js.map +1 -0
  50. package/dist/esm/mcp/mcpClient.js +108 -23
  51. package/dist/esm/mcp/mcpClient.js.map +1 -1
  52. package/dist/esm/mcp/toolList.d.ts +90 -0
  53. package/dist/esm/mcp/toolList.js +123 -0
  54. package/dist/esm/mcp/toolList.js.map +1 -0
  55. package/dist/esm/mcp/types.d.ts +118 -2
  56. package/dist/esm/tool-providers/index.d.ts +2 -2
  57. package/dist/esm/tool-providers/index.js +8 -0
  58. package/dist/esm/tool-providers/index.js.map +1 -1
  59. package/dist/identity/types.js.map +1 -1
  60. package/dist/identity/withCredentialRetry.js +16 -3
  61. package/dist/identity/withCredentialRetry.js.map +1 -1
  62. package/dist/lib/boundedJson.js +35 -1
  63. package/dist/lib/boundedJson.js.map +1 -1
  64. package/dist/mcp/callChecks.js +247 -0
  65. package/dist/mcp/callChecks.js.map +1 -0
  66. package/dist/mcp/gatewayTransport.js +35 -2
  67. package/dist/mcp/gatewayTransport.js.map +1 -1
  68. package/dist/mcp/index.js +10 -1
  69. package/dist/mcp/index.js.map +1 -1
  70. package/dist/mcp/listingGenerations.js +80 -0
  71. package/dist/mcp/listingGenerations.js.map +1 -0
  72. package/dist/mcp/mcpClient.js +108 -23
  73. package/dist/mcp/mcpClient.js.map +1 -1
  74. package/dist/mcp/toolList.js +128 -0
  75. package/dist/mcp/toolList.js.map +1 -0
  76. package/dist/tool-providers/index.js +9 -1
  77. package/dist/tool-providers/index.js.map +1 -1
  78. package/dist/types/answer-account/templates.d.ts +1 -1
  79. package/dist/types/answer-account/templates.d.ts.map +1 -1
  80. package/dist/types/answer-validation/types.d.ts +10 -0
  81. package/dist/types/answer-validation/types.d.ts.map +1 -1
  82. package/dist/types/core/agent/assessment/assess.d.ts +6 -3
  83. package/dist/types/core/agent/assessment/assess.d.ts.map +1 -1
  84. package/dist/types/core/agent/assessment/reasons.d.ts.map +1 -1
  85. package/dist/types/core/agent/assessment/sources.d.ts +26 -1
  86. package/dist/types/core/agent/assessment/sources.d.ts.map +1 -1
  87. package/dist/types/core/agent/assessment/types.d.ts +3 -1
  88. package/dist/types/core/agent/assessment/types.d.ts.map +1 -1
  89. package/dist/types/core/agent/negativeClaims/delivery.d.ts +9 -1
  90. package/dist/types/core/agent/negativeClaims/delivery.d.ts.map +1 -1
  91. package/dist/types/identity/types.d.ts +12 -0
  92. package/dist/types/identity/types.d.ts.map +1 -1
  93. package/dist/types/identity/withCredentialRetry.d.ts +5 -0
  94. package/dist/types/identity/withCredentialRetry.d.ts.map +1 -1
  95. package/dist/types/lib/boundedJson.d.ts +27 -0
  96. package/dist/types/lib/boundedJson.d.ts.map +1 -1
  97. package/dist/types/mcp/callChecks.d.ts +161 -0
  98. package/dist/types/mcp/callChecks.d.ts.map +1 -0
  99. package/dist/types/mcp/gatewayTransport.d.ts +8 -0
  100. package/dist/types/mcp/gatewayTransport.d.ts.map +1 -1
  101. package/dist/types/mcp/index.d.ts +3 -1
  102. package/dist/types/mcp/index.d.ts.map +1 -1
  103. package/dist/types/mcp/listingGenerations.d.ts +55 -0
  104. package/dist/types/mcp/listingGenerations.d.ts.map +1 -0
  105. package/dist/types/mcp/mcpClient.d.ts.map +1 -1
  106. package/dist/types/mcp/toolList.d.ts +91 -0
  107. package/dist/types/mcp/toolList.d.ts.map +1 -0
  108. package/dist/types/mcp/types.d.ts +118 -2
  109. package/dist/types/mcp/types.d.ts.map +1 -1
  110. package/dist/types/tool-providers/index.d.ts +2 -2
  111. package/dist/types/tool-providers/index.d.ts.map +1 -1
  112. package/package.json +1 -1
@@ -51,7 +51,7 @@ export { staticTools } from './staticTools.js';
51
51
  export { gatedTools } from './gatedTools.js';
52
52
  export { skillScopedTools, skillScopedToolsTarget, SKILL_SCOPED_TOOLS_ID_PREFIX, } from '../tools/skillScopedTools.js';
53
53
  export type { ToolProvider, ToolDispatchContext, ToolGatePredicate, } from '../tools/toolProvider.js';
54
- export { mcpClient, mcpServe, mockMcpClient, gatewayTransport, GatewayAuthorizationRequiredError, McpReplayUnavailableError, MCP_TOOL_EXTRAS_KEY, retryingFetch, } from '../mcp/index.js';
54
+ export { mcpClient, mcpServe, mockMcpClient, gatewayTransport, GatewayAuthorizationRequiredError, McpReplayUnavailableError, McpToolListIncompleteError, McpOutputUncheckedError, MCP_TOOL_EXTRAS_KEY, retryingFetch, } from '../mcp/index.js';
55
55
  export { agentCoreGatewayTransport, agentCoreGatewayUrl, gatewaySearchTool, hasGatewaySearch, AGENTCORE_GATEWAY_SEARCH_TOOL, AGENTCORE_POLICY_SESSION_HEADER, AGENTCORE_SIGV4_SERVICE, } from '../adapters/mcp/agentcore.js';
56
56
  export type { AgentCoreGatewayTransportOptions, AgentCoreGatewayUrlOptions, } from '../adapters/mcp/agentcore.js';
57
57
  export { agentCoreRuntimeMcpTransport, agentCoreRuntimeUrl, } from '../adapters/mcp/agentcoreRuntime/transport.js';
@@ -59,4 +59,4 @@ export { AGENTCORE_RUNTIME_SESSION_HEADER } from '../adapters/mcp/agentcoreRunti
59
59
  export type { AgentCoreRuntimeAuth, AgentCoreRuntimeBearerAuth, AgentCoreRuntimeMcpTransportOptions, AgentCoreRuntimeRetryOptions, AgentCoreRuntimeUrlOptions, } from '../adapters/mcp/agentcoreRuntime/transport.js';
60
60
  export type { AgentCoreRuntimeSession } from '../adapters/mcp/agentcoreRuntime/session.js';
61
61
  export type { AgentCoreRuntimeSdkClient, BedrockAgentCoreRuntimeSdkModule, } from '../adapters/mcp/agentcoreRuntime/invoke.js';
62
- export type { GatewayTransportOptions, McpCallToolResult, McpClient, McpClientOptions, McpReplayDeduplication, McpReplayKind, McpReplayOptions, McpReplayPolicy, McpReplayTool, McpReplayUnavailableReason, McpConnection, McpConnectionOptions, McpSdk, McpSdkClient, ThrottleFetch, McpTransport, McpStdioTransport, McpHttpTransport, McpGatewayTransport, MockMcpClientOptions, MockMcpTool, McpServeOptions, McpServeHandle, McpServeTransport, McpStdioServeTransport, McpHttpServeTransport, McpSdkServer, McpToolExtras, } from '../mcp/index.js';
62
+ export type { GatewayTransportOptions, McpCallToolResult, McpClient, McpClientOptions, McpReplayDeduplication, McpReplayKind, McpReplayOptions, McpReplayPolicy, McpReplayTool, McpReplayUnavailableReason, McpToolListIncompleteReason, McpConnection, McpConnectionOptions, McpJsonSchemaValidator, McpSdk, McpSdkClient, ThrottleFetch, McpTransport, McpStdioTransport, McpHttpTransport, McpGatewayTransport, MockMcpClientOptions, MockMcpTool, McpServeOptions, McpServeHandle, McpServeTransport, McpStdioServeTransport, McpHttpServeTransport, McpSdkServer, McpToolExtras, } from '../mcp/index.js';
@@ -61,6 +61,14 @@ export { mcpClient, mcpServe, mockMcpClient, gatewayTransport, GatewayAuthorizat
61
61
  // cannot honour (its requests unmatched, or its answers unseen) is refused
62
62
  // before it is sent, with this error and a typed reason.
63
63
  McpReplayUnavailableError,
64
+ // A server's tool list that could not be read to its end — past 100 requests,
65
+ // or a cursor it already sent — is refused with this error and a typed
66
+ // reason; what was listed travels on it, never as a list cut short.
67
+ McpToolListIncompleteError,
68
+ // A tool whose list the SDK no longer holds, and whose output this connection
69
+ // cannot check (no JSON Schema validator reachable), is refused, never
70
+ // answered unchecked.
71
+ McpOutputUncheckedError,
64
72
  // The `_meta` key agentfootprint's tool declarations travel under, in both
65
73
  // directions (9.71.0). Public so a server this library did not write can
66
74
  // speak it, and so a client can read a bag it received.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tool-providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,gBAAgB;AAChB,kFAAkF;AAClF,kFAAkF;AAClF,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AAOtC,uEAAuE;AACvE,wEAAwE;AACxE,0CAA0C;AAC1C,OAAO,EACL,SAAS,EACT,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,iCAAiC;AACjC,0EAA0E;AAC1E,2EAA2E;AAC3E,yDAAyD;AACzD,yBAAyB;AACzB,2EAA2E;AAC3E,yEAAyE;AACzE,wDAAwD;AACxD,mBAAmB;AACnB,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,iCAAiC;AACjC,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,yEAAyE;AACzE,8EAA8E;AAC9E,8EAA8E;AAC9E,yCAAyC;AACzC,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,6BAA6B,EAC7B,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AAKtC,8EAA8E;AAC9E,4EAA4E;AAC5E,iFAAiF;AACjF,mCAAmC;AACnC,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tool-providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,gBAAgB;AAChB,kFAAkF;AAClF,kFAAkF;AAClF,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AAOtC,uEAAuE;AACvE,wEAAwE;AACxE,0CAA0C;AAC1C,OAAO,EACL,SAAS,EACT,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,iCAAiC;AACjC,0EAA0E;AAC1E,2EAA2E;AAC3E,yDAAyD;AACzD,yBAAyB;AACzB,8EAA8E;AAC9E,uEAAuE;AACvE,oEAAoE;AACpE,0BAA0B;AAC1B,8EAA8E;AAC9E,uEAAuE;AACvE,sBAAsB;AACtB,uBAAuB;AACvB,2EAA2E;AAC3E,yEAAyE;AACzE,wDAAwD;AACxD,mBAAmB;AACnB,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,iCAAiC;AACjC,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,yEAAyE;AACzE,8EAA8E;AAC9E,8EAA8E;AAC9E,yCAAyC;AACzC,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,6BAA6B,EAC7B,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AAKtC,8EAA8E;AAC9E,4EAA4E;AAC5E,iFAAiF;AACjF,mCAAmC;AACnC,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/identity/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAgHH,yEAAyE;AACzE,SAAgB,kBAAkB,CAAC,CAAmB;IACpD,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAFD,gDAEC;AAgBD;;;;;;GAMG;AACH,SAAgB,8BAA8B;IAC5C,OAAO;QACL,EAAE,EAAE,cAAc;QAClB,aAAa,CAAC,GAAsB;YAClC,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,4DAA4D,GAAG,CAAC,OAAO,QAAQ;gBAC7E,wEAAwE;gBACxE,gEAAgE,CACnE,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAbD,wEAaC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/identity/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AA4HH,yEAAyE;AACzE,SAAgB,kBAAkB,CAAC,CAAmB;IACpD,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAFD,gDAEC;AAgBD;;;;;;GAMG;AACH,SAAgB,8BAA8B;IAC5C,OAAO;QACL,EAAE,EAAE,cAAc;QAClB,aAAa,CAAC,GAAsB;YAClC,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,4DAA4D,GAAG,CAAC,OAAO,QAAQ;gBAC7E,wEAAwE;gBACxE,gEAAgE,CACnE,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAbD,wEAaC"}
@@ -26,6 +26,11 @@
26
26
  * `issued` is success; `authorization-required` is a HUMAN flow (3LO
27
27
  * consent), not a transient fault — retrying it would hammer the IdP
28
28
  * without the user having authorized anything.
29
+ * • The request's `signal` (`CredentialRequest.signal`) is passed through to
30
+ * the wrapped provider, ends the backoff wait, and is checked immediately
31
+ * before every attempt, the first included: a request whose signal has
32
+ * fired never asks the provider (again), and the call rejects with the
33
+ * abort. An attempt already running is the provider's to stop.
29
34
  * • After retries exhaust, the LAST error is rethrown — the call site
30
35
  * behaves byte-identically to an unwrapped provider (fail-closed:
31
36
  * `agentfootprint.credential.failed` emit + error tool result; the tool
@@ -48,6 +53,7 @@
48
53
  */
49
54
  Object.defineProperty(exports, "__esModule", { value: true });
50
55
  exports.withCredentialRetry = void 0;
56
+ const abort_js_1 = require("../lib/abort.js");
51
57
  const sleep_js_1 = require("../lib/sleep.js");
52
58
  const withRetry_js_1 = require("../resilience/withRetry.js");
53
59
  /**
@@ -70,6 +76,11 @@ function withCredentialRetry(provider, options = {}) {
70
76
  async getCredential(req) {
71
77
  let lastError;
72
78
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
79
+ // Immediately before EVERY attempt, the first included: a request whose
80
+ // signal has fired never asks the provider — not before the first
81
+ // attempt, and not after a wait or an `onRetry` that cancelled it (a
82
+ // zero wait never consults the signal).
83
+ (0, abort_js_1.throwIfAborted)(req.signal);
73
84
  try {
74
85
  // Both result branches return as-is (same object — the wrapper never
75
86
  // clones or serializes the credential): `issued` is success;
@@ -78,14 +89,16 @@ function withCredentialRetry(provider, options = {}) {
78
89
  }
79
90
  catch (err) {
80
91
  lastError = err;
92
+ // A failure that lands after the abort is the abort, whatever
93
+ // `shouldRetry` says: nobody is waiting for the credential (`lib/abort.ts`).
94
+ (0, abort_js_1.throwIfAborted)(req.signal);
81
95
  if (attempt >= maxAttempts || !shouldRetry(err, attempt)) {
82
96
  throw err;
83
97
  }
84
98
  const delay = Math.min(maxDelayMs, initialDelayMs * Math.pow(backoffFactor, attempt - 1));
85
99
  onRetry?.(err, attempt + 1, delay);
86
- // `CredentialRequest` carries no AbortSignal (port contract), so the
87
- // wait has none to honour. If the port ever grows one, pass it here.
88
- await (0, sleep_js_1.sleep)(delay);
100
+ // The request's signal (`CredentialRequest.signal`) ends the wait too.
101
+ await (0, sleep_js_1.sleep)(delay, req.signal, abort_js_1.abortErrorOf);
89
102
  }
90
103
  }
91
104
  // Unreachable — the last attempt either returned or threw above.
@@ -1 +1 @@
1
- {"version":3,"file":"withCredentialRetry.js","sourceRoot":"","sources":["../../src/identity/withCredentialRetry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;;;AAEH,8CAAwC;AACxC,6DAAuF;AAUvF;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,QAA4B,EAC5B,UAAsC,EAAE;IAExC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC;IAC1D,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,GAAG,CAAC;IACrD,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,MAAM,CAAC;IAChD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,iCAAkB,CAAC;IAC9D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAEhC,OAAO;QACL,EAAE,EAAE,GAAG,QAAQ,CAAC,EAAE,QAAQ;QAC1B,KAAK,CAAC,aAAa,CAAC,GAAsB;YACxC,IAAI,SAAkB,CAAC;YACvB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC;gBACxD,IAAI,CAAC;oBACH,qEAAqE;oBACrE,6DAA6D;oBAC7D,oEAAoE;oBACpE,OAAO,MAAM,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;gBAC3C,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,SAAS,GAAG,GAAG,CAAC;oBAChB,IAAI,OAAO,IAAI,WA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value: true });
3
- exports.copyJson = exports.ownData = void 0;
3
+ exports.copyJson = exports.readOwnList = exports.ownData = void 0;
4
4
  /** Strict, bounded JSON data helpers shared by internal validation boundaries. */
5
5
  const encoder = new TextEncoder();
6
6
  function ownData(value, allowed) {
@@ -21,6 +21,40 @@ function ownData(value, allowed) {
21
21
  return result;
22
22
  }
23
23
  exports.ownData = ownData;
24
+ /**
25
+ * Read a list the way {@link copyJson} reads an array — a plain array only
26
+ * (`Array.prototype`), its own `length`, the own DATA property at each index —
27
+ * as a READER that never refuses: at most `maxEntries` entries, a hole or an
28
+ * accessor entry read as `undefined` (the getter is never called), and the
29
+ * entries past the bound counted in `unread`, never walked. It never calls the
30
+ * list's iterator, a getter or a method, so a list from a record the library
31
+ * did not build cannot hide its entries or run code inside the reader.
32
+ * `undefined` when `value` is not a plain array: the caller says what that
33
+ * means for its own question, the conservative way.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const list = ['a'];
38
+ * list.length = 3; // a hole at 1 and 2
39
+ * Object.defineProperty(list, Symbol.iterator, { value: function* () {} }); // never called
40
+ * readOwnList(list, 2); // { entries: ['a', undefined], unread: 1 }
41
+ * ```
42
+ */
43
+ function readOwnList(value, maxEntries) {
44
+ if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype)
45
+ return undefined;
46
+ const length = Object.getOwnPropertyDescriptor(value, 'length')?.value;
47
+ if (typeof length !== 'number' || !Number.isSafeInteger(length) || length < 0)
48
+ return undefined;
49
+ const read = Math.min(length, maxEntries);
50
+ const entries = [];
51
+ for (let index = 0; index < read; index++) {
52
+ const slot = Object.getOwnPropertyDescriptor(value, String(index));
53
+ entries.push(slot !== undefined && 'value' in slot ? slot.value : undefined);
54
+ }
55
+ return { entries, unread: length - read };
56
+ }
57
+ exports.readOwnList = readOwnList;
24
58
  /** JSON copy without invoking toJSON/getters or silently dropping data. */
25
59
  function copyJson(value, maxBytes, freeze, maxDepth = 100) {
26
60
  if (!Number.isSafeInteger(maxDepth) || ma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D,CAAC,CAAC;IACF,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;AACxB,CAAC;AA/ED,4BA+EC"}
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ /**
3
+ * callChecks — a listing never makes a callable tool lose its checks.
4
+ *
5
+ * Pattern: the SDK's three per-tool call checks, carried by every tool the
6
+ * library hands out, plus one typed refusal.
7
+ * Role: The MCP SDK's `Client` runs three checks inside `callTool`, and it
8
+ * keeps them only for the tools of its most recent `tools/list`
9
+ * answer (1.32: `cacheToolMetadata` replaces them on every answer):
10
+ *
11
+ * 1. a tool with `execution.taskSupport: 'required'` is refused before a
12
+ * plain `tools/call` is sent;
13
+ * 2. a tool with an `outputSchema` must answer with `structuredContent`,
14
+ * unless the answer is an error;
15
+ * 3. that `structuredContent` must match the schema.
16
+ *
17
+ * So a tool that declares any of them carries them itself, as the listing it
18
+ * came from declared them. The library leaves them to the SDK only for a tool
19
+ * of a ONE-page list whose answer is still the latest, with no list request
20
+ * out (`listingGenerations.ts`), both when the call starts and when its answer
21
+ * comes in: the one-page normal case, which runs exactly as it always did.
22
+ * Every other call runs the tool's own checks, at the SDK's moments — the first
23
+ * before sending, the other two once the answer is in, before anything reads it
24
+ * — and raises the SDK's error: its own `McpError` where this arm loaded the
25
+ * SDK, otherwise an error with the same name, code and message. Those calls
26
+ * are to a tool of a paged list, a tool whose list a later answer replaced (a
27
+ * refresh that failed or succeeded; a reference held across it), and any call
28
+ * made while a list is being read.
29
+ *
30
+ * All of this covers the lists the library reads (`tools()`, `refresh()`); a
31
+ * listing it does not send — the SDK client's own automatic refresh, a
32
+ * `listTools` call of the caller's — is not seen (`listingGenerations.ts`).
33
+ *
34
+ * The output checks need a JSON Schema validator equal to the client's: the
35
+ * SDK's default (`AjvJsonSchemaValidator`, loaded with the SDK on the Node
36
+ * loader arm), or the caller's `jsonSchemaValidator`. Where neither exists — an
37
+ * `sdk` or `connection` arm given none — an answer under these rules is never
38
+ * returned unchecked (`McpOutputUncheckedError`):
39
+ *
40
+ * - a call under the tool's own checks from the start, to a tool that
41
+ * declares an `outputSchema`, is refused before it is sent (`sent: false`);
42
+ * - a call that started under the SDK's checks is refused once its answer is
43
+ * in, unread, when the library sent a `tools/list` request while the call
44
+ * was out (`sent: true`): the SDK may have checked it against another list.
45
+ *
46
+ * A schema is compiled when a tool's own checks first need it, never before:
47
+ * the one-page normal case compiles nothing twice.
48
+ */
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.McpOutputUncheckedError = exports.checkOutput = exports.refuseRequiredTask = exports.outputUnchecked = exports.checksFor = exports.validatorOption = exports.callCheckKit = void 0;
51
+ /** JSON-RPC's codes for the two errors the SDK raises here. */
52
+ const INVALID_REQUEST = -32600;
53
+ const INVALID_PARAMS = -32602;
54
+ /**
55
+ * The kit for one connection, named `server`, whose list requests `listings`
56
+ * counts (`listingsOf(connection)`, shared by every client over it). `given` is
57
+ * the caller's `jsonSchemaValidator`; `loaded` holds what the library loaded
58
+ * with the SDK on the Node loader arm — the SDK's default validator class and
59
+ * its `McpError` — each `undefined` where it is not a constructor (another arm,
60
+ * or an SDK without it).
61
+ */
62
+ function callCheckKit(server, listings, given, loaded = {}) {
63
+ const Default = typeof loaded.Validator === 'function' ? loaded.Validator : undefined;
64
+ let created;
65
+ return {
66
+ server,
67
+ validator: () => {
68
+ if (given !== undefined)
69
+ return given;
70
+ if (Default === undefined)
71
+ return undefined;
72
+ created ??= new Default();
73
+ return created;
74
+ },
75
+ ...(typeof loaded.McpError === 'function' && { McpError: loaded.McpError }),
76
+ listings,
77
+ };
78
+ }
79
+ exports.callCheckKit = callCheckKit;
80
+ /**
81
+ * `value` as a validator, or `undefined` when it was not given. Refused by name
82
+ * when it is something else, before anything connects.
83
+ */
84
+ function validatorOption(value, at) {
85
+ if (value === undefined)
86
+ return undefined;
87
+ const getValidator = value !== null && (typeof value === 'object' || typeof value === 'function')
88
+ ? value.getValidator
89
+ : undefined;
90
+ if (typeof getValidator === 'function')
91
+ return value;
92
+ throw new TypeError(`${at}: \`jsonSchemaValidator\` has no \`getValidator\` method. Pass a JSON Schema ` +
93
+ "validator as the MCP SDK's `Client` takes one: `new AjvJsonSchemaValidator()` from " +
94
+ "'@modelcontextprotocol/sdk/validation/ajv', or the one your client uses.");
95
+ }
96
+ exports.validatorOption = validatorOption;
97
+ /**
98
+ * The checks `listed` carries — `undefined` when it declares none. `generation`
99
+ * is the one answer its list was read in, when it was read in one
100
+ * (`toolList.ts` · `ToolListing`); a paged list's tools have none, so the SDK
101
+ * never holds all of them.
102
+ */
103
+ function checksFor(listed, kit, generation) {
104
+ const schema = ownObject(listed, 'outputSchema');
105
+ const taskRequired = ownValue(ownObject(listed, 'execution'), 'taskSupport') === 'required';
106
+ if (schema === undefined && !taskRequired)
107
+ return undefined;
108
+ let compiled;
109
+ return {
110
+ server: kit.server,
111
+ tool: listed.name,
112
+ taskRequired,
113
+ outputDeclared: schema !== undefined,
114
+ heldBySdk: () => generation !== undefined && kit.listings.isLatest(generation),
115
+ validate: () => {
116
+ if (schema !== undefined)
117
+ compiled ??= kit.validator()?.getValidator(schema);
118
+ return compiled;
119
+ },
120
+ fail: (code, message) => kit.McpError !== undefined
121
+ ? new kit.McpError(code, message)
122
+ : new McpErrorShape(code, message),
123
+ };
124
+ }
125
+ exports.checksFor = checksFor;
126
+ /**
127
+ * True when this call's output cannot be checked here: it runs under the
128
+ * tool's own checks, the tool declares an `outputSchema`, no validator is
129
+ * reachable, and it is not refused as a required task anyway (that refusal is
130
+ * the SDK's, and comes first). The call is then refused before it is sent.
131
+ */
132
+ function outputUnchecked(checks) {
133
+ return checks.outputDeclared && !checks.taskRequired && checks.validate() === undefined;
134
+ }
135
+ exports.outputUnchecked = outputUnchecked;
136
+ /** The SDK's task refusal, word for word, before anything is sent. */
137
+ function refuseRequiredTask(checks) {
138
+ if (!checks.taskRequired)
139
+ return;
140
+ throw checks.fail(INVALID_REQUEST, `Tool "${checks.tool}" requires task-based execution. ` +
141
+ 'Use client.experimental.tasks.callToolStream() instead.');
142
+ }
143
+ exports.refuseRequiredTask = refuseRequiredTask;
144
+ /**
145
+ * The SDK's two output checks, in its order and with its sentences, once the
146
+ * answer is in and before anything reads it. An answer no validator here can
147
+ * check is never returned: it is refused, unread, as sent.
148
+ */
149
+ function checkOutput(checks, result) {
150
+ if (!checks.outputDeclared)
151
+ return;
152
+ const validate = checks.validate();
153
+ if (validate === undefined)
154
+ throw new McpOutputUncheckedError(checks.server, checks.tool, true);
155
+ const structured = ownValue(result, 'structuredContent');
156
+ if (!structured && !ownValue(result, 'isError')) {
157
+ throw checks.fail(INVALID_REQUEST, `Tool ${checks.tool} has an output schema but did not return structured content`);
158
+ }
159
+ if (!structured)
160
+ return;
161
+ let mismatch;
162
+ try {
163
+ const verdict = validate(structured);
164
+ if (!verdict.valid) {
165
+ mismatch = `Structured content does not match the tool's output schema: ${verdict.errorMessage}`;
166
+ }
167
+ }
168
+ catch (error) {
169
+ throw checks.fail(INVALID_PARAMS, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`);
170
+ }
171
+ if (mismatch !== undefined)
172
+ throw checks.fail(INVALID_PARAMS, mismatch);
173
+ }
174
+ exports.checkOutput = checkOutput;
175
+ /**
176
+ * The SDK's `McpError`, for an arm that cannot reach the class itself (`sdk`,
177
+ * `connection`): the same name, `code`, `data` and message, so a caller that
178
+ * branches on those handles it as it handles the SDK's.
179
+ */
180
+ class McpErrorShape extends Error {
181
+ code;
182
+ data;
183
+ constructor(code, message) {
184
+ super(`MCP error ${code}: ${message}`);
185
+ this.code = code;
186
+ this.data = undefined;
187
+ this.name = 'McpError';
188
+ }
189
+ }
190
+ /** What the refusal says happened, refused before sending. */
191
+ const NOT_SENT = 'was not sent. The tool declares an outputSchema, the MCP SDK no longer holds the checks of ' +
192
+ 'the tool list it came from (that list was paged, a later list replaced it, or a list is ' +
193
+ 'being read)';
194
+ /** What the refusal says happened, refused once the answer was in. */
195
+ const SENT_UNREAD = 'was sent, and its answer is not returned. The tool declares an outputSchema, a tool list ' +
196
+ 'was read while the call was out (so the MCP SDK may not have checked the answer against ' +
197
+ "this tool's schema)";
198
+ /**
199
+ * A tool call whose output this connection cannot check, refused. The tool
200
+ * declares an `outputSchema`, the MCP SDK no longer holds the checks of the
201
+ * tool list it came from, and this connection has no JSON Schema validator to
202
+ * check it with — so its answer is never returned:
203
+ *
204
+ * - `sent: false` — refused before it was sent: nothing reached the server.
205
+ * The tool came from a paged list, from a list a later answer replaced, or
206
+ * the call was made while a list was being read.
207
+ * - `sent: true` — the call was sent, and a `tools/list` request went out
208
+ * before its answer came in: the SDK may have checked that answer against
209
+ * the other list, so it is refused unread. The tool may have run.
210
+ *
211
+ * Pass `jsonSchemaValidator` — the validator your client uses — to `mcpClient`.
212
+ * Names the server and the tool, never an argument or an answer.
213
+ */
214
+ class McpOutputUncheckedError extends Error {
215
+ server;
216
+ tool;
217
+ sent;
218
+ code = 'ERR_MCP_OUTPUT_UNCHECKED';
219
+ reason = 'output-unchecked';
220
+ constructor(server, tool,
221
+ /** Whether the request left the client: `false` when the refusal came before it. */
222
+ sent) {
223
+ super(`mcpClient[${server}]: the call to '${tool}' ${sent ? SENT_UNREAD : NOT_SENT}, and this ` +
224
+ 'connection has no JSON Schema validator to check its output with. Pass ' +
225
+ '`jsonSchemaValidator` to mcpClient: the validator your client uses.');
226
+ this.server = server;
227
+ this.tool = tool;
228
+ this.sent = sent;
229
+ this.name = 'McpOutputUncheckedError';
230
+ }
231
+ }
232
+ exports.McpOutputUncheckedError = McpOutputUncheckedError;
233
+ /** An own data property, never an accessor's result; `undefined` otherwise. */
234
+ function ownValue(value, key) {
235
+ if (value === null || typeof value !== 'object')
236
+ return undefined;
237
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
238
+ return descriptor !== undefined && 'value' in descriptor ? descriptor.value : undefined;
239
+ }
240
+ /** An own data property that is a plain object (not an array); `undefined` otherwise. */
241
+ function ownObject(value, key) {
242
+ const found = ownValue(value, key);
243
+ return found !== null && typeof found === 'object' && !Array.isArray(found)
244
+ ? found
245
+ : undefined;
246
+ }
247
+ //# sourceMappingURL=callChecks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callChecks.js","sourceRoot":"","sources":["../../src/mcp/callChecks.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;;;AAQH,+DAA+D;AAC/D,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC;AAC/B,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC;AAqB9B;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC1B,MAAc,EACd,QAA4B,EAC5B,KAAyC,EACzC,SAAwE,EAAE;IAE1E,MAAM,OAAO,GAAG,OAAO,MAAM,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IACtF,IAAI,OAA2C,CAAC;IAChD,OAAO;QACL,MAAM;QACN,SAAS,EAAE,GAAG,EAAE;YACd,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,KAAK,CAAC;YACtC,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;YAC5C,OAAO,KAAK,IAAK,OAA4C,EAAE,CAAC;YAChE,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,GAAG,CAAC,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAyB,EAAE,CAAC;QAC5F,QAAQ;KACT,CAAC;AACJ,CAAC;AAnBD,oCAmBC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,KAAc,EAAE,EAAU;IACxD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,YAAY,GAChB,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC;Q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MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QAEZ,SAAI,GAAJ,IAAI,CAAS;QAOtB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAjBD,0DAiBC;AAED,+EAA+E;AAC/E,SAAS,QAAQ,CAAC,KAAc,EAAE,GAAW;IAC3C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAClE,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC/D,OAAO,UAAU,KAAK,SAAS,IAAI,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1F,CAAC;AAED,yFAAyF;AACzF,SAAS,SAAS,CAAC,KAAc,EAAE,GAAW;IAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAA2C;QAC9C,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
@@ -37,6 +37,7 @@
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.createVendingFetch = exports.GatewayAuthorizationRequiredError = exports.gatewayTransport = void 0;
39
39
  const types_js_1 = require("../identity/types.js");
40
+ const abort_js_1 = require("../lib/abort.js");
40
41
  const DEFAULT_SERVICE = 'gateway';
41
42
  /**
42
43
  * Describe an MCP connection whose auth headers are vended per request.
@@ -93,10 +94,29 @@ class GatewayAuthorizationRequiredError extends Error {
93
94
  }
94
95
  }
95
96
  exports.GatewayAuthorizationRequiredError = GatewayAuthorizationRequiredError;
97
+ /**
98
+ * The signal `fetch(input, init)` would honour — fetch's own rule, as
99
+ * `new Request(input, init)` applies it: an `init` that names a `signal`
100
+ * replaces the Request's, and `null` there means no signal at all; otherwise a
101
+ * Request input keeps its own.
102
+ */
103
+ function effectiveSignal(input, init) {
104
+ if (init?.signal !== undefined)
105
+ return init.signal ?? undefined;
106
+ return typeof Request !== 'undefined' && input instanceof Request ? input.signal : undefined;
107
+ }
96
108
  /**
97
109
  * Build the `fetch` the MCP SDK will use: one that vends a credential, applies
98
110
  * it to this one request, and keeps nothing.
99
111
  *
112
+ * The vend is a wait, and it honours the request's abort signal — resolved as
113
+ * fetch resolves it (`init.signal`, else a Request input's own): the provider
114
+ * is handed it (`CredentialRequest.signal`), the wait ends at the abort with the
115
+ * abort, and the signal is checked again once the credential arrives. So an
116
+ * aborted or timed-out request is never sent: the gateway stops waiting and
117
+ * never uses a late credential. A provider that ignores cancellation may still
118
+ * finish its own work.
119
+ *
100
120
  * Exported for tests — the secrecy invariant is asserted against this function
101
121
  * directly, because that is where a leak would happen and driving a whole SDK
102
122
  * to reach it would test less while looking like it tested more.
@@ -105,11 +125,24 @@ exports.GatewayAuthorizationRequiredError = GatewayAuthorizationRequiredError;
105
125
  */
106
126
  function createVendingFetch(transport, baseFetch = globalThis.fetch.bind(globalThis)) {
107
127
  return async (input, init) => {
108
- const result = await transport.credentials.getCredential({
128
+ // The request's own signal, as fetch itself resolves it: the transport's,
129
+ // plus — for a dispatched call or under a deadline — the cancellation the
130
+ // retry series links in; or a Request input's own.
131
+ const signal = effectiveSignal(input, init);
132
+ // An aborted request asks no provider and sends nothing (`lib/abort.ts`).
133
+ (0, abort_js_1.throwIfAborted)(signal);
134
+ // The provider gets the signal, to stop its own work. The wait is raced
135
+ // against it, so a provider that ignores it cannot hold the request open.
136
+ const result = await (0, abort_js_1.untilAborted)(transport.credentials.getCredential({
109
137
  service: transport.service,
110
138
  ...(transport.scopes !== undefined && { scopes: transport.scopes }),
111
139
  ...(transport.mode !== undefined && { mode: transport.mode }),
112
- });
140
+ ...(signal !== undefined && { signal }),
141
+ }), signal);
142
+ // Checked again once the credential is here, before the request is handed
143
+ // on: a credential that lands after the abort is never used, so an aborted
144
+ // or timed-out request is never sent, however late the provider answers.
145
+ (0, abort_js_1.throwIfAborted)(signal);
113
146
  if (!(0, types_js_1.isCredentialIssued)(result)) {
114
147
  throw new GatewayAuthorizationRequiredError(transport.service, result.authorizationUrl);
115
148
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gatewayTransport.js","sourceRoot":"","sources":["../../src/mcp/gatewayTransport.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAEH,mDAAmF;AA8EnF,MAAM,eAAe,GAAG,SAAS,CAAC;AAElC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,gBAAgB,CAAC,OAAgC;IAC/D,IAAI,CAAC,OAAO,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtE,IAAI,CAAC,OAAO,CAAC,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IACtF,OAAO;QACL,SAAS,EAAE,SAAS;QACpB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,eAAe;QAC3C,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/D,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QACzD,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;QAClE,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,C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;YACzE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;QAED,yEAAyE;QACzE,kEAAkE;QAClE,OAAO,SAAS,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC;AA1CD,gDA0CC"}
package/dist/mcp/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.McpReplayUnavailableError = exports.retryingFetch = exports.GatewayAuthorizationRequiredError = exports.gatewayTransport = exports.mockMcpClient = exports.MCP_TOOL_EXTRAS_KEY = exports.mcpServe = exports.mcpClient = void 0;
3
+ exports.McpOutputUncheckedError = exports.McpToolListIncompleteError = exports.McpReplayUnavailableError = exports.retryingFetch = exports.GatewayAuthorizationRequiredError = exports.gatewayTransport = exports.mockMcpClient = exports.MCP_TOOL_EXTRAS_KEY = exports.mcpServe = exports.mcpClient = void 0;
4
4
  /**
5
5
  * MCP — Model Context Protocol, both directions. `mcpClient` connects to
6
6
  * someone else's MCP server and registers its tools on your Agent;
@@ -29,4 +29,13 @@ Object.defineProperty(exports, "retryingFetch", { enumerable: true, get: functio
29
29
  // before it is sent, with a typed reason.
30
30
  var replayUnavailable_js_1 = require("./replayUnavailable.js");
31
31
  Object.defineProperty(exports, "McpReplayUnavailableError", { enumerable: true, get: function () { return replayUnavailable_js_1.McpReplayUnavailableError; } });
32
+ // A tool list that could not be read to its end (past 100 requests, or a cursor
33
+ // sent twice) is refused with this error and a typed reason, never cut short.
34
+ var toolList_js_1 = require("./toolList.js");
35
+ Object.defineProperty(exports, "McpToolListIncompleteError", { enumerable: true, get: function () { return toolList_js_1.McpToolListIncompleteError; } });
36
+ // A tool whose list the SDK no longer holds, and whose output this connection
37
+ // cannot check — no JSON Schema validator reachable — is refused, never answered
38
+ // unchecked.
39
+ var callChecks_js_1 = require("./callChecks.js");
40
+ Object.defineProperty(exports, "McpOutputUncheckedError", { enumerable: true, get: function () { return callChecks_js_1.McpOutputUncheckedError; } });
32
41
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,+CAA2C;AAAlC,yGAAA,SAAS,OAAA;AAClB,6CAAyC;AAAhC,uGAAA,QAAQ,OAAA;AACjB,8EAA8E;AAC9E,0EAA0E;AAC1E,iDAA0E;AAAjE,oHAAA,mBAAmB,OAAA;AAC5B,uDAAgG;AAAvF,iHAAA,aAAa,OAAA;AACtB,6DAI+B;AAH7B,uHAAA,gBAAgB,OAAA;AAChB,wIAAA,iCAAiC,OAAA;AAGnC,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AAgBtB,2EAA2E;AAC3E,0CAA0C;AAC1C,+DAAoG;AAA3F,iIAAA,yBAAyB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,+CAA2C;AAAlC,yGAAA,SAAS,OAAA;AAClB,6CAAyC;AAAhC,uGAAA,QAAQ,OAAA;AACjB,8EAA8E;AAC9E,0EAA0E;AAC1E,iDAA0E;AAAjE,oHAAA,mBAAmB,OAAA;AAC5B,uDAAgG;AAAvF,iHAAA,aAAa,OAAA;AACtB,6DAI+B;AAH7B,uHAAA,gBAAgB,OAAA;AAChB,wIAAA,iCAAiC,OAAA;AAGnC,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AAgBtB,2EAA2E;AAC3E,0CAA0C;AAC1C,+DAAoG;AAA3F,iIAAA,yBAAyB,OAAA;AAClC,gFAAgF;AAChF,8EAA8E;AAC9E,6CAA6F;AAApF,yHAAA,0BAA0B,OAAA;AACnC,8EAA8E;AAC9E,iFAAiF;AACjF,aAAa;AACb,iDAA0D;AAAjD,wHAAA,uBAAuB,OAAA"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * listingGenerations — which `tools/list` answer the MCP SDK's `Client` holds
4
+ * its per-tool call checks for, as far as one connection can tell.
5
+ *
6
+ * Pattern: a count of the list requests one connection sent and settled.
7
+ * Role: The SDK's `Client` keeps its per-tool call checks (`callChecks.ts`)
8
+ * for the tools of the last `tools/list` answer it received: every
9
+ * answer replaces them. A request that FAILED can replace them too: the
10
+ * SDK caches an answer before it returns it, and caching can throw after
11
+ * the old checks are cleared (1.32: an `outputSchema` its validator
12
+ * cannot compile). The library cannot see inside the SDK, but it sends
13
+ * every list request it makes. So it counts them:
14
+ *
15
+ * - a request is OUT from the moment it is sent until it settles, because the
16
+ * SDK replaces its checks before the library sees the answer;
17
+ * - each request that settles, answered or failed, starts a new GENERATION.
18
+ *
19
+ * The SDK holds the checks of a listing's one answer only while the generation
20
+ * that answer settled at is the latest and no request is out. The SDK keeps one
21
+ * set of checks per client, so there is one count per connection object: every
22
+ * `mcpClient` over the same client shares it (`listingsOf`). A `tools/list`
23
+ * request the library did not send — your own code calling `listTools` on a
24
+ * client passed as `connection`, or that client's own automatic refresh
25
+ * (`listChanged.tools` with `autoRefresh`) — is not counted: the library cannot
26
+ * see it, and a tool it handed out goes on leaving its checks to an SDK that no
27
+ * longer holds them. That limit is documented, and pinned by
28
+ * `test/mcp/listingKeepsChecks.limits.test.ts`.
29
+ */
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.listingsOf = exports.ListingGenerations = void 0;
32
+ /** The `tools/list` requests one connection has out, and the generations they settled at. */
33
+ class ListingGenerations {
34
+ settled = 0;
35
+ out = 0;
36
+ /**
37
+ * Send one `tools/list` request with `send`, counted as out from the moment it
38
+ * is sent until it settles. Settling starts a new generation, answered or not.
39
+ *
40
+ * @throws whatever `send` rejects with, as it rejected
41
+ */
42
+ async ask(send) {
43
+ this.out += 1;
44
+ try {
45
+ const answer = await send();
46
+ return { answer, generation: this.settle() };
47
+ }
48
+ catch (error) {
49
+ this.settle();
50
+ throw error;
51
+ }
52
+ }
53
+ /** True while `generation` is the latest settled one and no request is out. */
54
+ isLatest(generation) {
55
+ return this.out === 0 && this.settled === generation;
56
+ }
57
+ settle() {
58
+ this.out -= 1;
59
+ this.settled += 1;
60
+ return this.settled;
61
+ }
62
+ }
63
+ exports.ListingGenerations = ListingGenerations;
64
+ /** One count per connection object, held only as long as the connection is. */
65
+ const BY_CONNECTION = new WeakMap();
66
+ /**
67
+ * The count for `connection`: the same one for every `mcpClient` that adapts
68
+ * the same client, because the SDK keeps one set of checks per client and a
69
+ * listing by any of them replaces it.
70
+ */
71
+ function listingsOf(connection) {
72
+ let listings = BY_CONNECTION.get(connection);
73
+ if (listings === undefined) {
74
+ listings = new ListingGenerations();
75
+ BY_CONNECTION.set(connection, listings);
76
+ }
77
+ return listings;
78
+ }
79
+ exports.listingsOf = listingsOf;
80
+ //# sourceMappingURL=listingGenerations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listingGenerations.js","sourceRoot":"","sources":["../../src/mcp/listingGenerations.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;AAQH,6FAA6F;AAC7F,MAAa,kBAAkB;IACrB,OAAO,GAAG,CAAC,CAAC;IACZ,GAAG,GAAG,CAAC,CAAC;IAEhB;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAI,IAAsB;QACjC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACd,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;YAC5B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QAC/C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,MAAM,K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