@herbertgao/pi-extensions 2026.9.17 → 2026.9.19

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 (307) hide show
  1. package/README.md +31 -33
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/node_modules/@herbertgao/pi-bark/package.json +2 -2
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +4 -1
  5. package/node_modules/@herbertgao/pi-cc-extensions/README.md +4 -1
  6. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/working-message.ts +21 -6
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +15 -4
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/index.ts +43 -7
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +7 -2
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/result.ts +1 -1
  11. package/node_modules/@herbertgao/pi-cc-extensions/package.json +75 -75
  12. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  13. package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
  14. package/node_modules/@herbertgao/resume-from/package.json +4 -2
  15. package/node_modules/@herbertgao/sol-pi/package.json +6 -6
  16. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +99 -99
  17. package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
  18. package/node_modules/@tifan/pi-handoff/package.json +1 -1
  19. package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
  20. package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
  21. package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
  22. package/node_modules/@tifan/pi-recap/package.json +1 -1
  23. package/node_modules/@tifan/pi-rename/package.json +1 -1
  24. package/node_modules/pi-antigravity/README.md +29 -6
  25. package/node_modules/pi-antigravity/package.json +14 -9
  26. package/node_modules/pi-antigravity/src/auth/accounts.ts +327 -0
  27. package/node_modules/pi-antigravity/src/auth/index.ts +9 -0
  28. package/node_modules/pi-antigravity/src/client/client.ts +1 -1
  29. package/node_modules/pi-antigravity/src/image/image.ts +4 -4
  30. package/node_modules/pi-antigravity/src/index.ts +203 -13
  31. package/node_modules/pi-antigravity/src/search/index.ts +1 -0
  32. package/node_modules/pi-antigravity/src/search/search.ts +325 -0
  33. package/node_modules/pi-antigravity/src/stream/stream.ts +191 -14
  34. package/node_modules/pi-antigravity/src/types/enums.ts +45 -36
  35. package/node_modules/pi-antigravity/src/types/types.ts +5 -12
  36. package/node_modules/pi-antigravity/src/utils/http.ts +7 -2
  37. package/node_modules/pi-antigravity/src/utils/util.ts +31 -3
  38. package/node_modules/pi-lens/package.json +158 -158
  39. package/node_modules/pi-multi-account/package.json +2 -2
  40. package/node_modules/pi-typesafe/README.md +3 -1
  41. package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
  42. package/node_modules/pi-typesafe/dist/auth.js +7 -3
  43. package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
  44. package/node_modules/pi-typesafe/dist/backends.js +95 -1
  45. package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
  46. package/node_modules/pi-typesafe/dist/client.js +12 -9
  47. package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
  48. package/node_modules/pi-typesafe/dist/credentials.js +10 -7
  49. package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
  50. package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
  51. package/node_modules/pi-typesafe/dist/index.js +1 -1
  52. package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
  53. package/node_modules/pi-typesafe/dist/login.js +2 -2
  54. package/node_modules/pi-typesafe/package.json +6 -5
  55. package/node_modules/pi-web-access/CHANGELOG.md +72 -0
  56. package/node_modules/pi-web-access/README.md +34 -13
  57. package/node_modules/pi-web-access/chrome-cookies.ts +79 -25
  58. package/node_modules/pi-web-access/curator-page.ts +5 -1
  59. package/node_modules/pi-web-access/curator-server.ts +2 -0
  60. package/node_modules/pi-web-access/dist/index.js +1337 -1009
  61. package/node_modules/pi-web-access/exa.ts +20 -52
  62. package/node_modules/pi-web-access/extract.ts +41 -4
  63. package/node_modules/pi-web-access/gemini-search.ts +12 -4
  64. package/node_modules/pi-web-access/index.ts +29 -37
  65. package/node_modules/pi-web-access/openai-search.ts +35 -7
  66. package/node_modules/pi-web-access/package.json +8 -7
  67. package/node_modules/pi-web-access/page-query.ts +2 -2
  68. package/node_modules/pi-web-access/query-rewrite.ts +2 -3
  69. package/node_modules/pi-web-access/ssrf-protection.ts +27 -10
  70. package/node_modules/pi-web-access/storage.ts +48 -77
  71. package/node_modules/pi-web-access/summary-model-scope.ts +6 -77
  72. package/node_modules/pi-web-access/summary-review.ts +3 -4
  73. package/node_modules/pi-web-access/tavily.ts +67 -20
  74. package/node_modules/pi-web-access/tool-activation.ts +53 -33
  75. package/node_modules/pi-web-access/utils.ts +1 -1
  76. package/node_modules/pi-web-access/you.ts +164 -0
  77. package/node_modules/pi-web-access/zai.ts +161 -0
  78. package/node_modules/remote-pi/package.json +5 -1
  79. package/package.json +19 -31
  80. package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
  81. package/node_modules/pi-mcp-adapter/LICENSE +0 -21
  82. package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
  83. package/node_modules/pi-mcp-adapter/README.md +0 -1021
  84. package/node_modules/pi-mcp-adapter/abort.ts +0 -34
  85. package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
  86. package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
  87. package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
  88. package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
  89. package/node_modules/pi-mcp-adapter/banner.png +0 -0
  90. package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
  91. package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
  92. package/node_modules/pi-mcp-adapter/cli.js +0 -454
  93. package/node_modules/pi-mcp-adapter/commands.ts +0 -861
  94. package/node_modules/pi-mcp-adapter/config.ts +0 -1565
  95. package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
  96. package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
  97. package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
  98. package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
  99. package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
  100. package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
  101. package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
  102. package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
  103. package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
  104. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
  105. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
  106. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
  107. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
  108. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
  109. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
  110. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
  111. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
  112. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
  113. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
  114. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
  115. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
  116. package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
  117. package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
  118. package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
  119. package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
  120. package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
  121. package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
  122. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
  123. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
  124. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
  125. package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
  126. package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
  127. package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
  128. package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
  129. package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
  130. package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
  131. package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
  132. package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
  133. package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
  134. package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
  135. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
  136. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
  137. package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
  138. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
  139. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
  140. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
  141. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
  142. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
  143. package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
  144. package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
  145. package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
  146. package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
  147. package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
  148. package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
  149. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
  150. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
  151. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
  152. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
  153. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
  154. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
  155. package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
  156. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
  157. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
  158. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
  159. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
  160. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
  161. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
  162. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
  163. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
  164. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
  165. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
  166. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
  167. package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
  168. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
  169. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
  170. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
  171. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
  172. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
  173. package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
  174. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
  175. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
  176. package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
  177. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
  178. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
  179. package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
  180. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
  181. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
  182. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
  183. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
  184. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
  185. package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
  186. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
  187. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
  188. package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
  189. package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
  190. package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
  191. package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
  192. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
  193. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
  194. package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
  195. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
  196. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
  197. package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
  198. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
  199. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
  200. package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
  201. package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
  202. package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
  203. package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
  204. package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
  205. package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
  206. package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
  207. package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
  208. package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
  209. package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
  210. package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
  211. package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
  212. package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
  213. package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
  214. package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
  215. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
  216. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
  217. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
  218. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
  219. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
  220. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
  221. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
  222. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
  223. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
  224. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
  225. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
  226. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
  227. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
  228. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
  229. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
  230. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
  231. package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
  232. package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
  233. package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
  234. package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
  235. package/node_modules/pi-mcp-adapter/errors.ts +0 -364
  236. package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
  237. package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
  238. package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
  239. package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
  240. package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
  241. package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
  242. package/node_modules/pi-mcp-adapter/index.ts +0 -2106
  243. package/node_modules/pi-mcp-adapter/init.ts +0 -721
  244. package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
  245. package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
  246. package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
  247. package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
  248. package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
  249. package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
  250. package/node_modules/pi-mcp-adapter/logger.ts +0 -169
  251. package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
  252. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
  253. package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
  254. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
  255. package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
  256. package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
  257. package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
  258. package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
  259. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
  260. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
  261. package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
  262. package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
  263. package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
  264. package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
  265. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
  266. package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
  267. package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
  268. package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
  269. package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
  270. package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
  271. package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
  272. package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
  273. package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
  274. package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
  275. package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
  276. package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
  277. package/node_modules/pi-mcp-adapter/package.json +0 -219
  278. package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
  279. package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
  280. package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
  281. package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
  282. package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
  283. package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
  284. package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
  285. package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
  286. package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
  287. package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
  288. package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
  289. package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
  290. package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
  291. package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
  292. package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
  293. package/node_modules/pi-mcp-adapter/state.ts +0 -71
  294. package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
  295. package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
  296. package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
  297. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
  298. package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
  299. package/node_modules/pi-mcp-adapter/types.ts +0 -1120
  300. package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
  301. package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
  302. package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
  303. package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
  304. package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
  305. package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
  306. package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
  307. package/node_modules/pi-mcp-adapter/utils.ts +0 -464
