agentfootprint 12.0.1 → 12.2.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 (296) hide show
  1. package/AGENTS.md +1 -1
  2. package/CAPABILITIES.md +3 -0
  3. package/ai-instructions/claude-code/SKILL.md +1 -1
  4. package/dist/adapters/mcp/agentcoreRuntime/invoke.js +113 -7
  5. package/dist/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
  6. package/dist/adapters/mcp/agentcoreRuntime/session.js +21 -21
  7. package/dist/adapters/mcp/agentcoreRuntime/session.js.map +1 -1
  8. package/dist/adapters/mcp/agentcoreRuntime/transport.js +79 -5
  9. package/dist/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
  10. package/dist/core/Agent.js +6 -0
  11. package/dist/core/Agent.js.map +1 -1
  12. package/dist/core/agent/stages/toolCalls.js +4 -0
  13. package/dist/core/agent/stages/toolCalls.js.map +1 -1
  14. package/dist/core/slots/buildToolsSlot.js +8 -0
  15. package/dist/core/slots/buildToolsSlot.js.map +1 -1
  16. package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.d.ts +23 -4
  17. package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js +112 -6
  18. package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
  19. package/dist/esm/adapters/mcp/agentcoreRuntime/session.d.ts +20 -6
  20. package/dist/esm/adapters/mcp/agentcoreRuntime/session.js +21 -21
  21. package/dist/esm/adapters/mcp/agentcoreRuntime/session.js.map +1 -1
  22. package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js +81 -7
  23. package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
  24. package/dist/esm/core/Agent.js +6 -0
  25. package/dist/esm/core/Agent.js.map +1 -1
  26. package/dist/esm/core/agent/stages/toolCalls.js +4 -0
  27. package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
  28. package/dist/esm/core/slots/buildToolsSlot.d.ts +12 -0
  29. package/dist/esm/core/slots/buildToolsSlot.js +8 -0
  30. package/dist/esm/core/slots/buildToolsSlot.js.map +1 -1
  31. package/dist/esm/events/payloads.d.ts +41 -0
  32. package/dist/esm/events/registry.d.ts +3 -1
  33. package/dist/esm/events/registry.js +2 -0
  34. package/dist/esm/events/registry.js.map +1 -1
  35. package/dist/esm/identity/types.d.ts +7 -3
  36. package/dist/esm/identity/types.js.map +1 -1
  37. package/dist/esm/index.d.ts +1 -1
  38. package/dist/esm/index.js +4 -1
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/lib/boundedJson.d.ts +14 -7
  41. package/dist/esm/lib/boundedJson.js +14 -7
  42. package/dist/esm/lib/boundedJson.js.map +1 -1
  43. package/dist/esm/mcp/callChecks.d.ts +160 -0
  44. package/dist/esm/mcp/callChecks.js +237 -0
  45. package/dist/esm/mcp/callChecks.js.map +1 -0
  46. package/dist/esm/mcp/callLifetime.js +5 -2
  47. package/dist/esm/mcp/callLifetime.js.map +1 -1
  48. package/dist/esm/mcp/clientPort.d.ts +78 -0
  49. package/dist/esm/mcp/clientPort.js +33 -0
  50. package/dist/esm/mcp/clientPort.js.map +1 -0
  51. package/dist/esm/mcp/gatewayTransport.js +13 -3
  52. package/dist/esm/mcp/gatewayTransport.js.map +1 -1
  53. package/dist/esm/mcp/index.d.ts +11 -1
  54. package/dist/esm/mcp/index.js +15 -0
  55. package/dist/esm/mcp/index.js.map +1 -1
  56. package/dist/esm/mcp/listingGenerations.d.ts +54 -0
  57. package/dist/esm/mcp/listingGenerations.js +75 -0
  58. package/dist/esm/mcp/listingGenerations.js.map +1 -0
  59. package/dist/esm/mcp/mcpClient.d.ts +18 -1
  60. package/dist/esm/mcp/mcpClient.js +302 -57
  61. package/dist/esm/mcp/mcpClient.js.map +1 -1
  62. package/dist/esm/mcp/mockMcpClient.js +13 -0
  63. package/dist/esm/mcp/mockMcpClient.js.map +1 -1
  64. package/dist/esm/mcp/pool/boundTool.d.ts +58 -0
  65. package/dist/esm/mcp/pool/boundTool.js +218 -0
  66. package/dist/esm/mcp/pool/boundTool.js.map +1 -0
  67. package/dist/esm/mcp/pool/clientSet.d.ts +73 -0
  68. package/dist/esm/mcp/pool/clientSet.js +152 -0
  69. package/dist/esm/mcp/pool/clientSet.js.map +1 -0
  70. package/dist/esm/mcp/pool/definitions.d.ts +103 -0
  71. package/dist/esm/mcp/pool/definitions.js +168 -0
  72. package/dist/esm/mcp/pool/definitions.js.map +1 -0
  73. package/dist/esm/mcp/pool/errors.d.ts +76 -0
  74. package/dist/esm/mcp/pool/errors.js +91 -0
  75. package/dist/esm/mcp/pool/errors.js.map +1 -0
  76. package/dist/esm/mcp/pool/identityKey.d.ts +57 -0
  77. package/dist/esm/mcp/pool/identityKey.js +94 -0
  78. package/dist/esm/mcp/pool/identityKey.js.map +1 -0
  79. package/dist/esm/mcp/pool/lease.d.ts +36 -0
  80. package/dist/esm/mcp/pool/lease.js +51 -0
  81. package/dist/esm/mcp/pool/lease.js.map +1 -0
  82. package/dist/esm/mcp/pool/listTools.d.ts +33 -0
  83. package/dist/esm/mcp/pool/listTools.js +146 -0
  84. package/dist/esm/mcp/pool/listTools.js.map +1 -0
  85. package/dist/esm/mcp/pool/mcpClientPool.d.ts +121 -0
  86. package/dist/esm/mcp/pool/mcpClientPool.js +151 -0
  87. package/dist/esm/mcp/pool/mcpClientPool.js.map +1 -0
  88. package/dist/esm/mcp/pool/options.d.ts +183 -0
  89. package/dist/esm/mcp/pool/options.js +119 -0
  90. package/dist/esm/mcp/pool/options.js.map +1 -0
  91. package/dist/esm/mcp/pool/plan.d.ts +77 -0
  92. package/dist/esm/mcp/pool/plan.js +134 -0
  93. package/dist/esm/mcp/pool/plan.js.map +1 -0
  94. package/dist/esm/mcp/pool/pool.d.ts +307 -0
  95. package/dist/esm/mcp/pool/pool.js +1071 -0
  96. package/dist/esm/mcp/pool/pool.js.map +1 -0
  97. package/dist/esm/mcp/pool/pooledClient.d.ts +93 -0
  98. package/dist/esm/mcp/pool/pooledClient.js +90 -0
  99. package/dist/esm/mcp/pool/pooledClient.js.map +1 -0
  100. package/dist/esm/mcp/pool/record.d.ts +80 -0
  101. package/dist/esm/mcp/pool/record.js +75 -0
  102. package/dist/esm/mcp/pool/record.js.map +1 -0
  103. package/dist/esm/mcp/pool/sessionEnded.d.ts +24 -0
  104. package/dist/esm/mcp/pool/sessionEnded.js +31 -0
  105. package/dist/esm/mcp/pool/sessionEnded.js.map +1 -0
  106. package/dist/esm/mcp/pool/work.d.ts +116 -0
  107. package/dist/esm/mcp/pool/work.js +213 -0
  108. package/dist/esm/mcp/pool/work.js.map +1 -0
  109. package/dist/esm/mcp/requestGuard.d.ts +70 -0
  110. package/dist/esm/mcp/requestGuard.js +98 -0
  111. package/dist/esm/mcp/requestGuard.js.map +1 -0
  112. package/dist/esm/mcp/requestLedger.d.ts +35 -1
  113. package/dist/esm/mcp/requestLedger.js +76 -3
  114. package/dist/esm/mcp/requestLedger.js.map +1 -1
  115. package/dist/esm/mcp/seriesEvidence.d.ts +10 -6
  116. package/dist/esm/mcp/seriesEvidence.js +16 -7
  117. package/dist/esm/mcp/seriesEvidence.js.map +1 -1
  118. package/dist/esm/mcp/terminate.d.ts +94 -0
  119. package/dist/esm/mcp/terminate.js +184 -0
  120. package/dist/esm/mcp/terminate.js.map +1 -0
  121. package/dist/esm/mcp/throttleRetry.js +71 -7
  122. package/dist/esm/mcp/throttleRetry.js.map +1 -1
  123. package/dist/esm/mcp/toolList.d.ts +90 -0
  124. package/dist/esm/mcp/toolList.js +123 -0
  125. package/dist/esm/mcp/toolList.js.map +1 -0
  126. package/dist/esm/mcp/types.d.ts +197 -3
  127. package/dist/esm/redaction/knownStrings.js +34 -0
  128. package/dist/esm/redaction/knownStrings.js.map +1 -1
  129. package/dist/esm/tool-providers/index.d.ts +2 -2
  130. package/dist/esm/tool-providers/index.js +15 -1
  131. package/dist/esm/tool-providers/index.js.map +1 -1
  132. package/dist/esm/tools/mcpClientUse.d.ts +59 -0
  133. package/dist/esm/tools/mcpClientUse.js +216 -0
  134. package/dist/esm/tools/mcpClientUse.js.map +1 -0
  135. package/dist/esm/tools/toolProvider.d.ts +16 -0
  136. package/dist/esm/tools/toolSessions.d.ts +41 -0
  137. package/dist/esm/tools/toolSessions.js +41 -1
  138. package/dist/esm/tools/toolSessions.js.map +1 -1
  139. package/dist/events/registry.js +2 -0
  140. package/dist/events/registry.js.map +1 -1
  141. package/dist/identity/types.js.map +1 -1
  142. package/dist/index.js +6 -3
  143. package/dist/index.js.map +1 -1
  144. package/dist/lib/boundedJson.js +14 -7
  145. package/dist/lib/boundedJson.js.map +1 -1
  146. package/dist/mcp/callChecks.js +247 -0
  147. package/dist/mcp/callChecks.js.map +1 -0
  148. package/dist/mcp/callLifetime.js +5 -2
  149. package/dist/mcp/callLifetime.js.map +1 -1
  150. package/dist/mcp/clientPort.js +38 -0
  151. package/dist/mcp/clientPort.js.map +1 -0
  152. package/dist/mcp/gatewayTransport.js +13 -3
  153. package/dist/mcp/gatewayTransport.js.map +1 -1
  154. package/dist/mcp/index.js +25 -1
  155. package/dist/mcp/index.js.map +1 -1
  156. package/dist/mcp/listingGenerations.js +80 -0
  157. package/dist/mcp/listingGenerations.js.map +1 -0
  158. package/dist/mcp/mcpClient.js +306 -59
  159. package/dist/mcp/mcpClient.js.map +1 -1
  160. package/dist/mcp/mockMcpClient.js +13 -0
  161. package/dist/mcp/mockMcpClient.js.map +1 -1
  162. package/dist/mcp/pool/boundTool.js +223 -0
  163. package/dist/mcp/pool/boundTool.js.map +1 -0
  164. package/dist/mcp/pool/clientSet.js +157 -0
  165. package/dist/mcp/pool/clientSet.js.map +1 -0
  166. package/dist/mcp/pool/definitions.js +174 -0
  167. package/dist/mcp/pool/definitions.js.map +1 -0
  168. package/dist/mcp/pool/errors.js +96 -0
  169. package/dist/mcp/pool/errors.js.map +1 -0
  170. package/dist/mcp/pool/identityKey.js +99 -0
  171. package/dist/mcp/pool/identityKey.js.map +1 -0
  172. package/dist/mcp/pool/lease.js +55 -0
  173. package/dist/mcp/pool/lease.js.map +1 -0
  174. package/dist/mcp/pool/listTools.js +150 -0
  175. package/dist/mcp/pool/listTools.js.map +1 -0
  176. package/dist/mcp/pool/mcpClientPool.js +155 -0
  177. package/dist/mcp/pool/mcpClientPool.js.map +1 -0
  178. package/dist/mcp/pool/options.js +123 -0
  179. package/dist/mcp/pool/options.js.map +1 -0
  180. package/dist/mcp/pool/plan.js +140 -0
  181. package/dist/mcp/pool/plan.js.map +1 -0
  182. package/dist/mcp/pool/pool.js +1075 -0
  183. package/dist/mcp/pool/pool.js.map +1 -0
  184. package/dist/mcp/pool/pooledClient.js +94 -0
  185. package/dist/mcp/pool/pooledClient.js.map +1 -0
  186. package/dist/mcp/pool/record.js +80 -0
  187. package/dist/mcp/pool/record.js.map +1 -0
  188. package/dist/mcp/pool/sessionEnded.js +35 -0
  189. package/dist/mcp/pool/sessionEnded.js.map +1 -0
  190. package/dist/mcp/pool/work.js +219 -0
  191. package/dist/mcp/pool/work.js.map +1 -0
  192. package/dist/mcp/requestGuard.js +106 -0
  193. package/dist/mcp/requestGuard.js.map +1 -0
  194. package/dist/mcp/requestLedger.js +76 -3
  195. package/dist/mcp/requestLedger.js.map +1 -1
  196. package/dist/mcp/seriesEvidence.js +16 -7
  197. package/dist/mcp/seriesEvidence.js.map +1 -1
  198. package/dist/mcp/terminate.js +193 -0
  199. package/dist/mcp/terminate.js.map +1 -0
  200. package/dist/mcp/throttleRetry.js +71 -7
  201. package/dist/mcp/throttleRetry.js.map +1 -1
  202. package/dist/mcp/toolList.js +128 -0
  203. package/dist/mcp/toolList.js.map +1 -0
  204. package/dist/redaction/knownStrings.js +34 -0
  205. package/dist/redaction/knownStrings.js.map +1 -1
  206. package/dist/tool-providers/index.js +20 -1
  207. package/dist/tool-providers/index.js.map +1 -1
  208. package/dist/tools/mcpClientUse.js +225 -0
  209. package/dist/tools/mcpClientUse.js.map +1 -0
  210. package/dist/tools/toolSessions.js +44 -1
  211. package/dist/tools/toolSessions.js.map +1 -1
  212. package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts +23 -4
  213. package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts.map +1 -1
  214. package/dist/types/adapters/mcp/agentcoreRuntime/session.d.ts +20 -6
  215. package/dist/types/adapters/mcp/agentcoreRuntime/session.d.ts.map +1 -1
  216. package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts.map +1 -1
  217. package/dist/types/core/Agent.d.ts.map +1 -1
  218. package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
  219. package/dist/types/core/slots/buildToolsSlot.d.ts +12 -0
  220. package/dist/types/core/slots/buildToolsSlot.d.ts.map +1 -1
  221. package/dist/types/events/payloads.d.ts +41 -0
  222. package/dist/types/events/payloads.d.ts.map +1 -1
  223. package/dist/types/events/registry.d.ts +3 -1
  224. package/dist/types/events/registry.d.ts.map +1 -1
  225. package/dist/types/identity/types.d.ts +7 -3
  226. package/dist/types/identity/types.d.ts.map +1 -1
  227. package/dist/types/index.d.ts +1 -1
  228. package/dist/types/index.d.ts.map +1 -1
  229. package/dist/types/lib/boundedJson.d.ts +14 -7
  230. package/dist/types/lib/boundedJson.d.ts.map +1 -1
  231. package/dist/types/mcp/callChecks.d.ts +161 -0
  232. package/dist/types/mcp/callChecks.d.ts.map +1 -0
  233. package/dist/types/mcp/callLifetime.d.ts.map +1 -1
  234. package/dist/types/mcp/clientPort.d.ts +79 -0
  235. package/dist/types/mcp/clientPort.d.ts.map +1 -0
  236. package/dist/types/mcp/gatewayTransport.d.ts.map +1 -1
  237. package/dist/types/mcp/index.d.ts +11 -1
  238. package/dist/types/mcp/index.d.ts.map +1 -1
  239. package/dist/types/mcp/listingGenerations.d.ts +55 -0
  240. package/dist/types/mcp/listingGenerations.d.ts.map +1 -0
  241. package/dist/types/mcp/mcpClient.d.ts +18 -1
  242. package/dist/types/mcp/mcpClient.d.ts.map +1 -1
  243. package/dist/types/mcp/mockMcpClient.d.ts.map +1 -1
  244. package/dist/types/mcp/pool/boundTool.d.ts +59 -0
  245. package/dist/types/mcp/pool/boundTool.d.ts.map +1 -0
  246. package/dist/types/mcp/pool/clientSet.d.ts +74 -0
  247. package/dist/types/mcp/pool/clientSet.d.ts.map +1 -0
  248. package/dist/types/mcp/pool/definitions.d.ts +104 -0
  249. package/dist/types/mcp/pool/definitions.d.ts.map +1 -0
  250. package/dist/types/mcp/pool/errors.d.ts +77 -0
  251. package/dist/types/mcp/pool/errors.d.ts.map +1 -0
  252. package/dist/types/mcp/pool/identityKey.d.ts +58 -0
  253. package/dist/types/mcp/pool/identityKey.d.ts.map +1 -0
  254. package/dist/types/mcp/pool/lease.d.ts +37 -0
  255. package/dist/types/mcp/pool/lease.d.ts.map +1 -0
  256. package/dist/types/mcp/pool/listTools.d.ts +34 -0
  257. package/dist/types/mcp/pool/listTools.d.ts.map +1 -0
  258. package/dist/types/mcp/pool/mcpClientPool.d.ts +122 -0
  259. package/dist/types/mcp/pool/mcpClientPool.d.ts.map +1 -0
  260. package/dist/types/mcp/pool/options.d.ts +184 -0
  261. package/dist/types/mcp/pool/options.d.ts.map +1 -0
  262. package/dist/types/mcp/pool/plan.d.ts +78 -0
  263. package/dist/types/mcp/pool/plan.d.ts.map +1 -0
  264. package/dist/types/mcp/pool/pool.d.ts +308 -0
  265. package/dist/types/mcp/pool/pool.d.ts.map +1 -0
  266. package/dist/types/mcp/pool/pooledClient.d.ts +94 -0
  267. package/dist/types/mcp/pool/pooledClient.d.ts.map +1 -0
  268. package/dist/types/mcp/pool/record.d.ts +81 -0
  269. package/dist/types/mcp/pool/record.d.ts.map +1 -0
  270. package/dist/types/mcp/pool/sessionEnded.d.ts +25 -0
  271. package/dist/types/mcp/pool/sessionEnded.d.ts.map +1 -0
  272. package/dist/types/mcp/pool/work.d.ts +117 -0
  273. package/dist/types/mcp/pool/work.d.ts.map +1 -0
  274. package/dist/types/mcp/requestGuard.d.ts +71 -0
  275. package/dist/types/mcp/requestGuard.d.ts.map +1 -0
  276. package/dist/types/mcp/requestLedger.d.ts +35 -1
  277. package/dist/types/mcp/requestLedger.d.ts.map +1 -1
  278. package/dist/types/mcp/seriesEvidence.d.ts +10 -6
  279. package/dist/types/mcp/seriesEvidence.d.ts.map +1 -1
  280. package/dist/types/mcp/terminate.d.ts +95 -0
  281. package/dist/types/mcp/terminate.d.ts.map +1 -0
  282. package/dist/types/mcp/throttleRetry.d.ts.map +1 -1
  283. package/dist/types/mcp/toolList.d.ts +91 -0
  284. package/dist/types/mcp/toolList.d.ts.map +1 -0
  285. package/dist/types/mcp/types.d.ts +197 -3
  286. package/dist/types/mcp/types.d.ts.map +1 -1
  287. package/dist/types/redaction/knownStrings.d.ts.map +1 -1
  288. package/dist/types/tool-providers/index.d.ts +2 -2
  289. package/dist/types/tool-providers/index.d.ts.map +1 -1
  290. package/dist/types/tools/mcpClientUse.d.ts +60 -0
  291. package/dist/types/tools/mcpClientUse.d.ts.map +1 -0
  292. package/dist/types/tools/toolProvider.d.ts +16 -0
  293. package/dist/types/tools/toolProvider.d.ts.map +1 -1
  294. package/dist/types/tools/toolSessions.d.ts +41 -0
  295. package/dist/types/tools/toolSessions.d.ts.map +1 -1
  296. package/package.json +3 -3
