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,160 @@
1
+ /**
2
+ * callChecks — a listing never makes a callable tool lose its checks.
3
+ *
4
+ * Pattern: the SDK's three per-tool call checks, carried by every tool the
5
+ * library hands out, plus one typed refusal.
6
+ * Role: The MCP SDK's `Client` runs three checks inside `callTool`, and it
7
+ * keeps them only for the tools of its most recent `tools/list`
8
+ * answer (1.32: `cacheToolMetadata` replaces them on every answer):
9
+ *
10
+ * 1. a tool with `execution.taskSupport: 'required'` is refused before a
11
+ * plain `tools/call` is sent;
12
+ * 2. a tool with an `outputSchema` must answer with `structuredContent`,
13
+ * unless the answer is an error;
14
+ * 3. that `structuredContent` must match the schema.
15
+ *
16
+ * So a tool that declares any of them carries them itself, as the listing it
17
+ * came from declared them. The library leaves them to the SDK only for a tool
18
+ * of a ONE-page list whose answer is still the latest, with no list request
19
+ * out (`listingGenerations.ts`), both when the call starts and when its answer
20
+ * comes in: the one-page normal case, which runs exactly as it always did.
21
+ * Every other call runs the tool's own checks, at the SDK's moments — the first
22
+ * before sending, the other two once the answer is in, before anything reads it
23
+ * — and raises the SDK's error: its own `McpError` where this arm loaded the
24
+ * SDK, otherwise an error with the same name, code and message. Those calls
25
+ * are to a tool of a paged list, a tool whose list a later answer replaced (a
26
+ * refresh that failed or succeeded; a reference held across it), and any call
27
+ * made while a list is being read.
28
+ *
29
+ * All of this covers the lists the library reads (`tools()`, `refresh()`); a
30
+ * listing it does not send — the SDK client's own automatic refresh, a
31
+ * `listTools` call of the caller's — is not seen (`listingGenerations.ts`).
32
+ *
33
+ * The output checks need a JSON Schema validator equal to the client's: the
34
+ * SDK's default (`AjvJsonSchemaValidator`, loaded with the SDK on the Node
35
+ * loader arm), or the caller's `jsonSchemaValidator`. Where neither exists — an
36
+ * `sdk` or `connection` arm given none — an answer under these rules is never
37
+ * returned unchecked (`McpOutputUncheckedError`):
38
+ *
39
+ * - a call under the tool's own checks from the start, to a tool that
40
+ * declares an `outputSchema`, is refused before it is sent (`sent: false`);
41
+ * - a call that started under the SDK's checks is refused once its answer is
42
+ * in, unread, when the library sent a `tools/list` request while the call
43
+ * was out (`sent: true`): the SDK may have checked it against another list.
44
+ *
45
+ * A schema is compiled when a tool's own checks first need it, never before:
46
+ * the one-page normal case compiles nothing twice.
47
+ */
48
+ import type { McpCallToolResult, McpJsonSchemaValidator, McpListedTool } from './types.js';
49
+ import type { ListingGenerations } from './listingGenerations.js';
50
+ /** The SDK's `McpError` constructor, as `@modelcontextprotocol/sdk/types.js` exports it. */
51
+ export type McpErrorClass = new (code: number, message: string, data?: unknown) => Error;
52
+ /** A compiled output check, as the SDK's validator returns one. */
53
+ type Validate = (input: unknown) => {
54
+ readonly valid: boolean;
55
+ readonly errorMessage?: string;
56
+ };
57
+ /**
58
+ * What one connection checks its tools' calls with: a validator equal to its
59
+ * client's, the SDK's own error class where the library loaded the SDK, and
60
+ * which `tools/list` answer the SDK holds its checks for.
61
+ */
62
+ export interface CallCheckKit {
63
+ /** The client's name, as its refusals name it. */
64
+ readonly server: string;
65
+ /** The validator; created on first use. `undefined` when none is reachable. */
66
+ validator(): McpJsonSchemaValidator | undefined;
67
+ /** The SDK's own `McpError`, when this arm loaded the SDK. */
68
+ readonly McpError?: McpErrorClass;
69
+ /** This connection's list requests, counted (`listingGenerations.ts` · `listingsOf`). */
70
+ readonly listings: ListingGenerations;
71
+ }
72
+ /**
73
+ * The kit for one connection, named `server`, whose list requests `listings`
74
+ * counts (`listingsOf(connection)`, shared by every client over it). `given` is
75
+ * the caller's `jsonSchemaValidator`; `loaded` holds what the library loaded
76
+ * with the SDK on the Node loader arm — the SDK's default validator class and
77
+ * its `McpError` — each `undefined` where it is not a constructor (another arm,
78
+ * or an SDK without it).
79
+ */
80
+ export declare function callCheckKit(server: string, listings: ListingGenerations, given: McpJsonSchemaValidator | undefined, loaded?: {
81
+ readonly Validator?: unknown;
82
+ readonly McpError?: unknown;
83
+ }): CallCheckKit;
84
+ /**
85
+ * `value` as a validator, or `undefined` when it was not given. Refused by name
86
+ * when it is something else, before anything connects.
87
+ */
88
+ export declare function validatorOption(value: unknown, at: string): McpJsonSchemaValidator | undefined;
89
+ /** The checks one listed tool carries, as the listing it came from declared them. */
90
+ export interface CallChecks {
91
+ readonly server: string;
92
+ readonly tool: string;
93
+ /** `execution.taskSupport: 'required'`: only ever run as a task. */
94
+ readonly taskRequired: boolean;
95
+ /** The tool declares an `outputSchema`. */
96
+ readonly outputDeclared: boolean;
97
+ /**
98
+ * True while the SDK's `Client` holds this tool's checks: the tool came from
99
+ * a one-page list whose answer is still the latest, and no list request is
100
+ * out. Then the SDK checks the call, and nothing here runs.
101
+ */
102
+ heldBySdk(): boolean;
103
+ /**
104
+ * The compiled output check, compiled from the declared schema on first use.
105
+ * `undefined` when no output is declared or no validator is reachable.
106
+ */
107
+ validate(): Validate | undefined;
108
+ /** Raise an SDK error, as this arm can: the SDK's class, or its exact shape. */
109
+ fail(code: number, message: string): Error;
110
+ }
111
+ /**
112
+ * The checks `listed` carries — `undefined` when it declares none. `generation`
113
+ * is the one answer its list was read in, when it was read in one
114
+ * (`toolList.ts` · `ToolListing`); a paged list's tools have none, so the SDK
115
+ * never holds all of them.
116
+ */
117
+ export declare function checksFor(listed: McpListedTool, kit: CallCheckKit, generation: number | undefined): CallChecks | undefined;
118
+ /**
119
+ * True when this call's output cannot be checked here: it runs under the
120
+ * tool's own checks, the tool declares an `outputSchema`, no validator is
121
+ * reachable, and it is not refused as a required task anyway (that refusal is
122
+ * the SDK's, and comes first). The call is then refused before it is sent.
123
+ */
124
+ export declare function outputUnchecked(checks: CallChecks): boolean;
125
+ /** The SDK's task refusal, word for word, before anything is sent. */
126
+ export declare function refuseRequiredTask(checks: CallChecks): void;
127
+ /**
128
+ * The SDK's two output checks, in its order and with its sentences, once the
129
+ * answer is in and before anything reads it. An answer no validator here can
130
+ * check is never returned: it is refused, unread, as sent.
131
+ */
132
+ export declare function checkOutput(checks: CallChecks, result: McpCallToolResult): void;
133
+ /**
134
+ * A tool call whose output this connection cannot check, refused. The tool
135
+ * declares an `outputSchema`, the MCP SDK no longer holds the checks of the
136
+ * tool list it came from, and this connection has no JSON Schema validator to
137
+ * check it with — so its answer is never returned:
138
+ *
139
+ * - `sent: false` — refused before it was sent: nothing reached the server.
140
+ * The tool came from a paged list, from a list a later answer replaced, or
141
+ * the call was made while a list was being read.
142
+ * - `sent: true` — the call was sent, and a `tools/list` request went out
143
+ * before its answer came in: the SDK may have checked that answer against
144
+ * the other list, so it is refused unread. The tool may have run.
145
+ *
146
+ * Pass `jsonSchemaValidator` — the validator your client uses — to `mcpClient`.
147
+ * Names the server and the tool, never an argument or an answer.
148
+ */
149
+ export declare class McpOutputUncheckedError extends Error {
150
+ readonly server: string;
151
+ readonly tool: string;
152
+ /** Whether the request left the client: `false` when the refusal came before it. */
153
+ readonly sent: boolean;
154
+ readonly code: "ERR_MCP_OUTPUT_UNCHECKED";
155
+ readonly reason: "output-unchecked";
156
+ constructor(server: string, tool: string,
157
+ /** Whether the request left the client: `false` when the refusal came before it. */
158
+ sent: boolean);
159
+ }
160
+ export {};
@@ -0,0 +1,237 @@
1
+ /**
2
+ * callChecks — a listing never makes a callable tool lose its checks.
3
+ *
4
+ * Pattern: the SDK's three per-tool call checks, carried by every tool the
5
+ * library hands out, plus one typed refusal.
6
+ * Role: The MCP SDK's `Client` runs three checks inside `callTool`, and it
7
+ * keeps them only for the tools of its most recent `tools/list`
8
+ * answer (1.32: `cacheToolMetadata` replaces them on every answer):
9
+ *
10
+ * 1. a tool with `execution.taskSupport: 'required'` is refused before a
11
+ * plain `tools/call` is sent;
12
+ * 2. a tool with an `outputSchema` must answer with `structuredContent`,
13
+ * unless the answer is an error;
14
+ * 3. that `structuredContent` must match the schema.
15
+ *
16
+ * So a tool that declares any of them carries them itself, as the listing it
17
+ * came from declared them. The library leaves them to the SDK only for a tool
18
+ * of a ONE-page list whose answer is still the latest, with no list request
19
+ * out (`listingGenerations.ts`), both when the call starts and when its answer
20
+ * comes in: the one-page normal case, which runs exactly as it always did.
21
+ * Every other call runs the tool's own checks, at the SDK's moments — the first
22
+ * before sending, the other two once the answer is in, before anything reads it
23
+ * — and raises the SDK's error: its own `McpError` where this arm loaded the
24
+ * SDK, otherwise an error with the same name, code and message. Those calls
25
+ * are to a tool of a paged list, a tool whose list a later answer replaced (a
26
+ * refresh that failed or succeeded; a reference held across it), and any call
27
+ * made while a list is being read.
28
+ *
29
+ * All of this covers the lists the library reads (`tools()`, `refresh()`); a
30
+ * listing it does not send — the SDK client's own automatic refresh, a
31
+ * `listTools` call of the caller's — is not seen (`listingGenerations.ts`).
32
+ *
33
+ * The output checks need a JSON Schema validator equal to the client's: the
34
+ * SDK's default (`AjvJsonSchemaValidator`, loaded with the SDK on the Node
35
+ * loader arm), or the caller's `jsonSchemaValidator`. Where neither exists — an
36
+ * `sdk` or `connection` arm given none — an answer under these rules is never
37
+ * returned unchecked (`McpOutputUncheckedError`):
38
+ *
39
+ * - a call under the tool's own checks from the start, to a tool that
40
+ * declares an `outputSchema`, is refused before it is sent (`sent: false`);
41
+ * - a call that started under the SDK's checks is refused once its answer is
42
+ * in, unread, when the library sent a `tools/list` request while the call
43
+ * was out (`sent: true`): the SDK may have checked it against another list.
44
+ *
45
+ * A schema is compiled when a tool's own checks first need it, never before:
46
+ * the one-page normal case compiles nothing twice.
47
+ */
48
+ /** JSON-RPC's codes for the two errors the SDK raises here. */
49
+ const INVALID_REQUEST = -32600;
50
+ const INVALID_PARAMS = -32602;
51
+ /**
52
+ * The kit for one connection, named `server`, whose list requests `listings`
53
+ * counts (`listingsOf(connection)`, shared by every client over it). `given` is
54
+ * the caller's `jsonSchemaValidator`; `loaded` holds what the library loaded
55
+ * with the SDK on the Node loader arm — the SDK's default validator class and
56
+ * its `McpError` — each `undefined` where it is not a constructor (another arm,
57
+ * or an SDK without it).
58
+ */
59
+ export function callCheckKit(server, listings, given, loaded = {}) {
60
+ const Default = typeof loaded.Validator === 'function' ? loaded.Validator : undefined;
61
+ let created;
62
+ return {
63
+ server,
64
+ validator: () => {
65
+ if (given !== undefined)
66
+ return given;
67
+ if (Default === undefined)
68
+ return undefined;
69
+ created ??= new Default();
70
+ return created;
71
+ },
72
+ ...(typeof loaded.McpError === 'function' && { McpError: loaded.McpError }),
73
+ listings,
74
+ };
75
+ }
76
+ /**
77
+ * `value` as a validator, or `undefined` when it was not given. Refused by name
78
+ * when it is something else, before anything connects.
79
+ */
80
+ export function validatorOption(value, at) {
81
+ if (value === undefined)
82
+ return undefined;
83
+ const getValidator = value !== null && (typeof value === 'object' || typeof value === 'function')
84
+ ? value.getValidator
85
+ : undefined;
86
+ if (typeof getValidator === 'function')
87
+ return value;
88
+ throw new TypeError(`${at}: \`jsonSchemaValidator\` has no \`getValidator\` method. Pass a JSON Schema ` +
89
+ "validator as the MCP SDK's `Client` takes one: `new AjvJsonSchemaValidator()` from " +
90
+ "'@modelcontextprotocol/sdk/validation/ajv', or the one your client uses.");
91
+ }
92
+ /**
93
+ * The checks `listed` carries — `undefined` when it declares none. `generation`
94
+ * is the one answer its list was read in, when it was read in one
95
+ * (`toolList.ts` · `ToolListing`); a paged list's tools have none, so the SDK
96
+ * never holds all of them.
97
+ */
98
+ export function checksFor(listed, kit, generation) {
99
+ const schema = ownObject(listed, 'outputSchema');
100
+ const taskRequired = ownValue(ownObject(listed, 'execution'), 'taskSupport') === 'required';
101
+ if (schema === undefined && !taskRequired)
102
+ return undefined;
103
+ let compiled;
104
+ return {
105
+ server: kit.server,
106
+ tool: listed.name,
107
+ taskRequired,
108
+ outputDeclared: schema !== undefined,
109
+ heldBySdk: () => generation !== undefined && kit.listings.isLatest(generation),
110
+ validate: () => {
111
+ if (schema !== undefined)
112
+ compiled ??= kit.validator()?.getValidator(schema);
113
+ return compiled;
114
+ },
115
+ fail: (code, message) => kit.McpError !== undefined
116
+ ? new kit.McpError(code, message)
117
+ : new McpErrorShape(code, message),
118
+ };
119
+ }
120
+ /**
121
+ * True when this call's output cannot be checked here: it runs under the
122
+ * tool's own checks, the tool declares an `outputSchema`, no validator is
123
+ * reachable, and it is not refused as a required task anyway (that refusal is
124
+ * the SDK's, and comes first). The call is then refused before it is sent.
125
+ */
126
+ export function outputUnchecked(checks) {
127
+ return checks.outputDeclared && !checks.taskRequired && checks.validate() === undefined;
128
+ }
129
+ /** The SDK's task refusal, word for word, before anything is sent. */
130
+ export function refuseRequiredTask(checks) {
131
+ if (!checks.taskRequired)
132
+ return;
133
+ throw checks.fail(INVALID_REQUEST, `Tool "${checks.tool}" requires task-based execution. ` +
134
+ 'Use client.experimental.tasks.callToolStream() instead.');
135
+ }
136
+ /**
137
+ * The SDK's two output checks, in its order and with its sentences, once the
138
+ * answer is in and before anything reads it. An answer no validator here can
139
+ * check is never returned: it is refused, unread, as sent.
140
+ */
141
+ export function checkOutput(checks, result) {
142
+ if (!checks.outputDeclared)
143
+ return;
144
+ const validate = checks.validate();
145
+ if (validate === undefined)
146
+ throw new McpOutputUncheckedError(checks.server, checks.tool, true);
147
+ const structured = ownValue(result, 'structuredContent');
148
+ if (!structured && !ownValue(result, 'isError')) {
149
+ throw checks.fail(INVALID_REQUEST, `Tool ${checks.tool} has an output schema but did not return structured content`);
150
+ }
151
+ if (!structured)
152
+ return;
153
+ let mismatch;
154
+ try {
155
+ const verdict = validate(structured);
156
+ if (!verdict.valid) {
157
+ mismatch = `Structured content does not match the tool's output schema: ${verdict.errorMessage}`;
158
+ }
159
+ }
160
+ catch (error) {
161
+ throw checks.fail(INVALID_PARAMS, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`);
162
+ }
163
+ if (mismatch !== undefined)
164
+ throw checks.fail(INVALID_PARAMS, mismatch);
165
+ }
166
+ /**
167
+ * The SDK's `McpError`, for an arm that cannot reach the class itself (`sdk`,
168
+ * `connection`): the same name, `code`, `data` and message, so a caller that
169
+ * branches on those handles it as it handles the SDK's.
170
+ */
171
+ class McpErrorShape extends Error {
172
+ code;
173
+ data;
174
+ constructor(code, message) {
175
+ super(`MCP error ${code}: ${message}`);
176
+ this.code = code;
177
+ this.data = undefined;
178
+ this.name = 'McpError';
179
+ }
180
+ }
181
+ /** What the refusal says happened, refused before sending. */
182
+ const NOT_SENT = 'was not sent. The tool declares an outputSchema, the MCP SDK no longer holds the checks of ' +
183
+ 'the tool list it came from (that list was paged, a later list replaced it, or a list is ' +
184
+ 'being read)';
185
+ /** What the refusal says happened, refused once the answer was in. */
186
+ const SENT_UNREAD = 'was sent, and its answer is not returned. The tool declares an outputSchema, a tool list ' +
187
+ 'was read while the call was out (so the MCP SDK may not have checked the answer against ' +
188
+ "this tool's schema)";
189
+ /**
190
+ * A tool call whose output this connection cannot check, refused. The tool
191
+ * declares an `outputSchema`, the MCP SDK no longer holds the checks of the
192
+ * tool list it came from, and this connection has no JSON Schema validator to
193
+ * check it with — so its answer is never returned:
194
+ *
195
+ * - `sent: false` — refused before it was sent: nothing reached the server.
196
+ * The tool came from a paged list, from a list a later answer replaced, or
197
+ * the call was made while a list was being read.
198
+ * - `sent: true` — the call was sent, and a `tools/list` request went out
199
+ * before its answer came in: the SDK may have checked that answer against
200
+ * the other list, so it is refused unread. The tool may have run.
201
+ *
202
+ * Pass `jsonSchemaValidator` — the validator your client uses — to `mcpClient`.
203
+ * Names the server and the tool, never an argument or an answer.
204
+ */
205
+ export class McpOutputUncheckedError extends Error {
206
+ server;
207
+ tool;
208
+ sent;
209
+ code = 'ERR_MCP_OUTPUT_UNCHECKED';
210
+ reason = 'output-unchecked';
211
+ constructor(server, tool,
212
+ /** Whether the request left the client: `false` when the refusal came before it. */
213
+ sent) {
214
+ super(`mcpClient[${server}]: the call to '${tool}' ${sent ? SENT_UNREAD : NOT_SENT}, and this ` +
215
+ 'connection has no JSON Schema validator to check its output with. Pass ' +
216
+ '`jsonSchemaValidator` to mcpClient: the validator your client uses.');
217
+ this.server = server;
218
+ this.tool = tool;
219
+ this.sent = sent;
220
+ this.name = 'McpOutputUncheckedError';
221
+ }
222
+ }
223
+ /** An own data property, never an accessor's result; `undefined` otherwise. */
224
+ function ownValue(value, key) {
225
+ if (value === null || typeof value !== 'object')
226
+ return undefined;
227
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
228
+ return descriptor !== undefined && 'value' in descriptor ? descriptor.value : undefined;
229
+ }
230
+ /** An own data property that is a plain object (not an array); `undefined` otherwise. */
231
+ function ownObject(value, key) {
232
+ const found = ownValue(value, key);
233
+ return found !== null && typeof found === 'object' && !Array.isArray(found)
234
+ ? found
235
+ : undefined;
236
+ }
237
+ //# 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/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C,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"}
@@ -56,6 +56,7 @@ import { isDevMode, UnknownEffectError } from 'footprintjs';
56
56
  import { eitherSignal, linkedController } from '../lib/abort.js';
57
57
  import { requestEvidenceOf } from '../tools/requestEvidence.js';
58
58
  import { markParams } from './callMarker.js';
59
+ import { callGuardOf } from './requestGuard.js';
59
60
  /**
60
61
  * Open one call.
61
62
  *
@@ -79,8 +80,10 @@ export function openCall(params, ctx, clientSignal, ledger, server) {
79
80
  const sentBefore = ledger?.toolCallsSent ?? 0;
80
81
  // Every call on a watched connection gets a marker, ticket or not: under
81
82
  // 'app-authorized' its request must be matched to it either way. The call
82
- // holds its entry, so what it reads survives the connection closing.
83
- const issued = ledger?.issue(ticket);
83
+ // holds its entry, so what it reads survives the connection closing. A call
84
+ // a pool made carries its send gate too (`requestGuard.ts`), asked at every
85
+ // boundary its request crosses.
86
+ const issued = ledger?.issue(ticket, callGuardOf(ctx));
84
87
  let mayHaveRun = false;
85
88
  return {
86
89
  params: issued === undefined ? params : markParams(params, issued.marker),
@@ -1 +1 @@
1
- {"version":3,"file":"callLifetime.js","sourceRoot":"","sources":["../../../src/mcp/callLifetime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;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C,CAAC;YACzE,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,kEAAkE;AAClE,SAAS,QAAQ,CAAC,GAAY;IAC5B,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE,CAAC;QAClF,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAI,GAAqC,CAAC,MAAM,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,MAAM,YAAY,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5D,CAAC;AAED,0EAA0E;AAC1E,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,SAAS,EAAE,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,78 @@
1
+ /**
2
+ * clientPort — what the MCP client pool asks of a client it opens, and what the
3
+ * client hands back beside the ordinary `McpClient`.
4
+ *
5
+ * Pattern: an internal seam, never on a door.
6
+ * Role: The pool's clients are ordinary `mcpClient`s (`mcpClient.ts`): their
7
+ * discovery, their per-tool checks (`callChecks.ts`, counted per
8
+ * client object by `listingGenerations.ts`), their retry series and
9
+ * their request ledger are the library's, unchanged. A pool needs
10
+ * four things more, and only a pool does, so they cross here:
11
+ *
12
+ * - a CONNECT signal apart from the client's lifetime signal: one open runs
13
+ * under the pool's own signal and open deadline, never a caller's;
14
+ * - the request guard of whatever the pool is doing on the client
15
+ * (`requestGuard.ts`), so every request is checked and counted;
16
+ * - the server's tools-changed notice, heard through the SDK's
17
+ * `listChanged.tools` with its automatic refresh OFF — a notice can only
18
+ * make the pool list again, through `listing`, which `mcpClient` counts;
19
+ * - a port back: a listing under the pool's own signal, a callable tool for a
20
+ * definition this client did not list (a shared one), and an ending whose
21
+ * settlement is reported apart from its answer.
22
+ */
23
+ import type { Tool } from '../tools/tools.js';
24
+ import type { RequestGuard } from './requestGuard.js';
25
+ import type { Ending } from './terminate.js';
26
+ import type { McpListedTool } from './types.js';
27
+ import type { ThrottleFetch } from './throttleRetry.js';
28
+ /** @internal What a pool passes when it opens a client. */
29
+ export interface PooledClientSeam {
30
+ /** Bounds the connect (`initialize`) only: the pool's signal and its open deadline. */
31
+ readonly connectSignal: AbortSignal;
32
+ /**
33
+ * Wrap the transport's outermost `fetch`. `claim` finds the guard of the
34
+ * pooled tool call a request body belongs to (its ledger), `undefined` for
35
+ * any other request.
36
+ */
37
+ readonly wrapFetch: (inner: ThrottleFetch, claim: (body: unknown) => RequestGuard | undefined) => ThrottleFetch;
38
+ /** The guard for a message that is not a pooled tool call — asked at the watched `send`. */
39
+ readonly guardFor: (message: unknown) => RequestGuard | undefined;
40
+ /** The server said its tool list changed. Called by the SDK; must not throw. */
41
+ readonly onToolsChanged: () => void;
42
+ }
43
+ /** @internal One listing, through the client's own discovery. */
44
+ export interface ClientListing {
45
+ /** The tools as `mcpClient` wraps them: each carries the checks of this listing. */
46
+ readonly tools: readonly Tool[];
47
+ /** The definitions as the server listed them, in the same order. */
48
+ readonly listed: readonly McpListedTool[];
49
+ }
50
+ /** @internal What a pooled client hands the pool. */
51
+ export interface ClientPort {
52
+ /** List every page through the client's own discovery, under `signal`. Replaces its cache. */
53
+ listing(signal: AbortSignal | undefined): Promise<ClientListing>;
54
+ /**
55
+ * A callable tool for `listed` on this connection that carries its OWN
56
+ * checks — for a definition this client did not list itself, so the SDK on
57
+ * this connection holds none for it.
58
+ */
59
+ bind(listed: McpListedTool): Tool;
60
+ /** End the remote session and close: the answer by its deadline, the settlement apart. */
61
+ end(): Ending;
62
+ }
63
+ /**
64
+ * @internal What a pooled open that FAILED leaves behind: the server may have
65
+ * opened a session all the same (its `initialize` answer can land after the
66
+ * open was aborted), so the pool can still end it — once the open's work has
67
+ * settled, it asks `hasSession` and, if so, ends it under the ending rule.
68
+ */
69
+ export interface HalfOpen {
70
+ /** Does the transport hold a session id the server issued — read when asked. */
71
+ hasSession(): boolean;
72
+ /** End that session, then close locally. */
73
+ end(): Ending;
74
+ }
75
+ /** @internal Remember what `error` (a failed pooled open's) left behind. */
76
+ export declare function rememberHalfOpen(error: unknown, halfOpen: HalfOpen): void;
77
+ /** @internal What a failed pooled open left behind, if anything. */
78
+ export declare function halfOpenOf(error: unknown): HalfOpen | undefined;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * clientPort — what the MCP client pool asks of a client it opens, and what the
3
+ * client hands back beside the ordinary `McpClient`.
4
+ *
5
+ * Pattern: an internal seam, never on a door.
6
+ * Role: The pool's clients are ordinary `mcpClient`s (`mcpClient.ts`): their
7
+ * discovery, their per-tool checks (`callChecks.ts`, counted per
8
+ * client object by `listingGenerations.ts`), their retry series and
9
+ * their request ledger are the library's, unchanged. A pool needs
10
+ * four things more, and only a pool does, so they cross here:
11
+ *
12
+ * - a CONNECT signal apart from the client's lifetime signal: one open runs
13
+ * under the pool's own signal and open deadline, never a caller's;
14
+ * - the request guard of whatever the pool is doing on the client
15
+ * (`requestGuard.ts`), so every request is checked and counted;
16
+ * - the server's tools-changed notice, heard through the SDK's
17
+ * `listChanged.tools` with its automatic refresh OFF — a notice can only
18
+ * make the pool list again, through `listing`, which `mcpClient` counts;
19
+ * - a port back: a listing under the pool's own signal, a callable tool for a
20
+ * definition this client did not list (a shared one), and an ending whose
21
+ * settlement is reported apart from its answer.
22
+ */
23
+ const HALF_OPENS = new WeakMap();
24
+ /** @internal Remember what `error` (a failed pooled open's) left behind. */
25
+ export function rememberHalfOpen(error, halfOpen) {
26
+ if (error !== null && typeof error === 'object')
27
+ HALF_OPENS.set(error, halfOpen);
28
+ }
29
+ /** @internal What a failed pooled open left behind, if anything. */
30
+ export function halfOpenOf(error) {
31
+ return error !== null && typeof error === 'object' ? HALF_OPENS.get(error) : undefined;
32
+ }
33
+ //# 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,MAAM,UAAU,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;AAED,oEAAoE;AACpE,MAAM,UAAU,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"}
@@ -35,6 +35,7 @@
35
35
  */
36
36
  import { isCredentialIssued } from '../identity/types.js';
37
37
  import { throwIfAborted, untilAborted } from '../lib/abort.js';
38
+ import { guardOf, trackedBy } from './requestGuard.js';
38
39
  const DEFAULT_SERVICE = 'gateway';
39
40
  /**
40
41
  * Describe an MCP connection whose auth headers are vended per request.
@@ -128,16 +129,25 @@ export function createVendingFetch(transport, baseFetch = globalThis.fetch.bind(
128
129
  throwIfAborted(signal);
129
130
  // The provider gets the signal, to stop its own work. The wait is raced
130
131
  // against it, so a provider that ignores it cannot hold the request open.
131
- const result = await untilAborted(transport.credentials.getCredential({
132
+ const vend = Promise.resolve(transport.credentials.getCredential({
132
133
  service: transport.service,
133
134
  ...(transport.scopes !== undefined && { scopes: transport.scopes }),
134
135
  ...(transport.mode !== undefined && { mode: transport.mode }),
135
136
  ...(signal !== undefined && { signal }),
136
- }), signal);
137
+ }));
138
+ // A pooled request counts the vend itself, not the raced wait: a provider
139
+ // that ignores the abort is still work under the operation until it
140
+ // settles (`requestGuard.ts`).
141
+ const guard = guardOf(init);
142
+ guard?.track(vend);
143
+ const result = await untilAborted(vend, signal);
137
144
  // Checked again once the credential is here, before the request is handed
138
145
  // on: a credential that lands after the abort is never used, so an aborted
139
146
  // or timed-out request is never sent, however late the provider answers.
147
+ // A pooled request's send gate is asked here too: a binding that went
148
+ // stale while the credential was vended sends nothing.
140
149
  throwIfAborted(signal);
150
+ guard?.check();
141
151
  if (!isCredentialIssued(result)) {
142
152
  throw new GatewayAuthorizationRequiredError(transport.service, result.authorizationUrl);
143
153
  }
@@ -151,7 +161,7 @@ export function createVendingFetch(transport, baseFetch = globalThis.fetch.bind(
151
161
  }
152
162
  // The vended value exists only inside this call, on this Headers object,
153
163
  // for the duration of this request. Nothing above closes over it.
154
- return baseFetch(input, { ...init, headers });
164
+ return trackedBy(init, baseFetch(input, { ...init, headers }));
155
165
  };
156
166
  }
157
167
  //# sourceMappingURL=gatewayTransport.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gatewayTransport.js","sourceRoot":"","sources":["../../../src/mcp/gatewayTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,kBAAkB,EAA2B,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBA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uD;QACvD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,KAAK,EAAE,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,kBAAkB,CAAC,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,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC;AACJ,CAAC"}
@@ -13,4 +13,14 @@ export { retryingFetch } from './throttleRetry.js';
13
13
  export type { RetryOnThrottle, ThrottleFetch, ThrottleRetryInfo, ThrottleRetryOptions, } from './throttleRetry.js';
14
14
  export type { McpReplayDeduplication, McpReplayKind, McpReplayOptions, McpReplayPolicy, McpReplayTool, } from './replay.js';
15
15
  export { McpReplayUnavailableError, type McpReplayUnavailableReason } from './replayUnavailable.js';
16
- export type { McpCallToolResult, McpClient, McpClientOptions, McpConnection, McpConnectionOptions, McpSdk, McpGatewayTransport, McpHttpTransport, McpStdioTransport, McpTransport, McpSdkClient, McpServeOptions, McpServeHandle, McpServeTransport, McpHttpServeTransport, McpStdioServeTransport, McpSdkServer, } from './types.js';
16
+ export { McpToolListIncompleteError, type McpToolListIncompleteReason } from './toolList.js';
17
+ export { McpOutputUncheckedError } from './callChecks.js';
18
+ export { canTerminate, type TerminableMcpClient } from './terminate.js';
19
+ export { mcpClientPool, type McpClientPool, type McpPoolScope } from './pool/mcpClientPool.js';
20
+ export { MCP_POOL_DEFAULTS, MAX_DEFINITION_ENTRIES, MAX_SHARED_TOOLS, type McpClientPoolOptions, type McpPoolDefinitionSharing, type McpPoolIdentity, type McpPoolShareContext, } from './pool/options.js';
21
+ export { McpPoolRefusedError, PoolFullError, type McpPoolLimit, type McpPoolRefusal, } from './pool/errors.js';
22
+ export type { McpPoolLease } from './pool/lease.js';
23
+ export type { McpPoolReport } from './pool/record.js';
24
+ export type { McpPoolStats } from './pool/pool.js';
25
+ export type { EndReason as McpPoolEndReason } from './pool/pooledClient.js';
26
+ export type { McpCallToolResult, McpClient, McpClientOptions, McpConnection, McpConnectionOptions, McpJsonSchemaValidator, McpSdk, McpGatewayTransport, McpHttpTransport, McpStdioTransport, McpTerminateOutcome, McpTransport, McpTransportSettings, McpSdkClient, McpServeOptions, McpServeHandle, McpServeTransport, McpHttpServeTransport, McpStdioServeTransport, McpSdkServer, } from './types.js';