skybridge 0.0.0-dev.e9a7859 → 0.0.0-dev.e9ac102

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 (357) 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 +195 -0
  44. package/dist/server/app.js +268 -0
  45. package/dist/server/app.js.map +1 -0
  46. package/dist/server/app.test.js +196 -0
  47. package/dist/server/app.test.js.map +1 -0
  48. package/dist/server/auth/discovery.d.ts +2 -1
  49. package/dist/server/auth/discovery.js +2 -2
  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 +25 -3
  54. package/dist/server/auth/providers/auth0.js +13 -8
  55. package/dist/server/auth/providers/auth0.js.map +1 -1
  56. package/dist/server/auth/providers/auth0.test.js +5 -3
  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 +40 -3
  64. package/dist/server/auth/providers/clerk.js +4 -1
  65. package/dist/server/auth/providers/clerk.js.map +1 -1
  66. package/dist/server/auth/providers/clerk.test.js +5 -3
  67. package/dist/server/auth/providers/clerk.test.js.map +1 -1
  68. package/dist/server/auth/providers/custom.d.ts +24 -6
  69. package/dist/server/auth/providers/custom.js +33 -11
  70. package/dist/server/auth/providers/custom.js.map +1 -1
  71. package/dist/server/auth/providers/custom.test.js +71 -17
  72. package/dist/server/auth/providers/custom.test.js.map +1 -1
  73. package/dist/server/auth/providers/descope.d.ts +32 -3
  74. package/dist/server/auth/providers/descope.js +12 -2
  75. package/dist/server/auth/providers/descope.js.map +1 -1
  76. package/dist/server/auth/providers/descope.test.js +42 -18
  77. package/dist/server/auth/providers/descope.test.js.map +1 -1
  78. package/dist/server/auth/providers/stytch.d.ts +16 -3
  79. package/dist/server/auth/providers/stytch.js +4 -1
  80. package/dist/server/auth/providers/stytch.js.map +1 -1
  81. package/dist/server/auth/providers/verify-spy.d.ts +12 -0
  82. package/dist/server/auth/providers/verify-spy.js +21 -0
  83. package/dist/server/auth/providers/verify-spy.js.map +1 -0
  84. package/dist/server/auth/providers/workos.d.ts +28 -5
  85. package/dist/server/auth/providers/workos.js +6 -2
  86. package/dist/server/auth/providers/workos.js.map +1 -1
  87. package/dist/server/auth/security-schemes.d.ts +23 -0
  88. package/dist/server/auth/security-schemes.js +64 -0
  89. package/dist/server/auth/security-schemes.js.map +1 -0
  90. package/dist/server/auth/security-schemes.test.d.ts +1 -0
  91. package/dist/server/auth/security-schemes.test.js +99 -0
  92. package/dist/server/auth/security-schemes.test.js.map +1 -0
  93. package/dist/server/auth/setup.d.ts +3 -1
  94. package/dist/server/auth/setup.js +66 -26
  95. package/dist/server/auth/setup.js.map +1 -1
  96. package/dist/server/auth/setup.test.js +349 -20
  97. package/dist/server/auth/setup.test.js.map +1 -1
  98. package/dist/server/auth/verify.d.ts +42 -6
  99. package/dist/server/auth/verify.js +27 -3
  100. package/dist/server/auth/verify.js.map +1 -1
  101. package/dist/server/auth/verify.test.js +65 -0
  102. package/dist/server/auth/verify.test.js.map +1 -1
  103. package/dist/server/auth-extra.test-d.js +130 -0
  104. package/dist/server/auth-extra.test-d.js.map +1 -0
  105. package/dist/server/auth.d.ts +43 -6
  106. package/dist/server/auth.js +4 -5
  107. package/dist/server/auth.js.map +1 -1
  108. package/dist/server/build-manifest.test.js +7 -6
  109. package/dist/server/build-manifest.test.js.map +1 -1
  110. package/dist/server/content-helpers.d.ts +1 -1
  111. package/dist/server/content-helpers.js.map +1 -1
  112. package/dist/server/events.d.ts +113 -0
  113. package/dist/server/events.js +318 -0
  114. package/dist/server/events.js.map +1 -0
  115. package/dist/server/events.test.d.ts +1 -0
  116. package/dist/server/events.test.js +172 -0
  117. package/dist/server/events.test.js.map +1 -0
  118. package/dist/server/express.d.ts +23 -3
  119. package/dist/server/express.js +43 -32
  120. package/dist/server/express.js.map +1 -1
  121. package/dist/server/express.test.js +221 -103
  122. package/dist/server/express.test.js.map +1 -1
  123. package/dist/server/file-ref.d.ts +1 -1
  124. package/dist/server/file-ref.js +1 -1
  125. package/dist/server/file-ref.js.map +1 -1
  126. package/dist/server/form-input.d.ts +120 -0
  127. package/dist/server/form-input.js +89 -0
  128. package/dist/server/form-input.js.map +1 -0
  129. package/dist/server/host.d.ts +2 -0
  130. package/dist/server/host.js +11 -0
  131. package/dist/server/host.js.map +1 -0
  132. package/dist/server/host.test.d.ts +1 -0
  133. package/dist/server/host.test.js +13 -0
  134. package/dist/server/host.test.js.map +1 -0
  135. package/dist/server/index.d.ts +18 -9
  136. package/dist/server/index.js +11 -3
  137. package/dist/server/index.js.map +1 -1
  138. package/dist/server/mcp-errors.test.d.ts +1 -0
  139. package/dist/server/mcp-errors.test.js +41 -0
  140. package/dist/server/mcp-errors.test.js.map +1 -0
  141. package/dist/server/middleware.d.ts +35 -10
  142. package/dist/server/middleware.js +33 -0
  143. package/dist/server/middleware.js.map +1 -1
  144. package/dist/server/middleware.test-d.js +1 -1
  145. package/dist/server/middleware.test-d.js.map +1 -1
  146. package/dist/server/middleware.test.js +242 -134
  147. package/dist/server/middleware.test.js.map +1 -1
  148. package/dist/server/register-tool.test.d.ts +1 -0
  149. package/dist/server/register-tool.test.js +230 -0
  150. package/dist/server/register-tool.test.js.map +1 -0
  151. package/dist/server/server.d.ts +373 -128
  152. package/dist/server/server.js +441 -274
  153. package/dist/server/server.js.map +1 -1
  154. package/dist/server/skills-integration.test.d.ts +1 -0
  155. package/dist/server/skills-integration.test.js +86 -0
  156. package/dist/server/skills-integration.test.js.map +1 -0
  157. package/dist/server/skills.d.ts +27 -0
  158. package/dist/server/skills.js +188 -0
  159. package/dist/server/skills.js.map +1 -0
  160. package/dist/server/skills.test.d.ts +1 -0
  161. package/dist/server/skills.test.js +243 -0
  162. package/dist/server/skills.test.js.map +1 -0
  163. package/dist/server/templateHelper.d.ts +0 -3
  164. package/dist/server/templateHelper.js.map +1 -1
  165. package/dist/server/templates.generated.js +4 -8
  166. package/dist/server/templates.generated.js.map +1 -1
  167. package/dist/server/tool-extra.test.d.ts +1 -0
  168. package/dist/server/tool-extra.test.js +167 -0
  169. package/dist/server/tool-extra.test.js.map +1 -0
  170. package/dist/server/view-resource-resolution.test.js +18 -13
  171. package/dist/server/view-resource-resolution.test.js.map +1 -1
  172. package/dist/server/viewsDevServer.js +4 -1
  173. package/dist/server/viewsDevServer.js.map +1 -1
  174. package/dist/test/utils.d.ts +9 -11
  175. package/dist/test/utils.js +220 -201
  176. package/dist/test/utils.js.map +1 -1
  177. package/dist/test/view.test.js +44 -40
  178. package/dist/test/view.test.js.map +1 -1
  179. package/dist/views/index.d.ts +10 -0
  180. package/dist/views/index.js +3 -0
  181. package/dist/views/index.js.map +1 -0
  182. package/dist/{web/plugin → views}/scan-views.js +1 -1
  183. package/dist/views/scan-views.js.map +1 -0
  184. package/dist/views/scan-views.test.d.ts +1 -0
  185. package/dist/views/scan-views.test.js.map +1 -0
  186. package/dist/views/validate-view.d.ts +1 -0
  187. package/dist/{web/plugin → views}/validate-view.js +2 -2
  188. package/dist/views/validate-view.js.map +1 -0
  189. package/dist/views/validate-view.test.d.ts +1 -0
  190. package/dist/views/validate-view.test.js.map +1 -0
  191. package/dist/web/bridges/adaptor.d.ts +14 -3
  192. package/dist/web/bridges/adaptor.js +181 -17
  193. package/dist/web/bridges/adaptor.js.map +1 -1
  194. package/dist/web/bridges/adaptor.test.js +95 -11
  195. package/dist/web/bridges/adaptor.test.js.map +1 -1
  196. package/dist/web/bridges/apps-sdk/bridge.js +1 -1
  197. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  198. package/dist/web/bridges/apps-sdk/types.d.ts +2 -3
  199. package/dist/web/bridges/apps-sdk/types.js.map +1 -1
  200. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +4 -4
  201. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +4 -4
  202. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  203. package/dist/web/bridges/get-adaptor.test.js +2 -2
  204. package/dist/web/bridges/get-adaptor.test.js.map +1 -1
  205. package/dist/web/bridges/mcp-app/bridge.d.ts +1 -1
  206. package/dist/web/bridges/mcp-app/bridge.js +15 -6
  207. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  208. package/dist/web/bridges/mcp-app/bridge.test.js +2 -2
  209. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -1
  210. package/dist/web/bridges/mcp-app/types.d.ts +19 -2
  211. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  212. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +2 -2
  213. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
  214. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  215. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
  216. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  217. package/dist/web/bridges/mcp-app/view-tools.test.js +1 -1
  218. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
  219. package/dist/web/bridges/types.d.ts +74 -16
  220. package/dist/web/bridges/types.js +1 -1
  221. package/dist/web/bridges/types.js.map +1 -1
  222. package/dist/web/components/modal-provider.d.ts +1 -1
  223. package/dist/web/create-store.test.js +2 -2
  224. package/dist/web/create-store.test.js.map +1 -1
  225. package/dist/web/data-llm.d.ts +1 -1
  226. package/dist/web/data-llm.js +3 -2
  227. package/dist/web/data-llm.js.map +1 -1
  228. package/dist/web/data-llm.test.js +17 -2
  229. package/dist/web/data-llm.test.js.map +1 -1
  230. package/dist/web/generate-helpers.d.ts +23 -19
  231. package/dist/web/generate-helpers.js +21 -17
  232. package/dist/web/generate-helpers.js.map +1 -1
  233. package/dist/web/generate-helpers.test-d.js +3 -3
  234. package/dist/web/generate-helpers.test-d.js.map +1 -1
  235. package/dist/web/generate-helpers.test.js +2 -2
  236. package/dist/web/generate-helpers.test.js.map +1 -1
  237. package/dist/web/hooks/index.d.ts +6 -1
  238. package/dist/web/hooks/index.js +6 -1
  239. package/dist/web/hooks/index.js.map +1 -1
  240. package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
  241. package/dist/web/hooks/openai-extensions.test.js +107 -0
  242. package/dist/web/hooks/openai-extensions.test.js.map +1 -0
  243. package/dist/web/hooks/test/utils.d.ts +2 -1
  244. package/dist/web/hooks/test/utils.js +1 -1
  245. package/dist/web/hooks/test/utils.js.map +1 -1
  246. package/dist/web/hooks/use-call-tool.d.ts +2 -2
  247. package/dist/web/hooks/use-call-tool.js +15 -10
  248. package/dist/web/hooks/use-call-tool.js.map +1 -1
  249. package/dist/web/hooks/use-call-tool.test.js +15 -4
  250. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  251. package/dist/web/hooks/use-deep-link.d.ts +22 -0
  252. package/dist/web/hooks/use-deep-link.js +34 -0
  253. package/dist/web/hooks/use-deep-link.js.map +1 -0
  254. package/dist/web/hooks/use-display-mode.d.ts +1 -1
  255. package/dist/web/hooks/use-display-mode.js +1 -1
  256. package/dist/web/hooks/use-display-mode.js.map +1 -1
  257. package/dist/web/hooks/use-display-mode.test.js +1 -1
  258. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  259. package/dist/web/hooks/use-download.d.ts +1 -3
  260. package/dist/web/hooks/use-download.js +1 -2
  261. package/dist/web/hooks/use-download.js.map +1 -1
  262. package/dist/web/hooks/use-download.test.js +7 -7
  263. package/dist/web/hooks/use-download.test.js.map +1 -1
  264. package/dist/web/hooks/use-file-resource.d.ts +37 -0
  265. package/dist/web/hooks/use-file-resource.js +98 -0
  266. package/dist/web/hooks/use-file-resource.js.map +1 -0
  267. package/dist/web/hooks/use-file-resource.test.d.ts +1 -0
  268. package/dist/web/hooks/use-file-resource.test.js +65 -0
  269. package/dist/web/hooks/use-file-resource.test.js.map +1 -0
  270. package/dist/web/hooks/use-files.test.js +1 -1
  271. package/dist/web/hooks/use-files.test.js.map +1 -1
  272. package/dist/web/hooks/use-host.d.ts +44 -0
  273. package/dist/web/hooks/use-host.js +45 -0
  274. package/dist/web/hooks/use-host.js.map +1 -0
  275. package/dist/web/hooks/use-host.test.d.ts +1 -0
  276. package/dist/web/hooks/use-host.test.js +59 -0
  277. package/dist/web/hooks/use-host.test.js.map +1 -0
  278. package/dist/web/hooks/use-model-context.d.ts +44 -0
  279. package/dist/web/hooks/use-model-context.js +63 -0
  280. package/dist/web/hooks/use-model-context.js.map +1 -0
  281. package/dist/web/hooks/use-open-external.test.js +2 -2
  282. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  283. package/dist/web/hooks/use-open-file.d.ts +20 -0
  284. package/dist/web/hooks/use-open-file.js +25 -0
  285. package/dist/web/hooks/use-open-file.js.map +1 -0
  286. package/dist/web/hooks/use-register-view-tool.d.ts +3 -4
  287. package/dist/web/hooks/use-register-view-tool.js +1 -1
  288. package/dist/web/hooks/use-register-view-tool.js.map +1 -1
  289. package/dist/web/hooks/use-request-close.test.js +1 -1
  290. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  291. package/dist/web/hooks/use-request-modal.test.js +1 -1
  292. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  293. package/dist/web/hooks/use-request-size.d.ts +1 -1
  294. package/dist/web/hooks/use-request-size.js +1 -1
  295. package/dist/web/hooks/use-request-size.js.map +1 -1
  296. package/dist/web/hooks/use-request-size.test.js +1 -1
  297. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  298. package/dist/web/hooks/use-send-follow-up-message.d.ts +8 -2
  299. package/dist/web/hooks/use-send-follow-up-message.js +6 -0
  300. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  301. package/dist/web/hooks/use-set-open-in-app-url.test.js +2 -8
  302. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  303. package/dist/web/hooks/use-tool-info.d.ts +1 -20
  304. package/dist/web/hooks/use-tool-info.js +0 -1
  305. package/dist/web/hooks/use-tool-info.js.map +1 -1
  306. package/dist/web/hooks/use-tool-info.test-d.js +0 -5
  307. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  308. package/dist/web/hooks/use-tool-info.test.js +2 -7
  309. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  310. package/dist/web/hooks/use-user.d.ts +3 -2
  311. package/dist/web/hooks/use-user.js +4 -3
  312. package/dist/web/hooks/use-user.js.map +1 -1
  313. package/dist/web/hooks/use-user.test.js +5 -3
  314. package/dist/web/hooks/use-user.test.js.map +1 -1
  315. package/dist/web/hooks/use-view-state.js +19 -9
  316. package/dist/web/hooks/use-view-state.js.map +1 -1
  317. package/dist/web/hooks/use-view-state.test.js +33 -2
  318. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  319. package/dist/web/hooks/use-viewport.d.ts +20 -0
  320. package/dist/web/hooks/use-viewport.js +21 -0
  321. package/dist/web/hooks/use-viewport.js.map +1 -0
  322. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  323. package/dist/web/hooks/{use-layout.test.js → use-viewport.test.js} +12 -32
  324. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  325. package/dist/web/mount-view.d.ts +3 -2
  326. package/dist/web/mount-view.js +5 -8
  327. package/dist/web/mount-view.js.map +1 -1
  328. package/package.json +34 -29
  329. package/dist/cli/resolve-views-dir.d.ts +0 -1
  330. package/dist/cli/resolve-views-dir.js.map +0 -1
  331. package/dist/web/hooks/use-layout.d.ts +0 -24
  332. package/dist/web/hooks/use-layout.js +0 -25
  333. package/dist/web/hooks/use-layout.js.map +0 -1
  334. package/dist/web/hooks/use-layout.test.js.map +0 -1
  335. package/dist/web/plugin/data-llm.test.js +0 -81
  336. package/dist/web/plugin/data-llm.test.js.map +0 -1
  337. package/dist/web/plugin/plugin.d.ts +0 -33
  338. package/dist/web/plugin/plugin.js +0 -189
  339. package/dist/web/plugin/plugin.js.map +0 -1
  340. package/dist/web/plugin/scan-views.js.map +0 -1
  341. package/dist/web/plugin/scan-views.test.js.map +0 -1
  342. package/dist/web/plugin/transform-data-llm.d.ts +0 -12
  343. package/dist/web/plugin/transform-data-llm.js +0 -96
  344. package/dist/web/plugin/transform-data-llm.js.map +0 -1
  345. package/dist/web/plugin/transform-data-llm.test.js +0 -81
  346. package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
  347. package/dist/web/plugin/validate-view.d.ts +0 -1
  348. package/dist/web/plugin/validate-view.js.map +0 -1
  349. package/dist/web/plugin/validate-view.test.js.map +0 -1
  350. /package/dist/{web/hooks/use-layout.test.d.ts → cli/build-steps.test.d.ts} +0 -0
  351. /package/dist/{web/plugin/data-llm.test.d.ts → context-warnings.test.d.ts} +0 -0
  352. /package/dist/{web/plugin/scan-views.test.d.ts → server/app.test.d.ts} +0 -0
  353. /package/dist/{web/plugin/validate-view.test.d.ts → server/auth/providers/authplane.test.d.ts} +0 -0
  354. /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
  355. /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
  356. /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
  357. /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
