@herbertgao/pi-extensions 2026.9.16 → 2026.9.18

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 (267) hide show
  1. package/README.md +14 -15
  2. package/node_modules/@herbertgao/pi-bark/package.json +2 -2
  3. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +4 -1
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.md +4 -1
  5. package/node_modules/@herbertgao/pi-cc-extensions/package.json +75 -75
  6. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  7. package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
  8. package/node_modules/@herbertgao/resume-from/package.json +4 -2
  9. package/node_modules/@herbertgao/sol-pi/package.json +6 -6
  10. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/extension.ts +11 -53
  11. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +99 -99
  12. package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
  13. package/node_modules/@tifan/pi-handoff/package.json +1 -1
  14. package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
  15. package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
  16. package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
  17. package/node_modules/@tifan/pi-recap/package.json +1 -1
  18. package/node_modules/@tifan/pi-rename/package.json +1 -1
  19. package/node_modules/pi-antigravity/package.json +2 -2
  20. package/node_modules/pi-lens/package.json +158 -158
  21. package/node_modules/pi-multi-account/package.json +2 -2
  22. package/node_modules/pi-typesafe/README.md +1 -1
  23. package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
  24. package/node_modules/pi-typesafe/dist/auth.js +7 -3
  25. package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
  26. package/node_modules/pi-typesafe/dist/backends.js +95 -1
  27. package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
  28. package/node_modules/pi-typesafe/dist/client.js +12 -9
  29. package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
  30. package/node_modules/pi-typesafe/dist/credentials.js +10 -7
  31. package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
  32. package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
  33. package/node_modules/pi-typesafe/dist/index.js +1 -1
  34. package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
  35. package/node_modules/pi-typesafe/dist/login.js +2 -2
  36. package/node_modules/pi-typesafe/package.json +5 -5
  37. package/node_modules/pi-web-access/package.json +2 -2
  38. package/node_modules/remote-pi/package.json +5 -1
  39. package/package.json +16 -28
  40. package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
  41. package/node_modules/pi-mcp-adapter/LICENSE +0 -21
  42. package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
  43. package/node_modules/pi-mcp-adapter/README.md +0 -1021
  44. package/node_modules/pi-mcp-adapter/abort.ts +0 -34
  45. package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
  46. package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
  47. package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
  48. package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
  49. package/node_modules/pi-mcp-adapter/banner.png +0 -0
  50. package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
  51. package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
  52. package/node_modules/pi-mcp-adapter/cli.js +0 -454
  53. package/node_modules/pi-mcp-adapter/commands.ts +0 -861
  54. package/node_modules/pi-mcp-adapter/config.ts +0 -1565
  55. package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
  56. package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
  57. package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
  58. package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
  59. package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
  60. package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
  61. package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
  62. package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
  63. package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
  64. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
  65. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
  66. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
  67. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
  68. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
  69. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
  70. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
  71. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
  72. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
  73. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
  74. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
  75. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
  76. package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
  77. package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
  78. package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
  79. package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
  80. package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
  81. package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
  82. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
  83. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
  84. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
  85. package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
  86. package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
  87. package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
  88. package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
  89. package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
  90. package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
  91. package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
  92. package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
  93. package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
  94. package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
  95. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
  96. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
  97. package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
  98. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
  99. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
  100. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
  101. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
  102. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
  103. package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
  104. package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
  105. package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
  106. package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
  107. package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
  108. package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
  109. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
  110. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
  111. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
  112. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
  113. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
  114. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
  115. package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
  116. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
  117. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
  118. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
  119. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
  120. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
  121. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
  122. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
  123. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
  124. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
  125. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
  126. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
  127. package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
  128. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
  129. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
  130. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
  131. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
  132. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
  133. package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
  134. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
  135. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
  136. package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
  137. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
  138. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
  139. package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
  140. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
  141. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
  142. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
  143. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
  144. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
  145. package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
  146. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
  147. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
  148. package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
  149. package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
  150. package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
  151. package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
  152. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
  153. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
  154. package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
  155. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
  156. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
  157. package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
  158. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
  159. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
  160. package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
  161. package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
  162. package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
  163. package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
  164. package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
  165. package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
  166. package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
  167. package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
  168. package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
  169. package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
  170. package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
  171. package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
  172. package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
  173. package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
  174. package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
  175. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
  176. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
  177. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
  178. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
  179. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
  180. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
  181. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
  182. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
  183. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
  184. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
  185. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
  186. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
  187. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
  188. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
  189. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
  190. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
  191. package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
  192. package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
  193. package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
  194. package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
  195. package/node_modules/pi-mcp-adapter/errors.ts +0 -364
  196. package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
  197. package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
  198. package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
  199. package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
  200. package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
  201. package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
  202. package/node_modules/pi-mcp-adapter/index.ts +0 -2106
  203. package/node_modules/pi-mcp-adapter/init.ts +0 -721
  204. package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
  205. package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
  206. package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
  207. package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
  208. package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
  209. package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
  210. package/node_modules/pi-mcp-adapter/logger.ts +0 -169
  211. package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
  212. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
  213. package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
  214. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
  215. package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
  216. package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
  217. package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
  218. package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
  219. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
  220. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
  221. package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
  222. package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
  223. package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
  224. package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
  225. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
  226. package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
  227. package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
  228. package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
  229. package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
  230. package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
  231. package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
  232. package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
  233. package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
  234. package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
  235. package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
  236. package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
  237. package/node_modules/pi-mcp-adapter/package.json +0 -219
  238. package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
  239. package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
  240. package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
  241. package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
  242. package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
  243. package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
  244. package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
  245. package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
  246. package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
  247. package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
  248. package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
  249. package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
  250. package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
  251. package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
  252. package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
  253. package/node_modules/pi-mcp-adapter/state.ts +0 -71
  254. package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
  255. package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
  256. package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
  257. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
  258. package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
  259. package/node_modules/pi-mcp-adapter/types.ts +0 -1120
  260. package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
  261. package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
  262. package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
  263. package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
  264. package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
  265. package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
  266. package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
  267. package/node_modules/pi-mcp-adapter/utils.ts +0 -464
