@office-ai/aioncli-core 0.1.21 → 0.2.2

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 (349) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.js +3 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/code_assist/converter.d.ts +3 -2
  5. package/dist/src/code_assist/converter.js +1 -0
  6. package/dist/src/code_assist/converter.js.map +1 -1
  7. package/dist/src/code_assist/oauth2.d.ts +2 -0
  8. package/dist/src/code_assist/oauth2.js +47 -25
  9. package/dist/src/code_assist/oauth2.js.map +1 -1
  10. package/dist/src/code_assist/oauth2.test.js +99 -8
  11. package/dist/src/code_assist/oauth2.test.js.map +1 -1
  12. package/dist/src/code_assist/server.js +1 -1
  13. package/dist/src/code_assist/server.js.map +1 -1
  14. package/dist/src/code_assist/setup.js +48 -17
  15. package/dist/src/code_assist/setup.js.map +1 -1
  16. package/dist/src/code_assist/setup.test.js +114 -8
  17. package/dist/src/code_assist/setup.test.js.map +1 -1
  18. package/dist/src/config/config.d.ts +27 -8
  19. package/dist/src/config/config.js +54 -25
  20. package/dist/src/config/config.js.map +1 -1
  21. package/dist/src/config/config.test.js +109 -1
  22. package/dist/src/config/config.test.js.map +1 -1
  23. package/dist/src/core/client.d.ts +13 -15
  24. package/dist/src/core/client.js +215 -54
  25. package/dist/src/core/client.js.map +1 -1
  26. package/dist/src/core/client.test.js +631 -36
  27. package/dist/src/core/client.test.js.map +1 -1
  28. package/dist/src/core/contentGenerator.js +20 -12
  29. package/dist/src/core/contentGenerator.js.map +1 -1
  30. package/dist/src/core/contentGenerator.test.js +39 -15
  31. package/dist/src/core/contentGenerator.test.js.map +1 -1
  32. package/dist/src/core/coreToolScheduler.d.ts +2 -1
  33. package/dist/src/core/coreToolScheduler.js +26 -4
  34. package/dist/src/core/coreToolScheduler.js.map +1 -1
  35. package/dist/src/core/coreToolScheduler.test.js +230 -71
  36. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  37. package/dist/src/core/geminiChat.js +1 -1
  38. package/dist/src/core/geminiChat.js.map +1 -1
  39. package/dist/src/core/logger.d.ts +22 -1
  40. package/dist/src/core/logger.js +103 -17
  41. package/dist/src/core/logger.js.map +1 -1
  42. package/dist/src/core/logger.test.js +86 -20
  43. package/dist/src/core/logger.test.js.map +1 -1
  44. package/dist/src/core/loggingContentGenerator.d.ts +1 -0
  45. package/dist/src/core/loggingContentGenerator.js +7 -1
  46. package/dist/src/core/loggingContentGenerator.js.map +1 -1
  47. package/dist/src/core/nonInteractiveToolExecutor.d.ts +2 -2
  48. package/dist/src/core/nonInteractiveToolExecutor.js +11 -3
  49. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
  50. package/dist/src/core/nonInteractiveToolExecutor.test.js +95 -46
  51. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  52. package/dist/src/core/openaiContentGenerator.js +71 -25
  53. package/dist/src/core/openaiContentGenerator.js.map +1 -1
  54. package/dist/src/core/openaiContentGenerator.test.js +1 -1
  55. package/dist/src/core/openaiContentGenerator.test.js.map +1 -1
  56. package/dist/src/core/prompts.js +4 -4
  57. package/dist/src/core/prompts.js.map +1 -1
  58. package/dist/src/core/subagent.js +5 -5
  59. package/dist/src/core/subagent.js.map +1 -1
  60. package/dist/src/core/subagent.test.js +3 -3
  61. package/dist/src/core/subagent.test.js.map +1 -1
  62. package/dist/src/generated/git-commit.d.ts +7 -0
  63. package/dist/src/generated/git-commit.js +10 -0
  64. package/dist/src/generated/git-commit.js.map +1 -0
  65. package/dist/src/ide/constants.d.ts +6 -0
  66. package/dist/src/ide/constants.js +7 -0
  67. package/dist/src/ide/constants.js.map +1 -0
  68. package/dist/src/ide/detect-ide.d.ts +12 -2
  69. package/dist/src/ide/detect-ide.js +64 -5
  70. package/dist/src/ide/detect-ide.js.map +1 -1
  71. package/dist/src/ide/detect-ide.test.d.ts +6 -0
  72. package/dist/src/ide/detect-ide.test.js +65 -0
  73. package/dist/src/ide/detect-ide.test.js.map +1 -0
  74. package/dist/src/ide/ide-client.d.ts +9 -1
  75. package/dist/src/ide/ide-client.js +113 -30
  76. package/dist/src/ide/ide-client.js.map +1 -1
  77. package/dist/src/ide/ide-client.test.d.ts +6 -0
  78. package/dist/src/ide/ide-client.test.js +43 -0
  79. package/dist/src/ide/ide-client.test.js.map +1 -0
  80. package/dist/src/ide/ide-installer.js +23 -34
  81. package/dist/src/ide/ide-installer.js.map +1 -1
  82. package/dist/src/ide/ide-installer.test.js +6 -8
  83. package/dist/src/ide/ide-installer.test.js.map +1 -1
  84. package/dist/src/ide/ideContext.d.ts +6 -6
  85. package/dist/src/ide/process-utils.d.ts +19 -0
  86. package/dist/src/ide/process-utils.js +140 -0
  87. package/dist/src/ide/process-utils.js.map +1 -0
  88. package/dist/src/index.d.ts +6 -1
  89. package/dist/src/index.js +6 -1
  90. package/dist/src/index.js.map +1 -1
  91. package/dist/src/mcp/google-auth-provider.js +9 -0
  92. package/dist/src/mcp/google-auth-provider.js.map +1 -1
  93. package/dist/src/mcp/google-auth-provider.test.js +45 -10
  94. package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
  95. package/dist/src/mcp/oauth-provider.d.ts +0 -1
  96. package/dist/src/mcp/oauth-provider.js +176 -59
  97. package/dist/src/mcp/oauth-provider.js.map +1 -1
  98. package/dist/src/mcp/oauth-provider.test.js +132 -62
  99. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  100. package/dist/src/mcp/oauth-utils.d.ts +3 -1
  101. package/dist/src/mcp/oauth-utils.js +50 -12
  102. package/dist/src/mcp/oauth-utils.js.map +1 -1
  103. package/dist/src/mcp/oauth-utils.test.js +17 -2
  104. package/dist/src/mcp/oauth-utils.test.js.map +1 -1
  105. package/dist/src/mocks/msw.d.ts +6 -0
  106. package/dist/src/mocks/msw.js +8 -0
  107. package/dist/src/mocks/msw.js.map +1 -0
  108. package/dist/src/services/chatRecordingService.d.ts +150 -0
  109. package/dist/src/services/chatRecordingService.js +318 -0
  110. package/dist/src/services/chatRecordingService.js.map +1 -0
  111. package/dist/src/services/chatRecordingService.test.d.ts +6 -0
  112. package/dist/src/services/chatRecordingService.test.js +288 -0
  113. package/dist/src/services/chatRecordingService.test.js.map +1 -0
  114. package/dist/src/services/fileSystemService.d.ts +31 -0
  115. package/dist/src/services/fileSystemService.js +18 -0
  116. package/dist/src/services/fileSystemService.js.map +1 -0
  117. package/dist/src/services/fileSystemService.test.d.ts +6 -0
  118. package/dist/src/services/fileSystemService.test.js +41 -0
  119. package/dist/src/services/fileSystemService.test.js.map +1 -0
  120. package/dist/src/services/loopDetectionService.js +9 -10
  121. package/dist/src/services/loopDetectionService.js.map +1 -1
  122. package/dist/src/services/loopDetectionService.test.js +52 -0
  123. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  124. package/dist/src/services/shellExecutionService.d.ts +8 -10
  125. package/dist/src/services/shellExecutionService.js +289 -133
  126. package/dist/src/services/shellExecutionService.js.map +1 -1
  127. package/dist/src/services/shellExecutionService.test.js +274 -30
  128. package/dist/src/services/shellExecutionService.test.js.map +1 -1
  129. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +61 -17
  130. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +211 -233
  131. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  132. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +11 -0
  133. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +250 -94
  134. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
  135. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +9 -2
  136. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +19 -9
  137. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  138. package/dist/src/telemetry/constants.d.ts +1 -0
  139. package/dist/src/telemetry/constants.js +1 -0
  140. package/dist/src/telemetry/constants.js.map +1 -1
  141. package/dist/src/telemetry/index.d.ts +2 -2
  142. package/dist/src/telemetry/index.js +2 -2
  143. package/dist/src/telemetry/index.js.map +1 -1
  144. package/dist/src/telemetry/integration.test.circular.js +1 -0
  145. package/dist/src/telemetry/integration.test.circular.js.map +1 -1
  146. package/dist/src/telemetry/loggers.d.ts +3 -1
  147. package/dist/src/telemetry/loggers.js +39 -6
  148. package/dist/src/telemetry/loggers.js.map +1 -1
  149. package/dist/src/telemetry/loggers.test.js +37 -7
  150. package/dist/src/telemetry/loggers.test.js.map +1 -1
  151. package/dist/src/telemetry/metrics.d.ts +5 -1
  152. package/dist/src/telemetry/metrics.js +23 -9
  153. package/dist/src/telemetry/metrics.js.map +1 -1
  154. package/dist/src/telemetry/metrics.test.js +31 -1
  155. package/dist/src/telemetry/metrics.test.js.map +1 -1
  156. package/dist/src/telemetry/sdk.d.ts +1 -1
  157. package/dist/src/telemetry/sdk.js +80 -44
  158. package/dist/src/telemetry/sdk.js.map +1 -1
  159. package/dist/src/telemetry/sdk.test.d.ts +6 -0
  160. package/dist/src/telemetry/sdk.test.js +82 -0
  161. package/dist/src/telemetry/sdk.test.js.map +1 -0
  162. package/dist/src/telemetry/telemetry.test.js +2 -2
  163. package/dist/src/telemetry/telemetry.test.js.map +1 -1
  164. package/dist/src/telemetry/types.d.ts +41 -14
  165. package/dist/src/telemetry/types.js +52 -23
  166. package/dist/src/telemetry/types.js.map +1 -1
  167. package/dist/src/telemetry/uiTelemetry.d.ts +4 -0
  168. package/dist/src/telemetry/uiTelemetry.js +14 -1
  169. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  170. package/dist/src/telemetry/uiTelemetry.test.js +45 -9
  171. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  172. package/dist/src/test-utils/config.d.ts +16 -0
  173. package/dist/src/test-utils/config.js +32 -0
  174. package/dist/src/test-utils/config.js.map +1 -0
  175. package/dist/src/test-utils/tools.d.ts +29 -8
  176. package/dist/src/test-utils/tools.js +80 -16
  177. package/dist/src/test-utils/tools.js.map +1 -1
  178. package/dist/src/tools/edit.d.ts +1 -1
  179. package/dist/src/tools/edit.js +23 -19
  180. package/dist/src/tools/edit.js.map +1 -1
  181. package/dist/src/tools/edit.test.js +11 -3
  182. package/dist/src/tools/edit.test.js.map +1 -1
  183. package/dist/src/tools/glob.d.ts +1 -1
  184. package/dist/src/tools/glob.js +15 -16
  185. package/dist/src/tools/glob.js.map +1 -1
  186. package/dist/src/tools/glob.test.js +20 -0
  187. package/dist/src/tools/glob.test.js.map +1 -1
  188. package/dist/src/tools/grep.d.ts +1 -1
  189. package/dist/src/tools/grep.js +7 -13
  190. package/dist/src/tools/grep.js.map +1 -1
  191. package/dist/src/tools/ls.d.ts +4 -23
  192. package/dist/src/tools/ls.js +77 -79
  193. package/dist/src/tools/ls.js.map +1 -1
  194. package/dist/src/tools/ls.test.js +62 -34
  195. package/dist/src/tools/ls.test.js.map +1 -1
  196. package/dist/src/tools/mcp-client-manager.d.ts +38 -0
  197. package/dist/src/tools/mcp-client-manager.js +74 -0
  198. package/dist/src/tools/mcp-client-manager.js.map +1 -0
  199. package/dist/src/tools/mcp-client-manager.test.d.ts +6 -0
  200. package/dist/src/tools/mcp-client-manager.test.js +39 -0
  201. package/dist/src/tools/mcp-client-manager.test.js.map +1 -0
  202. package/dist/src/tools/mcp-client.d.ts +43 -0
  203. package/dist/src/tools/mcp-client.js +157 -11
  204. package/dist/src/tools/mcp-client.js.map +1 -1
  205. package/dist/src/tools/mcp-client.test.js +62 -276
  206. package/dist/src/tools/mcp-client.test.js.map +1 -1
  207. package/dist/src/tools/mcp-tool.d.ts +6 -13
  208. package/dist/src/tools/mcp-tool.js +62 -34
  209. package/dist/src/tools/mcp-tool.js.map +1 -1
  210. package/dist/src/tools/mcp-tool.test.js +118 -59
  211. package/dist/src/tools/mcp-tool.test.js.map +1 -1
  212. package/dist/src/tools/memoryTool.d.ts +9 -13
  213. package/dist/src/tools/memoryTool.js +122 -121
  214. package/dist/src/tools/memoryTool.js.map +1 -1
  215. package/dist/src/tools/memoryTool.test.js +38 -18
  216. package/dist/src/tools/memoryTool.test.js.map +1 -1
  217. package/dist/src/tools/read-file.d.ts +1 -1
  218. package/dist/src/tools/read-file.js +11 -14
  219. package/dist/src/tools/read-file.js.map +1 -1
  220. package/dist/src/tools/read-file.test.js +8 -0
  221. package/dist/src/tools/read-file.test.js.map +1 -1
  222. package/dist/src/tools/read-many-files.d.ts +3 -5
  223. package/dist/src/tools/read-many-files.js +121 -105
  224. package/dist/src/tools/read-many-files.js.map +1 -1
  225. package/dist/src/tools/read-many-files.test.js +94 -37
  226. package/dist/src/tools/read-many-files.test.js.map +1 -1
  227. package/dist/src/tools/shell.d.ts +4 -6
  228. package/dist/src/tools/shell.js +120 -124
  229. package/dist/src/tools/shell.js.map +1 -1
  230. package/dist/src/tools/shell.test.js +63 -65
  231. package/dist/src/tools/shell.test.js.map +1 -1
  232. package/dist/src/tools/tool-error.d.ts +1 -0
  233. package/dist/src/tools/tool-error.js +1 -0
  234. package/dist/src/tools/tool-error.js.map +1 -1
  235. package/dist/src/tools/tool-registry.d.ts +14 -18
  236. package/dist/src/tools/tool-registry.js +73 -106
  237. package/dist/src/tools/tool-registry.js.map +1 -1
  238. package/dist/src/tools/tool-registry.test.js +24 -192
  239. package/dist/src/tools/tool-registry.test.js.map +1 -1
  240. package/dist/src/tools/tools.d.ts +33 -89
  241. package/dist/src/tools/tools.js +76 -119
  242. package/dist/src/tools/tools.js.map +1 -1
  243. package/dist/src/tools/tools.test.js +91 -2
  244. package/dist/src/tools/tools.test.js.map +1 -1
  245. package/dist/src/tools/web-fetch.d.ts +4 -7
  246. package/dist/src/tools/web-fetch.js +58 -64
  247. package/dist/src/tools/web-fetch.js.map +1 -1
  248. package/dist/src/tools/web-fetch.test.js +8 -4
  249. package/dist/src/tools/web-fetch.test.js.map +1 -1
  250. package/dist/src/tools/web-search.d.ts +4 -5
  251. package/dist/src/tools/web-search.js +47 -51
  252. package/dist/src/tools/web-search.js.map +1 -1
  253. package/dist/src/tools/web-search.test.d.ts +6 -0
  254. package/dist/src/tools/web-search.test.js +139 -0
  255. package/dist/src/tools/web-search.test.js.map +1 -0
  256. package/dist/src/tools/write-file.d.ts +15 -10
  257. package/dist/src/tools/write-file.js +134 -145
  258. package/dist/src/tools/write-file.js.map +1 -1
  259. package/dist/src/tools/write-file.test.js +82 -127
  260. package/dist/src/tools/write-file.test.js.map +1 -1
  261. package/dist/src/utils/browser.js +4 -3
  262. package/dist/src/utils/browser.js.map +1 -1
  263. package/dist/src/utils/editCorrector.js +21 -22
  264. package/dist/src/utils/editCorrector.js.map +1 -1
  265. package/dist/src/utils/editor.js +1 -1
  266. package/dist/src/utils/editor.js.map +1 -1
  267. package/dist/src/utils/editor.test.js +10 -10
  268. package/dist/src/utils/editor.test.js.map +1 -1
  269. package/dist/src/utils/environmentContext.js +2 -2
  270. package/dist/src/utils/environmentContext.js.map +1 -1
  271. package/dist/src/utils/environmentContext.test.js +3 -2
  272. package/dist/src/utils/environmentContext.test.js.map +1 -1
  273. package/dist/src/utils/errorParsing.d.ts +8 -0
  274. package/dist/src/utils/errorParsing.js +93 -0
  275. package/dist/src/utils/errorParsing.js.map +1 -0
  276. package/dist/src/utils/errorParsing.test.d.ts +6 -0
  277. package/dist/src/utils/errorParsing.test.js +172 -0
  278. package/dist/src/utils/errorParsing.test.js.map +1 -0
  279. package/dist/src/utils/fileUtils.d.ts +2 -1
  280. package/dist/src/utils/fileUtils.js +3 -3
  281. package/dist/src/utils/fileUtils.js.map +1 -1
  282. package/dist/src/utils/fileUtils.test.js +18 -17
  283. package/dist/src/utils/fileUtils.test.js.map +1 -1
  284. package/dist/src/utils/filesearch/crawler.d.ts +15 -0
  285. package/dist/src/utils/filesearch/crawler.js +50 -0
  286. package/dist/src/utils/filesearch/crawler.js.map +1 -0
  287. package/dist/src/utils/filesearch/crawler.test.d.ts +6 -0
  288. package/dist/src/utils/filesearch/crawler.test.js +468 -0
  289. package/dist/src/utils/filesearch/crawler.test.js.map +1 -0
  290. package/dist/src/utils/filesearch/fileSearch.d.ts +9 -53
  291. package/dist/src/utils/filesearch/fileSearch.js +63 -118
  292. package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
  293. package/dist/src/utils/filesearch/fileSearch.test.js +95 -197
  294. package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -1
  295. package/dist/src/utils/filesearch/ignore.d.ts +7 -0
  296. package/dist/src/utils/filesearch/ignore.js +25 -0
  297. package/dist/src/utils/filesearch/ignore.js.map +1 -1
  298. package/dist/src/utils/filesearch/ignore.test.js +89 -2
  299. package/dist/src/utils/filesearch/ignore.test.js.map +1 -1
  300. package/dist/src/utils/filesearch/result-cache.d.ts +1 -2
  301. package/dist/src/utils/filesearch/result-cache.js +1 -3
  302. package/dist/src/utils/filesearch/result-cache.js.map +1 -1
  303. package/dist/src/utils/filesearch/result-cache.test.js +3 -4
  304. package/dist/src/utils/filesearch/result-cache.test.js.map +1 -1
  305. package/dist/src/utils/getPty.d.ts +19 -0
  306. package/dist/src/utils/getPty.js +23 -0
  307. package/dist/src/utils/getPty.js.map +1 -0
  308. package/dist/src/utils/memoryDiscovery.js +3 -3
  309. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  310. package/dist/src/utils/memoryDiscovery.test.js +3 -2
  311. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  312. package/dist/src/utils/memoryImportProcessor.js +3 -7
  313. package/dist/src/utils/memoryImportProcessor.js.map +1 -1
  314. package/dist/src/utils/memoryImportProcessor.test.js +17 -20
  315. package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
  316. package/dist/src/utils/nextSpeakerChecker.js +3 -4
  317. package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
  318. package/dist/src/utils/paths.d.ts +7 -0
  319. package/dist/src/utils/paths.js +15 -0
  320. package/dist/src/utils/paths.js.map +1 -1
  321. package/dist/src/utils/paths.test.js +74 -2
  322. package/dist/src/utils/paths.test.js.map +1 -1
  323. package/dist/src/utils/quotaErrorDetection.d.ts +1 -5
  324. package/dist/src/utils/quotaErrorDetection.js.map +1 -1
  325. package/dist/src/utils/schemaValidator.d.ts +1 -8
  326. package/dist/src/utils/schemaValidator.js +1 -32
  327. package/dist/src/utils/schemaValidator.js.map +1 -1
  328. package/dist/src/utils/secure-browser-launcher.js +4 -3
  329. package/dist/src/utils/secure-browser-launcher.js.map +1 -1
  330. package/dist/src/utils/shell-utils.d.ts +39 -0
  331. package/dist/src/utils/shell-utils.js +72 -2
  332. package/dist/src/utils/shell-utils.js.map +1 -1
  333. package/dist/src/utils/shell-utils.test.js +132 -4
  334. package/dist/src/utils/shell-utils.test.js.map +1 -1
  335. package/dist/src/utils/systemEncoding.js +1 -1
  336. package/dist/src/utils/systemEncoding.js.map +1 -1
  337. package/dist/src/utils/systemEncoding.test.js +23 -23
  338. package/dist/src/utils/systemEncoding.test.js.map +1 -1
  339. package/dist/src/utils/user_account.js +58 -48
  340. package/dist/src/utils/user_account.js.map +1 -1
  341. package/dist/src/utils/user_account.test.js +76 -9
  342. package/dist/src/utils/user_account.test.js.map +1 -1
  343. package/dist/src/utils/workspaceContext.d.ts +22 -7
  344. package/dist/src/utils/workspaceContext.js +81 -55
  345. package/dist/src/utils/workspaceContext.js.map +1 -1
  346. package/dist/src/utils/workspaceContext.test.js +221 -137
  347. package/dist/src/utils/workspaceContext.test.js.map +1 -1
  348. package/dist/tsconfig.tsbuildinfo +1 -1
  349. package/package.json +21 -8