@@ -0,0 +1,99 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { authToSecuritySchemes, clientPrefersInBandChallenge, evaluateSecuritySchemes, securitySchemesAllowAnonymous, wwwAuthenticateHeader, } from "./security-schemes.js";
3
+ describe("clientPrefersInBandChallenge", () => {
4
+ it("detects ChatGPT / OpenAI user agents", () => {
5
+ expect(clientPrefersInBandChallenge("openai-mcp/1.0")).toBe(true);
6
+ expect(clientPrefersInBandChallenge("ChatGPT")).toBe(true);
7
+ expect(clientPrefersInBandChallenge("Claude-User/1.0")).toBe(false);
8
+ expect(clientPrefersInBandChallenge(undefined)).toBe(false);
9
+ });
10
+ });
11
+ describe("authToSecuritySchemes", () => {
12
+ it("maps the auth shorthand", () => {
13
+ expect(authToSecuritySchemes({ allowsAnonymous: true })).toEqual([
14
+ { type: "noauth" },
15
+ { type: "oauth2" },
16
+ ]);
17
+ expect(authToSecuritySchemes({})).toEqual([{ type: "oauth2" }]);
18
+ expect(authToSecuritySchemes({ scopes: ["checkout"] })).toEqual([
19
+ { type: "oauth2", scopes: ["checkout"] },
20
+ ]);
21
+ expect(authToSecuritySchemes({ allowsAnonymous: true, scopes: ["checkout"] })).toEqual([{ type: "noauth" }, { type: "oauth2", scopes: ["checkout"] }]);
22
+ });
23
+ });
24
+ const authInfo = (scopes) => ({
25
+ token: "t",
26
+ clientId: "c",
27
+ scopes,
28
+ });
29
+ describe("securitySchemesAllowAnonymous", () => {
30
+ it("is true only when a noauth scheme is present", () => {
31
+ expect(securitySchemesAllowAnonymous([{ type: "noauth" }])).toBe(true);
32
+ expect(securitySchemesAllowAnonymous([{ type: "noauth" }, { type: "oauth2" }])).toBe(true);
33
+ expect(securitySchemesAllowAnonymous([{ type: "oauth2" }])).toBe(false);
34
+ expect(securitySchemesAllowAnonymous(undefined)).toBe(false);
35
+ });
36
+ });
37
+ describe("evaluateSecuritySchemes", () => {
38
+ it("lets anonymous callers through a noauth tool", () => {
39
+ const schemes = [{ type: "noauth" }, { type: "oauth2" }];
40
+ expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();
41
+ });
42
+ it("enforces oauth2 scopes on a public tool once a token is present", () => {
43
+ const schemes = [
44
+ { type: "noauth" },
45
+ { type: "oauth2", scopes: ["checkout"] },
46
+ ];
47
+ expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();
48
+ expect(evaluateSecuritySchemes(schemes, authInfo(["openid"]))?.error).toBe("insufficient_scope");
49
+ expect(evaluateSecuritySchemes(schemes, authInfo(["checkout"]))).toBeUndefined();
50
+ });
51
+ it("fails an oauth2-only tool with no token (invalid_token / 401)", () => {
52
+ expect(evaluateSecuritySchemes([{ type: "oauth2" }], undefined)?.error).toBe("invalid_token");
53
+ });
54
+ it("fails when the token is missing a required scope (insufficient_scope / 403)", () => {
55
+ const schemes = [
56
+ { type: "oauth2", scopes: ["checkout"] },
57
+ ];
58
+ expect(evaluateSecuritySchemes(schemes, authInfo(["openid"]))?.error).toBe("insufficient_scope");
59
+ });
60
+ it("passes when the token carries every required scope", () => {
61
+ const schemes = [
62
+ { type: "oauth2", scopes: ["checkout"] },
63
+ ];
64
+ expect(evaluateSecuritySchemes(schemes, authInfo(["openid", "checkout"]))).toBeUndefined();
65
+ });
66
+ it("treats an undeclared tool as auth-required, satisfied by any valid token", () => {
67
+ expect(evaluateSecuritySchemes(undefined, undefined)?.error).toBe("invalid_token");
68
+ expect(evaluateSecuritySchemes(undefined, authInfo([]))).toBeUndefined();
69
+ });
70
+ it("carries the tool's required scopes on the failure", () => {
71
+ const schemes = [
72
+ { type: "oauth2", scopes: ["checkout"] },
73
+ ];
74
+ expect(evaluateSecuritySchemes(schemes, undefined)?.scopes).toEqual([
75
+ "checkout",
76
+ ]);
77
+ expect(evaluateSecuritySchemes(schemes, authInfo(["openid"]))?.scopes).toEqual(["checkout"]);
78
+ });
79
+ });
80
+ describe("wwwAuthenticateHeader", () => {
81
+ it("names the required scopes so the client can step up", () => {
82
+ const header = wwwAuthenticateHeader({
83
+ error: "insufficient_scope",
84
+ description: "Missing required scope for this tool.",
85
+ scopes: ["checkout"],
86
+ });
87
+ expect(header).toContain('error="insufficient_scope"');
88
+ expect(header).toContain('scope="checkout"');
89
+ });
90
+ it("omits the scope parameter when there are none", () => {
91
+ const header = wwwAuthenticateHeader({
92
+ error: "invalid_token",
93
+ description: "Sign in to use this tool.",
94
+ scopes: [],
95
+ });
96
+ expect(header).not.toContain("scope=");
97
+ });
98
+ });
99
+ //# sourceMappingURL=security-schemes.test.js.map
@@ -0,0 +1 @@
1
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CAAC;AAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,MAAM,GAAG,qBAAqB,CAAC;YACnC,KAAK,EAAE,oBAAoB;YAC3B,WAAW,EAAE,uCAAuC;YACpD,MAAM,EAAE,CAAC,UAAU,CAAC;SACrB,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QACvD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,MAAM,GAAG,qBAAqB,CAAC;YACnC,KAAK,EAAE,eAAe;YACtB,WAAW,EAAE,2BAA2B;YACxC,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport type { AuthInfo } from \"../auth.js\";\nimport type { SecurityScheme } from \"../server.js\";\nimport {\n authToSecuritySchemes,\n clientPrefersInBandChallenge,\n evaluateSecuritySchemes,\n securitySchemesAllowAnonymous,\n wwwAuthenticateHeader,\n} from \"./security-schemes.js\";\n\ndescribe(\"clientPrefersInBandChallenge\", () => {\n it(\"detects ChatGPT / OpenAI user agents\", () => {\n expect(clientPrefersInBandChallenge(\"openai-mcp/1.0\")).toBe(true);\n expect(clientPrefersInBandChallenge(\"ChatGPT\")).toBe(true);\n expect(clientPrefersInBandChallenge(\"Claude-User/1.0\")).toBe(false);\n expect(clientPrefersInBandChallenge(undefined)).toBe(false);\n });\n});\n\ndescribe(\"authToSecuritySchemes\", () => {\n it(\"maps the auth shorthand\", () => {\n expect(authToSecuritySchemes({ allowsAnonymous: true })).toEqual([\n { type: \"noauth\" },\n { type: \"oauth2\" },\n ]);\n expect(authToSecuritySchemes({})).toEqual([{ type: \"oauth2\" }]);\n expect(authToSecuritySchemes({ scopes: [\"checkout\"] })).toEqual([\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ]);\n expect(\n authToSecuritySchemes({ allowsAnonymous: true, scopes: [\"checkout\"] }),\n ).toEqual([{ type: \"noauth\" }, { type: \"oauth2\", scopes: [\"checkout\"] }]);\n });\n});\n\nconst authInfo = (scopes: string[]): AuthInfo => ({\n token: \"t\",\n clientId: \"c\",\n scopes,\n});\n\ndescribe(\"securitySchemesAllowAnonymous\", () => {\n it(\"is true only when a noauth scheme is present\", () => {\n expect(securitySchemesAllowAnonymous([{ type: \"noauth\" }])).toBe(true);\n expect(\n securitySchemesAllowAnonymous([{ type: \"noauth\" }, { type: \"oauth2\" }]),\n ).toBe(true);\n expect(securitySchemesAllowAnonymous([{ type: \"oauth2\" }])).toBe(false);\n expect(securitySchemesAllowAnonymous(undefined)).toBe(false);\n });\n});\n\ndescribe(\"evaluateSecuritySchemes\", () => {\n it(\"lets anonymous callers through a noauth tool\", () => {\n const schemes: SecurityScheme[] = [{ type: \"noauth\" }, { type: \"oauth2\" }];\n expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();\n });\n\n it(\"enforces oauth2 scopes on a public tool once a token is present\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"noauth\" },\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();\n expect(evaluateSecuritySchemes(schemes, authInfo([\"openid\"]))?.error).toBe(\n \"insufficient_scope\",\n );\n expect(\n evaluateSecuritySchemes(schemes, authInfo([\"checkout\"])),\n ).toBeUndefined();\n });\n\n it(\"fails an oauth2-only tool with no token (invalid_token / 401)\", () => {\n expect(\n evaluateSecuritySchemes([{ type: \"oauth2\" }], undefined)?.error,\n ).toBe(\"invalid_token\");\n });\n\n it(\"fails when the token is missing a required scope (insufficient_scope / 403)\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(evaluateSecuritySchemes(schemes, authInfo([\"openid\"]))?.error).toBe(\n \"insufficient_scope\",\n );\n });\n\n it(\"passes when the token carries every required scope\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(\n evaluateSecuritySchemes(schemes, authInfo([\"openid\", \"checkout\"])),\n ).toBeUndefined();\n });\n\n it(\"treats an undeclared tool as auth-required, satisfied by any valid token\", () => {\n expect(evaluateSecuritySchemes(undefined, undefined)?.error).toBe(\n \"invalid_token\",\n );\n expect(evaluateSecuritySchemes(undefined, authInfo([]))).toBeUndefined();\n });\n\n it(\"carries the tool's required scopes on the failure\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(evaluateSecuritySchemes(schemes, undefined)?.scopes).toEqual([\n \"checkout\",\n ]);\n expect(\n evaluateSecuritySchemes(schemes, authInfo([\"openid\"]))?.scopes,\n ).toEqual([\"checkout\"]);\n });\n});\n\ndescribe(\"wwwAuthenticateHeader\", () => {\n it(\"names the required scopes so the client can step up\", () => {\n const header = wwwAuthenticateHeader({\n error: \"insufficient_scope\",\n description: \"Missing required scope for this tool.\",\n scopes: [\"checkout\"],\n });\n expect(header).toContain('error=\"insufficient_scope\"');\n expect(header).toContain('scope=\"checkout\"');\n });\n\n it(\"omits the scope parameter when there are none\", () => {\n const header = wwwAuthenticateHeader({\n error: \"invalid_token\",\n description: \"Sign in to use this tool.\",\n scopes: [],\n });\n expect(header).not.toContain(\"scope=\");\n });\n});\n"]}
@@ -1,4 +1,6 @@
1
1
  import type { Express } from "express";
