@herbertgao/pi-extensions 2026.9.17 → 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 (266) 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/@juicesharp/rpiv-ask-user-question/package.json +99 -99
  11. package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
  12. package/node_modules/@tifan/pi-handoff/package.json +1 -1
  13. package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
  14. package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
  15. package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
  16. package/node_modules/@tifan/pi-recap/package.json +1 -1
  17. package/node_modules/@tifan/pi-rename/package.json +1 -1
  18. package/node_modules/pi-antigravity/package.json +2 -2
  19. package/node_modules/pi-lens/package.json +158 -158
  20. package/node_modules/pi-multi-account/package.json +2 -2
  21. package/node_modules/pi-typesafe/README.md +1 -1
  22. package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
  23. package/node_modules/pi-typesafe/dist/auth.js +7 -3
  24. package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
  25. package/node_modules/pi-typesafe/dist/backends.js +95 -1
  26. package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
  27. package/node_modules/pi-typesafe/dist/client.js +12 -9
  28. package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
  29. package/node_modules/pi-typesafe/dist/credentials.js +10 -7
  30. package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
  31. package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
  32. package/node_modules/pi-typesafe/dist/index.js +1 -1
  33. package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
  34. package/node_modules/pi-typesafe/dist/login.js +2 -2
  35. package/node_modules/pi-typesafe/package.json +5 -5
  36. package/node_modules/pi-web-access/package.json +2 -2
  37. package/node_modules/remote-pi/package.json +5 -1
  38. package/package.json +16 -28
  39. package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
  40. package/node_modules/pi-mcp-adapter/LICENSE +0 -21
  41. package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
  42. package/node_modules/pi-mcp-adapter/README.md +0 -1021
  43. package/node_modules/pi-mcp-adapter/abort.ts +0 -34
  44. package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
  45. package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
  46. package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
  47. package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
  48. package/node_modules/pi-mcp-adapter/banner.png +0 -0
  49. package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
  50. package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
  51. package/node_modules/pi-mcp-adapter/cli.js +0 -454
  52. package/node_modules/pi-mcp-adapter/commands.ts +0 -861
  53. package/node_modules/pi-mcp-adapter/config.ts +0 -1565
  54. package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
  55. package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
  56. package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
  57. package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
  58. package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
  59. package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
  60. package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
  61. package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
  62. package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
  63. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
  64. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
  65. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
  66. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
  67. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
  68. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
  69. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
  70. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
  71. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
  72. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
  73. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
  74. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
  75. package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
  76. package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
  77. package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
  78. package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
  79. package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
  80. package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
  81. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
  82. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
  83. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
  84. package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
  85. package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
  86. package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
  87. package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
  88. package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
  89. package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
  90. package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
  91. package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
  92. package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
  93. package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
  94. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
  95. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
  96. package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
  97. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
  98. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
  99. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
  100. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
  101. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
  102. package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
  103. package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
  104. package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
  105. package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
  106. package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
  107. package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
  108. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
  109. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
  110. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
  111. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
  112. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
  113. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
  114. package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
  115. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
  116. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
  117. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
  118. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
  119. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
  120. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
  121. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
  122. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
  123. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
  124. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
  125. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
  126. package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
  127. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
  128. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
  129. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
  130. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
  131. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
  132. package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
  133. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
  134. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
  135. package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
  136. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
  137. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
  138. package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
  139. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
  140. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
  141. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
  142. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
  143. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
  144. package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
  145. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
  146. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
  147. package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
  148. package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
  149. package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
  150. package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
  151. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
  152. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
  153. package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
  154. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
  155. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
  156. package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
  157. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
  158. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
  159. package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
  160. package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
  161. package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
  162. package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
  163. package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
  164. package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
  165. package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
  166. package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
  167. package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
  168. package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
  169. package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
  170. package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
  171. package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
  172. package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
  173. package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
  174. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
  175. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
  176. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
  177. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
  178. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
  179. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
  180. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
  181. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
  182. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
  183. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
  184. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
  185. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
  186. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
  187. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
  188. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
  189. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
  190. package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
  191. package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
  192. package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
  193. package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
  194. package/node_modules/pi-mcp-adapter/errors.ts +0 -364
  195. package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
  196. package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
  197. package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
  198. package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
  199. package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
  200. package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
  201. package/node_modules/pi-mcp-adapter/index.ts +0 -2106
  202. package/node_modules/pi-mcp-adapter/init.ts +0 -721
  203. package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
  204. package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
  205. package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
  206. package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
  207. package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
  208. package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
  209. package/node_modules/pi-mcp-adapter/logger.ts +0 -169
  210. package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
  211. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
  212. package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
  213. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
  214. package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
  215. package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
  216. package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
  217. package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
  218. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
  219. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
  220. package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
  221. package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
  222. package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
  223. package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
  224. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
  225. package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
  226. package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
  227. package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
  228. package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
  229. package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
  230. package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
  231. package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
  232. package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
  233. package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
  234. package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
  235. package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
  236. package/node_modules/pi-mcp-adapter/package.json +0 -219
  237. package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
  238. package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
  239. package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
  240. package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
  241. package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
  242. package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
  243. package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
  244. package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
  245. package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
  246. package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
  247. package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
  248. package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
  249. package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
  250. package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
  251. package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
  252. package/node_modules/pi-mcp-adapter/state.ts +0 -71
  253. package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
  254. package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
  255. package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
  256. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
  257. package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
  258. package/node_modules/pi-mcp-adapter/types.ts +0 -1120
  259. package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
  260. package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
  261. package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
  262. package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
  263. package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
  264. package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
  265. package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
  266. package/node_modules/pi-mcp-adapter/utils.ts +0 -464