@@ -1,105 +0,0 @@
1
- import type { McpExtensionState } from "./state.ts";
2
- import {
3
- MCP_STATUS_EVENT,
4
- MCP_STATUS_SNAPSHOT_VERSION,
5
- type McpServerStatusSnapshot,
6
- type McpStatusEventBus,
7
- type McpStatusSnapshot,
8
- } from "./types.ts";
9
- import { getFailureAgeSeconds, isServerInActiveFailureBackoff } from "./failure-backoff.ts";
10
-
11
- /** Build a sanitized snapshot without connecting or querying any MCP server. */
12
- export function createMcpStatusSnapshot(state: McpExtensionState): McpStatusSnapshot {
13
- const servers: McpServerStatusSnapshot[] = [];
14
- let totalTools = 0;
15
- let totalResources = 0;
16
- let connectedCount = 0;
17
- let disabledCount = 0;
18
-
19
- for (const name of Object.keys(state.config.mcpServers)) {
20
- const definition = state.config.mcpServers[name];
21
- const disabled = definition?.disabled === true;
22
- const connection = disabled ? undefined : state.manager.getConnection(name);
23
- const failedAgoSeconds = disabled ? null : getFailureAgeSeconds(state, name);
24
- const activeFailure = !disabled && isServerInActiveFailureBackoff(state, name);
25
- const metadata = disabled || activeFailure ? undefined : state.toolMetadata.get(name);
26
- const toolCount = metadata?.length ?? (connection?.status === "connected" ? connection.tools.length : 0);
27
- // This is the last active direct-tool sync result, rather than a fresh
28
- // resolution. A frozen direct surface may intentionally retain its
29
- // registrations while the server is in failure backoff.
30
- const directToolCount = disabled ? 0 : state.directToolCounts?.get(name) ?? 0;
31
- const resourceCount = disabled || activeFailure
32
- ? undefined
33
- : state.resourceCounts?.get(name) ?? (connection?.status === "connected" ? connection.resources.length : undefined);
34
-
35
- let status: McpServerStatusSnapshot["status"] = "not-connected";
36
- if (disabled) {
37
- status = "disabled";
38
- disabledCount++;
39
- } else if (connection?.status === "connected") {
40
- status = "connected";
41
- connectedCount++;
42
- } else if (connection?.status === "needs-auth") {
43
- status = "needs-auth";
44
- } else if (activeFailure) {
45
- status = "failed";
46
- } else if (metadata !== undefined) {
47
- status = "cached";
48
- }
49
-
50
- totalTools += disabled ? 0 : toolCount;
51
- if (!disabled && resourceCount !== undefined) totalResources += resourceCount;
52
- servers.push({
53
- name,
54
- status,
55
- listenState: connection?.status === "connected" ? connection.listenState : "disconnected",
56
- toolCount,
57
- directToolCount,
58
- ...(connection?.status === "connected" && connection.listenCatalogStale ? { catalogStale: true } : {}),
59
- ...(resourceCount !== undefined ? { resourceCount } : {}),
60
- ...(status === "failed" && failedAgoSeconds !== null ? { failedAgoSeconds } : {}),
61
- disabled,
62
- });
63
- }
64
-
65
- return {
66
- version: MCP_STATUS_SNAPSHOT_VERSION,
67
- servers,
68
- totalTools,
69
- totalResources,
70
- connectedCount,
71
- disabledCount,
72
- };
73
- }
74
-
75
- export function publishMcpStatusSnapshot(
76
- state: McpExtensionState,
77
- snapshot?: McpStatusSnapshot,
78
- ): void {
79
- const events = state.statusEvents;
80
- if (!events) return;
81
- try {
82
- events.emit(MCP_STATUS_EVENT, snapshot ?? createMcpStatusSnapshot(state));
83
- } catch {
84
- // Event consumers must not be able to interrupt MCP operations.
85
- }
86
- }
87
-
88
- export function publishMcpStatusShutdown(events: McpStatusEventBus | undefined): void {
89
- if (!events) return;
90
- try {
91
- events.emit(MCP_STATUS_EVENT, {
92
- version: MCP_STATUS_SNAPSHOT_VERSION,
93
- servers: [],
94
- totalTools: 0,
95
- totalResources: 0,
96
- connectedCount: 0,
97
- disabledCount: 0,
98
- } satisfies McpStatusSnapshot);
99
- } catch {
100
- // Event consumers must not be able to interrupt MCP shutdown.
101
- }
102
- }
103
-
104
- export type { McpServerStatusSnapshot, McpStatusSnapshot } from "./types.ts";
105
- export { MCP_STATUS_EVENT, MCP_STATUS_SNAPSHOT_VERSION } from "./types.ts";
@@ -1,467 +0,0 @@
1
- /**
2
- * MCP Tasks extension support (io.modelcontextprotocol/tasks, SEP-2663).
3
- *
4
- * Built on @modelcontextprotocol/ext-tasks, the official requester-side
5
- * package. On 2026-07-28 connections the SDK client's wire codec rejects
6
- * task-shaped traffic (resultType: "task" inbound, tasks/* methods outbound),
7
- * so ext-tasks requires a host-supplied raw dispatch channel: a way to send
8
- * JSON-RPC frames on the connection's transport and correlate their responses
9
- * below the SDK client. RawRequestChannel provides that channel, mirroring
10
- * the reference integration in the MCP Inspector.
11
- *
12
- * The channel attaches to the already-connected transport by chaining its
13
- * message and close handlers, never replacing the transport object itself.
14
- * This keeps the transport's class identity and optional surface
15
- * (hasPerRequestStream, stdio stderr/pid) intact for the SDK's version
16
- * negotiation probe and per-request-stream cancellation, and it means inbound
17
- * raw responses pass through an installed trace wrapper before being
18
- * consumed, so both directions of task traffic appear in /mcp-trace.
19
- *
20
- * Enabled per server via `tasks: true`. A task session is only attached when
21
- * the connected 2026-07-28 server advertises the extension, so non-task
22
- * servers keep the exact pre-existing call path.
23
- */
24
- import type {
25
- Client,
26
- CreateMessageRequest,
27
- CreateMessageResult,
28
- ElicitRequest,
29
- ElicitResult,
30
- JSONRPCMessage,
31
- JSONRPCRequest,
32
- Transport,
33
- } from "@modelcontextprotocol/client";
34
- import { ProtocolError } from "@modelcontextprotocol/client";
35
- import {
36
- createApplicationInputHandler,
37
- createTaskSessionEndpointId,
38
- createTaskSessionFromClient,
39
- DispatchError,
40
- JsonRpcResponseError,
41
- resultFromTaskOutcome,
42
- TaskCancelledError,
43
- TaskFailedError,
44
- type ApplicationElicitContentValue,
45
- type RawClientDispatch,
46
- type TaskEnabledSession,
47
- } from "@modelcontextprotocol/ext-tasks/client";
48
- import type { ServerDefinition } from "./types.ts";
49
- import { logger } from "./logger.ts";
50
-
51
- export const TASKS_EXTENSION_ID = "io.modelcontextprotocol/tasks";
52
-
53
- const RAW_REQUEST_ID_PREFIX = "pi-mcp-tasks-";
54
-
55
- const DEFAULT_RAW_REQUEST_TIMEOUT_MS = 60_000;
56
- const LATE_TASK_HANDLE_GRACE_MS = 60_000;
57
-
58
- type JsonRpcResponseShape = { kind: "result"; result: unknown } | {
59
- kind: "error";
60
- error: { code: number; message: string; data?: unknown };
61
- };
62
-
63
- interface PendingRawRequest {
64
- id: string;
65
- resolve: (response: JsonRpcResponseShape) => void;
66
- reject: (error: Error) => void;
67
- state: "pending" | "observing";
68
- signal?: AbortSignal;
69
- onAbort?: () => void;
70
- requestTimer?: ReturnType<typeof setTimeout>;
71
- observationTimer?: ReturnType<typeof setTimeout>;
72
- observationController?: AbortController;
73
- }
74
-
75
- function abortError(signal: AbortSignal): Error {
76
- return signal.reason instanceof Error
77
- ? signal.reason
78
- : new DOMException("This operation was aborted", "AbortError");
79
- }
80
-
81
- function isJsonRecord(value: unknown): value is Record<string, unknown> {
82
- return value !== null && typeof value === "object" && !Array.isArray(value);
83
- }
84
-
85
- /**
86
- * Raw JSON-RPC request channel chained onto a connected transport. Raw
87
- * requests use string ids with a reserved prefix, which cannot collide with
88
- * the SDK's numeric ids; their responses are consumed before the SDK client
89
- * sees them. All other traffic passes through unchanged.
90
- *
91
- * Attach only after Client.connect has installed its transport handlers:
92
- * attach() reads the current onmessage/onclose (through any wrapper
93
- * accessors) and chains in front of them.
94
- */
95
- export class RawRequestChannel {
96
- private readonly transport: Transport;
97
- private readonly pending = new Map<string, PendingRawRequest>();
98
- private requestCounter = 0;
99
- private readonly defaultTimeoutMs: number;
100
- private attached = false;
101
-
102
- constructor(transport: Transport, defaultTimeoutMs?: number) {
103
- this.transport = transport;
104
- this.defaultTimeoutMs = defaultTimeoutMs ?? DEFAULT_RAW_REQUEST_TIMEOUT_MS;
105
- }
106
-
107
- attach(): void {
108
- if (this.attached) return;
109
- this.attached = true;
110
- const previousOnMessage = this.transport.onmessage;
111
- this.transport.onmessage = (message, extra) => {
112
- if (this.consumeRawResponse(message)) return;
113
- previousOnMessage?.(message, extra);
114
- };
115
- const previousOnClose = this.transport.onclose;
116
- this.transport.onclose = () => {
117
- this.rejectAll("MCP connection closed");
118
- previousOnClose?.();
119
- };
120
- }
121
-
122
- /** Sends a raw JSON-RPC request and resolves with its correlated response. */
123
- rawDispatch: RawClientDispatch = (request, options) => {
124
- if (!isJsonRecord(request) || typeof request.method !== "string") {
125
- return Promise.reject(new Error("Raw MCP request must be a JSON object with a string method"));
126
- }
127
- const params = request.params;
128
- if (params !== undefined && !isJsonRecord(params)) {
129
- return Promise.reject(new Error("Raw MCP request params must be a JSON object"));
130
- }
131
- const signal = options?.signal;
132
- if (signal?.aborted) return Promise.reject(abortError(signal));
133
-
134
- const id = `${RAW_REQUEST_ID_PREFIX}${++this.requestCounter}`;
135
- const message = {
136
- jsonrpc: "2.0",
137
- id,
138
- method: request.method,
139
- ...(params === undefined ? {} : { params }),
140
- } as unknown as JSONRPCRequest;
141
- const timeoutMs = options?.context?.requestTimeoutMs ?? this.defaultTimeoutMs;
142
-
143
- return new Promise<JsonRpcResponseShape>((resolve, reject) => {
144
- const entry: PendingRawRequest = {
145
- id,
146
- resolve,
147
- reject,
148
- state: "pending",
149
- ...(signal === undefined ? {} : { signal }),
150
- ...(message.method === "tools/call" ? { observationController: new AbortController() } : {}),
151
- };
152
- entry.requestTimer = setTimeout(() => {
153
- this.terminateLocalWait(entry, new Error(`MCP task request "${message.method}" timed out after ${timeoutMs}ms`));
154
- }, timeoutMs);
155
- this.pending.set(id, entry);
156
- if (signal) {
157
- entry.onAbort = () => {
158
- this.terminateLocalWait(entry, abortError(signal));
159
- };
160
- signal.addEventListener("abort", entry.onAbort, { once: true });
161
- }
162
- const fail = (error: unknown) => {
163
- if (this.pending.get(id) !== entry) return;
164
- const wasPending = entry.state === "pending";
165
- this.finishRequest(entry, true);
166
- if (wasPending) reject(error instanceof Error ? error : new Error(String(error)));
167
- };
168
- // ext-tasks supplies the SEP-2663 Mcp-Name routing header (and any
169
- // host headers) via context.headers. A task-producing tools/call owns
170
- // its transport observation independently from the caller's wait.
171
- try {
172
- Promise.resolve(this.transport.send(message, {
173
- ...(options?.context?.headers === undefined ? {} : { headers: options.context.headers }),
174
- ...(entry.observationController !== undefined
175
- ? { requestSignal: entry.observationController.signal }
176
- : signal === undefined ? {} : { requestSignal: signal }),
177
- })).catch(fail);
178
- } catch (error) {
179
- fail(error);
180
- }
181
- }) as ReturnType<RawClientDispatch>;
182
- };
183
-
184
- private consumeRawResponse(message: JSONRPCMessage): boolean {
185
- if (!("id" in message) || typeof message.id !== "string") return false;
186
- if (!message.id.startsWith(RAW_REQUEST_ID_PREFIX)) return false;
187
- // A server request may choose any string ID, including our client-side
188
- // prefix. Method-bearing frames still belong to the SDK request handler.
189
- if ("method" in message) return false;
190
- const entry = this.pending.get(message.id);
191
- if (!entry) return true; // ours, but already completed or its bounded observation expired
192
- const wasObserving = entry.state === "observing";
193
- this.finishRequest(entry, true);
194
- if (wasObserving) {
195
- this.cancelLateTask(message);
196
- return true;
197
- }
198
- if ("error" in message) {
199
- const { code, message: errorMessage, data } = message.error;
200
- entry.resolve({ kind: "error", error: { code, message: errorMessage, ...(data === undefined ? {} : { data }) } });
201
- } else if ("result" in message) {
202
- entry.resolve({ kind: "result", result: message.result });
203
- } else {
204
- entry.reject(new Error("MCP task response frame carried neither result nor error"));
205
- }
206
- return true;
207
- }
208
-
209
- private terminateLocalWait(entry: PendingRawRequest, error: Error): void {
210
- if (this.pending.get(entry.id) !== entry || entry.state !== "pending") return;
211
- if (entry.observationController === undefined) {
212
- this.finishRequest(entry, false);
213
- } else {
214
- entry.state = "observing";
215
- this.clearLocalWait(entry);
216
- entry.observationTimer = setTimeout(() => {
217
- this.finishRequest(entry, true);
218
- }, LATE_TASK_HANDLE_GRACE_MS);
219
- }
220
- entry.reject(error);
221
- }
222
-
223
- private clearLocalWait(entry: PendingRawRequest): void {
224
- if (entry.requestTimer !== undefined) clearTimeout(entry.requestTimer);
225
- delete entry.requestTimer;
226
- if (entry.signal !== undefined && entry.onAbort !== undefined) {
227
- entry.signal.removeEventListener("abort", entry.onAbort);
228
- }
229
- delete entry.onAbort;
230
- }
231
-
232
- private finishRequest(entry: PendingRawRequest, abortObservation: boolean): void {
233
- if (this.pending.get(entry.id) !== entry) return;
234
- this.clearLocalWait(entry);
235
- if (entry.observationTimer !== undefined) clearTimeout(entry.observationTimer);
236
- delete entry.observationTimer;
237
- this.pending.delete(entry.id);
238
- if (abortObservation) entry.observationController?.abort();
239
- }
240
-
241
- private cancelLateTask(message: JSONRPCMessage): void {
242
- if (!("result" in message) || !isJsonRecord(message.result)) return;
243
- if (message.result.resultType !== "task" || typeof message.result.taskId !== "string") return;
244
- const taskId = message.result.taskId;
245
- void this.rawDispatch(
246
- { method: "tasks/cancel", params: { taskId } },
247
- { context: { headers: { "Mcp-Name": taskId } } },
248
- ).catch(() => {});
249
- }
250
-
251
- rejectAll(reason: string): void {
252
- const entries = [...this.pending.values()];
253
- for (const entry of entries) {
254
- const wasPending = entry.state === "pending";
255
- this.finishRequest(entry, true);
256
- if (wasPending) entry.reject(new Error(reason));
257
- }
258
- }
259
- }
260
-
261
- /**
262
- * Whether a connected 2026-07-28 server advertises the tasks extension.
263
- * ext-tasks requires the exact empty-object declaration; anything else
264
- * downgrades the session, so mirror its check here.
265
- *
266
- * Legacy (2025-11-25) task servers are intentionally out of scope: driving
267
- * their opt-in `task` parameter requires per-tool taskSupport declarations,
268
- * which this integration does not supply.
269
- */
270
- export function serverAdvertisesTasks(client: Client): boolean {
271
- if (client.getProtocolEra?.() !== "modern") return false;
272
- const capabilities = client.getServerCapabilities();
273
- const extension = (capabilities?.extensions as Record<string, unknown> | undefined)?.[TASKS_EXTENSION_ID];
274
- return isJsonRecord(extension) && Object.keys(extension).length === 0;
275
- }
276
-
277
- /** Missing-handler errors carry the SDK's capability shape so call sites can classify them. */
278
- function capabilityNotSupportedError(serverName: string, method: string, inputKey: string | undefined): Error {
279
- const error = new Error(
280
- `MCP server ${serverName} requested ${method} during a task, but this session has no handler for it`,
281
- );
282
- Object.assign(error, {
283
- code: "CAPABILITY_NOT_SUPPORTED",
284
- data: { key: inputKey ?? "unknown", method },
285
- });
286
- return error;
287
- }
288
-
289
- export interface AttachTaskSessionOptions {
290
- client: Client;
291
- serverName: string;
292
- definition: ServerDefinition;
293
- transport: Transport;
294
- requestTimeoutMs?: number | undefined;
295
- clientInfo: { name: string; version: string };
296
- clientCapabilities: Record<string, unknown>;
297
- onElicitation?: (request: ElicitRequest, signal?: AbortSignal) => Promise<ElicitResult>;
298
- onSampling?: (request: CreateMessageRequest, signal?: AbortSignal) => Promise<CreateMessageResult>;
299
- }
300
-
301
- export interface TaskSessionAttachment {
302
- session: TaskEnabledSession;
303
- channel: RawRequestChannel;
304
- }
305
-
306
- /**
307
- * Attaches an ext-tasks requester session to a connected client when the
308
- * server advertises task support. Returns undefined otherwise, leaving the
309
- * plain callTool path untouched.
310
- */
311
- export async function attachTaskSession(
312
- options: AttachTaskSessionOptions,
313
- ): Promise<TaskSessionAttachment | undefined> {
314
- const { client, serverName, definition } = options;
315
- if (!serverAdvertisesTasks(client)) return undefined;
316
- const protocolVersion = client.getNegotiatedProtocolVersion?.();
317
- if (protocolVersion === undefined) return undefined;
318
-
319
- const endpointId = await createTaskSessionEndpointId("pi-mcp-adapter", {
320
- server: serverName,
321
- ...(definition.command !== undefined
322
- ? { transport: { type: "stdio", command: definition.command, args: definition.args ?? [] } }
323
- : definition.url !== undefined
324
- ? { transport: { type: "http", url: definition.url } }
325
- : { transport: { type: "unix-socket", socket: definition.socket ?? null } }),
326
- });
327
-
328
- const onInputRequest = createApplicationInputHandler({
329
- elicitation: async (request, context) => {
330
- if (options.onElicitation === undefined) {
331
- throw capabilityNotSupportedError(serverName, "elicitation/create", context.inputId);
332
- }
333
- const result = await options.onElicitation(
334
- { method: "elicitation/create", params: request.params } as unknown as ElicitRequest,
335
- context.signal,
336
- );
337
- return {
338
- action: result.action,
339
- ...(result.content === undefined
340
- ? {}
341
- : { content: result.content as Readonly<Record<string, ApplicationElicitContentValue>> }),
342
- };
343
- },
344
- sampling: async (request, context) => {
345
- if (options.onSampling === undefined) {
346
- throw capabilityNotSupportedError(serverName, "sampling/createMessage", context.inputId);
347
- }
348
- const result = await options.onSampling(
349
- { method: "sampling/createMessage", params: request.params } as unknown as CreateMessageRequest,
350
- context.signal,
351
- );
352
- return {
353
- model: result.model,
354
- role: result.role,
355
- content: result.content as never,
356
- };
357
- },
358
- roots: async () => ({ roots: [] }),
359
- });
360
-
361
- const channel = new RawRequestChannel(options.transport, options.requestTimeoutMs);
362
- channel.attach();
363
- const session = createTaskSessionFromClient(client, {
364
- endpointId,
365
- rawDispatch: channel.rawDispatch,
366
- v2RequestFraming: {
367
- protocolVersion,
368
- clientInfo: options.clientInfo,
369
- clientCapabilities: options.clientCapabilities as never,
370
- },
371
- // Tool declarations only add per-tool taskSupport hints; the adapter's
372
- // cached tools/list is not threaded through here, and a miss is harmless.
373
- tools: { currentTool: () => undefined },
374
- onInputRequest,
375
- onError: (error) => logger.warn(`ext-tasks background error for ${serverName}: ${String(error)}`),
376
- });
377
- // A downgraded session (server capability mismatch) would silently route
378
- // plain tool calls through the generic request path, skipping callTool's
379
- // output-schema validation. Refuse it and keep the plain path instead.
380
- if (!session.capabilities.execution) {
381
- await session.close().catch(() => {});
382
- channel.rejectAll("Task session downgraded");
383
- return undefined;
384
- }
385
- return { session, channel };
386
- }
387
-
388
- export interface TaskToolCallOptions {
389
- name: string;
390
- args: Record<string, unknown>;
391
- meta?: Record<string, unknown> | undefined;
392
- signal?: AbortSignal | undefined;
393
- requestTimeoutMs?: number | undefined;
394
- }
395
-
396
- /**
397
- * Preserves error-shape parity with Client.callTool: JSON-RPC failures —
398
- * immediate (JsonRpcResponseError) or terminal task errors (TaskFailedError
399
- * with a code) — become the typed ProtocolError subclass for their code, so
400
- * call-site handling (session recovery, URL elicitation) keeps working.
401
- * Local failures rethrow their original cause instead of being relabeled.
402
- */
403
- function toCallToolError(error: unknown, signal: AbortSignal | undefined): unknown {
404
- if (error instanceof TaskCancelledError && signal?.aborted === true) {
405
- return abortError(signal);
406
- }
407
- if (error instanceof JsonRpcResponseError) {
408
- return ProtocolError.fromError(error.code, error.message, error.data);
409
- }
410
- if (error instanceof TaskFailedError && error.code !== undefined) {
411
- return ProtocolError.fromError(error.code, error.message, error.data);
412
- }
413
- if (error instanceof DispatchError) {
414
- return error.cause ?? error;
415
- }
416
- return error;
417
- }
418
-
419
- /**
420
- * Calls a tool through a task session and blocks until settlement, preserving
421
- * the plain callTool contract: an immediate result returns as-is, a
422
- * task-backed execution is polled to completion, a failed task throws the
423
- * underlying JSON-RPC error, and aborting cancels the remote task.
424
- */
425
- export async function callToolViaTaskSession(
426
- session: TaskEnabledSession,
427
- options: TaskToolCallOptions,
428
- ): Promise<Record<string, unknown>> {
429
- const { signal } = options;
430
- let execution;
431
- try {
432
- execution = await session.callTool(options.name, options.args as never, {
433
- ...(options.meta === undefined ? {} : { metadata: options.meta as never }),
434
- ...(signal === undefined ? {} : { signal }),
435
- ...(options.requestTimeoutMs === undefined ? {} : { requestTimeoutMs: options.requestTimeoutMs }),
436
- });
437
- } catch (error) {
438
- throw toCallToolError(error, signal);
439
- }
440
- let onAbort: (() => void) | undefined;
441
- if (signal !== undefined && execution.kind === "task") {
442
- // settle({ signal }) only stops waiting locally; propagate the abort as a
443
- // cooperative remote cancellation so the server can stop the work. The
444
- // signal may have aborted while callTool was resolving, so fire directly
445
- // for an abort the listener would miss.
446
- onAbort = () => {
447
- void execution.cancel().catch(() => {});
448
- };
449
- if (signal.aborted) onAbort();
450
- else signal.addEventListener("abort", onAbort, { once: true });
451
- }
452
- try {
453
- const settlement = await execution.settle(signal === undefined ? {} : { signal });
454
- const result = resultFromTaskOutcome(settlement.outcome);
455
- if (!isJsonRecord(result)) {
456
- throw new Error(`Task-backed tool ${options.name} settled with a non-object result`);
457
- }
458
- // Match Client.callTool's lifted shape, which strips the wire-only discriminator.
459
- const { resultType: _resultType, ...lifted } = result;
460
- return lifted;
461
- } catch (error) {
462
- throw toCallToolError(error, signal);
463
- } finally {
464
- if (signal !== undefined && onAbort !== undefined) signal.removeEventListener("abort", onAbort);
465
- await execution.close().catch(() => {});
466
- }
467
- }