@@ -3,49 +3,32 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { BaseTool, ToolConfirmationOutcome, Icon, } from './tools.js';
7
- import { Type, } from '@google/genai';
8
- export class DiscoveredMCPTool extends BaseTool {
6
+ import { BaseDeclarativeTool, BaseToolInvocation, Kind, ToolConfirmationOutcome, } from './tools.js';
7
+ class DiscoveredMCPToolInvocation extends BaseToolInvocation {
9
8
  mcpTool;
10
9
  serverName;
11
10
  serverToolName;
12
- parameterSchemaJson;
11
+ displayName;
13
12
  timeout;
14
13
  trust;
15
14
  static allowlist = new Set();
16
- constructor(mcpTool, serverName, serverToolName, description, parameterSchemaJson, timeout, trust, nameOverride) {
17
- super(nameOverride ?? generateValidName(serverToolName), `${serverToolName} (${serverName} MCP Server)`, description, Icon.Hammer, { type: Type.OBJECT }, // this is a dummy Schema for MCP, will be not be used to construct the FunctionDeclaration
18
- true, // isOutputMarkdown
19
- false);
15
+ constructor(mcpTool, serverName, serverToolName, displayName, timeout, trust, params = {}) {
16
+ super(params);
20
17
  this.mcpTool = mcpTool;
21
18
  this.serverName = serverName;
22
19
  this.serverToolName = serverToolName;
23
- this.parameterSchemaJson = parameterSchemaJson;
20
+ this.displayName = displayName;
24
21
  this.timeout = timeout;
25
22
  this.trust = trust;
26
23
  }
27
- asFullyQualifiedTool() {
28
- return new DiscoveredMCPTool(this.mcpTool, this.serverName, this.serverToolName, this.description, this.parameterSchemaJson, this.timeout, this.trust, `${this.serverName}__${this.serverToolName}`);
29
- }
30
- /**
31
- * Overrides the base schema to use parametersJsonSchema when building
32
- * FunctionDeclaration
33
- */
34
- get schema() {
35
- return {
36
- name: this.name,
37
- description: this.description,
38
- parametersJsonSchema: this.parameterSchemaJson,
39
- };
40
- }
41
- async shouldConfirmExecute(_params, _abortSignal) {
24
+ async shouldConfirmExecute(_abortSignal) {
42
25
  const serverAllowListKey = this.serverName;
43
26
  const toolAllowListKey = `${this.serverName}.${this.serverToolName}`;
44
27
  if (this.trust) {
45
28
  return false; // server is trusted, no confirmation needed
46
29
  }
47
- if (DiscoveredMCPTool.allowlist.has(serverAllowListKey) ||
48
- DiscoveredMCPTool.allowlist.has(toolAllowListKey)) {
30
+ if (DiscoveredMCPToolInvocation.allowlist.has(serverAllowListKey) ||
31
+ DiscoveredMCPToolInvocation.allowlist.has(toolAllowListKey)) {
49
32
  return false; // server and/or tool already allowlisted
50
33
  }
51
34
  const confirmationDetails = {
@@ -53,32 +36,78 @@ export class DiscoveredMCPTool extends BaseTool {
53
36
  title: 'Confirm MCP Tool Execution',
54
37
  serverName: this.serverName,
55
38
  toolName: this.serverToolName, // Display original tool name in confirmation
56
- toolDisplayName: this.name, // Display global registry name exposed to model and user
39
+ toolDisplayName: this.displayName, // Display global registry name exposed to model and user
57
40
  onConfirm: async (outcome) => {
58
41
  if (outcome === ToolConfirmationOutcome.ProceedAlwaysServer) {
59
- DiscoveredMCPTool.allowlist.add(serverAllowListKey);
42
+ DiscoveredMCPToolInvocation.allowlist.add(serverAllowListKey);
60
43
  }
61
44
  else if (outcome === ToolConfirmationOutcome.ProceedAlwaysTool) {
62
- DiscoveredMCPTool.allowlist.add(toolAllowListKey);
45
+ DiscoveredMCPToolInvocation.allowlist.add(toolAllowListKey);
63
46
  }
64
47
  },
65
48
  };
66
49
  return confirmationDetails;
67
50
  }
68
- async execute(params) {
51
+ // Determine if the response contains tool errors
52
+ // This is needed because CallToolResults should return errors inside the response.
53
+ // ref: https://modelcontextprotocol.io/specification/2025-06-18/schema#calltoolresult
54
+ isMCPToolError(rawResponseParts) {
55
+ const functionResponse = rawResponseParts?.[0]?.functionResponse;
56
+ const response = functionResponse?.response;
57
+ if (response) {
58
+ const error = response?.error;
59
+ const isError = error?.isError;
60
+ if (error && (isError === true || isError === 'true')) {
61
+ return true;
62
+ }
63
+ }
64
+ return false;
65
+ }
66
+ async execute() {
69
67
  const functionCalls = [
70
68
  {
71
69
  name: this.serverToolName,
72
- args: params,
70
+ args: this.params,
73
71
  },
74
72
  ];
75
73
  const rawResponseParts = await this.mcpTool.callTool(functionCalls);
74
+ // Ensure the response is not an error
75
+ if (this.isMCPToolError(rawResponseParts)) {
76
+ throw new Error(`MCP tool '${this.serverToolName}' reported tool error with response: ${JSON.stringify(rawResponseParts)}`);
77
+ }
76
78
  const transformedParts = transformMcpContentToParts(rawResponseParts);
77
79
  return {
78
80
  llmContent: transformedParts,
79
81
  returnDisplay: getStringifiedResultForDisplay(rawResponseParts),
80
82
  };
81
83
  }
84
+ getDescription() {
85
+ return this.displayName;
86
+ }
87
+ }
88
+ export class DiscoveredMCPTool extends BaseDeclarativeTool {
89
+ mcpTool;
90
+ serverName;
91
+ serverToolName;
92
+ parameterSchema;
93
+ timeout;
94
+ trust;
95
+ constructor(mcpTool, serverName, serverToolName, description, parameterSchema, timeout, trust, nameOverride) {
96
+ super(nameOverride ?? generateValidName(serverToolName), `${serverToolName} (${serverName} MCP Server)`, description, Kind.Other, parameterSchema, true, // isOutputMarkdown
97
+ false);
98
+ this.mcpTool = mcpTool;
99
+ this.serverName = serverName;
100
+ this.serverToolName = serverToolName;
101
+ this.parameterSchema = parameterSchema;
102
+ this.timeout = timeout;
103
+ this.trust = trust;
104
+ }
105
+ asFullyQualifiedTool() {
106
+ return new DiscoveredMCPTool(this.mcpTool, this.serverName, this.serverToolName, this.description, this.parameterSchema, this.timeout, this.trust, `${this.serverName}__${this.serverToolName}`);
107
+ }
108
+ createInvocation(params) {
109
+ return new DiscoveredMCPToolInvocation(this.mcpTool, this.serverName, this.serverToolName, this.displayName, this.timeout, this.trust, params);
110
+ }
82
111
  }
83
112
  function transformTextBlock(block) {
84
113
  return { text: block.text };
@@ -130,7 +159,7 @@ function transformResourceLinkBlock(block) {
130
159
  */
131
160
  function transformMcpContentToParts(sdkResponse) {
132
161
  const funcResponse = sdkResponse?.[0]?.functionResponse;
133
- const mcpContent = funcResponse?.response?.content;
162
+ const mcpContent = funcResponse?.response?.['content'];
134
163
  const toolName = funcResponse?.name || 'unknown tool';
135
164
  if (!Array.isArray(mcpContent)) {
136
165
  return [{ text: '[Error: Could not parse tool response]' }];
@@ -161,8 +190,7 @@ function transformMcpContentToParts(sdkResponse) {
161
190
  * @returns A formatted string representing the tool's output.
162
191
  */
163
192
  function getStringifiedResultForDisplay(rawResponse) {
164
- const mcpContent = rawResponse?.[0]?.functionResponse?.response
165
- ?.content;
193
+ const mcpContent = rawResponse?.[0]?.functionResponse?.response?.['content'];
166
194
  if (!Array.isArray(mcpContent)) {
167
195
  return '```json\n' + JSON.stringify(rawResponse, null, 2) + '\n```';
168
196
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-tool.js","sourceRoot":"","sources":["../../../src/tools/mcp-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,QAAQ,EAGR,uBAAuB,EAEvB,IAAI,GACL,MAAM,YAAY,CAAC;AACpB,OAAO,EAKL,IAAI,GACL,MAAM,eAAe,CAAC;AAsCvB,MAAM,OAAO,iBAAkB,SAAQ,QAAgC;IAIlD;IACR;IACA;IAEA;IACA;IACA;IATH,MAAM,CAAU,SAAS,GAAgB,IAAI,GAAG,EAAE,CAAC;IAE3D,YACmB,OAAqB,EAC7B,UAAkB,EAClB,cAAsB,EAC/B,WAAmB,EACV,mBAA4B,EAC5B,OAAgB,EAChB,KAAe,EACxB,YAAqB;QAErB,KAAK,CACH,YAAY,IAAI,iBAAiB,CAAC,cAAc,CAAC,EACjD,GAAG,cAAc,KAAK,UAAU,cAAc,EAC9C,WAAW,EACX,IAAI,CAAC,MAAM,EACX,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,2FAA2F;QAClH,IAAI,EAAE,mBAAmB;QACzB,KAAK,CACN,CAAC;QAjBe,YAAO,GAAP,OAAO,CAAc;QAC7B,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAAQ;QAEtB,wBAAmB,GAAnB,mBAAmB,CAAS;QAC5B,YAAO,GAAP,OAAO,CAAS;QAChB,UAAK,GAAL,KAAK,CAAU;IAY1B,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,EACV,GAAG,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,cAAc,E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C;gBAC7B,CAAC;gBACD,OAAO,uBACL,KAAK,CAAC,QAAQ,EAAE,QAAQ,IAAI,cAC9B,GAAG,CAAC;YACN;gBACE,OAAO,0BAA2B,KAA0B,CAAC,IAAI,GAAG,CAAC;QACzE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,0BAA0B;AAC1B,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,2FAA2F;IAC3F,IAAI,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;IAE1D,0DAA0D;IAC1D,mEAAmE;IACnE,IAAI,aAAa,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QAC9B,aAAa;YACX,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -48,18 +48,20 @@ describe('DiscoveredMCPTool', () => {
48
48
  properties: { param: { type: 'string' } },
49
49
  required: ['param'],
50
50
  };
51
+ let tool;
51
52
  beforeEach(() => {
52
53
  mockCallTool.mockClear();
53
54
  mockToolMethod.mockClear();
55
+ tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
54
56
  // Clear allowlist before each relevant test, especially for shouldConfirmExecute
55
- DiscoveredMCPTool.allowlist.clear();
57
+ const invocation = tool.build({ param: 'mock' });
58
+ invocation.constructor.allowlist.clear();
56
59
  });
57
60
  afterEach(() => {
58
61
  vi.restoreAllMocks();
59
62
  });
60
63
  describe('constructor', () => {
61
64
  it('should set properties correctly', () => {
62
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
63
65
  expect(tool.name).toBe(serverToolName);
64
66
  expect(tool.schema.name).toBe(serverToolName);
65
67
  expect(tool.schema.description).toBe(baseDescription);
@@ -70,13 +72,12 @@ describe('DiscoveredMCPTool', () => {
70
72
  });
71
73
  it('should accept and store a custom timeout', () => {
72
74
  const customTimeout = 5000;
73
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema, customTimeout);
74
- expect(tool.timeout).toBe(customTimeout);
75
+ const toolWithTimeout = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema, customTimeout);
76
+ expect(toolWithTimeout.timeout).toBe(customTimeout);
75
77
  });
76
78
  });
77
79
  describe('execute', () => {
78
80
  it('should call mcpTool.callTool with correct parameters and format display output', async () => {
79
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
80
81
  const params = { param: 'testValue' };
81
82
  const mockToolSuccessResultObject = {
82
83
  success: true,
@@ -97,7 +98,8 @@ describe('DiscoveredMCPTool', () => {
97
98
  },
98
99
  ];
99
100
  mockCallTool.mockResolvedValue(mockMcpToolResponseParts);
100
- const toolResult = await tool.execute(params);
101
+ const invocation = tool.build(params);
102
+ const toolResult = await invocation.execute(new AbortController().signal);
101
103
  expect(mockCallTool).toHaveBeenCalledWith([
102
104
  { name: serverToolName, args: params },
103
105
  ]);
@@ -108,26 +110,82 @@ describe('DiscoveredMCPTool', () => {
108
110
  expect(toolResult.returnDisplay).toBe(stringifiedResponseContent);
109
111
  });
110
112
  it('should handle empty result from getStringifiedResultForDisplay', async () => {
111
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
112
113
  const params = { param: 'testValue' };
113
114
  const mockMcpToolResponsePartsEmpty = [];
114
115
  mockCallTool.mockResolvedValue(mockMcpToolResponsePartsEmpty);
115
- const toolResult = await tool.execute(params);
116
+ const invocation = tool.build(params);
117
+ const toolResult = await invocation.execute(new AbortController().signal);
116
118
  expect(toolResult.returnDisplay).toBe('```json\n[]\n```');
117
119
  expect(toolResult.llmContent).toEqual([
118
120
  { text: '[Error: Could not parse tool response]' },
119
121
  ]);
120
122
  });
121
123
  it('should propagate rejection if mcpTool.callTool rejects', async () => {
122
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
123
124
  const params = { param: 'failCase' };
124
125
  const expectedError = new Error('MCP call failed');
125
126
  mockCallTool.mockRejectedValue(expectedError);
126
- await expect(tool.execute(params)).rejects.toThrow(expectedError);
127
+ const invocation = tool.build(params);
128
+ await expect(invocation.execute(new AbortController().signal)).rejects.toThrow(expectedError);
127
129
  });
128
- it('should handle a simple text response correctly', async () => {
130
+ it.each([
131
+ { isErrorValue: true, description: 'true (bool)' },
132
+ { isErrorValue: 'true', description: '"true" (str)' },
133
+ ])('should consider a ToolResult with isError $description to be a failure', async ({ isErrorValue }) => {
134
+ const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
135
+ const params = { param: 'isErrorTrueCase' };
136
+ const errorResponse = { isError: isErrorValue };
137
+ const mockMcpToolResponseParts = [
138
+ {
139
+ functionResponse: {
140
+ name: serverToolName,
141
+ response: { error: errorResponse },
142
+ },
143
+ },
144
+ ];
145
+ mockCallTool.mockResolvedValue(mockMcpToolResponseParts);
146
+ const expectedError = new Error(`MCP tool '${serverToolName}' reported tool error with response: ${JSON.stringify(mockMcpToolResponseParts)}`);
147
+ const invocation = tool.build(params);
148
+ await expect(invocation.execute(new AbortController().signal)).rejects.toThrow(expectedError);
149
+ });
150
+ it.each([
151
+ { isErrorValue: false, description: 'false (bool)' },
152
+ { isErrorValue: 'false', description: '"false" (str)' },
153
+ ])('should consider a ToolResult with isError ${description} to be a success', async ({ isErrorValue }) => {
129
154
  const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
130
- const params = { query: 'test' };
155
+ const params = { param: 'isErrorFalseCase' };
156
+ const mockToolSuccessResultObject = {
157
+ success: true,
158
+ details: 'executed',
159
+ };
160
+ const mockFunctionResponseContent = [
161
+ {
162
+ type: 'text',
163
+ text: JSON.stringify(mockToolSuccessResultObject),
164
+ },
165
+ ];
166
+ const errorResponse = { isError: isErrorValue };
167
+ const mockMcpToolResponseParts = [
168
+ {
169
+ functionResponse: {
170
+ name: serverToolName,
171
+ response: {
172
+ error: errorResponse,
173
+ content: mockFunctionResponseContent,
174
+ },
175
+ },
176
+ },
177
+ ];
178
+ mockCallTool.mockResolvedValue(mockMcpToolResponseParts);
179
+ const invocation = tool.build(params);
180
+ const toolResult = await invocation.execute(new AbortController().signal);
181
+ const stringifiedResponseContent = JSON.stringify(mockToolSuccessResultObject);
182
+ expect(toolResult.llmContent).toEqual([
183
+ { text: stringifiedResponseContent },
184
+ ]);
185
+ expect(toolResult.returnDisplay).toBe(stringifiedResponseContent);
186
+ });
187
+ it('should handle a simple text response correctly', async () => {
188
+ const params = { param: 'test' };
131
189
  const successMessage = 'This is a success message.';
132
190
  // Simulate the response from the GenAI SDK, which wraps the MCP
133
191
  // response in a functionResponse Part.
@@ -143,7 +201,8 @@ describe('DiscoveredMCPTool', () => {
143
201
  },
144
202
  ];
145
203
  mockCallTool.mockResolvedValue(sdkResponse);
146
- const toolResult = await tool.execute(params);
204
+ const invocation = tool.build(params);
205
+ const toolResult = await invocation.execute(new AbortController().signal);
147
206
  // 1. Assert that the llmContent sent to the scheduler is a clean Part array.
148
207
  expect(toolResult.llmContent).toEqual([{ text: successMessage }]);
149
208
  // 2. Assert that the display output is the simple text message.
@@ -154,8 +213,7 @@ describe('DiscoveredMCPTool', () => {
154
213
  ]);
155
214
  });
156
215
  it('should handle an AudioBlock response', async () => {
157
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
158
- const params = { action: 'play' };
216
+ const params = { param: 'play' };
159
217
  const sdkResponse = [
160
218
  {
161
219
  functionResponse: {
@@ -173,7 +231,8 @@ describe('DiscoveredMCPTool', () => {
173
231
  },
174
232
  ];
175
233
  mockCallTool.mockResolvedValue(sdkResponse);
176
- const toolResult = await tool.execute(params);
234
+ const invocation = tool.build(params);
235
+ const toolResult = await invocation.execute(new AbortController().signal);
177
236
  expect(toolResult.llmContent).toEqual([
178
237
  {
179
238
  text: `[Tool '${serverToolName}' provided the following audio data with mime-type: audio/mp3]`,
@@ -188,8 +247,7 @@ describe('DiscoveredMCPTool', () => {
188
247
  expect(toolResult.returnDisplay).toBe('[Audio: audio/mp3]');
189
248
  });
190
249
  it('should handle a ResourceLinkBlock response', async () => {
191
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
192
- const params = { resource: 'get' };
250
+ const params = { param: 'get' };
193
251
  const sdkResponse = [
194
252
  {
195
253
  functionResponse: {
@@ -208,7 +266,8 @@ describe('DiscoveredMCPTool', () => {
208
266
  },
209
267
  ];
210
268
  mockCallTool.mockResolvedValue(sdkResponse);
211
- const toolResult = await tool.execute(params);
269
+ const invocation = tool.build(params);
270
+ const toolResult = await invocation.execute(new AbortController().signal);
212
271
  expect(toolResult.llmContent).toEqual([
213
272
  {
214
273
  text: 'Resource Link: My Resource at file:///path/to/thing',
@@ -217,8 +276,7 @@ describe('DiscoveredMCPTool', () => {
217
276
  expect(toolResult.returnDisplay).toBe('[Link to My Resource: file:///path/to/thing]');
218
277
  });
219
278
  it('should handle an embedded text ResourceBlock response', async () => {
220
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
221
- const params = { resource: 'get' };
279
+ const params = { param: 'get' };
222
280
  const sdkResponse = [
223
281
  {
224
282
  functionResponse: {
@@ -239,15 +297,15 @@ describe('DiscoveredMCPTool', () => {
239
297
  },
240
298
  ];
241
299
  mockCallTool.mockResolvedValue(sdkResponse);
242
- const toolResult = await tool.execute(params);
300
+ const invocation = tool.build(params);
301
+ const toolResult = await invocation.execute(new AbortController().signal);
243
302
  expect(toolResult.llmContent).toEqual([
244
303
  { text: 'This is the text content.' },
245
304
  ]);
246
305
  expect(toolResult.returnDisplay).toBe('This is the text content.');
247
306
  });
248
307
  it('should handle an embedded binary ResourceBlock response', async () => {
249
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
250
- const params = { resource: 'get' };
308
+ const params = { param: 'get' };
251
309
  const sdkResponse = [
252
310
  {
253
311
  functionResponse: {
@@ -268,7 +326,8 @@ describe('DiscoveredMCPTool', () => {
268
326
  },
269
327
  ];
270
328
  mockCallTool.mockResolvedValue(sdkResponse);
271
- const toolResult = await tool.execute(params);
329
+ const invocation = tool.build(params);
330
+ const toolResult = await invocation.execute(new AbortController().signal);
272
331
  expect(toolResult.llmContent).toEqual([
273
332
  {
274
333
  text: `[Tool '${serverToolName}' provided the following embedded resource with mime-type: application/octet-stream]`,
@@ -283,8 +342,7 @@ describe('DiscoveredMCPTool', () => {
283
342
  expect(toolResult.returnDisplay).toBe('[Embedded Resource: application/octet-stream]');
284
343
  });
285
344
  it('should handle a mix of content block types', async () => {
286
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
287
- const params = { action: 'complex' };
345
+ const params = { param: 'complex' };
288
346
  const sdkResponse = [
289
347
  {
290
348
  functionResponse: {
@@ -304,7 +362,8 @@ describe('DiscoveredMCPTool', () => {
304
362
  },
305
363
  ];
306
364
  mockCallTool.mockResolvedValue(sdkResponse);
307
- const toolResult = await tool.execute(params);
365
+ const invocation = tool.build(params);
366
+ const toolResult = await invocation.execute(new AbortController().signal);
308
367
  expect(toolResult.llmContent).toEqual([
309
368
  { text: 'First part.' },
310
369
  {
@@ -321,8 +380,7 @@ describe('DiscoveredMCPTool', () => {
321
380
  expect(toolResult.returnDisplay).toBe('First part.\n[Image: image/jpeg]\nSecond part.');
322
381
  });
323
382
  it('should ignore unknown content block types', async () => {
324
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
325
- const params = { action: 'test' };
383
+ const params = { param: 'test' };
326
384
  const sdkResponse = [
327
385
  {
328
386
  functionResponse: {
@@ -337,13 +395,13 @@ describe('DiscoveredMCPTool', () => {
337
395
  },
338
396
  ];
339
397
  mockCallTool.mockResolvedValue(sdkResponse);
340
- const toolResult = await tool.execute(params);
398
+ const invocation = tool.build(params);
399
+ const toolResult = await invocation.execute(new AbortController().signal);
341
400
  expect(toolResult.llmContent).toEqual([{ text: 'Valid part.' }]);
342
401
  expect(toolResult.returnDisplay).toBe('Valid part.\n[Unknown content type: future_block]');
343
402
  });
344
403
  it('should handle a complex mix of content block types', async () => {
345
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
346
- const params = { action: 'super-complex' };
404
+ const params = { param: 'super-complex' };
347
405
  const sdkResponse = [
348
406
  {
349
407
  functionResponse: {
@@ -376,7 +434,8 @@ describe('DiscoveredMCPTool', () => {
376
434
  },
377
435
  ];
378
436
  mockCallTool.mockResolvedValue(sdkResponse);
379
- const toolResult = await tool.execute(params);
437
+ const invocation = tool.build(params);
438
+ const toolResult = await invocation.execute(new AbortController().signal);
380
439
  expect(toolResult.llmContent).toEqual([
381
440
  { text: 'Here is a resource.' },
382
441
  {
@@ -397,25 +456,25 @@ describe('DiscoveredMCPTool', () => {
397
456
  });
398
457
  });
399
458
  describe('shouldConfirmExecute', () => {
400
- // beforeEach is already clearing allowlist
401
459
  it('should return false if trust is true', async () => {
402
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema, undefined, true);
403
- expect(await tool.shouldConfirmExecute({}, new AbortController().signal)).toBe(false);
460
+ const trustedTool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema, undefined, true);
461
+ const invocation = trustedTool.build({ param: 'mock' });
462
+ expect(await invocation.shouldConfirmExecute(new AbortController().signal)).toBe(false);
404
463
  });
405
464
  it('should return false if server is allowlisted', async () => {
406
- DiscoveredMCPTool.allowlist.add(serverName);
407
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
408
- expect(await tool.shouldConfirmExecute({}, new AbortController().signal)).toBe(false);
465
+ const invocation = tool.build({ param: 'mock' });
466
+ invocation.constructor.allowlist.add(serverName);
467
+ expect(await invocation.shouldConfirmExecute(new AbortController().signal)).toBe(false);
409
468
  });
410
469
  it('should return false if tool is allowlisted', async () => {
411
470
  const toolAllowlistKey = `${serverName}.${serverToolName}`;
412
- DiscoveredMCPTool.allowlist.add(toolAllowlistKey);
413
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
414
- expect(await tool.shouldConfirmExecute({}, new AbortController().signal)).toBe(false);
471
+ const invocation = tool.build({ param: 'mock' });
472
+ invocation.constructor.allowlist.add(toolAllowlistKey);
473
+ expect(await invocation.shouldConfirmExecute(new AbortController().signal)).toBe(false);
415
474
  });
416
475
  it('should return confirmation details if not trusted and not allowlisted', async () => {
417
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
418
- const confirmation = await tool.shouldConfirmExecute({}, new AbortController().signal);
476
+ const invocation = tool.build({ param: 'mock' });
477
+ const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
419
478
  expect(confirmation).not.toBe(false);
420
479
  if (confirmation && confirmation.type === 'mcp') {
421
480
  // Type guard for ToolMcpConfirmationDetails
@@ -432,39 +491,39 @@ describe('DiscoveredMCPTool', () => {
432
491
  }
433
492
  });
434
493
  it('should add server to allowlist on ProceedAlwaysServer', async () => {
435
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
436
- const confirmation = await tool.shouldConfirmExecute({}, new AbortController().signal);
494
+ const invocation = tool.build({ param: 'mock' });
495
+ const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
437
496
  expect(confirmation).not.toBe(false);
438
497
  if (confirmation &&
439
498
  typeof confirmation === 'object' &&
440
499
  'onConfirm' in confirmation &&
441
500
  typeof confirmation.onConfirm === 'function') {
442
501
  await confirmation.onConfirm(ToolConfirmationOutcome.ProceedAlwaysServer);
443
- expect(DiscoveredMCPTool.allowlist.has(serverName)).toBe(true);
502
+ expect(invocation.constructor.allowlist.has(serverName)).toBe(true);
444
503
  }
445
504
  else {
446
505
  throw new Error('Confirmation details or onConfirm not in expected format');
447
506
  }
448
507
  });
449
508
  it('should add tool to allowlist on ProceedAlwaysTool', async () => {
450
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
451
509
  const toolAllowlistKey = `${serverName}.${serverToolName}`;
452
- const confirmation = await tool.shouldConfirmExecute({}, new AbortController().signal);
510
+ const invocation = tool.build({ param: 'mock' });
511
+ const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
453
512
  expect(confirmation).not.toBe(false);
454
513
  if (confirmation &&
455
514
  typeof confirmation === 'object' &&
456
515
  'onConfirm' in confirmation &&
457
516
  typeof confirmation.onConfirm === 'function') {
458
517
  await confirmation.onConfirm(ToolConfirmationOutcome.ProceedAlwaysTool);
459
- expect(DiscoveredMCPTool.allowlist.has(toolAllowlistKey)).toBe(true);
518
+ expect(invocation.constructor.allowlist.has(toolAllowlistKey)).toBe(true);
460
519
  }
461
520
  else {
462
521
  throw new Error('Confirmation details or onConfirm not in expected format');
463
522
  }
464
523
  });
465
524
  it('should handle Cancel confirmation outcome', async () => {
466
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
467
- const confirmation = await tool.shouldConfirmExecute({}, new AbortController().signal);
525
+ const invocation = tool.build({ param: 'mock' });
526
+ const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
468
527
  expect(confirmation).not.toBe(false);
469
528
  if (confirmation &&
470
529
  typeof confirmation === 'object' &&
@@ -472,16 +531,16 @@ describe('DiscoveredMCPTool', () => {
472
531
  typeof confirmation.onConfirm === 'function') {
473
532
  // Cancel should not add anything to allowlist
474
533
  await confirmation.onConfirm(ToolConfirmationOutcome.Cancel);
475
- expect(DiscoveredMCPTool.allowlist.has(serverName)).toBe(false);
476
- expect(DiscoveredMCPTool.allowlist.has(`${serverName}.${serverToolName}`)).toBe(false);
534
+ expect(invocation.constructor.allowlist.has(serverName)).toBe(false);
535
+ expect(invocation.constructor.allowlist.has(`${serverName}.${serverToolName}`)).toBe(false);
477
536
  }
478
537
  else {
479
538
  throw new Error('Confirmation details or onConfirm not in expected format');
480
539
  }
481
540
  });
482
541
  it('should handle ProceedOnce confirmation outcome', async () => {
483
- const tool = new DiscoveredMCPTool(mockCallableToolInstance, serverName, serverToolName, baseDescription, inputSchema);
484
- const confirmation = await tool.shouldConfirmExecute({}, new AbortController().signal);
542
+ const invocation = tool.build({ param: 'mock' });
543
+ const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
485
544
  expect(confirmation).not.toBe(false);
486
545
  if (confirmation &&
487
546
  typeof confirmation === 'object' &&
@@ -489,8 +548,8 @@ describe('DiscoveredMCPTool', () => {
489
548
  typeof confirmation.onConfirm === 'function') {
490
549
  // ProceedOnce should not add anything to allowlist
491
550
  await confirmation.onConfirm(ToolConfirmationOutcome.ProceedOnce);
492
- expect(DiscoveredMCPTool.allowlist.has(serverName)).toBe(false);
493
- expect(DiscoveredMCPTool.allowlist.has(`${serverName}.${serverToolName}`)).toBe(false);
551
+ expect(invocation.constructor.allowlist.has(serverName)).toBe(false);
552
+ expect(invocation.constructor.allowlist.has(`${serverName}.${serverToolName}`)).toBe(false);
494
553
  }
495
554
  else {
496
555
  throw new Error('Confirmation details or onConfirm not in expected format');