@@ -1,1097 +0,0 @@
1
- /**
2
- * MCP Auth Flow
3
- *
4
- * High-level OAuth flow management using the MCP SDK's built-in auth functions.
5
- */
6
- import { auth as runSdkAuth, extractWWWAuthenticateParams, LATEST_PROTOCOL_VERSION, UnauthorizedError, validateClientMetadataUrl, } from "@modelcontextprotocol/client";
7
- import open from "open";
8
- import { getOAuthCallbackPort, McpOAuthProvider, } from "./mcp-oauth-provider.js";
9
- import { ensureCallbackServer, waitForCallback, cancelPendingCallback, stopCallbackServer, stopCallbackServerIfIdle, releaseCallbackServer, } from "./mcp-callback-server.js";
10
- import { getAuthForUrl, getAuthEntry, clearAllCredentials, clearClientInfo, clearCodeVerifier, getOAuthState, clearOAuthState, getAuthBaseDir, beginOAuthRevocation, captureOAuthAuthority, OAuthCredentialStoreError, } from "./mcp-auth.js";
11
- import { isServerDisabled } from "./types.js";
12
- import { formatTerminalError, interpolateEnvVars } from "./utils.js";
13
- import { createOAuthFetch, oauthHeaderResolver, resolveOAuthHeaders } from "./mcp-auth-fetch.js";
14
- import { isBuiltInAgentPlugin } from "./agent-plugin-provenance.js";
15
- import { abortable, throwIfAborted } from "./abort.js";
16
- import { combineAbortSignals, isAbortError } from "./runtime-owner.js";
17
- function pluginAwareOAuthHeaders(definition) {
18
- return oauthHeaderResolver(definition?.headers, {
19
- literal: definition ? isBuiltInAgentPlugin(definition, "headers") : false,
20
- });
21
- }
22
- function applyOAuthConfig(discovery, config) {
23
- return {
24
- ...discovery,
25
- ...(config.scope !== undefined ? { scope: config.scope } : {}),
26
- ...(config.skipIssuerMetadataValidation === true ? { skipIssuerMetadataValidation: true } : {}),
27
- };
28
- }
29
- const runtimeStates = new WeakMap();
30
- const activeRuntimes = new Set();
31
- export function createOAuthRuntime(signal) {
32
- const controller = new AbortController();
33
- const runtime = { signal: combineAbortSignals(signal, controller.signal) };
34
- runtimeStates.set(runtime, {
35
- controller,
36
- generation: 0,
37
- pendingAuths: new Map(),
38
- pendingAuthStates: new Map(),
39
- pendingAuthCleanupTimers: new Map(),
40
- pendingAuthentications: new Map(),
41
- });
42
- activeRuntimes.add(runtime);
43
- return runtime;
44
- }
45
- let legacyRuntime = createOAuthRuntime();
46
- activeRuntimes.delete(legacyRuntime);
47
- function getRuntime(options) {
48
- if (options?.runtime) {
49
- options.runtime.signal.throwIfAborted();
50
- activeRuntimes.add(options.runtime);
51
- return options.runtime;
52
- }
53
- if (legacyRuntime.signal.aborted)
54
- legacyRuntime = createOAuthRuntime();
55
- activeRuntimes.add(legacyRuntime);
56
- return legacyRuntime;
57
- }
58
- function getRuntimeState(runtime) {
59
- const state = runtimeStates.get(runtime);
60
- if (!state)
61
- throw new Error("Unknown OAuth runtime");
62
- return state;
63
- }
64
- function getAuthStorageIdentity(options) {
65
- return options.credentialStore === "encrypted-file"
66
- ? ["encrypted-file"]
67
- : ["os", getAuthBaseDir(options)];
68
- }
69
- function getPendingAuthKey(serverName, options) {
70
- return JSON.stringify([serverName, ...getAuthStorageIdentity(options)]);
71
- }
72
- function hasOAuthAuthority(authority) {
73
- try {
74
- authority();
75
- return true;
76
- }
77
- catch {
78
- return false;
79
- }
80
- }
81
- export function hasPendingAuth(serverName, options, runtime) {
82
- const state = getRuntimeState(runtime ?? legacyRuntime);
83
- if (options) {
84
- return state.pendingAuths.has(getPendingAuthKey(serverName, options));
85
- }
86
- return Array.from(state.pendingAuths.values()).some(pendingAuth => pendingAuth.serverName === serverName);
87
- }
88
- /** Timeout for manual auth completion (5 minutes) */
89
- const MANUAL_AUTH_TIMEOUT_MS = 5 * 60 * 1000;
90
- /**
91
- * Generate a cryptographically secure random state parameter.
92
- */
93
- function generateState() {
94
- return Array.from(crypto.getRandomValues(new Uint8Array(32)))
95
- .map((b) => b.toString(16).padStart(2, "0"))
96
- .join("");
97
- }
98
- /**
99
- * Extract OAuth configuration from a ServerEntry.
100
- */
101
- export function extractOAuthConfig(definition) {
102
- if (definition.oauth === false) {
103
- return {};
104
- }
105
- const config = {};
106
- if (definition.oauth?.grantType !== undefined)
107
- config.grantType = definition.oauth.grantType;
108
- if (definition.oauth?.clientId !== undefined) {
109
- if (typeof definition.oauth.clientId !== "string")
110
- throw new Error("OAuth clientId must be a string");
111
- config.clientId = interpolateEnvVars(definition.oauth.clientId);
112
- }
113
- if (definition.oauth?.clientSecret !== undefined) {
114
- if (typeof definition.oauth.clientSecret !== "string")
115
- throw new Error("OAuth clientSecret must be a string");
116
- // Preserve command expressions for the provider; interpolation remains eager for ordinary values.
117
- config.clientSecret = definition.oauth.clientSecret.startsWith("!")
118
- ? definition.oauth.clientSecret
119
- : interpolateEnvVars(definition.oauth.clientSecret);
120
- }
121
- if (definition.oauth?.clientMetadataUrl !== undefined) {
122
- if (typeof definition.oauth.clientMetadataUrl !== "string") {
123
- throw new Error("OAuth clientMetadataUrl must be a string");
124
- }
125
- const clientMetadataUrl = interpolateEnvVars(definition.oauth.clientMetadataUrl).trim();
126
- if (!clientMetadataUrl) {
127
- throw new Error("OAuth clientMetadataUrl must not be empty");
128
- }
129
- validateClientMetadataUrl(clientMetadataUrl);
130
- config.clientMetadataUrl = clientMetadataUrl;
131
- }
132
- if (config.clientMetadataUrl !== undefined && config.clientSecret !== undefined && !config.clientId) {
133
- throw new Error("OAuth clientSecret requires an explicit clientId when clientMetadataUrl is configured");
134
- }
135
- if (definition.oauth?.scope !== undefined) {
136
- if (typeof definition.oauth.scope !== "string")
137
- throw new Error("OAuth scope must be a string");
138
- config.scope = interpolateEnvVars(definition.oauth.scope);
139
- }
140
- if (definition.oauth?.authorizationParams !== undefined) {
141
- const params = definition.oauth.authorizationParams;
142
- if (!params || typeof params !== "object" || Array.isArray(params)) {
143
- throw new Error("OAuth authorizationParams must be an object");
144
- }
145
- config.authorizationParams = {};
146
- for (const [key, value] of Object.entries(params)) {
147
- if (!key)
148
- throw new Error("OAuth authorizationParams keys must not be empty");
149
- if (typeof value !== "string")
150
- throw new Error(`OAuth authorizationParams.${key} must be a string`);
151
- config.authorizationParams[key] = interpolateEnvVars(value);
152
- }
153
- }
154
- if (definition.oauth?.redirectUri !== undefined) {
155
- if (typeof definition.oauth.redirectUri !== "string") {
156
- throw new Error("OAuth redirectUri must be a string");
157
- }
158
- const redirectUri = interpolateEnvVars(definition.oauth.redirectUri).trim();
159
- if (!redirectUri) {
160
- throw new Error("OAuth redirectUri must not be empty");
161
- }
162
- config.redirectUri = redirectUri;
163
- }
164
- if (definition.oauth?.clientName !== undefined) {
165
- if (typeof definition.oauth.clientName !== "string") {
166
- throw new Error("OAuth clientName must be a string");
167
- }
168
- const clientName = interpolateEnvVars(definition.oauth.clientName).trim();
169
- if (!clientName) {
170
- throw new Error("OAuth clientName must not be empty");
171
- }
172
- config.clientName = clientName;
173
- }
174
- if (definition.oauth?.clientUri !== undefined) {
175
- if (typeof definition.oauth.clientUri !== "string") {
176
- throw new Error("OAuth clientUri must be a string");
177
- }
178
- const clientUri = interpolateEnvVars(definition.oauth.clientUri).trim();
179
- if (!clientUri) {
180
- throw new Error("OAuth clientUri must not be empty");
181
- }
182
- config.clientUri = clientUri;
183
- }
184
- if (definition.oauth?.logoUri !== undefined) {
185
- if (typeof definition.oauth.logoUri !== "string") {
186
- throw new Error("OAuth logoUri must be a string");
187
- }
188
- const logoUri = interpolateEnvVars(definition.oauth.logoUri).trim();
189
- if (!logoUri) {
190
- throw new Error("OAuth logoUri must not be empty");
191
- }
192
- // Consent screens fetch this server-side, so a local path silently renders
193
- // nothing. Fail here instead, where the message can say why.
194
- let parsed;
195
- try {
196
- parsed = new URL(logoUri);
197
- }
198
- catch {
199
- throw new Error("OAuth logoUri must be an absolute http(s) URL");
200
- }
201
- if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
202
- throw new Error("OAuth logoUri must be an absolute http(s) URL");
203
- }
204
- config.logoUri = logoUri;
205
- }
206
- if (definition.oauth?.authServerMetadataUrl !== undefined) {
207
- if (typeof definition.oauth.authServerMetadataUrl !== "string") {
208
- throw new Error("OAuth authServerMetadataUrl must be a string");
209
- }
210
- const authServerMetadataUrl = interpolateEnvVars(definition.oauth.authServerMetadataUrl).trim();
211
- if (!authServerMetadataUrl) {
212
- throw new Error("OAuth authServerMetadataUrl must not be empty");
213
- }
214
- let parsed;
215
- try {
216
- parsed = new URL(authServerMetadataUrl);
217
- }
218
- catch {
219
- throw new Error("OAuth authServerMetadataUrl must be an absolute https:// URL");
220
- }
221
- if (parsed.protocol !== "https:") {
222
- throw new Error("OAuth authServerMetadataUrl must be an absolute https:// URL");
223
- }
224
- config.authServerMetadataUrl = authServerMetadataUrl;
225
- }
226
- if (definition.oauth?.skipIssuerMetadataValidation !== undefined) {
227
- if (typeof definition.oauth.skipIssuerMetadataValidation !== "boolean") {
228
- throw new Error("OAuth skipIssuerMetadataValidation must be a boolean");
229
- }
230
- config.skipIssuerMetadataValidation = definition.oauth.skipIssuerMetadataValidation;
231
- }
232
- return config;
233
- }
234
- async function probeAuthDiscovery(serverUrl, definition, signal) {
235
- // The preliminary probe is command-free; real SDK discovery resolves commands.
236
- const serviceHeaders = resolveOAuthHeaders(definition?.headers, {
237
- commands: false,
238
- literal: definition ? isBuiltInAgentPlugin(definition, "headers") : false,
239
- });
240
- const probeFetch = createOAuthFetch(serverUrl, () => serviceHeaders, signal, { timeout: false });
241
- const headers = new Headers({ "content-type": "application/json" });
242
- const controller = new AbortController();
243
- const discoverySignal = combineAbortSignals(signal, controller.signal);
244
- const timer = setTimeout(() => controller.abort(), 5000);
245
- try {
246
- headers.set("accept", "application/json, text/event-stream");
247
- const response = await probeFetch(new URL(serverUrl), {
248
- method: "POST",
249
- headers,
250
- body: JSON.stringify({
251
- jsonrpc: "2.0",
252
- id: 0,
253
- method: "initialize",
254
- params: {
255
- protocolVersion: LATEST_PROTOCOL_VERSION,
256
- capabilities: {},
257
- clientInfo: { name: "pi-mcp-adapter", version: "2.11.0" },
258
- },
259
- }),
260
- ...(discoverySignal ? { signal: discoverySignal } : {}),
261
- });
262
- const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
263
- await response.body?.cancel().catch(() => { });
264
- return { ...(resourceMetadataUrl ? { resourceMetadataUrl } : {}), ...(scope ? { scope } : {}) };
265
- }
266
- catch (error) {
267
- if (signal?.aborted)
268
- throwIfAborted(signal);
269
- return {};
270
- }
271
- finally {
272
- clearTimeout(timer);
273
- }
274
- }
275
- function parseOAuthRedirectUri(redirectUri) {
276
- const dynamicPortPlaceholder = "{port}";
277
- const placeholderCount = redirectUri.split(dynamicPortPlaceholder).length - 1;
278
- if (placeholderCount > 1) {
279
- throw new Error("OAuth redirectUri may contain at most one {port} placeholder");
280
- }
281
- let parsedRedirectUri = redirectUri;
282
- const dynamicPort = placeholderCount === 1;
283
- if (dynamicPort) {
284
- const authorityStart = redirectUri.indexOf("://") + 3;
285
- const pathStart = redirectUri.slice(authorityStart).search(/[/?#]/);
286
- const authorityEnd = pathStart === -1 ? redirectUri.length : authorityStart + pathStart;
287
- const authority = redirectUri.slice(authorityStart, authorityEnd);
288
- if (authorityStart < 3 || !authority.endsWith(`:${dynamicPortPlaceholder}`)) {
289
- throw new Error("OAuth redirectUri {port} placeholder must be the loopback URI port");
290
- }
291
- // Parse with a real port, then replace the placeholder only after the OS
292
- // assigns the callback listener's port.
293
- parsedRedirectUri = redirectUri.replace(dynamicPortPlaceholder, "1");
294
- }
295
- let url;
296
- try {
297
- url = new URL(parsedRedirectUri);
298
- }
299
- catch (error) {
300
- throw new Error(`Invalid OAuth redirectUri: ${redirectUri}`, { cause: error });
301
- }
302
- if (url.username || url.password) {
303
- throw new Error("OAuth redirectUri must not include username or password");
304
- }
305
- if (url.hash) {
306
- throw new Error("OAuth redirectUri must not include a fragment");
307
- }
308
- const hostname = url.hostname.toLowerCase();
309
- const isLocalhost = hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
310
- if (dynamicPort && (url.protocol !== "http:" || !isLocalhost)) {
311
- throw new Error("OAuth redirectUri {port} placeholder is allowed only for an http:// localhost or loopback URI");
312
- }
313
- if (url.port) {
314
- const parsedPort = Number.parseInt(url.port, 10);
315
- if (!Number.isInteger(parsedPort) || parsedPort <= 0 || parsedPort > 65535) {
316
- throw new Error("OAuth redirectUri port must be a positive numeric port");
317
- }
318
- }
319
- if (url.protocol === "https:" && !isLocalhost) {
320
- return { mode: "manual" };
321
- }
322
- if (url.protocol !== "http:" || !isLocalhost) {
323
- throw new Error("OAuth redirectUri must be an https:// URI or an http:// localhost or loopback URI");
324
- }
325
- if (!url.port) {
326
- throw new Error("OAuth localhost redirectUri must include an explicit numeric port");
327
- }
328
- const port = Number.parseInt(url.port, 10);
329
- const callbackHost = hostname === "[::1]" ? "::1" : hostname;
330
- return {
331
- mode: "local",
332
- ...(dynamicPort ? {} : { port }),
333
- callbackHost,
334
- callbackPath: url.pathname,
335
- dynamicPort,
336
- resolveRedirectUri: assignedPort => dynamicPort
337
- ? redirectUri.replace(dynamicPortPlaceholder, String(assignedPort))
338
- : redirectUri,
339
- };
340
- }
341
- /**
342
- * Start OAuth authentication flow for a server.
343
- * Returns the authorization URL when browser authorization is required.
344
- */
345
- export async function startAuth(serverName, serverUrl, definition, options = {}, operationAuthority) {
346
- if (isServerDisabled(definition))
347
- throw new Error(`MCP server "${serverName}" is disabled`);
348
- const authority = operationAuthority ?? captureOAuthAuthority(serverName);
349
- authority();
350
- const runtime = getRuntime(options);
351
- const runtimeState = getRuntimeState(runtime);
352
- const config = definition ? extractOAuthConfig(definition) : {};
353
- const authStorageOptions = options.authStorageOptions ?? {};
354
- const signal = combineAbortSignals(runtime.signal, options.signal);
355
- const generation = runtimeState.generation;
356
- throwIfAborted(signal);
357
- if (config.grantType === "client_credentials") {
358
- const storedAuth = await getAuthForUrl(serverName, serverUrl, authStorageOptions);
359
- authority();
360
- if (storedAuth?.clientInfo && !storedAuth.tokens && !config.clientId) {
361
- clearClientInfo(serverName, authStorageOptions);
362
- clearCodeVerifier(serverName, authStorageOptions);
363
- clearOAuthState(serverName, authStorageOptions);
364
- }
365
- authority();
366
- const authProvider = new McpOAuthProvider(serverName, serverUrl, config, {
367
- onRedirect: async () => {
368
- throw new Error("Browser redirect is not used for client_credentials flow");
369
- },
370
- }, authStorageOptions, runtime.signal, undefined, authority);
371
- try {
372
- const fetchFn = createOAuthFetch(serverUrl, pluginAwareOAuthHeaders(definition), signal);
373
- authProvider.setAuthFetch(fetchFn);
374
- const discovery = applyOAuthConfig(await probeAuthDiscovery(serverUrl, definition, signal), config);
375
- authority();
376
- throwIfAborted(signal);
377
- const result = await abortable(runSdkAuth(authProvider, { serverUrl, ...discovery, fetchFn }), signal);
378
- authority();
379
- throwIfAborted(signal);
380
- if (result !== "AUTHORIZED") {
381
- throw new UnauthorizedError("Failed to authorize");
382
- }
383
- return { authorizationUrl: "" };
384
- }
385
- finally {
386
- authProvider.deactivate();
387
- }
388
- }
389
- const existingPendingAuth = runtimeState.pendingAuths.get(getPendingAuthKey(serverName, authStorageOptions));
390
- if (existingPendingAuth?.serverUrl === serverUrl) {
391
- existingPendingAuth.authority();
392
- return { authorizationUrl: existingPendingAuth.authorizationUrl };
393
- }
394
- const redirectTarget = config.redirectUri !== undefined ? parseOAuthRedirectUri(config.redirectUri) : undefined;
395
- const manualRedirect = redirectTarget?.mode === "manual";
396
- const oauthState = generateState();
397
- if (!manualRedirect) {
398
- try {
399
- await ensureCallbackServer({
400
- strictPort: redirectTarget?.mode === "local"
401
- ? !redirectTarget.dynamicPort
402
- : Boolean(config.clientId),
403
- oauthState,
404
- reserveState: true,
405
- ...(redirectTarget?.mode === "local"
406
- ? {
407
- ...(redirectTarget.port !== undefined ? { port: redirectTarget.port } : {}),
408
- callbackHost: redirectTarget.callbackHost,
409
- callbackPath: redirectTarget.callbackPath,
410
- }
411
- : {}),
412
- });
413
- authority();
414
- throwIfAborted(signal);
415
- if (redirectTarget?.mode === "local" && redirectTarget.dynamicPort) {
416
- config.redirectUri = redirectTarget.resolveRedirectUri(getOAuthCallbackPort());
417
- }
418
- }
419
- catch (error) {
420
- releaseCallbackServer(oauthState);
421
- try {
422
- await cleanupAndReleaseCallbackServerIfIdle(() => {
423
- if (hasOAuthAuthority(authority))
424
- clearOAuthState(serverName, authStorageOptions);
425
- });
426
- }
427
- catch (cleanupError) {
428
- throw new AggregateError([error, cleanupError], "OAuth startup cleanup failed");
429
- }
430
- throw error;
431
- }
432
- }
433
- let capturedUrl;
434
- authority();
435
- const authProvider = new McpOAuthProvider(serverName, serverUrl, config, {
436
- onRedirect: async (url) => {
437
- capturedUrl = url;
438
- },
439
- }, authStorageOptions, runtime.signal, oauthState, authority);
440
- try {
441
- const storedAuth = await getAuthForUrl(serverName, serverUrl, authStorageOptions);
442
- authority();
443
- if (storedAuth?.clientInfo && !config.clientId) {
444
- if (!storedAuth.tokens) {
445
- clearClientInfo(serverName, authStorageOptions);
446
- clearCodeVerifier(serverName, authStorageOptions);
447
- clearOAuthState(serverName, authStorageOptions);
448
- }
449
- else {
450
- const redirectUris = storedAuth.clientInfo.redirectUris;
451
- const redirectUriMatches = Array.isArray(redirectUris)
452
- && redirectUris.includes(authProvider.redirectUrl ?? "");
453
- if (!redirectUriMatches && !storedAuth.tokens.refreshToken) {
454
- // A stale redirect URI only blocks the interactive leg; refresh does
455
- // not send redirect_uri, so keep refresh-capable credentials intact.
456
- clearClientInfo(serverName, authStorageOptions);
457
- clearCodeVerifier(serverName, authStorageOptions);
458
- clearOAuthState(serverName, authStorageOptions);
459
- }
460
- }
461
- }
462
- throwIfAborted(signal);
463
- const getHeaders = pluginAwareOAuthHeaders(definition);
464
- const fetchFn = createOAuthFetch(serverUrl, getHeaders, signal);
465
- authProvider.setAuthFetch(fetchFn);
466
- const discovery = applyOAuthConfig(await probeAuthDiscovery(serverUrl, definition, signal), config);
467
- authority();
468
- throwIfAborted(signal);
469
- const result = await abortable(runSdkAuth(authProvider, { serverUrl, ...discovery, fetchFn }), signal);
470
- authority();
471
- throwIfAborted(signal);
472
- if (result === "AUTHORIZED") {
473
- authProvider.deactivate();
474
- releaseCallbackServer(oauthState);
475
- clearOAuthState(serverName, authStorageOptions);
476
- await stopCallbackServerIfIdle();
477
- authority();
478
- return { authorizationUrl: "" };
479
- }
480
- if (!capturedUrl) {
481
- throw new UnauthorizedError("OAuth authorization URL was not provided");
482
- }
483
- await setPendingAuth(runtime, serverName, {
484
- serverName,
485
- authProvider,
486
- serverUrl,
487
- authorizationUrl: capturedUrl.toString(),
488
- manualRedirect,
489
- ...(manualRedirect ? { manualCompletionController: new AbortController() } : {}),
490
- discovery,
491
- getHeaders,
492
- authStorageOptions,
493
- authority,
494
- }, oauthState, signal, generation);
495
- authority();
496
- return { authorizationUrl: capturedUrl.toString() };
497
- }
498
- catch (error) {
499
- authProvider.deactivate();
500
- try {
501
- await clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, authStorageOptions);
502
- }
503
- catch (cleanupError) {
504
- throw new AggregateError([error, cleanupError], "OAuth startup cleanup failed");
505
- }
506
- throw error;
507
- }
508
- }
509
- async function setPendingAuth(runtime, serverName, pendingAuth, oauthState, signal, generation = getRuntimeState(runtime).generation) {
510
- const state = getRuntimeState(runtime);
511
- const key = getPendingAuthKey(serverName, pendingAuth.authStorageOptions);
512
- pendingAuth.authority();
513
- await clearPendingAuth(runtime, serverName, undefined, pendingAuth.authStorageOptions);
514
- pendingAuth.authority();
515
- throwIfAborted(signal);
516
- if (generation !== state.generation)
517
- throw new Error("OAuth runtime stopped");
518
- state.pendingAuths.set(key, pendingAuth);
519
- state.pendingAuthStates.set(key, oauthState);
520
- const cleanupTimer = setTimeout(() => {
521
- void clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, pendingAuth.authStorageOptions, new Error("OAuth authorization timeout - authorization took too long")).catch(error => {
522
- console.error(`MCP Auth: Timed-out flow cleanup failed: ${formatTerminalError(error)}`);
523
- });
524
- }, MANUAL_AUTH_TIMEOUT_MS);
525
- cleanupTimer.unref?.();
526
- state.pendingAuthCleanupTimers.set(key, cleanupTimer);
527
- }
528
- async function clearPendingAuth(runtime, serverName, oauthState, fallbackStorageOptions = {}, reason = new Error("Authorization cancelled")) {
529
- const state = getRuntimeState(runtime);
530
- const key = getPendingAuthKey(serverName, fallbackStorageOptions);
531
- const pendingState = state.pendingAuthStates.get(key);
532
- if (oauthState && pendingState !== oauthState) {
533
- cancelPendingCallback(oauthState);
534
- return;
535
- }
536
- const { pendingAuth } = detachPending(state, key, reason);
537
- const authStorageOptions = pendingAuth?.authStorageOptions ?? fallbackStorageOptions;
538
- const stateToRelease = pendingState ?? oauthState;
539
- if (stateToRelease) {
540
- if (!pendingState)
541
- cancelPendingCallback(stateToRelease);
542
- if (pendingAuth && hasOAuthAuthority(pendingAuth.authority)) {
543
- const storedState = getOAuthState(serverName, authStorageOptions);
544
- if (storedState === stateToRelease)
545
- clearOAuthState(serverName, authStorageOptions);
546
- }
547
- }
548
- }
549
- function detachPending(state, key, reason) {
550
- const pendingAuth = state.pendingAuths.get(key);
551
- const oauthState = state.pendingAuthStates.get(key);
552
- const timer = state.pendingAuthCleanupTimers.get(key);
553
- if (timer)
554
- clearTimeout(timer);
555
- state.pendingAuthCleanupTimers.delete(key);
556
- state.pendingAuths.delete(key);
557
- state.pendingAuthStates.delete(key);
558
- pendingAuth?.manualCompletionController?.abort(reason);
559
- pendingAuth?.authProvider.deactivate();
560
- if (oauthState)
561
- cancelPendingCallback(oauthState);
562
- return { pendingAuth, oauthState };
563
- }
564
- async function clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, fallbackStorageOptions = {}, reason) {
565
- await cleanupAndReleaseCallbackServerIfIdle(() => clearPendingAuth(runtime, serverName, oauthState, fallbackStorageOptions, reason));
566
- }
567
- async function cleanupAndReleaseCallbackServerIfIdle(cleanup) {
568
- let cleanupFailure;
569
- try {
570
- await cleanup();
571
- }
572
- catch (error) {
573
- cleanupFailure = { error };
574
- }
575
- try {
576
- await stopCallbackServerIfIdle();
577
- }
578
- catch (releaseError) {
579
- if (cleanupFailure) {
580
- throw new AggregateError([cleanupFailure.error, releaseError], "OAuth callback cleanup failed");
581
- }
582
- throw releaseError;
583
- }
584
- if (cleanupFailure)
585
- throw cleanupFailure.error;
586
- }
587
- function detachPendingAuthsForServer(serverName, reason) {
588
- for (const runtime of activeRuntimes) {
589
- const state = getRuntimeState(runtime);
590
- for (const [key, pendingAuth] of state.pendingAuths) {
591
- if (pendingAuth.serverName !== serverName)
592
- continue;
593
- if (state.pendingAuths.get(key) !== pendingAuth)
594
- continue;
595
- detachPending(state, key, reason);
596
- }
597
- }
598
- }
599
- function getSearchParamsFromInput(input) {
600
- try {
601
- const url = new URL(input);
602
- const params = new URLSearchParams(url.search);
603
- if (url.hash) {
604
- const hash = url.hash.startsWith("#") ? url.hash.slice(1) : url.hash;
605
- const hashParams = new URLSearchParams(hash);
606
- for (const [key, value] of hashParams) {
607
- if (!params.has(key))
608
- params.set(key, value);
609
- }
610
- }
611
- return params;
612
- }
613
- catch {
614
- const query = input.includes("?") ? input.slice(input.indexOf("?") + 1) : input;
615
- const params = new URLSearchParams(query.startsWith("#") ? query.slice(1) : query);
616
- return params.has("code") || params.has("state") || params.has("error") ? params : undefined;
617
- }
618
- }
619
- /**
620
- * Extract an OAuth authorization code (and the RFC 9207 `iss` parameter, when
621
- * present) from either a raw code, a query string, or the full localhost
622
- * redirect URL copied from the browser address bar.
623
- */
624
- export function parseAuthorizationRedirectInput(input, expectedState) {
625
- const trimmed = input.trim();
626
- if (!trimmed) {
627
- throw new Error("Authorization code or redirect URL is required");
628
- }
629
- const params = getSearchParamsFromInput(trimmed);
630
- if (params) {
631
- const error = params.get("error");
632
- if (error) {
633
- const description = params.get("error_description");
634
- throw new Error(description ? `${error}: ${description}` : error);
635
- }
636
- const state = params.get("state");
637
- if (expectedState && !state) {
638
- throw new Error("OAuth state missing from redirect URL");
639
- }
640
- if (expectedState && state !== expectedState) {
641
- throw new Error("OAuth state mismatch - potential CSRF attack");
642
- }
643
- const code = params.get("code");
644
- if (code) {
645
- const iss = params.get("iss");
646
- return { code, ...(iss !== null ? { iss } : {}) };
647
- }
648
- }
649
- if (/^[A-Za-z0-9._~+/=-]+$/.test(trimmed)) {
650
- return { code: trimmed };
651
- }
652
- throw new Error("Could not find an OAuth authorization code in the provided input");
653
- }
654
- /**
655
- * Extract an OAuth authorization code from either a raw code, a query string,
656
- * or the full localhost redirect URL copied from the browser address bar.
657
- */
658
- export function parseAuthorizationCodeInput(input, expectedState) {
659
- return parseAuthorizationRedirectInput(input, expectedState).code;
660
- }
661
- function waitForManualCompletionCancellation(signal) {
662
- return new Promise((_, reject) => {
663
- const rejectFromSignal = () => {
664
- reject(signal.reason instanceof Error ? signal.reason : new Error("Authorization cancelled"));
665
- };
666
- if (signal.aborted) {
667
- rejectFromSignal();
668
- return;
669
- }
670
- signal.addEventListener("abort", rejectFromSignal, { once: true });
671
- });
672
- }
673
- /**
674
- * Wait for either the localhost callback or a manually pasted redirect URL.
675
- * The manual input prompt is dismissed as soon as either path finishes.
676
- */
677
- export async function waitForAuthorizationResponse(callbackPromise, authorizationUrl, expectedState, onAuthorizationInput, signal) {
678
- if (!onAuthorizationInput) {
679
- return {
680
- input: await abortable(callbackPromise, signal),
681
- source: "callback",
682
- };
683
- }
684
- const inputController = new AbortController();
685
- try {
686
- const response = await abortable(Promise.race([
687
- callbackPromise.then((input) => ({ input, source: "callback" })),
688
- onAuthorizationInput(authorizationUrl, inputController.signal).then((input) => ({
689
- input,
690
- source: "manual",
691
- })),
692
- ]), signal);
693
- if (response.source === "callback")
694
- return response;
695
- if (!response.input?.trim())
696
- throw new Error("OAuth authentication cancelled");
697
- if (!getSearchParamsFromInput(response.input.trim())) {
698
- throw new Error("Paste the full OAuth callback URL, including its code and state parameters");
699
- }
700
- return {
701
- input: parseAuthorizationRedirectInput(response.input, expectedState),
702
- source: "manual",
703
- };
704
- }
705
- finally {
706
- inputController.abort();
707
- }
708
- }
709
- /**
710
- * Complete OAuth authentication from manual user input.
711
- */
712
- export async function completeAuthFromInput(serverName, input, options = {}) {
713
- const runtime = getRuntime(options);
714
- const runtimeState = getRuntimeState(runtime);
715
- const fallbackAuthStorageOptions = options.authStorageOptions ?? {};
716
- const signal = combineAbortSignals(runtime.signal, options.signal);
717
- throwIfAborted(signal);
718
- const key = getPendingAuthKey(serverName, fallbackAuthStorageOptions);
719
- const oauthState = runtimeState.pendingAuthStates.get(key);
720
- const pendingAuth = runtimeState.pendingAuths.get(key);
721
- throwIfAborted(signal);
722
- if (pendingAuth?.manualRedirect && !getSearchParamsFromInput(input.trim())) {
723
- throw new Error("Paste the full OAuth callback URL, including its code and state parameters");
724
- }
725
- const parsed = parseAuthorizationRedirectInput(input, oauthState);
726
- return completeAuth(serverName, parsed, options);
727
- }
728
- /**
729
- * Complete OAuth authentication with the authorization code.
730
- */
731
- export async function completeAuth(serverName, authorizationCode, options = {}) {
732
- const runtime = getRuntime(options);
733
- const runtimeState = getRuntimeState(runtime);
734
- const { code, iss } = typeof authorizationCode === "string"
735
- ? { code: authorizationCode, iss: undefined }
736
- : authorizationCode;
737
- const fallbackAuthStorageOptions = options.authStorageOptions ?? {};
738
- const signal = combineAbortSignals(runtime.signal, options.signal);
739
- throwIfAborted(signal);
740
- const key = getPendingAuthKey(serverName, fallbackAuthStorageOptions);
741
- const pendingAuth = runtimeState.pendingAuths.get(key);
742
- const authStorageOptions = pendingAuth?.authStorageOptions ?? fallbackAuthStorageOptions;
743
- if (!pendingAuth) {
744
- throw new Error(`No pending OAuth flow for server: ${serverName}`);
745
- }
746
- pendingAuth.authority();
747
- const oauthState = runtimeState.pendingAuthStates.get(key);
748
- throwIfAborted(signal);
749
- let keepPendingForRetry = false;
750
- let caughtError;
751
- try {
752
- const fetchFn = createOAuthFetch(pendingAuth.serverUrl, pendingAuth.getHeaders, signal);
753
- pendingAuth.authProvider.setAuthFetch(fetchFn);
754
- const discoveryState = await pendingAuth.authProvider.discoveryState();
755
- pendingAuth.authority();
756
- const metadata = discoveryState?.authorizationServerMetadata;
757
- const expectedIssuer = metadata?.issuer ?? discoveryState?.authorizationServerUrl;
758
- const requiresIssuer = metadata
759
- ?.authorization_response_iss_parameter_supported === true;
760
- if (expectedIssuer !== undefined && iss === undefined && requiresIssuer) {
761
- keepPendingForRetry = true;
762
- throw new Error(`The authorization server for ${serverName} requires the RFC 9207 "iss" parameter. ` +
763
- "Paste the full redirect URL from the browser address bar (not just the authorization code).");
764
- }
765
- if (expectedIssuer !== undefined && iss !== undefined && iss !== expectedIssuer) {
766
- throw new Error(`The OAuth authorization response issuer does not match the discovered issuer for ${serverName}.`);
767
- }
768
- const result = await abortable(runSdkAuth(pendingAuth.authProvider, {
769
- serverUrl: pendingAuth.serverUrl,
770
- authorizationCode: code,
771
- ...(iss !== undefined ? { iss } : {}),
772
- ...pendingAuth.discovery,
773
- fetchFn,
774
- }), signal);
775
- pendingAuth.authority();
776
- throwIfAborted(signal);
777
- if (result !== "AUTHORIZED") {
778
- throw new UnauthorizedError("Failed to authorize");
779
- }
780
- return "authenticated";
781
- }
782
- catch (error) {
783
- caughtError = error;
784
- throw error;
785
- }
786
- finally {
787
- if (!keepPendingForRetry) {
788
- try {
789
- await clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, authStorageOptions);
790
- }
791
- catch (cleanupError) {
792
- if (caughtError !== undefined) {
793
- throw new AggregateError([caughtError, cleanupError], "OAuth completion cleanup failed");
794
- }
795
- throw cleanupError;
796
- }
797
- if (caughtError === undefined)
798
- pendingAuth.authority();
799
- }
800
- }
801
- }
802
- /**
803
- * Perform the complete OAuth authentication flow for a server.
804
- *
805
- * @param serverName - The name of the MCP server
806
- * @param serverUrl - The URL of the MCP server
807
- * @param definition - The server definition (optional)
808
- * @returns The final auth status
809
- */
810
- export async function authenticate(serverName, serverUrl, definition, options = {}) {
811
- if (isServerDisabled(definition))
812
- throw new Error(`MCP server "${serverName}" is disabled`);
813
- const authority = captureOAuthAuthority(serverName);
814
- const runtime = getRuntime(options);
815
- const runtimeState = getRuntimeState(runtime);
816
- const authStorageOptions = options.authStorageOptions ?? {};
817
- const signal = combineAbortSignals(runtime.signal, options.signal);
818
- throwIfAborted(signal);
819
- const authKey = JSON.stringify([serverName, serverUrl, ...getAuthStorageIdentity(authStorageOptions)]);
820
- const inFlight = runtimeState.pendingAuthentications.get(authKey);
821
- if (inFlight) {
822
- try {
823
- inFlight.authority();
824
- return inFlight.promise;
825
- }
826
- catch {
827
- if (runtimeState.pendingAuthentications.get(authKey) === inFlight) {
828
- runtimeState.pendingAuthentications.delete(authKey);
829
- }
830
- }
831
- }
832
- const operation = (async () => {
833
- const { authorizationUrl } = await startAuth(serverName, serverUrl, definition, {
834
- ...options,
835
- ...(signal ? { signal } : {}),
836
- runtime,
837
- }, authority);
838
- authority();
839
- if (!authorizationUrl) {
840
- return "authenticated";
841
- }
842
- let oauthState;
843
- try {
844
- // Get the state that was already generated and stored in startAuth().
845
- // Keep this lookup and its abort check inside the cleanup boundary because
846
- // startAuth already owns the pending flow at this point.
847
- oauthState = runtimeState.pendingAuthStates.get(getPendingAuthKey(serverName, authStorageOptions));
848
- throwIfAborted(signal);
849
- if (!oauthState) {
850
- throw new Error("OAuth state not found - this should not happen");
851
- }
852
- const pendingAuth = runtimeState.pendingAuths.get(getPendingAuthKey(serverName, authStorageOptions));
853
- if (!pendingAuth) {
854
- throw new Error(`No pending OAuth flow for server: ${serverName}`);
855
- }
856
- if (pendingAuth.manualRedirect && !options.onAuthorizationInput) {
857
- throw new Error(`OAuth for ${serverName} uses a remote redirect URI. Complete it with auth-start/auth-complete or /mcp-auth.`);
858
- }
859
- // Register the localhost callback before opening the browser. Remote
860
- // pre-registered callbacks are completed by pasting their full URL.
861
- const callbackPromise = pendingAuth.manualRedirect
862
- ? waitForManualCompletionCancellation(pendingAuth.manualCompletionController.signal)
863
- : waitForCallback(oauthState);
864
- void callbackPromise.catch(() => { });
865
- // Open browser. Always surface the URL first so remote/headless users can copy it
866
- // even when the OS browser handoff is unavailable or invisible.
867
- if (options.onAuthorizationUrl) {
868
- await abortable(Promise.resolve(options.onAuthorizationUrl(authorizationUrl)), signal);
869
- }
870
- else {
871
- console.log(`MCP Auth: Open this URL to authenticate ${serverName}:\n${authorizationUrl}`);
872
- }
873
- try {
874
- await abortable(Promise.resolve(options.openAuthorizationUrl
875
- ? options.openAuthorizationUrl(authorizationUrl)
876
- : open(authorizationUrl)), signal);
877
- }
878
- catch (error) {
879
- if (isAbortError(error, signal))
880
- throw error;
881
- console.warn(`MCP Auth: Failed to open browser for ${serverName}; waiting for manual callback`, { error });
882
- }
883
- const authorizationResponse = await waitForAuthorizationResponse(callbackPromise, authorizationUrl, oauthState, options.onAuthorizationInput, signal);
884
- if (authorizationResponse.source === "manual") {
885
- cancelPendingCallback(oauthState);
886
- }
887
- // The callback server accepted only the flow-local reserved state. Manual
888
- // input is checked against the same state before token exchange.
889
- throwIfAborted(signal);
890
- return await completeAuth(serverName, authorizationResponse.input, {
891
- ...options,
892
- ...(signal ? { signal } : {}),
893
- runtime,
894
- });
895
- }
896
- catch (error) {
897
- if (oauthState)
898
- cancelPendingCallback(oauthState);
899
- try {
900
- await clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, authStorageOptions);
901
- }
902
- catch (cleanupError) {
903
- throw new AggregateError([error, cleanupError], "OAuth cancellation cleanup failed");
904
- }
905
- throw error;
906
- }
907
- })();
908
- const pendingAuthentication = { promise: operation, authority };
909
- runtimeState.pendingAuthentications.set(authKey, pendingAuthentication);
910
- try {
911
- const result = await operation;
912
- authority();
913
- return result;
914
- }
915
- finally {
916
- if (runtimeState.pendingAuthentications.get(authKey) === pendingAuthentication) {
917
- runtimeState.pendingAuthentications.delete(authKey);
918
- }
919
- }
920
- }
921
- /**
922
- * Get a valid access token for a server, refreshing if necessary.
923
- *
924
- * @param serverName - The name of the MCP server
925
- * @param serverUrl - The URL of the MCP server
926
- * @returns The valid tokens or null if not authenticated
927
- */
928
- export async function getValidToken(serverName, serverUrl, options = {}) {
929
- const authority = captureOAuthAuthority(serverName);
930
- const runtime = getRuntime(options);
931
- const authStorageOptions = options.authStorageOptions ?? {};
932
- const signal = combineAbortSignals(runtime.signal, options.signal);
933
- throwIfAborted(signal);
934
- const entry = await getAuthForUrl(serverName, serverUrl, authStorageOptions);
935
- if (!hasOAuthAuthority(authority))
936
- return null;
937
- throwIfAborted(signal);
938
- if (!entry?.tokens) {
939
- return null;
940
- }
941
- const expired = entry.tokens.expiresAt
942
- ? entry.tokens.expiresAt < Date.now() / 1000
943
- : false;
944
- if (expired === false) {
945
- authority();
946
- return entry.tokens;
947
- }
948
- if (expired === true && entry.tokens.refreshToken) {
949
- console.log(`MCP Auth: Token expired for ${serverName}, attempting refresh`);
950
- try {
951
- const config = options.definition ? extractOAuthConfig(options.definition) : {};
952
- const fetchFn = createOAuthFetch(serverUrl, pluginAwareOAuthHeaders(options.definition), signal);
953
- authority();
954
- const authProvider = new McpOAuthProvider(serverName, serverUrl, config, {
955
- onRedirect: async () => { },
956
- }, authStorageOptions, runtime.signal, undefined, authority);
957
- try {
958
- authProvider.setAuthFetch(fetchFn);
959
- const clientInfo = await authProvider.clientInformation();
960
- authority();
961
- throwIfAborted(signal);
962
- if (!clientInfo) {
963
- console.log(`MCP Auth: No client info for refresh for ${serverName}`);
964
- return null;
965
- }
966
- const discovery = applyOAuthConfig(await probeAuthDiscovery(serverUrl, options.definition, signal), config);
967
- authority();
968
- throwIfAborted(signal);
969
- const result = await abortable(runSdkAuth(authProvider, {
970
- serverUrl,
971
- ...discovery,
972
- ...(options.skipIssuerMetadataValidation === true ? { skipIssuerMetadataValidation: true } : {}),
973
- fetchFn,
974
- }), signal);
975
- authority();
976
- throwIfAborted(signal);
977
- if (result !== "AUTHORIZED") {
978
- return null;
979
- }
980
- const refreshed = await getAuthForUrl(serverName, serverUrl, authStorageOptions);
981
- authority();
982
- throwIfAborted(signal);
983
- return refreshed?.tokens ?? null;
984
- }
985
- finally {
986
- authProvider.deactivate();
987
- }
988
- }
989
- catch (error) {
990
- if (isAbortError(error, signal) || error instanceof OAuthCredentialStoreError)
991
- throw error;
992
- console.error(`MCP Auth: Token refresh failed for ${serverName}`);
993
- return null;
994
- }
995
- }
996
- authority();
997
- return null;
998
- }
999
- /**
1000
- * Check the authentication status for a server.
1001
- *
1002
- * @param serverName - The name of the MCP server
1003
- * @returns The current auth status
1004
- */
1005
- export async function getAuthStatus(serverName, options = {}) {
1006
- getRuntime(options);
1007
- const authStorageOptions = options.authStorageOptions ?? {};
1008
- const entry = getAuthEntry(serverName, authStorageOptions);
1009
- if (!entry?.tokens)
1010
- return "not_authenticated";
1011
- return entry.tokens.expiresAt && entry.tokens.expiresAt < Date.now() / 1000 ? "expired" : "authenticated";
1012
- }
1013
- /**
1014
- * Remove all OAuth credentials for a server.
1015
- *
1016
- * @param serverName - The name of the MCP server
1017
- */
1018
- export async function removeAuth(serverName, options = {}) {
1019
- const runtime = getRuntime(options);
1020
- const signal = combineAbortSignals(runtime.signal, options.signal);
1021
- throwIfAborted(signal);
1022
- const authStorageOptions = options.authStorageOptions ?? {};
1023
- const releaseRevocation = beginOAuthRevocation(serverName);
1024
- try {
1025
- detachPendingAuthsForServer(serverName, new Error("Authorization cancelled by logout"));
1026
- const storedOAuthState = getOAuthState(serverName, authStorageOptions);
1027
- if (storedOAuthState)
1028
- cancelPendingCallback(storedOAuthState);
1029
- await stopCallbackServerIfIdle();
1030
- throwIfAborted(signal);
1031
- clearAllCredentials(serverName, authStorageOptions);
1032
- console.log(`MCP Auth: Removed credentials for ${serverName}`);
1033
- }
1034
- finally {
1035
- releaseRevocation();
1036
- }
1037
- }
1038
- /**
1039
- * Check if OAuth is supported for a server configuration.
1040
- * OAuth is supported for HTTP servers unless explicitly disabled.
1041
- *
1042
- * @param definition - The server definition
1043
- * @returns True if OAuth is supported
1044
- */
1045
- export function supportsOAuth(definition) {
1046
- // OAuth requires a URL
1047
- if (!definition.url)
1048
- return false;
1049
- // Explicitly disabled via auth: false or oauth: false
1050
- if (definition.auth === false)
1051
- return false;
1052
- if (definition.oauth === false)
1053
- return false;
1054
- if (definition.auth === "oauth")
1055
- return true;
1056
- // Configured custom headers take precedence over implicit OAuth auto-detection.
1057
- if (definition.headers && Object.keys(definition.headers).length > 0)
1058
- return false;
1059
- // OAuth is enabled when auth is not specified (auto-detect)
1060
- return definition.auth === undefined;
1061
- }
1062
- /**
1063
- * Initialize the OAuth system on startup.
1064
- * OAuth callback binding is lazy and starts from startAuth() only.
1065
- */
1066
- export async function initializeOAuth(runtimeOrSignal) {
1067
- if (runtimeOrSignal && "signal" in runtimeOrSignal) {
1068
- runtimeOrSignal.signal.throwIfAborted();
1069
- activeRuntimes.add(runtimeOrSignal);
1070
- return runtimeOrSignal;
1071
- }
1072
- await shutdownOAuth(legacyRuntime);
1073
- legacyRuntime = createOAuthRuntime(runtimeOrSignal);
1074
- return legacyRuntime;
1075
- }
1076
- /**
1077
- * Shutdown one OAuth runtime. The callback server remains process-shared while
1078
- * another runtime has pending/reserved callback state or is still active.
1079
- */
1080
- export async function shutdownOAuth(runtime = legacyRuntime) {
1081
- const state = getRuntimeState(runtime);
1082
- if (state.controller.signal.aborted)
1083
- return;
1084
- state.generation += 1;
1085
- state.controller.abort(new Error("OAuth runtime stopped"));
1086
- for (const callbackState of Array.from(state.pendingAuthStates.values()))
1087
- cancelPendingCallback(callbackState);
1088
- for (const pendingAuth of Array.from(state.pendingAuths.values())) {
1089
- await clearPendingAuth(runtime, pendingAuth.serverName, undefined, pendingAuth.authStorageOptions);
1090
- }
1091
- state.pendingAuthentications.clear();
1092
- activeRuntimes.delete(runtime);
1093
- if (activeRuntimes.size === 0) {
1094
- await stopCallbackServer();
1095
- }
1096
- }
1097
- //# sourceMappingURL=mcp-auth-flow.js.map