@@ -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;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5C,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"}
@@ -59,6 +59,7 @@ const footprintjs_1 = require("footprintjs");
59
59
  const abort_js_1 = require("../lib/abort.js");
60
60
  const requestEvidence_js_1 = require("../tools/requestEvidence.js");
61
61
  const callMarker_js_1 = require("./callMarker.js");
62
+ const requestGuard_js_1 = require("./requestGuard.js");
62
63
  /**
63
64
  * Open one call.
64
65
  *
@@ -82,8 +83,10 @@ function openCall(params, ctx, clientSignal, ledger, server) {
82
83
  const sentBefore = ledger?.toolCallsSent ?? 0;
83
84
  // Every call on a watched connection gets a marker, ticket or not: under
84
85
  // 'app-authorized' its request must be matched to it either way. The call
85
- // holds its entry, so what it reads survives the connection closing.
86
- const issued = ledger?.issue(ticket);
86
+ // holds its entry, so what it reads survives the connection closing. A call
87
+ // a pool made carries its send gate too (`requestGuard.ts`), asked at every
88
+ // boundary its request crosses.
89
+ const issued = ledger?.issue(ticket, (0, requestGuard_js_1.callGuardOf)(ctx));
87
90
  let mayHaveRun = false;
88
91
  return {
89
92
  params: issued === undefined ? params : (0, callMarker_js_1.markParams)(params, issued.marker),
@@ -1 +1 @@
1
- {"version":3,"file":"callLifetime.js","sourceRoot":"","sources":["../../src/mcp/callLifetime.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;;;AAEH,6CAA4D;AAE5D,8CAAiE;AACjE,oEAAgE;AAChE,mDAA6C;AA6B7C;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CACtB,MAAS,EACT,GAAY,EACZ,YAAqC,EACrC,MAAiC,EACjC,MAAc;IAEd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,SAAS,WAAW;IAClB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,0DAA0D,CAAC,EAAE;QAC1F,IAAI,EAAE,YAAY;KACnB,CAAC,CAAC;AACL,CAAC;AAED,wGAAwG;AACxG,SAAS,WAAW,CAClB,MAAqB,EACrB,OAAgB,EAChB,UAAkB,EAClB,MAAc;IAEd,IAAI,CAAC,IAAA,uBAAS,GAAE,IAAI,OAAO,IAAI,MAAM,CAAC,aAAa,IAAI,UAAU;QAAE,OAAO;IAC1E,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;QAAE,OAAO;IACnC,sCAAsC;IACtC,OAAO,CAAC,IAAI,CACV,8BAA8B,MAAM,mDAAmD;QACrF,qFAAqF;QACrF,uFAAuF;QACvF,uEAAuE,CAC1E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * clientPort — what the MCP client pool asks of a client it opens, and what the
4
+ * client hands back beside the ordinary `McpClient`.
5
+ *
6
+ * Pattern: an internal seam, never on a door.
7
+ * Role: The pool's clients are ordinary `mcpClient`s (`mcpClient.ts`): their
8
+ * discovery, their per-tool checks (`callChecks.ts`, counted per
9
+ * client object by `listingGenerations.ts`), their retry series and
10
+ * their request ledger are the library's, unchanged. A pool needs
11
+ * four things more, and only a pool does, so they cross here:
12
+ *
13
+ * - a CONNECT signal apart from the client's lifetime signal: one open runs
14
+ * under the pool's own signal and open deadline, never a caller's;
15
+ * - the request guard of whatever the pool is doing on the client
16
+ * (`requestGuard.ts`), so every request is checked and counted;
17
+ * - the server's tools-changed notice, heard through the SDK's
18
+ * `listChanged.tools` with its automatic refresh OFF — a notice can only
19
+ * make the pool list again, through `listing`, which `mcpClient` counts;
20
+ * - a port back: a listing under the pool's own signal, a callable tool for a
21
+ * definition this client did not list (a shared one), and an ending whose
22
+ * settlement is reported apart from its answer.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.halfOpenOf = exports.rememberHalfOpen = void 0;
26
+ const HALF_OPENS = new WeakMap();
27
+ /** @internal Remember what `error` (a failed pooled open's) left behind. */
28
+ function rememberHalfOpen(error, halfOpen) {
29
+ if (error !== null && typeof error === 'object')
30
+ HALF_OPENS.set(error, halfOpen);
31
+ }
32
+ exports.rememberHalfOpen = rememberHalfOpen;
33
+ /** @internal What a failed pooled open left behind, if anything. */
34
+ function halfOpenOf(error) {
35
+ return error !== null && typeof error === 'object' ? HALF_OPENS.get(error) : undefined;
36
+ }
37
+ exports.halfOpenOf = halfOpenOf;
38
+ //# sourceMappingURL=clientPort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientPort.js","sourceRoot":"","sources":["../../src/mcp/clientPort.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AA8DH,MAAM,UAAU,GAAG,IAAI,OAAO,EAAoB,CAAC;AAEnD,4EAA4E;AAC5E,SAAgB,gBAAgB,CAAC,KAAc,EAAE,QAAkB;IACjE,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACnF,CAAC;AAFD,4CAEC;AAED,oEAAoE;AACpE,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACzF,CAAC;AAFD,gCAEC"}
@@ -38,6 +38,7 @@ 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
40
  const abort_js_1 = require("../lib/abort.js");