@@ -1,495 +0,0 @@
1
- import type { ToolInfo } from "@earendil-works/pi-coding-agent";
2
- import { formatWithOptions } from "node:util";
3
- import { Worker } from "node:worker_threads";
4
- import { throwIfAborted } from "./abort.ts";
5
- import { guardMcpOutput, guardedMcpDetails, resolveMcpOutputGuardOptions } from "./mcp-output-guard.ts";
6
- import { evaluateJev, validateJevSettings } from "./jev-client.ts";
7
- import type { JevErrorCode, JevEvaluateInput, JevEvaluationEnvelope } from "./jev-contracts.ts";
8
- import { executeCall } from "./proxy-modes.ts";
9
- import { combineAbortSignals } from "./runtime-owner.ts";
10
- import { paginate, rankSuggestions, rankToolMatches } from "./search-ranking.ts";
11
- import { semanticSearch, type SemanticSearchEvaluator } from "./semantic-search.ts";
12
- import { isServerInActiveFailureBackoff } from "./failure-backoff.ts";
13
- import type { McpExtensionState } from "./state.ts";
14
- import { findToolByName, formatSchema, hasSchemaDescriptions } from "./tool-metadata.ts";
15
- import { renderTsShape } from "./ts-shape.ts";
16
- import type { ContentBlock } from "./types.ts";
17
-
18
- export const DEFAULT_MCP_SCRIPT_TIMEOUT_MS = 30_000;
19
- const MCP_SCRIPT_INTERMEDIATE_MAX_BYTES = 16 * 1024 * 1024;
20
-
21
- class McpScriptTimeoutError extends Error {
22
- constructor(timeoutMs: number) {
23
- super(`mcpScript timed out after ${timeoutMs}ms`);
24
- this.name = "McpScriptTimeoutError";
25
- }
26
- }
27
-
28
- type SearchInput = { query?: unknown; server?: unknown; limit?: unknown; offset?: unknown; searchMode?: unknown; regex?: unknown };
29
- type DescribeInput = { path?: unknown };
30
- type WorkerMessage =
31
- | { type: "emit"; block: unknown }
32
- | { type: "call"; id: number; path: string; args?: unknown }
33
- | { type: "evaluate"; id: number; input: unknown }
34
- | { type: "search"; id: number; input?: unknown }
35
- | { type: "describe"; id: number; input?: unknown }
36
- | { type: "done"; returnBlock?: unknown }
37
- | { type: "error"; message: string };
38
-
39
- type WorkerResultPayload = { envelope: unknown } | { dataJson: string };
40
- type WorkerResultMessage = { type: "result"; id: number } & WorkerResultPayload;
41
-
42
- function needsInspectableFormatting(value: unknown, stack = new WeakSet<object>()): boolean {
43
- if (value === undefined || typeof value === "bigint" || typeof value === "function" || typeof value === "symbol") return true;
44
- if (typeof value !== "object" || value === null) return false;
45
- if (stack.has(value)) return true;
46
- if (value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet) return true;
47
- stack.add(value);
48
- try {
49
- return Object.values(value).some((entry) => needsInspectableFormatting(entry, stack));
50
- } finally {
51
- stack.delete(value);
52
- }
53
- }
54
-
55
- function formatValue(value: unknown): string {
56
- if (typeof value === "string") return value;
57
- try {
58
- if (!needsInspectableFormatting(value)) {
59
- const json = JSON.stringify(value, null, 2);
60
- if (json !== undefined) return json;
61
- }
62
- return formatWithOptions({ colors: false, depth: 6 }, value);
63
- } catch {
64
- return "[unserializable value]";
65
- }
66
- }
67
-
68
- function toContentBlock(value: unknown): ContentBlock {
69
- if (typeof value === "object" && value !== null) {
70
- const block = value as Record<string, unknown>;
71
- if (block.type === "text" && typeof block.text === "string") {
72
- return { type: "text", text: block.text };
73
- }
74
- if (block.type === "image" && typeof block.data === "string" && typeof block.mimeType === "string") {
75
- return { type: "image", data: block.data, mimeType: block.mimeType };
76
- }
77
- }
78
- return { type: "text", text: formatValue(value) };
79
- }
80
-
81
- function textFromContent(content: ContentBlock[]): string {
82
- return content
83
- .filter((block) => block.type === "text")
84
- .map((block) => block.text)
85
- .join("\n");
86
- }
87
-
88
- function abortReasonError(reason: unknown): Error {
89
- return reason instanceof Error ? reason : new Error(String(reason ?? "MCP request aborted"));
90
- }
91
-
92
- function parseWorkerMessage(value: unknown): WorkerMessage | null {
93
- if (typeof value !== "object" || value === null) return null;
94
- const message = value as Record<string, unknown>;
95
- if (message.type === "emit" && "block" in message) return { type: "emit", block: message.block };
96
- if (message.type === "call" && typeof message.id === "number" && typeof message.path === "string") {
97
- return "args" in message
98
- ? { type: "call", id: message.id, path: message.path, args: message.args }
99
- : { type: "call", id: message.id, path: message.path };
100
- }
101
- if (message.type === "evaluate" && typeof message.id === "number" && "input" in message) {
102
- return { type: "evaluate", id: message.id, input: message.input };
103
- }
104
- if ((message.type === "search" || message.type === "describe") && typeof message.id === "number") {
105
- return "input" in message
106
- ? { type: message.type, id: message.id, input: message.input }
107
- : { type: message.type, id: message.id };
108
- }
109
- if (message.type === "done") {
110
- return "returnBlock" in message ? { type: "done", returnBlock: message.returnBlock } : { type: "done" };
111
- }
112
- if (message.type === "error" && typeof message.message === "string") {
113
- return { type: "error", message: message.message };
114
- }
115
- return null;
116
- }
117
-
118
- export type McpScriptJevEvaluator = (
119
- state: McpExtensionState,
120
- input: JevEvaluateInput,
121
- options: { purpose: "script"; signal?: AbortSignal; observedSources?: readonly string[] },
122
- ) => Promise<JevEvaluationEnvelope>;
123
-
124
- export async function runMcpScript(
125
- state: McpExtensionState,
126
- code: string,
127
- timeoutMs = DEFAULT_MCP_SCRIPT_TIMEOUT_MS,
128
- getPiTools?: () => ToolInfo[],
129
- signal?: AbortSignal,
130
- jevEvaluator: McpScriptJevEvaluator = evaluateJev,
131
- semanticEvaluator?: SemanticSearchEvaluator,
132
- ) {
133
- const resolvedTimeoutMs = Number.isFinite(timeoutMs) && timeoutMs > 0
134
- ? Math.floor(timeoutMs)
135
- : DEFAULT_MCP_SCRIPT_TIMEOUT_MS;
136
- const output: ContentBlock[] = [];
137
- const externalSignal = combineAbortSignals(state.owner?.signal, signal);
138
- const timeoutController = new AbortController();
139
- const callSignal = combineAbortSignals(externalSignal, timeoutController.signal);
140
- const observedSources = new Set<string>();
141
-
142
- type ScriptOperation =
143
- | { operation: "call"; path: string; ok: true; durationMs: number }
144
- | { operation: "call"; path: string; ok: false; error: string; durationMs: number }
145
- | { operation: "search"; query: string; ok: true; durationMs: number }
146
- | { operation: "search"; query: string; ok: false; error: string; durationMs: number }
147
- | { operation: "describe"; path: string; ok: true; durationMs: number }
148
- | { operation: "describe"; path: string; ok: false; error: string; durationMs: number }
149
- | { operation: "evaluate"; ok: true; model: string; inputTokens: number; outputTokens: number; durationMs: number }
150
- | { operation: "evaluate"; ok: false; error: JevErrorCode | "incomplete"; durationMs: number };
151
- type TrackedScriptOperation = ScriptOperation & { startedAt: number };
152
- const calls: TrackedScriptOperation[] = [];
153
- const snapshotCalls = (): ScriptOperation[] => calls.map(({ startedAt, ...operation }) => ({
154
- ...operation,
155
- durationMs: "error" in operation && operation.error === "incomplete"
156
- ? Math.max(0, Date.now() - startedAt)
157
- : operation.durationMs,
158
- }));
159
- let callsSnapshot: ScriptOperation[] | undefined;
160
- let intermediateBytes = 0;
161
- const reserveIntermediateBytes = (dataJson: string): boolean => {
162
- const bytes = Buffer.byteLength(dataJson, "utf8");
163
- if (bytes > MCP_SCRIPT_INTERMEDIATE_MAX_BYTES - intermediateBytes) return false;
164
- intermediateBytes += bytes;
165
- return true;
166
- };
167
- const callTool = async (path: string, args?: Record<string, unknown>): Promise<WorkerResultPayload> => {
168
- // Record before dispatch so calls still in flight at timeout/abort appear in the trace.
169
- const startedAt = Date.now();
170
- const index = calls.push({ operation: "call", path, ok: false, error: "incomplete", durationMs: 0, startedAt }) - 1;
171
- let dataJson: string | undefined;
172
- const result = await executeCall(state, path, args, undefined, getPiTools, callSignal, "script", {
173
- onSuccess(data) {
174
- // Serialize once for both byte accounting and worker transfer, never for display.
175
- dataJson = JSON.stringify(data);
176
- },
177
- });
178
- const details = result.details;
179
- if (typeof details.server === "string") observedSources.add(details.server);
180
- if (details.error !== undefined) {
181
- const errorCode = String(details.error);
182
- const suggestions = Array.isArray(details.suggestions)
183
- ? details.suggestions.filter((suggestion): suggestion is string => typeof suggestion === "string")
184
- : [];
185
- const message = errorCode === "tool_not_found"
186
- ? `Tool "${path}" not found. Use await tools.search({ query: "..." }) inside mcpScript.${suggestions.length > 0 ? ` Did you mean: ${suggestions.join(", ")}` : ""}`
187
- : typeof details.message === "string"
188
- ? details.message
189
- : textFromContent(result.content);
190
- calls[index] = { operation: "call", path, ok: false, error: errorCode, durationMs: Date.now() - startedAt, startedAt };
191
- return {
192
- envelope: { ok: false, error: { code: errorCode, message } },
193
- };
194
- }
195
- throwIfAborted(callSignal);
196
- if (dataJson === undefined) throw new Error("MCP intermediate result was not JSON serializable");
197
- if (!reserveIntermediateBytes(dataJson)) {
198
- const code = "intermediate_result_too_large";
199
- calls[index] = { operation: "call", path, ok: false, error: code, durationMs: Date.now() - startedAt, startedAt };
200
- return {
201
- envelope: {
202
- ok: false,
203
- error: { code, message: "MCP result exceeds the remaining mcpScript intermediate transfer budget (16 MiB per script). Request less data or use a new script." },
204
- },
205
- };
206
- }
207
- // Rejected responses do not consume budget. This bounds transfer, not upstream allocation.
208
- calls[index] = { operation: "call", path, ok: true, durationMs: Date.now() - startedAt, startedAt };
209
- return { dataJson };
210
- };
211
-
212
- const jevSettings = validateJevSettings(state.config.settings?.jev);
213
- let evaluationAttempts = 0;
214
- let evaluationBytes = 0;
215
- let evaluationTokensRemaining = jevSettings.maxEvaluationTokensPerScript;
216
- const tokenBudgetExhausted = (): JevEvaluationEnvelope => ({ ok: false, error: { code: "budget_exhausted", message: "Jev evaluation token budget exhausted." } });
217
- const chargeEvaluationTokens = (envelope: JevEvaluationEnvelope): JevEvaluationEnvelope => {
218
- if (!envelope.ok) return envelope;
219
- const used = envelope.data.usage.inputTokens + envelope.data.usage.outputTokens;
220
- if (!Number.isSafeInteger(used) || used < 0 || used > evaluationTokensRemaining) {
221
- evaluationTokensRemaining = 0;
222
- return tokenBudgetExhausted();
223
- }
224
- evaluationTokensRemaining -= used;
225
- return envelope;
226
- };
227
- const admitEvaluation = (input: unknown): JevEvaluationEnvelope | undefined => {
228
- if (++evaluationAttempts > jevSettings.maxEvaluationsPerScript) {
229
- return { ok: false, error: { code: "budget_exhausted", message: "Jev evaluation count budget exhausted." } };
230
- }
231
- if (evaluationTokensRemaining === 0) return tokenBudgetExhausted();
232
- let serialized: string | undefined;
233
- try { serialized = JSON.stringify(input); }
234
- catch { return { ok: false, error: { code: "invalid_request", message: "Invalid Jev evaluation request." } }; }
235
- if (serialized === undefined) return { ok: false, error: { code: "invalid_request", message: "Invalid Jev evaluation request." } };
236
- const bytes = Buffer.byteLength(serialized, "utf8");
237
- if (bytes > jevSettings.maxEvaluationBytesPerScript - evaluationBytes) {
238
- return { ok: false, error: { code: "budget_exhausted", message: "Jev evaluation byte budget exhausted." } };
239
- }
240
- evaluationBytes += bytes;
241
- return undefined;
242
- };
243
- const evaluate = async (input: unknown): Promise<WorkerResultPayload> => {
244
- const startedAt = Date.now();
245
- const index = calls.push({ operation: "evaluate", ok: false, error: "incomplete", durationMs: 0, startedAt }) - 1;
246
- let envelope: JevEvaluationEnvelope;
247
- const rejected = admitEvaluation(input);
248
- if (rejected) {
249
- envelope = rejected;
250
- } else {
251
- envelope = await jevEvaluator(state, input as JevEvaluateInput, {
252
- purpose: "script",
253
- ...(callSignal ? { signal: callSignal } : {}),
254
- ...(observedSources.size > 0 ? { observedSources: [...observedSources] } : {}),
255
- });
256
- }
257
- envelope = chargeEvaluationTokens(envelope);
258
- throwIfAborted(callSignal);
259
- if (!reserveIntermediateBytes(JSON.stringify(envelope))) {
260
- envelope = { ok: false, error: { code: "budget_exhausted", message: "Jev evaluation exceeds the remaining mcpScript intermediate transfer budget (16 MiB per script)." } };
261
- }
262
- calls[index] = envelope.ok
263
- ? {
264
- operation: "evaluate", ok: true, model: envelope.data.model,
265
- inputTokens: envelope.data.usage.inputTokens, outputTokens: envelope.data.usage.outputTokens,
266
- durationMs: Date.now() - startedAt, startedAt,
267
- }
268
- : { operation: "evaluate", ok: false, error: envelope.error.code, durationMs: Date.now() - startedAt, startedAt };
269
- return { envelope };
270
- };
271
-
272
- const searchTools = async (input?: SearchInput) => {
273
- const startedAt = Date.now();
274
- const query = typeof input?.query === "string" ? input.query : "";
275
- const index = calls.push({ operation: "search", query, ok: false, error: "incomplete", durationMs: 0, startedAt }) - 1;
276
- let error: unknown;
277
- try {
278
- if (input?.searchMode !== undefined && input.searchMode !== "lexical" && input.searchMode !== "semantic") {
279
- error = "invalid_search_mode";
280
- return { items: [], total: 0, hasMore: false, nextOffset: null, error: { code: "invalid_search_mode", message: "Search mode must be lexical or semantic." } };
281
- }
282
- if (query.trim() === "" && input?.searchMode !== "semantic") {
283
- return { items: [], total: 0, hasMore: false, nextOffset: null };
284
- }
285
- const server = typeof input?.server === "string" ? input.server : undefined;
286
- const limit = typeof input?.limit === "number" ? input.limit : 12;
287
- const offset = typeof input?.offset === "number" ? input.offset : 0;
288
- const searchMode = input?.searchMode === "semantic" ? "semantic" : "lexical";
289
- if (searchMode === "semantic" && input?.regex === true) {
290
- error = "invalid_search_mode";
291
- return { items: [], total: 0, hasMore: false, nextOffset: null, error: { code: "invalid_search_mode", message: "Semantic search cannot be combined with regex search." } };
292
- }
293
- const semantic = searchMode === "semantic"
294
- ? await semanticSearch(state, query, server, callSignal, async (semanticState, semanticInput, options) => {
295
- const rejected = admitEvaluation(semanticInput);
296
- if (rejected) return rejected;
297
- const envelope = await (semanticEvaluator ?? evaluateJev)(semanticState, semanticInput, options);
298
- return chargeEvaluationTokens(envelope);
299
- }, [...observedSources])
300
- : undefined;
301
- if (semantic && !semantic.ok) {
302
- error = semantic.error.code;
303
- return { items: [], total: 0, hasMore: false, nextOffset: null, error: semantic.error };
304
- }
305
- const page = paginate(semantic?.matches ?? rankToolMatches(state, query, server), offset, limit);
306
- return {
307
- ...page,
308
- items: page.items.map(({ server: matchServer, tool, score }) => ({
309
- path: tool.name,
310
- name: tool.originalName,
311
- server: matchServer,
312
- ...(tool.description ? { description: tool.description } : {}),
313
- score,
314
- })),
315
- ...(semantic ? { backend: semantic.backend } : {}),
316
- };
317
- } catch (caught) {
318
- error = caught;
319
- throw caught;
320
- } finally {
321
- calls[index] = error === undefined
322
- ? { operation: "search", query, ok: true, durationMs: Date.now() - startedAt, startedAt }
323
- : { operation: "search", query, ok: false, error: error instanceof Error ? error.message : String(error), durationMs: Date.now() - startedAt, startedAt };
324
- }
325
- };
326
-
327
- const describeTool = (input?: DescribeInput) => {
328
- const startedAt = Date.now();
329
- const path = typeof input?.path === "string" ? input.path : "";
330
- let error: unknown;
331
- try {
332
- for (const [server, metadata] of state.toolMetadata) {
333
- if (isServerInActiveFailureBackoff(state, server)) continue;
334
- const tool = findToolByName(metadata, path);
335
- if (!tool) continue;
336
- const inputShape = tool.inputSchema ? renderTsShape(tool.inputSchema) : null;
337
- const inputTypeScript = inputShape ?? (tool.inputSchema ? formatSchema(tool.inputSchema) : null);
338
- return {
339
- path: tool.name,
340
- name: tool.originalName,
341
- server,
342
- ...(tool.description ? { description: tool.description } : {}),
343
- ...(inputTypeScript ? { inputTypeScript } : {}),
344
- ...(inputShape && hasSchemaDescriptions(tool.inputSchema)
345
- ? { inputGuidance: formatSchema(tool.inputSchema) } : {}),
346
- ...(tool.outputSchema !== undefined ? {
347
- outputSchemaTarget: "data.structuredContent",
348
- outputSchema: tool.outputSchema,
349
- } : {}),
350
- };
351
- }
352
- const suggestions = path ? rankSuggestions(state, path, 5) : [];
353
- error = "tool_not_found";
354
- return {
355
- path,
356
- error: {
357
- code: "tool_not_found",
358
- message: `Tool not found: ${path}`,
359
- suggestions,
360
- },
361
- };
362
- } catch (caught) {
363
- error = caught;
364
- throw caught;
365
- } finally {
366
- calls.push(error === undefined
367
- ? { operation: "describe", path, ok: true, durationMs: Date.now() - startedAt, startedAt }
368
- : { operation: "describe", path, ok: false, error: error instanceof Error ? error.message : String(error), durationMs: Date.now() - startedAt, startedAt });
369
- }
370
- };
371
-
372
- let worker: Worker | undefined;
373
- let timer: ReturnType<typeof setTimeout> | undefined;
374
- let removeAbortListener = () => {};
375
- let errorCode: "timeout" | "aborted" | "script_error" | undefined;
376
- let errorMessage: string | undefined;
377
-
378
- try {
379
- if (externalSignal?.aborted) {
380
- throw abortReasonError(externalSignal.reason);
381
- }
382
-
383
- worker = new Worker(new URL("./mcp-script-worker.mjs", import.meta.url), {
384
- workerData: { code },
385
- env: {},
386
- // The sandbox cannot open files, and the host always terminates this worker.
387
- // Disable Node's unmanaged FD bookkeeping, which emits false warnings when
388
- // short-lived workers are terminated on Node 24.
389
- trackUnmanagedFds: false,
390
- });
391
- const activeWorker = worker;
392
- const execution = new Promise<void>((resolve, reject) => {
393
- let completed = false;
394
- activeWorker.on("message", (value: unknown) => {
395
- const message = parseWorkerMessage(value);
396
- if (!message || completed) return;
397
- if (message.type === "emit") {
398
- output.push(toContentBlock(message.block));
399
- return;
400
- }
401
- if (message.type === "done") {
402
- completed = true;
403
- if ("returnBlock" in message) output.push(toContentBlock(message.returnBlock));
404
- resolve();
405
- return;
406
- }
407
- if (message.type === "error") {
408
- completed = true;
409
- reject(new Error(message.message));
410
- return;
411
- }
412
-
413
- void (async () => {
414
- let payload: WorkerResultPayload;
415
- if (message.type === "call") {
416
- payload = await callTool(message.path, message.args as Record<string, unknown> | undefined);
417
- } else if (message.type === "evaluate") {
418
- payload = await evaluate(message.input);
419
- } else if (message.type === "search") {
420
- payload = { envelope: await searchTools(message.input as SearchInput | undefined) };
421
- } else {
422
- payload = { envelope: describeTool(message.input as DescribeInput | undefined) };
423
- }
424
- if (completed || callSignal?.aborted) return;
425
- const response: WorkerResultMessage = { type: "result", id: message.id, ...payload };
426
- activeWorker.postMessage(response);
427
- })().catch(reject);
428
- });
429
- activeWorker.once("error", reject);
430
- activeWorker.once("exit", (code) => {
431
- if (!completed && code !== 0) reject(new Error(`mcpScript worker exited with code ${code}`));
432
- });
433
- });
434
- const timeoutError = new McpScriptTimeoutError(resolvedTimeoutMs);
435
- const timeout = new Promise<never>((_resolve, reject) => {
436
- timer = setTimeout(() => {
437
- callsSnapshot = snapshotCalls();
438
- timeoutController.abort(timeoutError);
439
- void activeWorker.terminate();
440
- reject(timeoutError);
441
- }, resolvedTimeoutMs);
442
- });
443
- const aborted = externalSignal
444
- ? new Promise<never>((_resolve, reject) => {
445
- const onAbort = () => {
446
- callsSnapshot = snapshotCalls();
447
- void activeWorker.terminate();
448
- reject(abortReasonError(externalSignal.reason));
449
- };
450
- externalSignal.addEventListener("abort", onAbort, { once: true });
451
- removeAbortListener = () => externalSignal.removeEventListener("abort", onAbort);
452
- })
453
- : new Promise<never>(() => {});
454
-
455
- await Promise.race([execution, timeout, aborted]);
456
- } catch (error) {
457
- if (error instanceof McpScriptTimeoutError) {
458
- errorCode = "timeout";
459
- errorMessage = `mcpScript timed out after ${resolvedTimeoutMs}ms`;
460
- } else if (externalSignal?.aborted) {
461
- errorCode = "aborted";
462
- errorMessage = error instanceof Error ? error.message : String(error);
463
- } else {
464
- errorCode = "script_error";
465
- errorMessage = error instanceof Error ? error.message : String(error);
466
- }
467
- output.push({ type: "text", text: errorMessage });
468
- } finally {
469
- clearTimeout(timer);
470
- removeAbortListener();
471
- // "incomplete" means the call had not settled when the script finished
472
- // (deadline, abort, or early return). Snapshot before aborting stragglers.
473
- callsSnapshot ??= snapshotCalls();
474
- // A script may finish without awaiting every call; abort leftovers so
475
- // parent-side dispatches do not outlive the script.
476
- timeoutController.abort(new Error("mcpScript finished"));
477
- await worker?.terminate();
478
- }
479
-
480
- // Snapshot before the asynchronous output guard; the terminated worker can no longer emit.
481
- const guarded = await guardMcpOutput(
482
- output.length > 0 ? [...output] : [{ type: "text", text: "(no output)" }],
483
- resolveMcpOutputGuardOptions(state.config.settings),
484
- );
485
- return {
486
- content: guarded.content,
487
- details: {
488
- mode: "script",
489
- ...(errorCode ? { error: errorCode, message: errorMessage } : {}),
490
- timeoutMs: resolvedTimeoutMs,
491
- ...(callsSnapshot.length > 0 ? { calls: callsSnapshot } : {}),
492
- ...guardedMcpDetails(guarded),
493
- },
494
- };
495
- }
@@ -1,60 +0,0 @@
1
- const SERVER_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
2
-
3
- export interface McpInstallRequest {
4
- url: string;
5
- serverName?: string;
6
- }
7
-
8
- export interface NormalizedMcpInstallRequest {
9
- url: string;
10
- serverName: string;
11
- }
12
-
13
- function isLoopbackHostname(hostname: string): boolean {
14
- return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
15
- }
16
-
17
- function deriveServerName(url: URL): string {
18
- const hostname = url.hostname.replace(/^\[|\]$/g, "");
19
- const firstLabel = isLoopbackHostname(url.hostname) ? "local-mcp" : hostname.split(".")[0];
20
- const normalized = (firstLabel || "mcp")
21
- .toLowerCase()
22
- .replace(/[^a-z0-9_-]+/g, "-")
23
- .replace(/^-+|-+$/g, "")
24
- .slice(0, 64);
25
- return normalized || "mcp";
26
- }
27
-
28
- export function normalizeMcpInstallRequest(request: McpInstallRequest): NormalizedMcpInstallRequest {
29
- if (typeof request.url !== "string" || request.url.trim() === "") {
30
- throw new Error("MCP install requires a non-empty URL");
31
- }
32
-
33
- let parsed: URL;
34
- try {
35
- parsed = new URL(request.url.trim());
36
- } catch (error) {
37
- throw new Error("MCP install URL must be an absolute URL", { cause: error });
38
- }
39
-
40
- if (parsed.username || parsed.password) throw new Error("MCP install URL must not contain credentials");
41
- if (parsed.hash) throw new Error("MCP install URL must not contain a fragment");
42
- if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && isLoopbackHostname(parsed.hostname))) {
43
- throw new Error("MCP install URL must use HTTPS, except for loopback HTTP servers");
44
- }
45
-
46
- const serverName = request.serverName?.trim() || deriveServerName(parsed);
47
- if (!SERVER_NAME_PATTERN.test(serverName)) {
48
- throw new Error("MCP server name must be 1-64 letters, numbers, underscores, or hyphens and start with a letter or number");
49
- }
50
-
51
- return { url: parsed.toString(), serverName };
52
- }
53
-
54
- export function canonicalMcpServerUrl(value: string): string | undefined {
55
- try {
56
- return new URL(value).toString();
57
- } catch {
58
- return undefined;
59
- }
60
- }
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const { createRequire } = require('node:module');
5
- const { dirname, join } = require('node:path');
6
-
7
- const requireFromHere = createRequire(__filename);
8
-
9
- function loadKeyringEntryClass() {
10
- try {
11
- return requireFromHere('@napi-rs/keyring').Entry;
12
- } catch (loaderError) {
13
- const suffixes = getNativeBindingSuffixes(process.platform, process.arch);
14
- let lastError;
15
- for (const suffix of suffixes) {
16
- try {
17
- const packageJsonPath = requireFromHere.resolve(`@napi-rs/keyring-${suffix}/package.json`);
18
- return requireFromHere(join(dirname(packageJsonPath), `keyring.${suffix}.node`)).Entry;
19
- } catch (error) {
20
- lastError = error;
21
- }
22
- }
23
- const error = new Error(`Failed to load @napi-rs/keyring in recovery helper: ${lastError?.message ?? loaderError.message}`);
24
- error.cause = loaderError;
25
- throw error;
26
- }
27
- }
28
-
29
- function getNativeBindingSuffixes(platform, arch) {
30
- if (platform === 'linux') {
31
- if (arch === 'arm64') return ['linux-arm64-gnu', 'linux-arm64-musl'];
32
- if (arch === 'arm') return ['linux-arm-gnueabihf'];
33
- if (arch === 'riscv64') return ['linux-riscv64-gnu'];
34
- if (arch === 'x64') return ['linux-x64-gnu', 'linux-x64-musl'];
35
- }
36
- return [];
37
- }
38
-
39
- function readStdin() {
40
- return new Promise((resolve, reject) => {
41
- let input = '';
42
- process.stdin.setEncoding('utf8');
43
- process.stdin.on('data', chunk => {
44
- input += chunk;
45
- if (input.length > 1024 * 1024) {
46
- reject(new Error('request too large'));
47
- process.stdin.destroy();
48
- }
49
- });
50
- process.stdin.on('error', reject);
51
- process.stdin.on('end', () => resolve(input));
52
- });
53
- }
54
-
55
- function writeResponse(response) {
56
- process.stdout.write(`${JSON.stringify(response)}\n`);
57
- }
58
-
59
- (async () => {
60
- try {
61
- const request = JSON.parse(await readStdin());
62
- if (!request || typeof request !== 'object') throw new Error('invalid request');
63
- const { operation, service, account, payload } = request;
64
- if (!['read', 'write', 'remove'].includes(operation)) throw new Error('invalid operation');
65
- if (typeof service !== 'string' || !service) throw new Error('invalid service');
66
- if (typeof account !== 'string' || !account) throw new Error('invalid account');
67
-
68
- const Entry = loadKeyringEntryClass();
69
- const entry = new Entry(service, account);
70
-
71
- if (operation === 'read') {
72
- const value = entry.getPassword();
73
- writeResponse(value === null ? { ok: true, found: false } : { ok: true, found: true, value });
74
- return;
75
- }
76
- if (operation === 'write') {
77
- if (typeof payload !== 'string') throw new Error('invalid payload');
78
- entry.setPassword(payload);
79
- writeResponse({ ok: true });
80
- return;
81
- }
82
-
83
- entry.deleteCredential();
84
- writeResponse({ ok: true });
85
- } catch (error) {
86
- writeResponse({ ok: false, error: error instanceof Error ? error.message : String(error) });
87
- process.exitCode = 1;
88
- }
89
- })();