skybridge 0.0.0-dev.c14a1d3 → 0.0.0-dev.c17120e

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 (395) hide show
  1. package/README.md +17 -14
  2. package/dist/cli/build-helpers.d.ts +6 -2
  3. package/dist/cli/build-helpers.js +39 -14
  4. package/dist/cli/build-helpers.js.map +1 -1
  5. package/dist/cli/build-helpers.test.js +73 -5
  6. package/dist/cli/build-helpers.test.js.map +1 -1
  7. package/dist/cli/build-steps.d.ts +2 -0
  8. package/dist/cli/build-steps.js +73 -0
  9. package/dist/cli/build-steps.js.map +1 -0
  10. package/dist/cli/build-steps.test.js +52 -0
  11. package/dist/cli/build-steps.test.js.map +1 -0
  12. package/dist/cli/detect-port.js +0 -1
  13. package/dist/cli/detect-port.js.map +1 -1
  14. package/dist/cli/header.d.ts +1 -1
  15. package/dist/cli/resolve-skybridge-config.d.ts +5 -0
  16. package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
  17. package/dist/cli/resolve-skybridge-config.js.map +1 -0
  18. package/dist/cli/run-plain.d.ts +18 -0
  19. package/dist/cli/run-plain.js +90 -0
  20. package/dist/cli/run-plain.js.map +1 -0
  21. package/dist/cli/telemetry.js +2 -0
  22. package/dist/cli/telemetry.js.map +1 -1
  23. package/dist/cli/use-execute-steps.d.ts +1 -1
  24. package/dist/cli/use-nodemon.d.ts +25 -1
  25. package/dist/cli/use-nodemon.js +96 -63
  26. package/dist/cli/use-nodemon.js.map +1 -1
  27. package/dist/cli/use-typescript-check.d.ts +8 -2
  28. package/dist/cli/use-typescript-check.js +70 -67
  29. package/dist/cli/use-typescript-check.js.map +1 -1
  30. package/dist/commands/build.d.ts +0 -2
  31. package/dist/commands/build.js +2 -61
  32. package/dist/commands/build.js.map +1 -1
  33. package/dist/commands/dev.d.ts +1 -0
  34. package/dist/commands/dev.js +38 -6
  35. package/dist/commands/dev.js.map +1 -1
  36. package/dist/commands/start.js +2 -2
  37. package/dist/commands/start.js.map +1 -1
  38. package/dist/context-warnings.d.ts +5 -0
  39. package/dist/context-warnings.js +31 -0
  40. package/dist/context-warnings.js.map +1 -0
  41. package/dist/context-warnings.test.js +28 -0
  42. package/dist/context-warnings.test.js.map +1 -0
  43. package/dist/server/app.d.ts +196 -0
  44. package/dist/server/app.js +279 -0
  45. package/dist/server/app.js.map +1 -0
  46. package/dist/server/app.test.js +231 -0
  47. package/dist/server/app.test.js.map +1 -0
  48. package/dist/server/auth/discovery.d.ts +29 -7
  49. package/dist/server/auth/discovery.js +16 -11
  50. package/dist/server/auth/discovery.js.map +1 -1
  51. package/dist/server/auth/index.d.ts +35 -5
  52. package/dist/server/auth/index.js.map +1 -1
  53. package/dist/server/auth/providers/auth0.d.ts +35 -7
  54. package/dist/server/auth/providers/auth0.js +29 -11
  55. package/dist/server/auth/providers/auth0.js.map +1 -1
  56. package/dist/server/auth/providers/auth0.test.js +31 -14
  57. package/dist/server/auth/providers/auth0.test.js.map +1 -1
  58. package/dist/server/auth/providers/authplane.d.ts +49 -0
  59. package/dist/server/auth/providers/authplane.js +57 -0
  60. package/dist/server/auth/providers/authplane.js.map +1 -0
  61. package/dist/server/auth/providers/authplane.test.js +143 -0
  62. package/dist/server/auth/providers/authplane.test.js.map +1 -0
  63. package/dist/server/auth/providers/clerk.d.ts +44 -5
  64. package/dist/server/auth/providers/clerk.js +9 -8
  65. package/dist/server/auth/providers/clerk.js.map +1 -1
  66. package/dist/server/auth/providers/clerk.test.js +7 -26
  67. package/dist/server/auth/providers/clerk.test.js.map +1 -1
  68. package/dist/server/auth/providers/custom.d.ts +33 -5
  69. package/dist/server/auth/providers/custom.js +46 -15
  70. package/dist/server/auth/providers/custom.js.map +1 -1
  71. package/dist/server/auth/providers/custom.test.js +86 -16
  72. package/dist/server/auth/providers/custom.test.js.map +1 -1
  73. package/dist/server/auth/providers/descope.d.ts +41 -10
  74. package/dist/server/auth/providers/descope.js +38 -8
  75. package/dist/server/auth/providers/descope.js.map +1 -1
  76. package/dist/server/auth/providers/descope.test.js +43 -16
  77. package/dist/server/auth/providers/descope.test.js.map +1 -1
  78. package/dist/server/auth/providers/shared.d.ts +2 -0
  79. package/dist/server/auth/providers/shared.js +6 -0
  80. package/dist/server/auth/providers/shared.js.map +1 -0
  81. package/dist/server/auth/providers/shared.test.js +10 -0
  82. package/dist/server/auth/providers/shared.test.js.map +1 -0
  83. package/dist/server/auth/providers/stytch.d.ts +17 -3
  84. package/dist/server/auth/providers/stytch.js +5 -6
  85. package/dist/server/auth/providers/stytch.js.map +1 -1
  86. package/dist/server/auth/providers/verify-spy.d.ts +12 -0
  87. package/dist/server/auth/providers/verify-spy.js +21 -0
  88. package/dist/server/auth/providers/verify-spy.js.map +1 -0
  89. package/dist/server/auth/providers/workos.d.ts +28 -4
  90. package/dist/server/auth/providers/workos.js +7 -7
  91. package/dist/server/auth/providers/workos.js.map +1 -1
  92. package/dist/server/auth/security-schemes.d.ts +23 -0
  93. package/dist/server/auth/security-schemes.js +64 -0
  94. package/dist/server/auth/security-schemes.js.map +1 -0
  95. package/dist/server/auth/security-schemes.test.js +99 -0
  96. package/dist/server/auth/security-schemes.test.js.map +1 -0
  97. package/dist/server/auth/setup.d.ts +3 -1
  98. package/dist/server/auth/setup.js +66 -26
  99. package/dist/server/auth/setup.js.map +1 -1
  100. package/dist/server/auth/setup.test.js +349 -20
  101. package/dist/server/auth/setup.test.js.map +1 -1
  102. package/dist/server/auth/verify.d.ts +42 -5
  103. package/dist/server/auth/verify.js +29 -4
  104. package/dist/server/auth/verify.js.map +1 -1
  105. package/dist/server/auth/verify.test.js +78 -0
  106. package/dist/server/auth/verify.test.js.map +1 -1
  107. package/dist/server/auth-extra.test-d.js +130 -0
  108. package/dist/server/auth-extra.test-d.js.map +1 -0
  109. package/dist/server/auth.d.ts +43 -6
  110. package/dist/server/auth.js +4 -5
  111. package/dist/server/auth.js.map +1 -1
  112. package/dist/server/build-manifest.test.js +7 -6
  113. package/dist/server/build-manifest.test.js.map +1 -1
  114. package/dist/server/content-helpers.d.ts +1 -1
  115. package/dist/server/content-helpers.js.map +1 -1
  116. package/dist/server/events.d.ts +113 -0
  117. package/dist/server/events.js +318 -0
  118. package/dist/server/events.js.map +1 -0
  119. package/dist/server/events.test.d.ts +1 -0
  120. package/dist/server/events.test.js +172 -0
  121. package/dist/server/events.test.js.map +1 -0
  122. package/dist/server/express.d.ts +23 -3
  123. package/dist/server/express.js +43 -32
  124. package/dist/server/express.js.map +1 -1
  125. package/dist/server/express.test.js +221 -103
  126. package/dist/server/express.test.js.map +1 -1
  127. package/dist/server/file-ref.d.ts +1 -1
  128. package/dist/server/file-ref.js +1 -1
  129. package/dist/server/file-ref.js.map +1 -1
  130. package/dist/server/form-input.d.ts +120 -0
  131. package/dist/server/form-input.js +89 -0
  132. package/dist/server/form-input.js.map +1 -0
  133. package/dist/server/host.d.ts +2 -0
  134. package/dist/server/host.js +11 -0
  135. package/dist/server/host.js.map +1 -0
  136. package/dist/server/host.test.d.ts +1 -0
  137. package/dist/server/host.test.js +13 -0
  138. package/dist/server/host.test.js.map +1 -0
  139. package/dist/server/index.d.ts +18 -9
  140. package/dist/server/index.js +11 -3
  141. package/dist/server/index.js.map +1 -1
  142. package/dist/server/mcp-errors.test.d.ts +1 -0
  143. package/dist/server/mcp-errors.test.js +41 -0
  144. package/dist/server/mcp-errors.test.js.map +1 -0
  145. package/dist/server/middleware.d.ts +35 -10
  146. package/dist/server/middleware.js +33 -0
  147. package/dist/server/middleware.js.map +1 -1
  148. package/dist/server/middleware.test-d.js +1 -1
  149. package/dist/server/middleware.test-d.js.map +1 -1
  150. package/dist/server/middleware.test.js +242 -134
  151. package/dist/server/middleware.test.js.map +1 -1
  152. package/dist/server/register-tool.test.d.ts +1 -0
  153. package/dist/server/register-tool.test.js +230 -0
  154. package/dist/server/register-tool.test.js.map +1 -0
  155. package/dist/server/server.d.ts +385 -124
  156. package/dist/server/server.js +506 -348
  157. package/dist/server/server.js.map +1 -1
  158. package/dist/server/skills-integration.test.d.ts +1 -0
  159. package/dist/server/skills-integration.test.js +86 -0
  160. package/dist/server/skills-integration.test.js.map +1 -0
  161. package/dist/server/skills.d.ts +27 -0
  162. package/dist/server/skills.js +188 -0
  163. package/dist/server/skills.js.map +1 -0
  164. package/dist/server/skills.test.d.ts +1 -0
  165. package/dist/server/skills.test.js +243 -0
  166. package/dist/server/skills.test.js.map +1 -0
  167. package/dist/server/templateHelper.d.ts +0 -3
  168. package/dist/server/templateHelper.js.map +1 -1
  169. package/dist/server/templates.generated.js +4 -8
  170. package/dist/server/templates.generated.js.map +1 -1
  171. package/dist/server/tool-extra.test.d.ts +1 -0
  172. package/dist/server/tool-extra.test.js +167 -0
  173. package/dist/server/tool-extra.test.js.map +1 -0
  174. package/dist/server/view-name.test-d.d.ts +1 -0
  175. package/dist/server/view-name.test-d.js +8 -0
  176. package/dist/server/view-name.test-d.js.map +1 -0
  177. package/dist/server/view-resource-resolution.test.js +105 -17
  178. package/dist/server/view-resource-resolution.test.js.map +1 -1
  179. package/dist/server/viewsDevServer.js +4 -1
  180. package/dist/server/viewsDevServer.js.map +1 -1
  181. package/dist/test/utils.d.ts +9 -11
  182. package/dist/test/utils.js +220 -201
  183. package/dist/test/utils.js.map +1 -1
  184. package/dist/test/view.test.js +105 -133
  185. package/dist/test/view.test.js.map +1 -1
  186. package/dist/views/index.d.ts +10 -0
  187. package/dist/views/index.js +3 -0
  188. package/dist/views/index.js.map +1 -0
  189. package/dist/{web/plugin → views}/scan-views.js +1 -1
  190. package/dist/views/scan-views.js.map +1 -0
  191. package/dist/views/scan-views.test.d.ts +1 -0
  192. package/dist/views/scan-views.test.js.map +1 -0
  193. package/dist/views/validate-view.d.ts +1 -0
  194. package/dist/{web/plugin → views}/validate-view.js +2 -2
  195. package/dist/views/validate-view.js.map +1 -0
  196. package/dist/views/validate-view.test.d.ts +1 -0
  197. package/dist/views/validate-view.test.js.map +1 -0
  198. package/dist/web/bridges/adaptor.d.ts +62 -0
  199. package/dist/web/bridges/adaptor.js +477 -0
  200. package/dist/web/bridges/adaptor.js.map +1 -0
  201. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  202. package/dist/web/bridges/adaptor.test.js +281 -0
  203. package/dist/web/bridges/adaptor.test.js.map +1 -0
  204. package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
  205. package/dist/web/bridges/apps-sdk/bridge.js +15 -4
  206. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  207. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  208. package/dist/web/bridges/apps-sdk/index.js +0 -1
  209. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  210. package/dist/web/bridges/apps-sdk/types.d.ts +2 -3
  211. package/dist/web/bridges/apps-sdk/types.js.map +1 -1
  212. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +4 -4
  213. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +4 -4
  214. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  215. package/dist/web/bridges/get-adaptor.d.ts +4 -4
  216. package/dist/web/bridges/get-adaptor.js +6 -11
  217. package/dist/web/bridges/get-adaptor.js.map +1 -1
  218. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  219. package/dist/web/bridges/get-adaptor.test.js +32 -0
  220. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  221. package/dist/web/bridges/mcp-app/bridge.d.ts +14 -3
  222. package/dist/web/bridges/mcp-app/bridge.js +60 -9
  223. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  224. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  225. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  226. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  227. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  228. package/dist/web/bridges/mcp-app/index.js +0 -1
  229. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  230. package/dist/web/bridges/mcp-app/types.d.ts +19 -2
  231. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  232. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +2 -2
  233. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
  234. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  235. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
  236. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  237. package/dist/web/bridges/mcp-app/view-tools.test.js +6 -7
  238. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
  239. package/dist/web/bridges/types.d.ts +83 -15
  240. package/dist/web/bridges/types.js +14 -1
  241. package/dist/web/bridges/types.js.map +1 -1
  242. package/dist/web/bridges/types.test.d.ts +1 -0
  243. package/dist/web/bridges/types.test.js +19 -0
  244. package/dist/web/bridges/types.test.js.map +1 -0
  245. package/dist/web/components/modal-provider.d.ts +1 -1
  246. package/dist/web/components/modal-provider.js +4 -3
  247. package/dist/web/components/modal-provider.js.map +1 -1
  248. package/dist/web/create-store.test.js +10 -7
  249. package/dist/web/create-store.test.js.map +1 -1
  250. package/dist/web/data-llm.d.ts +1 -1
  251. package/dist/web/data-llm.js +3 -2
  252. package/dist/web/data-llm.js.map +1 -1
  253. package/dist/web/data-llm.test.js +26 -7
  254. package/dist/web/data-llm.test.js.map +1 -1
  255. package/dist/web/generate-helpers.d.ts +23 -19
  256. package/dist/web/generate-helpers.js +21 -17
  257. package/dist/web/generate-helpers.js.map +1 -1
  258. package/dist/web/generate-helpers.test-d.js +3 -3
  259. package/dist/web/generate-helpers.test-d.js.map +1 -1
  260. package/dist/web/generate-helpers.test.js +2 -2
  261. package/dist/web/generate-helpers.test.js.map +1 -1
  262. package/dist/web/hooks/index.d.ts +6 -1
  263. package/dist/web/hooks/index.js +6 -1
  264. package/dist/web/hooks/index.js.map +1 -1
  265. package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
  266. package/dist/web/hooks/openai-extensions.test.js +107 -0
  267. package/dist/web/hooks/openai-extensions.test.js.map +1 -0
  268. package/dist/web/hooks/test/utils.d.ts +2 -1
  269. package/dist/web/hooks/test/utils.js +1 -1
  270. package/dist/web/hooks/test/utils.js.map +1 -1
  271. package/dist/web/hooks/use-call-tool.d.ts +2 -2
  272. package/dist/web/hooks/use-call-tool.js +15 -10
  273. package/dist/web/hooks/use-call-tool.js.map +1 -1
  274. package/dist/web/hooks/use-call-tool.test.js +50 -25
  275. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  276. package/dist/web/hooks/use-deep-link.d.ts +22 -0
  277. package/dist/web/hooks/use-deep-link.js +34 -0
  278. package/dist/web/hooks/use-deep-link.js.map +1 -0
  279. package/dist/web/hooks/use-display-mode.d.ts +1 -1
  280. package/dist/web/hooks/use-display-mode.js +1 -1
  281. package/dist/web/hooks/use-display-mode.js.map +1 -1
  282. package/dist/web/hooks/use-display-mode.test.js +57 -21
  283. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  284. package/dist/web/hooks/use-download.d.ts +1 -3
  285. package/dist/web/hooks/use-download.js +1 -2
  286. package/dist/web/hooks/use-download.js.map +1 -1
  287. package/dist/web/hooks/use-download.test.js +18 -10
  288. package/dist/web/hooks/use-download.test.js.map +1 -1
  289. package/dist/web/hooks/use-file-resource.d.ts +37 -0
  290. package/dist/web/hooks/use-file-resource.js +98 -0
  291. package/dist/web/hooks/use-file-resource.js.map +1 -0
  292. package/dist/web/hooks/use-file-resource.test.d.ts +1 -0
  293. package/dist/web/hooks/use-file-resource.test.js +65 -0
  294. package/dist/web/hooks/use-file-resource.test.js.map +1 -0
  295. package/dist/web/hooks/use-files.test.js +11 -3
  296. package/dist/web/hooks/use-files.test.js.map +1 -1
  297. package/dist/web/hooks/use-host.d.ts +44 -0
  298. package/dist/web/hooks/use-host.js +45 -0
  299. package/dist/web/hooks/use-host.js.map +1 -0
  300. package/dist/web/hooks/use-host.test.d.ts +1 -0
  301. package/dist/web/hooks/use-host.test.js +59 -0
  302. package/dist/web/hooks/use-host.test.js.map +1 -0
  303. package/dist/web/hooks/use-model-context.d.ts +44 -0
  304. package/dist/web/hooks/use-model-context.js +63 -0
  305. package/dist/web/hooks/use-model-context.js.map +1 -0
  306. package/dist/web/hooks/use-open-external.test.js +15 -5
  307. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  308. package/dist/web/hooks/use-open-file.d.ts +20 -0
  309. package/dist/web/hooks/use-open-file.js +25 -0
  310. package/dist/web/hooks/use-open-file.js.map +1 -0
  311. package/dist/web/hooks/use-register-view-tool.d.ts +3 -4
  312. package/dist/web/hooks/use-register-view-tool.js +1 -1
  313. package/dist/web/hooks/use-register-view-tool.js.map +1 -1
  314. package/dist/web/hooks/use-request-close.test.js +35 -40
  315. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  316. package/dist/web/hooks/use-request-modal.test.js +11 -1
  317. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  318. package/dist/web/hooks/use-request-size.d.ts +1 -1
  319. package/dist/web/hooks/use-request-size.js +1 -1
  320. package/dist/web/hooks/use-request-size.js.map +1 -1
  321. package/dist/web/hooks/use-request-size.test.js +35 -53
  322. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  323. package/dist/web/hooks/use-send-follow-up-message.d.ts +8 -2
  324. package/dist/web/hooks/use-send-follow-up-message.js +6 -0
  325. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  326. package/dist/web/hooks/use-set-open-in-app-url.test.js +26 -12
  327. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  328. package/dist/web/hooks/use-tool-info.d.ts +1 -20
  329. package/dist/web/hooks/use-tool-info.js +0 -1
  330. package/dist/web/hooks/use-tool-info.js.map +1 -1
  331. package/dist/web/hooks/use-tool-info.test-d.js +0 -5
  332. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  333. package/dist/web/hooks/use-tool-info.test.js +38 -33
  334. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  335. package/dist/web/hooks/use-user.d.ts +3 -2
  336. package/dist/web/hooks/use-user.js +4 -3
  337. package/dist/web/hooks/use-user.js.map +1 -1
  338. package/dist/web/hooks/use-user.test.js +85 -37
  339. package/dist/web/hooks/use-user.test.js.map +1 -1
  340. package/dist/web/hooks/use-view-state.js +19 -9
  341. package/dist/web/hooks/use-view-state.js.map +1 -1
  342. package/dist/web/hooks/use-view-state.test.js +39 -4
  343. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  344. package/dist/web/hooks/use-viewport.d.ts +20 -0
  345. package/dist/web/hooks/use-viewport.js +21 -0
  346. package/dist/web/hooks/use-viewport.js.map +1 -0
  347. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  348. package/dist/web/hooks/use-viewport.test.js +109 -0
  349. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  350. package/dist/web/mount-view.d.ts +3 -2
  351. package/dist/web/mount-view.js +5 -8
  352. package/dist/web/mount-view.js.map +1 -1
  353. package/package.json +34 -29
  354. package/dist/cli/resolve-views-dir.d.ts +0 -1
  355. package/dist/cli/resolve-views-dir.js.map +0 -1
  356. package/dist/server/auth/providers/stytch.test.js +0 -33
  357. package/dist/server/auth/providers/stytch.test.js.map +0 -1
  358. package/dist/server/auth/providers/workos.test.js +0 -41
  359. package/dist/server/auth/providers/workos.test.js.map +0 -1
  360. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -29
  361. package/dist/web/bridges/apps-sdk/adaptor.js +0 -117
  362. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  363. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -53
  364. package/dist/web/bridges/mcp-app/adaptor.js +0 -283
  365. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
  366. package/dist/web/hooks/use-layout.d.ts +0 -24
  367. package/dist/web/hooks/use-layout.js +0 -25
  368. package/dist/web/hooks/use-layout.js.map +0 -1
  369. package/dist/web/hooks/use-layout.test.js +0 -96
  370. package/dist/web/hooks/use-layout.test.js.map +0 -1
  371. package/dist/web/plugin/data-llm.test.js +0 -81
  372. package/dist/web/plugin/data-llm.test.js.map +0 -1
  373. package/dist/web/plugin/plugin.d.ts +0 -33
  374. package/dist/web/plugin/plugin.js +0 -189
  375. package/dist/web/plugin/plugin.js.map +0 -1
  376. package/dist/web/plugin/scan-views.js.map +0 -1
  377. package/dist/web/plugin/scan-views.test.js.map +0 -1
  378. package/dist/web/plugin/transform-data-llm.d.ts +0 -12
  379. package/dist/web/plugin/transform-data-llm.js +0 -96
  380. package/dist/web/plugin/transform-data-llm.js.map +0 -1
  381. package/dist/web/plugin/transform-data-llm.test.js +0 -81
  382. package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
  383. package/dist/web/plugin/validate-view.d.ts +0 -1
  384. package/dist/web/plugin/validate-view.js.map +0 -1
  385. package/dist/web/plugin/validate-view.test.js.map +0 -1
  386. /package/dist/{server/auth/providers/stytch.test.d.ts → cli/build-steps.test.d.ts} +0 -0
  387. /package/dist/{server/auth/providers/workos.test.d.ts → context-warnings.test.d.ts} +0 -0
  388. /package/dist/{web/hooks/use-layout.test.d.ts → server/app.test.d.ts} +0 -0
  389. /package/dist/{web/plugin/scan-views.test.d.ts → server/auth/providers/authplane.test.d.ts} +0 -0
  390. /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/auth/providers/shared.test.d.ts} +0 -0
  391. /package/dist/{web/plugin/validate-view.test.d.ts → server/auth/security-schemes.test.d.ts} +0 -0
  392. /package/dist/{web/plugin/data-llm.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
  393. /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
  394. /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
  395. /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
@@ -0,0 +1,231 @@
1
+ import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
2
+ import { describe, expect, expectTypeOf, it } from "vitest";
3
+ import { z } from "zod";
4
+ import { Skybridge } from "./app.js";
5
+ const oauthConfig = {
6
+ oauthMetadata: {
7
+ issuer: "https://issuer.example.com",
8
+ authorization_endpoint: "https://issuer.example.com/authorize",
9
+ token_endpoint: "https://issuer.example.com/token",
10
+ response_types_supported: ["code"],
11
+ },
12
+ verifier: {
13
+ verifyAccessToken: async () => ({
14
+ token: "t",
15
+ clientId: "c",
16
+ scopes: [],
17
+ extra: {},
18
+ }),
19
+ },
20
+ };
21
+ describe("Skybridge setup and handler", () => {
22
+ it("derives an app with outer middleware without changing the original", async () => {
23
+ const events = [];
24
+ let configured = 0;
25
+ let loaded = 0;
26
+ const app = new Skybridge({
27
+ name: "instance-hook",
28
+ version: "1",
29
+ setup: () => {
30
+ loaded += 1;
31
+ return "ready";
32
+ },
33
+ handler: (server, config) => server
34
+ .registerTool({
35
+ name: "echo",
36
+ inputSchema: { message: z.string() },
37
+ description: config,
38
+ }, async ({ message }) => {
39
+ events.push("handler");
40
+ return { content: message };
41
+ })
42
+ .mcpMiddleware("tools/call", async (_request, _extra, next) => {
43
+ events.push("app:before");
44
+ const result = await next();
45
+ events.push("app:after");
46
+ return result;
47
+ }),
48
+ });
49
+ const derived = app.withHandler((server, options, originalHandler) => {
50
+ expectTypeOf(options).toEqualTypeOf();
51
+ configured += 1;
52
+ server.mcpMiddleware("tools/list", async (_request, _extra, next) => {
53
+ const result = await next();
54
+ return {
55
+ ...result,
56
+ tools: result.tools.map((tool) => ({
57
+ ...tool,
58
+ description: "configured",
59
+ })),
60
+ };
61
+ });
62
+ server.mcpMiddleware("tools/call", async (request, _extra, next) => {
63
+ events.push("hook:before");
64
+ request.params.arguments = { message: "configured" };
65
+ const result = await next();
66
+ events.push("hook:after");
67
+ return result;
68
+ });
69
+ return originalHandler(server, options);
70
+ });
71
+ expectTypeOf().toEqualTypeOf();
72
+ expectTypeOf().toEqualTypeOf();
73
+ const instances = await Promise.all([
74
+ derived.createServerInstance(),
75
+ derived.createServerInstance(),
76
+ app.createServerInstance(),
77
+ ]);
78
+ for (const [index, instance] of instances.entries()) {
79
+ const client = new Client({ name: "client", version: "1" });
80
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
81
+ await instance.connect(serverTransport);
82
+ await client.connect(clientTransport);
83
+ try {
84
+ const expected = index < 2 ? "configured" : "ready";
85
+ expect((await client.listTools()).tools[0]?.description).toBe(expected);
86
+ events.length = 0;
87
+ expect(await client.callTool({
88
+ name: "echo",
89
+ arguments: { message: "original" },
90
+ })).toMatchObject({
91
+ content: [
92
+ { type: "text", text: index < 2 ? "configured" : "original" },
93
+ ],
94
+ });
95
+ expect(events).toEqual(index < 2
96
+ ? [
97
+ "hook:before",
98
+ "app:before",
99
+ "handler",
100
+ "app:after",
101
+ "hook:after",
102
+ ]
103
+ : ["app:before", "handler", "app:after"]);
104
+ }
105
+ finally {
106
+ await client.close();
107
+ }
108
+ }
109
+ expect(configured).toBe(3);
110
+ expect(loaded).toBe(2);
111
+ });
112
+ it("propagates a failed handler wrapper without changing the original app", async () => {
113
+ const app = new Skybridge({
114
+ name: "instance-hook",
115
+ version: "1",
116
+ handler: (server) => server,
117
+ });
118
+ await expect(app
119
+ .withHandler(() => {
120
+ throw new Error("configure failed");
121
+ })
122
+ .createServerInstance()).rejects.toThrow("configure failed");
123
+ const instance = await app.createServerInstance();
124
+ await instance.close();
125
+ });
126
+ it("infers additional tools returned by a handler wrapper", async () => {
127
+ const app = new Skybridge({
128
+ name: "wrapped-tools",
129
+ version: "1",
130
+ setup: async () => ({ greeting: "hello" }),
131
+ handler: (server, { greeting }) => server.registerTool({ name: "greet", inputSchema: { name: z.string() } }, ({ name }) => ({ content: `${greeting} ${name}` })),
132
+ });
133
+ expectTypeOf().toEqualTypeOf();
134
+ const derived = app.withHandler((server, options, originalHandler) => {
135
+ expectTypeOf(options).toEqualTypeOf();
136
+ return originalHandler(server, options).registerTool({ name: "echo", inputSchema: { message: z.string() } }, ({ message }) => ({ content: message }));
137
+ });
138
+ expectTypeOf().toEqualTypeOf();
139
+ expectTypeOf().toEqualTypeOf();
140
+ const client = new Client({ name: "client", version: "1" });
141
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
142
+ await derived.connect(serverTransport);
143
+ await client.connect(clientTransport);
144
+ try {
145
+ expect(await client.callTool({ name: "greet", arguments: { name: "Ada" } })).toMatchObject({ content: [{ type: "text", text: "hello Ada" }] });
146
+ expect(await client.callTool({
147
+ name: "echo",
148
+ arguments: { message: "goodbye" },
149
+ })).toMatchObject({ content: [{ type: "text", text: "goodbye" }] });
150
+ }
151
+ finally {
152
+ await client.close();
153
+ }
154
+ });
155
+ it("resolves setup once and passes the context to the per-request handler", async () => {
156
+ let loads = 0;
157
+ const app = new Skybridge({
158
+ name: "test",
159
+ version: "1.0.0",
160
+ setup: async () => {
161
+ loads++;
162
+ return { greeting: await Promise.resolve("hello") };
163
+ },
164
+ handler: (server, { greeting }) => server.registerTool({ name: "greet", description: "greet" }, async () => ({ content: [{ type: "text", text: greeting }] })),
165
+ });
166
+ expect(loads).toBe(0);
167
+ const call = async () => {
168
+ const client = new Client({ name: "client", version: "1.0.0" });
169
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
170
+ await app.connect(serverTransport);
171
+ await client.connect(clientTransport);
172
+ const result = await client.callTool({ name: "greet" });
173
+ await client.close();
174
+ return result;
175
+ };
176
+ expect(await call()).toMatchObject({
177
+ content: [{ type: "text", text: "hello" }],
178
+ });
179
+ expect(await call()).toMatchObject({
180
+ content: [{ type: "text", text: "hello" }],
181
+ });
182
+ expect(loads).toBe(1);
183
+ });
184
+ it("retries setup after a failed first resolution", async () => {
185
+ let attempts = 0;
186
+ const app = new Skybridge({
187
+ name: "test",
188
+ version: "1.0.0",
189
+ setup: async () => {
190
+ attempts++;
191
+ if (attempts === 1) {
192
+ throw new Error("transient");
193
+ }
194
+ },
195
+ handler: (server) => server,
196
+ });
197
+ const [, first] = InMemoryTransport.createLinkedPair();
198
+ await expect(app.connect(first)).rejects.toThrow("transient");
199
+ const [, second] = InMemoryTransport.createLinkedPair();
200
+ await expect(app.connect(second)).resolves.toBeUndefined();
201
+ expect(attempts).toBe(2);
202
+ });
203
+ it("rejects a handler that returns a promise", async () => {
204
+ const app = new Skybridge({
205
+ name: "test",
206
+ version: "1.0.0",
207
+ // @ts-expect-error the handler runs per request and must stay synchronous
208
+ handler: async (server) => server,
209
+ });
210
+ const [, serverTransport] = InMemoryTransport.createLinkedPair();
211
+ await expect(app.connect(serverTransport)).rejects.toThrow(/must be synchronous/);
212
+ });
213
+ it("resolves an oauth function with the setup config before wiring the routes", async () => {
214
+ let seen;
215
+ const app = new Skybridge({
216
+ name: "test",
217
+ version: "1.0.0",
218
+ setup: () => ({ issuer: "https://issuer.example.com" }),
219
+ oauth: (config) => {
220
+ seen = config;
221
+ return oauthConfig;
222
+ },
223
+ handler: (server) => server,
224
+ });
225
+ expect(seen).toBeUndefined();
226
+ const [, serverTransport] = InMemoryTransport.createLinkedPair();
227
+ await app.connect(serverTransport);
228
+ expect(seen).toEqual({ issuer: "https://issuer.example.com" });
229
+ });
230
+ });
231
+ //# sourceMappingURL=app.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.test.js","sourceRoot":"","sources":["../../src/server/app.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,MAAM,WAAW,GAAG;IAClB,aAAa,EAAE;QACb,MAAM,EAAE,4BAA4B;QACpC,sBAAsB,EAAE,sCAAsC;QAC9D,cAAc,EAAE,kCAAkC;QAClD,wBAAwB,EAAE,CAAC,MAAM,CAAC;KACnC;IACD,QAAQ,EAAE;QACR,iBAAiB,EAAE,KAAK,IAAI,EAAE,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,EAAE;gBAChB,IAAI,GAAG,MAAM,CAAC;gBACd,OAAO,WAAW,CAAC;YACrB,CAAC;YACD,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;SAC5B,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;QAC7B,MAAM,CAAC,EAAE,eAAe,CAAC,GAAG,iBAAiB,CAAC,gBAAgB,EAAE,CAAC;QACjE,MAAM,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACnC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,4BAA4B,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { Client, InMemoryTransport } from \"@modelcontextprotocol/client\";\nimport { describe, expect, expectTypeOf, it } from \"vitest\";\nimport { z } from \"zod\";\nimport { Skybridge } from \"./app.js\";\nimport type { ToolInput, ToolNames } from \"./inferUtilityTypes.js\";\n\nconst oauthConfig = {\n oauthMetadata: {\n issuer: \"https://issuer.example.com\",\n authorization_endpoint: \"https://issuer.example.com/authorize\",\n token_endpoint: \"https://issuer.example.com/token\",\n response_types_supported: [\"code\"],\n },\n verifier: {\n verifyAccessToken: async () => ({\n token: \"t\",\n clientId: \"c\",\n scopes: [],\n extra: {},\n }),\n },\n};\n\ndescribe(\"Skybridge setup and handler\", () => {\n it(\"derives an app with outer middleware without changing the original\", async () => {\n const events: string[] = [];\n let configured = 0;\n let loaded = 0;\n const app = new Skybridge({\n name: \"instance-hook\",\n version: \"1\",\n setup: () => {\n loaded += 1;\n return \"ready\";\n },\n handler: (server, config) =>\n server\n .registerTool(\n {\n name: \"echo\",\n inputSchema: { message: z.string() },\n description: config,\n },\n async ({ message }) => {\n events.push(\"handler\");\n return { content: message };\n },\n )\n .mcpMiddleware(\"tools/call\", async (_request, _extra, next) => {\n events.push(\"app:before\");\n const result = await next();\n events.push(\"app:after\");\n return result;\n }),\n });\n const derived = app.withHandler((server, options, originalHandler) => {\n expectTypeOf(options).toEqualTypeOf<string>();\n configured += 1;\n server.mcpMiddleware(\"tools/list\", async (_request, _extra, next) => {\n const result = await next();\n return {\n ...result,\n tools: result.tools.map((tool) => ({\n ...tool,\n description: \"configured\",\n })),\n };\n });\n server.mcpMiddleware(\"tools/call\", async (request, _extra, next) => {\n events.push(\"hook:before\");\n request.params.arguments = { message: \"configured\" };\n const result = await next();\n events.push(\"hook:after\");\n return result;\n });\n return originalHandler(server, options);\n });\n expectTypeOf<ToolNames<typeof derived>>().toEqualTypeOf<\"echo\">();\n expectTypeOf<ToolInput<typeof derived, \"echo\">>().toEqualTypeOf<{\n message: string;\n }>();\n const instances = await Promise.all([\n derived.createServerInstance(),\n derived.createServerInstance(),\n app.createServerInstance(),\n ]);\n for (const [index, instance] of instances.entries()) {\n const client = new Client({ name: \"client\", version: \"1\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await instance.connect(serverTransport);\n await client.connect(clientTransport);\n try {\n const expected = index < 2 ? \"configured\" : \"ready\";\n expect((await client.listTools()).tools[0]?.description).toBe(expected);\n events.length = 0;\n expect(\n await client.callTool({\n name: \"echo\",\n arguments: { message: \"original\" },\n }),\n ).toMatchObject({\n content: [\n { type: \"text\", text: index < 2 ? \"configured\" : \"original\" },\n ],\n });\n expect(events).toEqual(\n index < 2\n ? [\n \"hook:before\",\n \"app:before\",\n \"handler\",\n \"app:after\",\n \"hook:after\",\n ]\n : [\"app:before\", \"handler\", \"app:after\"],\n );\n } finally {\n await client.close();\n }\n }\n expect(configured).toBe(3);\n expect(loaded).toBe(2);\n });\n\n it(\"propagates a failed handler wrapper without changing the original app\", async () => {\n const app = new Skybridge({\n name: \"instance-hook\",\n version: \"1\",\n handler: (server) => server,\n });\n await expect(\n app\n .withHandler(() => {\n throw new Error(\"configure failed\");\n })\n .createServerInstance(),\n ).rejects.toThrow(\"configure failed\");\n const instance = await app.createServerInstance();\n await instance.close();\n });\n\n it(\"infers additional tools returned by a handler wrapper\", async () => {\n const app = new Skybridge({\n name: \"wrapped-tools\",\n version: \"1\",\n setup: async () => ({ greeting: \"hello\" }),\n handler: (server, { greeting }) =>\n server.registerTool(\n { name: \"greet\", inputSchema: { name: z.string() } },\n ({ name }) => ({ content: `${greeting} ${name}` }),\n ),\n });\n expectTypeOf<ToolNames<typeof app>>().toEqualTypeOf<\"greet\">();\n const derived = app.withHandler((server, options, originalHandler) => {\n expectTypeOf(options).toEqualTypeOf<{ greeting: string }>();\n return originalHandler(server, options).registerTool(\n { name: \"echo\", inputSchema: { message: z.string() } },\n ({ message }) => ({ content: message }),\n );\n });\n expectTypeOf<ToolNames<typeof derived>>().toEqualTypeOf<\"greet\" | \"echo\">();\n expectTypeOf<ToolInput<typeof derived, \"echo\">>().toEqualTypeOf<{\n message: string;\n }>();\n const client = new Client({ name: \"client\", version: \"1\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await derived.connect(serverTransport);\n await client.connect(clientTransport);\n try {\n expect(\n await client.callTool({ name: \"greet\", arguments: { name: \"Ada\" } }),\n ).toMatchObject({ content: [{ type: \"text\", text: \"hello Ada\" }] });\n expect(\n await client.callTool({\n name: \"echo\",\n arguments: { message: \"goodbye\" },\n }),\n ).toMatchObject({ content: [{ type: \"text\", text: \"goodbye\" }] });\n } finally {\n await client.close();\n }\n });\n\n it(\"resolves setup once and passes the context to the per-request handler\", async () => {\n let loads = 0;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n setup: async () => {\n loads++;\n return { greeting: await Promise.resolve(\"hello\") };\n },\n handler: (server, { greeting }) =>\n server.registerTool(\n { name: \"greet\", description: \"greet\" },\n async () => ({ content: [{ type: \"text\", text: greeting }] }),\n ),\n });\n\n expect(loads).toBe(0);\n\n const call = async () => {\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await app.connect(serverTransport);\n await client.connect(clientTransport);\n const result = await client.callTool({ name: \"greet\" });\n await client.close();\n return result;\n };\n\n expect(await call()).toMatchObject({\n content: [{ type: \"text\", text: \"hello\" }],\n });\n expect(await call()).toMatchObject({\n content: [{ type: \"text\", text: \"hello\" }],\n });\n expect(loads).toBe(1);\n });\n\n it(\"retries setup after a failed first resolution\", async () => {\n let attempts = 0;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n setup: async () => {\n attempts++;\n if (attempts === 1) {\n throw new Error(\"transient\");\n }\n },\n handler: (server) => server,\n });\n\n const [, first] = InMemoryTransport.createLinkedPair();\n await expect(app.connect(first)).rejects.toThrow(\"transient\");\n\n const [, second] = InMemoryTransport.createLinkedPair();\n await expect(app.connect(second)).resolves.toBeUndefined();\n expect(attempts).toBe(2);\n });\n\n it(\"rejects a handler that returns a promise\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n // @ts-expect-error the handler runs per request and must stay synchronous\n handler: async (server) => server,\n });\n const [, serverTransport] = InMemoryTransport.createLinkedPair();\n await expect(app.connect(serverTransport)).rejects.toThrow(\n /must be synchronous/,\n );\n });\n\n it(\"resolves an oauth function with the setup config before wiring the routes\", async () => {\n let seen: unknown;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n setup: () => ({ issuer: \"https://issuer.example.com\" }),\n oauth: (config) => {\n seen = config;\n return oauthConfig;\n },\n handler: (server) => server,\n });\n\n expect(seen).toBeUndefined();\n const [, serverTransport] = InMemoryTransport.createLinkedPair();\n await app.connect(serverTransport);\n expect(seen).toEqual({ issuer: \"https://issuer.example.com\" });\n });\n});\n"]}
@@ -1,11 +1,33 @@
1
- import { type OAuthMetadata } from "@modelcontextprotocol/sdk/shared/auth.js";
1
+ import { z } from "zod/v4";
2
2
  /**
3
- * Discovered AS metadata + `jwks_uri` — the SDK's `OAuthMetadata` omits it (its
4
- * OAuth client never verifies tokens), but we need it to verify token signatures
5
- * via JWKS, so we re-type the field for typed access.
3
+ * Discovery doc validated as OAuth AS metadata + `jwks_uri`. The SDK's
4
+ * `OAuthMetadataSchema` omits `jwks_uri` (its client never verifies tokens), but
5
+ * we need it for JWKS token verification, so we extend the schema to keep it.
6
6
  */
7
- export type DiscoveredMetadata = OAuthMetadata & {
8
- jwks_uri?: string;
9
- };
7
+ declare const DiscoverySchema: z.ZodObject<{
8
+ issuer: z.ZodString;
9
+ authorization_endpoint: z.ZodURL;
10
+ token_endpoint: z.ZodURL;
11
+ registration_endpoint: z.ZodOptional<z.ZodURL>;
12
+ scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
13
+ response_types_supported: z.ZodArray<z.ZodString>;
14
+ response_modes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
15
+ grant_types_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
16
+ token_endpoint_auth_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
17
+ token_endpoint_auth_signing_alg_values_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
18
+ service_documentation: z.ZodOptional<z.ZodURL>;
19
+ revocation_endpoint: z.ZodOptional<z.ZodURL>;
20
+ revocation_endpoint_auth_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
21
+ revocation_endpoint_auth_signing_alg_values_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
+ introspection_endpoint: z.ZodOptional<z.ZodString>;
23
+ introspection_endpoint_auth_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
24
+ introspection_endpoint_auth_signing_alg_values_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
25
+ code_challenge_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
26
+ client_id_metadata_document_supported: z.ZodOptional<z.ZodBoolean>;
27
+ authorization_response_iss_parameter_supported: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
28
+ jwks_uri: z.ZodOptional<z.ZodString>;
29
+ }, z.core.$loose>;
30
+ export type DiscoveredMetadata = z.infer<typeof DiscoverySchema>;
10
31
  /** Fetches and validates an authorization server's discovery document. */
11
32
  export declare function discoverAuthorizationServer(issuer: string): Promise<DiscoveredMetadata>;
33
+ export {};
@@ -1,4 +1,13 @@
1
- import { OAuthMetadataSchema, } from "@modelcontextprotocol/sdk/shared/auth.js";
1
+ import { OAuthMetadataSchema } from "@modelcontextprotocol/core";
2
+ import { z } from "zod/v4";
3
+ /**
4
+ * Discovery doc validated as OAuth AS metadata + `jwks_uri`. The SDK's
5
+ * `OAuthMetadataSchema` omits `jwks_uri` (its client never verifies tokens), but
6
+ * we need it for JWKS token verification, so we extend the schema to keep it.
7
+ */
8
+ const DiscoverySchema = OAuthMetadataSchema.extend({
9
+ jwks_uri: z.string().optional(),
10
+ });
2
11
  const WELL_KNOWN = [
3
12
  "/.well-known/openid-configuration",
4
13
  "/.well-known/oauth-authorization-server",
@@ -22,22 +31,18 @@ export async function discoverAuthorizationServer(issuer) {
22
31
  if (!res.ok) {
23
32
  throw new Error(`HTTP ${res.status}`);
24
33
  }
25
- const parsed = OAuthMetadataSchema.safeParse(await res.json());
26
- if (!parsed.success) {
27
- throw new Error(`invalid metadata (${parsed.error.message})`);
28
- }
34
+ const meta = DiscoverySchema.parse(await res.json());
29
35
  // RFC 8414 §3.3: issuer must match the fetch origin (slash-insensitive).
30
- if (parsed.data.issuer.replace(/\/$/, "") !== base) {
31
- throw new Error(`issuer mismatch: ${parsed.data.issuer}`);
36
+ if (meta.issuer.replace(/\/$/, "") !== base) {
37
+ throw new Error(`issuer mismatch: ${meta.issuer}`);
32
38
  }
33
- const metadata = parsed.data;
34
39
  // Prefer the document that advertises DCR: some IdPs (e.g. Clerk) serve a
35
40
  // valid openid-configuration without `registration_endpoint` yet expose
36
41
  // it at oauth-authorization-server. Keep looking past a doc that omits it.
37
- if (metadata.registration_endpoint) {
38
- return metadata;
42
+ if (meta.registration_endpoint) {
43
+ return meta;
39
44
  }
40
- fallback ??= metadata;
45
+ fallback ??= meta;
41
46
  }
42
47
  catch (err) {
43
48
  errors.push(`${url}: ${err instanceof Error ? err.message : String(err)}`);
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/server/auth/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,GACpB,MAAM,0CAA0C,CAAC;AASlD,MAAM,UAAU,GAAG;IACjB,mCAAmC;IACnC,yCAAyC;CAC1C,CAAC;AAEF,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC,0EAA0E;AAC1E,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,MAAc;IAEd,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACvC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,2EAA2E;IAC3E,8EAA8E;IAC9E,IAAI,QAAwC,CAAC;IAE7C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;QAC7B,4EAA4E;QAC5E,yEAAyE;QACzE,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC3B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC;aAClD,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;YACxC,CAAC;YACD,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YAC/D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC;YAChE,CAAC;YACD,yEAAyE;YACzE,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;gBACnD,MAAM,IAAI,KAAK,CAAC,oBAAoB,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC5D,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAA0B,CAAC;YACnD,0EAA0E;YAC1E,wEAAwE;YACxE,2EAA2E;YAC3E,IAAI,QAAQ,CAAC,qBAAqB,EAAE,CAAC;gBACnC,OAAO,QAAQ,CAAC;YAClB,CAAC;YACD,QAAQ,KAAK,QAAQ,CAAC;QACxB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CACT,GAAG,GAAG,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC9D,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import {\n type OAuthMetadata,\n OAuthMetadataSchema,\n} from \"@modelcontextprotocol/sdk/shared/auth.js\";\n\n/**\n * Discovered AS metadata + `jwks_uri` — the SDK's `OAuthMetadata` omits it (its\n * OAuth client never verifies tokens), but we need it to verify token signatures\n * via JWKS, so we re-type the field for typed access.\n */\nexport type DiscoveredMetadata = OAuthMetadata & { jwks_uri?: string };\n\nconst WELL_KNOWN = [\n \"/.well-known/openid-configuration\",\n \"/.well-known/oauth-authorization-server\",\n];\n\nconst DISCOVERY_TIMEOUT_MS = 5000;\n\n/** Fetches and validates an authorization server's discovery document. */\nexport async function discoverAuthorizationServer(\n issuer: string,\n): Promise<DiscoveredMetadata> {\n const base = issuer.replace(/\\/$/, \"\");\n const errors: string[] = [];\n // First valid doc lacking a registration_endpoint, kept as a fallback so a\n // genuinely non-DCR IdP still resolves (and is rejected later by the caller).\n let fallback: DiscoveredMetadata | undefined;\n\n for (const path of WELL_KNOWN) {\n const url = `${base}${path}`;\n // Any failure (network/timeout, non-2xx, non-JSON, invalid metadata, issuer\n // mismatch) records a per-URL reason and falls through to the next path.\n try {\n const res = await fetch(url, {\n signal: AbortSignal.timeout(DISCOVERY_TIMEOUT_MS),\n });\n if (!res.ok) {\n throw new Error(`HTTP ${res.status}`);\n }\n const parsed = OAuthMetadataSchema.safeParse(await res.json());\n if (!parsed.success) {\n throw new Error(`invalid metadata (${parsed.error.message})`);\n }\n // RFC 8414 §3.3: issuer must match the fetch origin (slash-insensitive).\n if (parsed.data.issuer.replace(/\\/$/, \"\") !== base) {\n throw new Error(`issuer mismatch: ${parsed.data.issuer}`);\n }\n const metadata = parsed.data as DiscoveredMetadata;\n // Prefer the document that advertises DCR: some IdPs (e.g. Clerk) serve a\n // valid openid-configuration without `registration_endpoint` yet expose\n // it at oauth-authorization-server. Keep looking past a doc that omits it.\n if (metadata.registration_endpoint) {\n return metadata;\n }\n fallback ??= metadata;\n } catch (err) {\n errors.push(\n `${url}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n\n if (fallback) {\n return fallback;\n }\n throw new Error(`OAuth discovery failed for ${issuer}: ${errors.join(\"; \")}`);\n}\n"]}
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/server/auth/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B;;;;GAIG;AACH,MAAM,eAAe,GAAG,mBAAmB,CAAC,MAAM,CAAC;IACjD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAChC,CAAC,C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AC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CACT,GAAG,GAAG,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC9D,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import { OAuthMetadataSchema } from \"@modelcontextprotocol/core\";\nimport { z } from \"zod/v4\";\n\n/**\n * Discovery doc validated as OAuth AS metadata + `jwks_uri`. The SDK's\n * `OAuthMetadataSchema` omits `jwks_uri` (its client never verifies tokens), but\n * we need it for JWKS token verification, so we extend the schema to keep it.\n */\nconst DiscoverySchema = OAuthMetadataSchema.extend({\n jwks_uri: z.string().optional(),\n});\nexport type DiscoveredMetadata = z.infer<typeof DiscoverySchema>;\n\nconst WELL_KNOWN = [\n \"/.well-known/openid-configuration\",\n \"/.well-known/oauth-authorization-server\",\n];\n\nconst DISCOVERY_TIMEOUT_MS = 5000;\n\n/** Fetches and validates an authorization server's discovery document. */\nexport async function discoverAuthorizationServer(\n issuer: string,\n): Promise<DiscoveredMetadata> {\n const base = issuer.replace(/\\/$/, \"\");\n const errors: string[] = [];\n // First valid doc lacking a registration_endpoint, kept as a fallback so a\n // genuinely non-DCR IdP still resolves (and is rejected later by the caller).\n let fallback: DiscoveredMetadata | undefined;\n\n for (const path of WELL_KNOWN) {\n const url = `${base}${path}`;\n // Any failure (network/timeout, non-2xx, non-JSON, invalid metadata, issuer\n // mismatch) records a per-URL reason and falls through to the next path.\n try {\n const res = await fetch(url, {\n signal: AbortSignal.timeout(DISCOVERY_TIMEOUT_MS),\n });\n if (!res.ok) {\n throw new Error(`HTTP ${res.status}`);\n }\n const meta = DiscoverySchema.parse(await res.json());\n // RFC 8414 §3.3: issuer must match the fetch origin (slash-insensitive).\n if (meta.issuer.replace(/\\/$/, \"\") !== base) {\n throw new Error(`issuer mismatch: ${meta.issuer}`);\n }\n // Prefer the document that advertises DCR: some IdPs (e.g. Clerk) serve a\n // valid openid-configuration without `registration_endpoint` yet expose\n // it at oauth-authorization-server. Keep looking past a doc that omits it.\n if (meta.registration_endpoint) {\n return meta;\n }\n fallback ??= meta;\n } catch (err) {\n errors.push(\n `${url}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n\n if (fallback) {\n return fallback;\n }\n throw new Error(`OAuth discovery failed for ${issuer}: ${errors.join(\"; \")}`);\n}\n"]}
@@ -1,7 +1,15 @@
1
- import type { OAuthMetadata } from "@modelcontextprotocol/sdk/shared/auth.js";
2
- import type { JwksVerifyConfig } from "./verify.js";
3
- /** Resource-server OAuth config for `SkybridgeServerOptions.oauth`. */
4
- export type OAuthConfig = {
1
+ import type { OAuthMetadata } from "@modelcontextprotocol/server";
2
+ import type { ExtraClaims, TokenVerifier } from "../auth.js";
3
+ /**
4
+ * Resource-server OAuth config for the `oauth` field of `SkybridgeConfig`.
5
+ *
6
+ * `TExtra` comes from the `verifier` and flows on to tool handlers and
7
+ * `mcpMiddleware`, so the claim shape is declared once by whoever checks the
8
+ * token. The branded providers set it from the claims their IdP documents.
9
+ *
10
+ * @typeParam TExtra - Claims the verifier populates in `AuthInfo["extra"]`.
11
+ */
12
+ export type OAuthConfig<TExtra extends ExtraClaims = ExtraClaims> = {
5
13
  /**
6
14
  * Public URL of this server; sets `resourceServerUrl` and the
7
15
  * `resource_metadata` URL. When omitted, it is inferred per request from
@@ -10,9 +18,31 @@ export type OAuthConfig = {
10
18
  baseUrl?: string;
11
19
  /** AS metadata served at `/.well-known/oauth-authorization-server`. */
12
20
  oauthMetadata: OAuthMetadata;
13
- verify: JwksVerifyConfig;
14
21
  /** Scopes advertised in protected-resource metadata. */
15
22
  scopesSupported?: string[];
16
23
  /** Server-wide required-scope floor. */
17
24
  requiredScopes?: string[];
25
+ /**
26
+ * Checks each bearer token. Build one with `createJwksVerifier` for a
27
+ * JWT-issuing IdP, or supply your own for opaque tokens.
28
+ */
29
+ verifier: TokenVerifier<TExtra>;
30
+ };
31
+ /**
32
+ * What the branded providers return: a deferred {@link OAuthConfig}. Discovery
33
+ * runs in `resolve`, so `oauth: auth0Provider(...)` at module scope performs
34
+ * no network access until `Skybridge.run`. Call `resolve` yourself
35
+ * (`await customProvider(...).resolve()`) when wiring the middleware by hand.
36
+ *
37
+ * This is an object rather than a bare `() => Promise<OAuthConfig>` on
38
+ * purpose. TypeScript defers, during the first inference pass, any argument
39
+ * that is a call to a generic function returning a function type. The
40
+ * providers are generic (`workosProvider<TCustom>`), so a function-shaped
41
+ * return written inline in `new Skybridge({ oauth: workosProvider(...) })`
42
+ * would be skipped and `TAuthExtra` would fall back to `ExtraClaims`, losing
43
+ * the claims typing in tool handlers. A non-function shape is inferred
44
+ * eagerly.
45
+ */
46
+ export type OAuthProvider<TExtra extends ExtraClaims = ExtraClaims> = {
47
+ resolve: () => Promise<OAuthConfig<TExtra>>;
18
48
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/auth/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { OAuthMetadata } from \"@modelcontextprotocol/sdk/shared/auth.js\";\nimport type { JwksVerifyConfig } from \"./verify.js\";\n\n/** Resource-server OAuth config for `SkybridgeServerOptions.oauth`. */\nexport type OAuthConfig = {\n /**\n * Public URL of this server; sets `resourceServerUrl` and the\n * `resource_metadata` URL. When omitted, it is inferred per request from\n * `x-forwarded-host`/`origin`/`host` headers.\n */\n baseUrl?: string;\n /** AS metadata served at `/.well-known/oauth-authorization-server`. */\n oauthMetadata: OAuthMetadata;\n verify: JwksVerifyConfig;\n /** Scopes advertised in protected-resource metadata. */\n scopesSupported?: string[];\n /** Server-wide required-scope floor. */\n requiredScopes?: string[];\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/auth/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { OAuthMetadata } from \"@modelcontextprotocol/server\";\nimport type { ExtraClaims, TokenVerifier } from \"../auth.js\";\n\n/**\n * Resource-server OAuth config for the `oauth` field of `SkybridgeConfig`.\n *\n * `TExtra` comes from the `verifier` and flows on to tool handlers and\n * `mcpMiddleware`, so the claim shape is declared once by whoever checks the\n * token. The branded providers set it from the claims their IdP documents.\n *\n * @typeParam TExtra - Claims the verifier populates in `AuthInfo[\"extra\"]`.\n */\nexport type OAuthConfig<TExtra extends ExtraClaims = ExtraClaims> = {\n /**\n * Public URL of this server; sets `resourceServerUrl` and the\n * `resource_metadata` URL. When omitted, it is inferred per request from\n * `x-forwarded-host`/`origin`/`host` headers.\n */\n baseUrl?: string;\n /** AS metadata served at `/.well-known/oauth-authorization-server`. */\n oauthMetadata: OAuthMetadata;\n /** Scopes advertised in protected-resource metadata. */\n scopesSupported?: string[];\n /** Server-wide required-scope floor. */\n requiredScopes?: string[];\n /**\n * Checks each bearer token. Build one with `createJwksVerifier` for a\n * JWT-issuing IdP, or supply your own for opaque tokens.\n */\n verifier: TokenVerifier<TExtra>;\n};\n\n/**\n * What the branded providers return: a deferred {@link OAuthConfig}. Discovery\n * runs in `resolve`, so `oauth: auth0Provider(...)` at module scope performs\n * no network access until `Skybridge.run`. Call `resolve` yourself\n * (`await customProvider(...).resolve()`) when wiring the middleware by hand.\n *\n * This is an object rather than a bare `() => Promise<OAuthConfig>` on\n * purpose. TypeScript defers, during the first inference pass, any argument\n * that is a call to a generic function returning a function type. The\n * providers are generic (`workosProvider<TCustom>`), so a function-shaped\n * return written inline in `new Skybridge({ oauth: workosProvider(...) })`\n * would be skipped and `TAuthExtra` would fall back to `ExtraClaims`, losing\n * the claims typing in tool handlers. A non-function shape is inferred\n * eagerly.\n */\nexport type OAuthProvider<TExtra extends ExtraClaims = ExtraClaims> = {\n resolve: () => Promise<OAuthConfig<TExtra>>;\n};\n"]}
@@ -1,12 +1,40 @@
1
- import type { OAuthConfig } from "../index.js";
1
+ import type { ExtraClaims } from "../../auth.js";
2
+ import type { OAuthProvider } from "../index.js";
3
+ import type { RegisteredClaims } from "../verify.js";
2
4
  import { type CustomProviderOptions } from "./custom.js";
5
+ /**
6
+ * Claims an Auth0 access token carries for a custom API audience. Auth0 puts no
7
+ * user attributes beyond the id in the token, so there is no `email`: call
8
+ * `/userinfo` for the profile. Custom claims must be namespaced (a bare `email`
9
+ * key is silently dropped), so add them through the type parameter under their
10
+ * full URI.
11
+ *
12
+ * @see https://auth0.com/docs/secure/tokens/access-tokens
13
+ * @see https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims
14
+ */
15
+ export type Auth0Claims = {
16
+ /** Authorized party: the client id the token was issued to. */
17
+ azp?: string;
18
+ /** Only when the API has RBAC and "Add Permissions in the Access Token" on. */
19
+ permissions?: string[];
20
+ /** Organization id, when the tenant uses Organizations. */
21
+ org_id?: string;
22
+ /** Organization name, when the tenant uses Organizations. */
23
+ org_name?: string;
24
+ };
3
25
  /**
4
26
  * OAuth provider for Auth0. `domain` is the tenant domain (e.g.
5
- * `acme.us.auth0.com`) or a custom domain. Requires Dynamic Client
6
- * Registration enabled on the tenant (`enable_dynamic_client_registration`).
7
- * `audience` is the registered API Identifier — Auth0 only issues a verifiable
8
- * JWT (rather than an opaque token) when the request targets that audience.
27
+ * `acme.us.auth0.com`); `audience` is the API Identifier; `serverUrl` is this
28
+ * server's public URL. Requires DCR enabled on the tenant.
29
+ *
30
+ * Auth0 can't use the client's resource indicator — `audience` must be *in* the
31
+ * authorize request. So it runs as skybridge-as-AS (`serverUrl`, see
32
+ * {@link customProvider}) and bakes `?audience=<id>` into the advertised
33
+ * `authorization_endpoint`. The token's `aud` is the API; `verify.issuer` stays
34
+ * Auth0 (the token's real `iss`).
9
35
  */
10
- export declare function auth0Provider(opts: {
36
+ export declare function auth0Provider<TCustom extends ExtraClaims = Record<never, never>>(opts: {
11
37
  domain: string;
12
- } & Omit<CustomProviderOptions, "issuer">): Promise<OAuthConfig>;
38
+ audience: string;
39
+ serverUrl: string;
40
+ } & Omit<CustomProviderOptions, "issuer" | "audience" | "baseUrl" | "serverUrl">): OAuthProvider<Auth0Claims & TCustom & RegisteredClaims>;
@@ -1,18 +1,36 @@
1
1
  import { customProvider } from "./custom.js";
2
- /** Normalises a bare host to an https issuer URL and strips a trailing slash. */
3
- function toIssuerUrl(domain) {
4
- const withScheme = /^https?:\/\//.test(domain) ? domain : `https://${domain}`;
5
- return withScheme.replace(/\/$/, "");
6
- }
2
+ import { toIssuerUrl } from "./shared.js";
7
3
  /**
8
4
  * OAuth provider for Auth0. `domain` is the tenant domain (e.g.
9
- * `acme.us.auth0.com`) or a custom domain. Requires Dynamic Client
10
- * Registration enabled on the tenant (`enable_dynamic_client_registration`).
11
- * `audience` is the registered API Identifier — Auth0 only issues a verifiable
12
- * JWT (rather than an opaque token) when the request targets that audience.
5
+ * `acme.us.auth0.com`); `audience` is the API Identifier; `serverUrl` is this
6
+ * server's public URL. Requires DCR enabled on the tenant.
7
+ *
8
+ * Auth0 can't use the client's resource indicator — `audience` must be *in* the
9
+ * authorize request. So it runs as skybridge-as-AS (`serverUrl`, see
10
+ * {@link customProvider}) and bakes `?audience=<id>` into the advertised
11
+ * `authorization_endpoint`. The token's `aud` is the API; `verify.issuer` stays
12
+ * Auth0 (the token's real `iss`).
13
13
  */
14
14
  export function auth0Provider(opts) {
15
- const { domain, ...rest } = opts;
16
- return customProvider({ issuer: toIssuerUrl(domain), ...rest });
15
+ const { domain, audience, ...rest } = opts;
16
+ const provider = customProvider({
17
+ issuer: toIssuerUrl(domain),
18
+ audience,
19
+ ...rest,
20
+ });
21
+ return {
22
+ resolve: async () => {
23
+ const config = await provider.resolve();
24
+ const authUrl = new URL(config.oauthMetadata.authorization_endpoint);
25
+ authUrl.searchParams.set("audience", audience);
26
+ return {
27
+ ...config,
28
+ oauthMetadata: {
29
+ ...config.oauthMetadata,
30
+ authorization_endpoint: authUrl.href,
31
+ },
32
+ };
33
+ },
34
+ };
17
35
  }
18
36
  //# sourceMappingURL=auth0.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth0.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/auth0.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzE,iFAAiF;AACjF,SAAS,WAAW,CAAC,MAAc;IACjC,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,EAAE,CAAC;IAC9E,OAAO,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAgE;IAEhE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IACjC,OAAO,cAAc,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import type { OAuthConfig } from \"../index.js\";\nimport { type CustomProviderOptions, customProvider } from \"./custom.js\";\n\n/** Normalises a bare host to an https issuer URL and strips a trailing slash. */\nfunction toIssuerUrl(domain: string): string {\n const withScheme = /^https?:\\/\\//.test(domain) ? domain : `https://${domain}`;\n return withScheme.replace(/\\/$/, \"\");\n}\n\n/**\n * OAuth provider for Auth0. `domain` is the tenant domain (e.g.\n * `acme.us.auth0.com`) or a custom domain. Requires Dynamic Client\n * Registration enabled on the tenant (`enable_dynamic_client_registration`).\n * `audience` is the registered API Identifier — Auth0 only issues a verifiable\n * JWT (rather than an opaque token) when the request targets that audience.\n */\nexport function auth0Provider(\n opts: { domain: string } & Omit<CustomProviderOptions, \"issuer\">,\n): Promise<OAuthConfig> {\n const { domain, ...rest } = opts;\n return customProvider({ issuer: toIssuerUrl(domain), ...rest });\n}\n"]}
1
+ {"version":3,"file":"auth0.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/auth0.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAuB1C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAG3B,IAGC;IAED,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC3C,MAAM,QAAQ,GAAG,cAAc,CAAwB;QACrD,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;QAC3B,QAAQ;QACR,GAAG,IAAI;KACR,CAAC,CAAC;IACH,OAAO;QACL,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;YACxC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,sBAAsB,CAAC,CAAC;YACrE,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YAC/C,OAAO;gBACL,GAAG,MAAM;gBACT,aAAa,EAAE;oBACb,GAAG,MAAM,CAAC,aAAa;oBACvB,sBAAsB,EAAE,OAAO,CAAC,IAAI;iBACrC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ExtraClaims } from \"../../auth.js\";\nimport type { OAuthProvider } from \"../index.js\";\nimport type { RegisteredClaims } from \"../verify.js\";\nimport { type CustomProviderOptions, customProvider } from \"./custom.js\";\nimport { toIssuerUrl } from \"./shared.js\";\n\n/**\n * Claims an Auth0 access token carries for a custom API audience. Auth0 puts no\n * user attributes beyond the id in the token, so there is no `email`: call\n * `/userinfo` for the profile. Custom claims must be namespaced (a bare `email`\n * key is silently dropped), so add them through the type parameter under their\n * full URI.\n *\n * @see https://auth0.com/docs/secure/tokens/access-tokens\n * @see https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims\n */\nexport type Auth0Claims = {\n /** Authorized party: the client id the token was issued to. */\n azp?: string;\n /** Only when the API has RBAC and \"Add Permissions in the Access Token\" on. */\n permissions?: string[];\n /** Organization id, when the tenant uses Organizations. */\n org_id?: string;\n /** Organization name, when the tenant uses Organizations. */\n org_name?: string;\n};\n\n/**\n * OAuth provider for Auth0. `domain` is the tenant domain (e.g.\n * `acme.us.auth0.com`); `audience` is the API Identifier; `serverUrl` is this\n * server's public URL. Requires DCR enabled on the tenant.\n *\n * Auth0 can't use the client's resource indicator — `audience` must be *in* the\n * authorize request. So it runs as skybridge-as-AS (`serverUrl`, see\n * {@link customProvider}) and bakes `?audience=<id>` into the advertised\n * `authorization_endpoint`. The token's `aud` is the API; `verify.issuer` stays\n * Auth0 (the token's real `iss`).\n */\nexport function auth0Provider<\n TCustom extends ExtraClaims = Record<never, never>,\n>(\n opts: { domain: string; audience: string; serverUrl: string } & Omit<\n CustomProviderOptions,\n \"issuer\" | \"audience\" | \"baseUrl\" | \"serverUrl\"\n >,\n): OAuthProvider<Auth0Claims & TCustom & RegisteredClaims> {\n const { domain, audience, ...rest } = opts;\n const provider = customProvider<Auth0Claims & TCustom>({\n issuer: toIssuerUrl(domain),\n audience,\n ...rest,\n });\n return {\n resolve: async () => {\n const config = await provider.resolve();\n const authUrl = new URL(config.oauthMetadata.authorization_endpoint);\n authUrl.searchParams.set(\"audience\", audience);\n return {\n ...config,\n oauthMetadata: {\n ...config.oauthMetadata,\n authorization_endpoint: authUrl.href,\n },\n };\n },\n };\n}\n"]}
@@ -1,33 +1,50 @@
1
1
  // @vitest-environment node