41
+ const requestGuard_js_1 = require("./requestGuard.js");
41
42
  const DEFAULT_SERVICE = 'gateway';
42
43
  /**
43
44
  * Describe an MCP connection whose auth headers are vended per request.
@@ -133,16 +134,25 @@ function createVendingFetch(transport, baseFetch = globalThis.fetch.bind(globalT
133
134
  (0, abort_js_1.throwIfAborted)(signal);
134
135
  // The provider gets the signal, to stop its own work. The wait is raced
135
136
  // 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({
137
+ const vend = Promise.resolve(transport.credentials.getCredential({
137
138
  service: transport.service,
138
139
  ...(transport.scopes !== undefined && { scopes: transport.scopes }),
139
140
  ...(transport.mode !== undefined && { mode: transport.mode }),
140
141
  ...(signal !== undefined && { signal }),
141
- }), signal);
142
+ }));
143
+ // A pooled request counts the vend itself, not the raced wait: a provider
144
+ // that ignores the abort is still work under the operation until it
145
+ // settles (`requestGuard.ts`).
146
+ const guard = (0, requestGuard_js_1.guardOf)(init);
147
+ guard?.track(vend);
148
+ const result = await (0, abort_js_1.untilAborted)(vend, signal);
142
149
  // Checked again once the credential is here, before the request is handed
143
150
  // on: a credential that lands after the abort is never used, so an aborted
144
151
  // or timed-out request is never sent, however late the provider answers.
152
+ // A pooled request's send gate is asked here too: a binding that went
153
+ // stale while the credential was vended sends nothing.
145
154
  (0, abort_js_1.throwIfAborted)(signal);
155
+ guard?.check();
146
156
  if (!(0, types_js_1.isCredentialIssued)(result)) {
147
157
  throw new GatewayAuthorizationRequiredError(transport.service, result.authorizationUrl);
148
158
  }
@@ -156,7 +166,7 @@ function createVendingFetch(transport, baseFetch = globalThis.fetch.bind(globalT
156
166
  }
157
167
  // The vended value exists only inside this call, on this Headers object,
158
168
  // for the duration of this request. Nothing above closes over it.
159
- return baseFetch(input, { ...init, headers });
169
+ return (0, requestGuard_js_1.trackedBy)(init, baseFetch(input, { ...init, headers }));
160
170
  };
161
171
  }
162
172
  exports.createVendingFetch = createVendingFetch;
@@ -1 +1 @@
1
- {"version":3,"file":"gatewayTransport.js","sourceRoot":"","sources":["../../src/mcp/gatewayTransport.ts"],"names":[],"mappings":";AA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zE,sEAAsE;QACtE,uDAAuD;QACvD,IAAA,yBAAc,EAAC,MAAM,CAAC,CAAC;QACvB,KAAK,EAAE,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,IAAA,6BAAkB,EAAC,MAAM,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,iCAAiC,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC1F,CAAC;QAED,4EAA4E;QAC5E,sEAAsE;QACtE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;QACjD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5F,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC;YACzE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;QAED,yEAAyE;QACzE,kEAAkE;QAClE,OAAO,IAAA,2BAAS,EAAC,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC;AACJ,CAAC;AAlDD,gDAkDC"}
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.PoolFullError = exports.McpPoolRefusedError = exports.MAX_SHARED_TOOLS = exports.MAX_DEFINITION_ENTRIES = exports.MCP_POOL_DEFAULTS = exports.mcpClientPool = exports.canTerminate = 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,28 @@ 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; } });
41
+ // Ending a client's remote session: a feature-detected capability, never a
42
+ // required member of `McpClient` (`close()` stays local).
43
+ var terminate_js_1 = require("./terminate.js");
44
+ Object.defineProperty(exports, "canTerminate", { enumerable: true, get: function () { return terminate_js_1.canTerminate; } });
45
+ // A client per conversation, for one server: bounded, ended remotely, and its
46
+ // tool definitions per client incarnation unless the app declares sharing.
47
+ var mcpClientPool_js_1 = require("./pool/mcpClientPool.js");
48
+ Object.defineProperty(exports, "mcpClientPool", { enumerable: true, get: function () { return mcpClientPool_js_1.mcpClientPool; } });
49
+ var options_js_1 = require("./pool/options.js");
50
+ Object.defineProperty(exports, "MCP_POOL_DEFAULTS", { enumerable: true, get: function () { return options_js_1.MCP_POOL_DEFAULTS; } });
51
+ Object.defineProperty(exports, "MAX_DEFINITION_ENTRIES", { enumerable: true, get: function () { return options_js_1.MAX_DEFINITION_ENTRIES; } });
52
+ Object.defineProperty(exports, "MAX_SHARED_TOOLS", { enumerable: true, get: function () { return options_js_1.MAX_SHARED_TOOLS; } });
53
+ var errors_js_1 = require("./pool/errors.js");
54
+ Object.defineProperty(exports, "McpPoolRefusedError", { enumerable: true, get: function () { return errors_js_1.McpPoolRefusedError; } });
55
+ Object.defineProperty(exports, "PoolFullError", { enumerable: true, get: function () { return errors_js_1.PoolFullError; } });
32
56
  //# 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;AAChC,2EAA2E;AAC3E,0DAA0D;AAC1D,+CAAwE;AAA/D,4GAAA,YAAY,OAAA;AACrB,8EAA8E;AAC9E,2EAA2E;AAC3E,4DAA+F;AAAtF,iHAAA,aAAa,OAAA;AACtB,gDAQ2B;AAPzB,+GAAA,iBAAiB,OAAA;AACjB,oHAAA,sBAAsB,OAAA;AACtB,8GAAA,gBAAgB,OAAA;AAMlB,8CAK0B;AAJxB,gHAAA,mBAAmB,OAAA;AACnB,0GAAA,aAAa,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,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,+EAA+E;IAC/E,QAAQ,CAAC,UAAkB;QACzB,OAAO,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,UAAU,CAAC;IACvD,CAAC;IAEO,MAAM;QACZ,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AA/BD,gDA+BC;AAED,+EAA+E;AAC/E,MAAM,aAAa,GAAG,IAAI,OAAO,EAA8B,CAAC;AAEhE;;;;GAIG;AACH,SAAgB,UAAU,CAAC,UAAkB;IAC3C,IAAI,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,UAA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