2
+ import type { SecurityScheme } from "../server.js";
2
3
  import type { OAuthConfig } from "./index.js";
4
+ export type ResourceMetadataUrlResolver = (getHeader: (key: string) => string | undefined) => string;
3
5
  /** Mounts the well-known OAuth metadata and bearer auth on `/mcp`. */
4
- export declare function setupOAuth(app: Express, config: OAuthConfig): void;
6
+ export declare function setupOAuth(app: Express, config: OAuthConfig<Record<string, unknown>>, schemesByTool: ReadonlyMap<string, SecurityScheme[] | undefined>): ResourceMetadataUrlResolver;
@@ -1,14 +1,21 @@
1
- import { getOAuthProtectedResourceMetadataUrl, mcpAuthMetadataRouter, } from "@modelcontextprotocol/sdk/server/auth/router.js";
1
+ import { getOAuthProtectedResourceMetadataUrl, mcpAuthMetadataRouter, } from "@modelcontextprotocol/express";
2
2
  import cors from "cors";
3
- import { requireBearerAuth } from "../auth.js";
3
+ import { optionalBearerAuth, requireBearerAuth } from "../auth.js";
4
4
  import { resolveServerOrigin } from "../requestOrigin.js";
5
- import { createJwksVerifier } from "./verify.js";
5
+ import { clientPrefersInBandChallenge, evaluateSecuritySchemes, httpStatusForFailure, inBandChallengeResult, securitySchemesAllowAnonymous, wwwAuthenticateHeader, } from "./security-schemes.js";
6
6
  /** Mounts the well-known OAuth metadata and bearer auth on `/mcp`. */