2
2
  import { afterEach, describe, expect, it, vi } from "vitest";
3
3
  import { auth0Provider } from "./auth0.js";
4
+ import { lastJwksConfig as jwks } from "./verify-spy.js";
5
+ vi.mock("../verify.js", () => import("./verify-spy.js"));
4
6
  afterEach(() => vi.restoreAllMocks());
5
- function discoveryDoc(issuer) {
7
+ function doc(issuer) {
6
8
  return {
7
9
  issuer,
8
10
  authorization_endpoint: `${issuer}/authorize`,
9
11
  token_endpoint: `${issuer}/oauth/token`,
10
12
  registration_endpoint: `${issuer}/oidc/register`,
11
13
  response_types_supported: ["code"],
12
- scopes_supported: ["openid"],
14
+ scopes_supported: ["openid", "profile", "email"],
13
15
  jwks_uri: `${issuer}/.well-known/jwks.json`,
14
16
  };
15
17
  }
16
- function mockDiscovery(issuer) {
17
- return vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify(discoveryDoc(issuer)), {
18
- headers: { "content-type": "application/json" },
19
- }));
20
- }
21
18
  describe("auth0Provider", () => {
22
- it("builds the issuer from the tenant domain", async () => {
23
- const fetchSpy = mockDiscovery("https://acme.us.auth0.com");
19
+ it("advertises skybridge as the AS (static issuer) and bakes audience; verifies against Auth0", async () => {
20
+ const issuer = "https://acme.us.auth0.com";
21
+ vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify(doc(issuer)), {
22
+ headers: { "content-type": "application/json" },
23
+ }));
24
24
  const config = await auth0Provider({
25
25
  domain: "acme.us.auth0.com",
26
- audience: "https://my-mcp-api",
27
- });
28
- expect(fetchSpy).toHaveBeenCalledWith("https://acme.us.auth0.com/.well-known/openid-configuration", expect.anything());
29
- expect(config.verify.issuer).toBe("https://acme.us.auth0.com");
30
- expect(config.verify.audience).toBe("https://my-mcp-api");
26
+ audience: "https://api.example.com/",
27
+ serverUrl: "https://app.example.com/",
28
+ scopes: ["openid", "profile", "email"],
29
+ }).resolve();
30
+ // skybridge is the advertised AS: static issuer = serverUrl (trailing slash stripped).
31
+ expect(config.oauthMetadata.issuer).toBe("https://app.example.com");
32
+ // AS metadata scopes match the advertised set (clients read scopes from here).
33
+ expect(config.oauthMetadata.scopes_supported).toEqual([
34
+ "openid",
35
+ "profile",
36
+ "email",
37
+ ]);
38
+ expect(config.scopesSupported).toEqual(["openid", "profile", "email"]);
39
+ // audience baked into the advertised authorize endpoint (still pointing at Auth0).
40
+ const url = new URL(config.oauthMetadata.authorization_endpoint);
41
+ expect(url.origin + url.pathname).toBe(`${issuer}/authorize`);
42
+ expect(url.searchParams.get("audience")).toBe("https://api.example.com/");
43
+ // baseUrl left unset so the PRM resource resolves per request (Alpic-safe).
44
+ expect(config.baseUrl).toBeUndefined();
45
+ // token verification still uses Auth0 as issuer + the API audience.
46
+ expect(jwks().issuer).toBe(issuer);
47
+ expect(jwks().audience).toBe("https://api.example.com/");
31
48
  });
32
49
  });
33
50
  //# sourceMappingURL=auth0.test.js.map