7
- export function setupOAuth(app, config) {
8
- if (!config.verify?.issuer) {
9
- throw new Error("oauth.verify requires an `issuer`");
7
+ export function setupOAuth(app, config, schemesByTool) {
8
+ if (!config.verifier) {
9
+ throw new Error("oauth requires a `verifier`");
10
10
  }
11
- const verifier = createJwksVerifier(config.verify);
11
+ const acceptsAnonymous = () => [...schemesByTool.values()].some(securitySchemesAllowAnonymous);
12
+ const verifier = config.verifier;
13
+ const bearer = (options) => {
14
+ const required = requireBearerAuth(options);
15
+ const optional = optionalBearerAuth(options);
16
+ return (req, res, next) => (acceptsAnonymous() ? optional : required)(req, res, next);
17
+ };
18
+ let resourceMetadataUrl;
12
19
  // baseUrl known at boot: bake the resource URLs once, no Host-header trust.
13
20
  if (config.baseUrl !== undefined) {
14
21
  let baseUrl;
@@ -23,29 +30,62 @@ export function setupOAuth(app, config) {
23
30
  resourceServerUrl: baseUrl,
24
31
  scopesSupported: config.scopesSupported,
25
32
  }));
26
- app.use("/mcp", requireBearerAuth({
27
- verifier,
28
- requiredScopes: config.requiredScopes,
29
- resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(baseUrl),
30
- }));
31
- return;
33
+ const url = getOAuthProtectedResourceMetadataUrl(baseUrl);
34
+ resourceMetadataUrl = () => url;
32
35
  }
33
- // No baseUrl: resolve the resource origin per request from forwarded headers
34
- // (same precedence the framework uses for view serverUrl). Origin headers are
35
- // pathless, so the PRM path stays at root, matching the SDK's static layout.
36
- const resolveOrigin = (req) => new URL(resolveServerOrigin((key) => req.get(key)));
37
- app.use("/.well-known/oauth-authorization-server", cors(), (_req, res) => void res.json(config.oauthMetadata));
38
- app.use("/.well-known/oauth-protected-resource", cors(), (req, res) => {
39
- res.json({
40
- resource: resolveOrigin(req).href,
41
- authorization_servers: [config.oauthMetadata.issuer],
42
- scopes_supported: config.scopesSupported,
36
+ else {
37
+ // No baseUrl: resolve the resource origin per request from forwarded headers
38
+ // (same precedence the framework uses for view serverUrl). Origin headers are
39
+ // pathless, so the PRM path stays at root, matching the SDK's static layout.
40
+ const resolveOrigin = (getHeader) => new URL(resolveServerOrigin(getHeader));
41
+ app.use("/.well-known/oauth-authorization-server", cors(), (_req, res) => void res.json(config.oauthMetadata));
42
+ app.use("/.well-known/oauth-protected-resource", cors(), (req, res) => {
43
+ res.json({
44
+ resource: resolveOrigin((key) => req.get(key)).href,
45
+ authorization_servers: [config.oauthMetadata.issuer],
46
+ scopes_supported: config.scopesSupported,
47
+ });
43
48
  });
44
- });
45
- app.use("/mcp", (req, res, next) => requireBearerAuth({
49
+ resourceMetadataUrl = (getHeader) => getOAuthProtectedResourceMetadataUrl(resolveOrigin(getHeader));
50
+ }
51
+ app.use("/mcp", (req, res, next) => bearer({
46
52
  verifier,
47
53
  requiredScopes: config.requiredScopes,
48
- resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(resolveOrigin(req)),
54
+ resourceMetadataUrl: resourceMetadataUrl((key) => req.get(key)),
49
55
  })(req, res, next));
56
+ app.use("/mcp", (req, res, next) => {
57
+ const body = req.body;
58
+ const calls = Array.isArray(body) ? body : [body];
59
+ const auth = req.auth;
60
+ let failure;
61
+ for (const call of calls) {
62
+ const tool = call?.params?.name;
63
+ if (call?.method === "tools/call" && tool && schemesByTool.has(tool)) {
64
+ failure = evaluateSecuritySchemes(schemesByTool.get(tool), auth);
65
+ if (failure) {
66
+ break;
67
+ }
68
+ }
69
+ }
70
+ if (!failure) {
71
+ return next();
72
+ }
73
+ const url = resourceMetadataUrl((key) => req.get(key));
74
+ if (!Array.isArray(body) &&
75
+ clientPrefersInBandChallenge(req.get("user-agent"))) {
76
+ res.json({
77
+ jsonrpc: "2.0",
78
+ id: body?.id ?? null,
79
+ result: inBandChallengeResult(failure, url),
80
+ });
81
+ return;
82
+ }
83
+ res.set("WWW-Authenticate", wwwAuthenticateHeader(failure, url));
84
+ res.status(httpStatusForFailure(failure)).json({
85
+ error: failure.error,
86
+ error_description: failure.description,
87
+ });
88
+ });
89
+ return resourceMetadataUrl;
50
90
  }
51
91
  //# sourceMappingURL=setup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/server/auth/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oCAAoC,EACpC,qBAAqB,GACtB,MAAM,iDAAiD,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,sEAAsE;AACtE,MAAM,UAAU,UAAU,CAAC,GAAY,EAAE,MAAmB;IAC1D,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,QAAQ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IAAI,CAAC;YACP,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI;YACjC,qBAAqB,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;YACpD,gBAAgB,EAAE,MAAM,CAAC,eAAe;SACzC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CACjC,iBAAiB,CAAC;QAChB,QAAQ;QACR,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,mBAAmB,EAAE,oCAAoC,CACvD,aAAa,CAAC,GAAG,CAAC,CACnB;KACF,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CACnB,CAAC;AACJ,CAAC","sourcesContent":["import {\n getOAuthProtectedResourceMetadataUrl,\n mcpAuthMetadataRouter,\n} from \"@modelcontextprotocol/sdk/server/auth/router.js\";\nimport cors from \"cors\";\nimport type { Express, Request } from \"express\";\nimport { requireBearerAuth } from \"../auth.js\";\nimport { resolveServerOrigin } from \"../requestOrigin.js\";\nimport type { OAuthConfig } from \"./index.js\";\nimport { createJwksVerifier } from \"./verify.js\";\n\n/** Mounts the well-known OAuth metadata and bearer auth on `/mcp`. */\nexport function setupOAuth(app: Express, config: OAuthConfig): void {\n if (!config.verify?.issuer) {\n throw new Error(\"oauth.verify requires an `issuer`\");\n }\n\n const verifier = createJwksVerifier(config.verify);\n\n // baseUrl known at boot: bake the resource URLs once, no Host-header trust.\n if (config.baseUrl !== undefined) {\n let baseUrl: URL;\n try {\n baseUrl = new URL(config.baseUrl);\n } catch {\n throw new Error(\n `oauth.baseUrl must be a valid absolute URL, got: ${JSON.stringify(\n config.baseUrl,\n )}`,\n );\n }\n app.use(\n mcpAuthMetadataRouter({\n oauthMetadata: config.oauthMetadata,\n resourceServerUrl: baseUrl,\n scopesSupported: config.scopesSupported,\n }),\n );\n app.use(\n \"/mcp\",\n requireBearerAuth({\n verifier,\n requiredScopes: config.requiredScopes,\n resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(baseUrl),\n }),\n );\n return;\n }\n\n // No baseUrl: resolve the resource origin per request from forwarded headers\n // (same precedence the framework uses for view serverUrl). Origin headers are\n // pathless, so the PRM path stays at root, matching the SDK's static layout.\n const resolveOrigin = (req: Request) =>\n new URL(resolveServerOrigin((key) => req.get(key)));\n\n app.use(\n \"/.well-known/oauth-authorization-server\",\n cors(),\n (_req, res) => void res.json(config.oauthMetadata),\n );\n app.use(\"/.well-known/oauth-protected-resource\", cors(), (req, res) => {\n res.json({\n resource: resolveOrigin(req).href,\n authorization_servers: [config.oauthMetadata.issuer],\n scopes_supported: config.scopesSupported,\n });\n });\n app.use(\"/mcp\", (req, res, next) =>\n requireBearerAuth({\n verifier,\n requiredScopes: config.requiredScopes,\n resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(\n resolveOrigin(req),\n ),\n })(req, res, next),\n );\n}\n"]}
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/server/auth/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oCAAoC,EACpC,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EAErB,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAM/B,sEAAsE;AACtE,MAAM,UAAU,UAAU,CACxB,GAAY,EACZ,MAA4C,EAC5C,aAAgE;IAEhE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACjD,CAA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QACjE,GAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;YAC7C,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,iBAAiB,EAAE,OAAO,CAAC,WAAW;SACvC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import {\n type BearerAuthMiddlewareOptions,\n getOAuthProtectedResourceMetadataUrl,\n mcpAuthMetadataRouter,\n} from \"@modelcontextprotocol/express\";\nimport cors from \"cors\";\nimport type { Express, Request, RequestHandler } from \"express\";\nimport type { AuthInfo } from \"../auth.js\";\nimport { optionalBearerAuth, requireBearerAuth } from \"../auth.js\";\nimport { resolveServerOrigin } from \"../requestOrigin.js\";\nimport type { SecurityScheme } from \"../server.js\";\nimport type { OAuthConfig } from \"./index.js\";\nimport {\n clientPrefersInBandChallenge,\n evaluateSecuritySchemes,\n httpStatusForFailure,\n inBandChallengeResult,\n type SchemeFailure,\n securitySchemesAllowAnonymous,\n wwwAuthenticateHeader,\n} from \"./security-schemes.js\";\n\nexport type ResourceMetadataUrlResolver = (\n getHeader: (key: string) => string | undefined,\n) => string;\n\n/** Mounts the well-known OAuth metadata and bearer auth on `/mcp`. */\nexport function setupOAuth(\n app: Express,\n config: OAuthConfig<Record<string, unknown>>,\n schemesByTool: ReadonlyMap<string, SecurityScheme[] | undefined>,\n): ResourceMetadataUrlResolver {\n if (!config.verifier) {\n throw new Error(\"oauth requires a `verifier`\");\n }\n\n const acceptsAnonymous = () =>\n [...schemesByTool.values()].some(securitySchemesAllowAnonymous);\n const verifier = config.verifier;\n const bearer = (options: BearerAuthMiddlewareOptions): RequestHandler => {\n const required = requireBearerAuth(options);\n const optional = optionalBearerAuth(options);\n return (req, res, next) =>\n (acceptsAnonymous() ? optional : required)(req, res, next);\n };\n\n let resourceMetadataUrl: ResourceMetadataUrlResolver;\n\n // baseUrl known at boot: bake the resource URLs once, no Host-header trust.\n if (config.baseUrl !== undefined) {\n let baseUrl: URL;\n try {\n baseUrl = new URL(config.baseUrl);\n } catch {\n throw new Error(\n `oauth.baseUrl must be a valid absolute URL, got: ${JSON.stringify(\n config.baseUrl,\n )}`,\n );\n }\n app.use(\n mcpAuthMetadataRouter({\n oauthMetadata: config.oauthMetadata,\n resourceServerUrl: baseUrl,\n scopesSupported: config.scopesSupported,\n }),\n );\n const url = getOAuthProtectedResourceMetadataUrl(baseUrl);\n resourceMetadataUrl = () => url;\n } else {\n // No baseUrl: resolve the resource origin per request from forwarded headers\n // (same precedence the framework uses for view serverUrl). Origin headers are\n // pathless, so the PRM path stays at root, matching the SDK's static layout.\n const resolveOrigin = (getHeader: (key: string) => string | undefined) =>\n new URL(resolveServerOrigin(getHeader));\n app.use(\n \"/.well-known/oauth-authorization-server\",\n cors(),\n (_req, res) => void res.json(config.oauthMetadata),\n );\n app.use(\"/.well-known/oauth-protected-resource\", cors(), (req, res) => {\n res.json({\n resource: resolveOrigin((key) => req.get(key)).href,\n authorization_servers: [config.oauthMetadata.issuer],\n scopes_supported: config.scopesSupported,\n });\n });\n resourceMetadataUrl = (getHeader) =>\n getOAuthProtectedResourceMetadataUrl(resolveOrigin(getHeader));\n }\n\n app.use(\"/mcp\", (req, res, next) =>\n bearer({\n verifier,\n requiredScopes: config.requiredScopes,\n resourceMetadataUrl: resourceMetadataUrl((key) => req.get(key)),\n })(req, res, next),\n );\n\n app.use(\"/mcp\", (req, res, next) => {\n type Call = {\n id?: string | number | null;\n method?: string;\n params?: { name?: string };\n };\n const body = req.body as Call | Call[] | undefined;\n const calls = Array.isArray(body) ? body : [body];\n const auth = (req as Request & { auth?: AuthInfo }).auth;\n let failure: SchemeFailure | undefined;\n for (const call of calls) {\n const tool = call?.params?.name;\n if (call?.method === \"tools/call\" && tool && schemesByTool.has(tool)) {\n failure = evaluateSecuritySchemes(schemesByTool.get(tool), auth);\n if (failure) {\n break;\n }\n }\n }\n if (!failure) {\n return next();\n }\n const url = resourceMetadataUrl((key) => req.get(key));\n if (\n !Array.isArray(body) &&\n clientPrefersInBandChallenge(req.get(\"user-agent\"))\n ) {\n res.json({\n jsonrpc: \"2.0\",\n id: body?.id ?? null,\n result: inBandChallengeResult(failure, url),\n });\n return;\n }\n res.set(\"WWW-Authenticate\", wwwAuthenticateHeader(failure, url));\n res.status(httpStatusForFailure(failure)).json({\n error: failure.error,\n error_description: failure.description,\n });\n });\n\n return resourceMetadataUrl;\n}\n"]}