@1mcp/agent 0.39.0-beta.3 → 0.39.0-beta.4

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 (391) hide show
  1. package/build/admin/assets/{admin-OAuthServicesWorkspace-D_GlqLxL.js → admin-OAuthServicesWorkspace-CKR1HA-8.js} +1 -1
  2. package/build/admin/assets/{admin-console-CMRxMjQo.js → admin-console-OfHKqRm-.js} +3 -3
  3. package/build/admin/index.html +1 -1
  4. package/build/auth/oauthAuthority.d.ts +149 -0
  5. package/build/auth/oauthAuthority.d.ts.map +1 -0
  6. package/build/auth/oauthAuthority.js +101 -0
  7. package/build/auth/oauthAuthority.js.map +1 -0
  8. package/build/auth/oauthAuthorizationFlow.d.ts +7 -1
  9. package/build/auth/oauthAuthorizationFlow.d.ts.map +1 -1
  10. package/build/auth/oauthAuthorizationFlow.js +60 -74
  11. package/build/auth/oauthAuthorizationFlow.js.map +1 -1
  12. package/build/auth/oauthEndpointFetch.d.ts +20 -0
  13. package/build/auth/oauthEndpointFetch.d.ts.map +1 -0
  14. package/build/auth/oauthEndpointFetch.js +246 -0
  15. package/build/auth/oauthEndpointFetch.js.map +1 -0
  16. package/build/auth/sessionTypes.d.ts +1 -1
  17. package/build/auth/storage/clientSessionRepository.d.ts +19 -0
  18. package/build/auth/storage/clientSessionRepository.d.ts.map +1 -1
  19. package/build/auth/storage/clientSessionRepository.js +178 -0
  20. package/build/auth/storage/clientSessionRepository.js.map +1 -1
  21. package/build/auth/storage/fileStorageService.d.ts +9 -1
  22. package/build/auth/storage/fileStorageService.d.ts.map +1 -1
  23. package/build/auth/storage/fileStorageService.js +32 -5
  24. package/build/auth/storage/fileStorageService.js.map +1 -1
  25. package/build/auth/storage/inboundOAuthStorage.d.ts +14 -0
  26. package/build/auth/storage/inboundOAuthStorage.d.ts.map +1 -0
  27. package/build/auth/storage/inboundOAuthStorage.js +29 -0
  28. package/build/auth/storage/inboundOAuthStorage.js.map +1 -0
  29. package/build/auth/storage/nativeCredentialStore.d.ts +44 -0
  30. package/build/auth/storage/nativeCredentialStore.d.ts.map +1 -0
  31. package/build/auth/storage/nativeCredentialStore.js +177 -0
  32. package/build/auth/storage/nativeCredentialStore.js.map +1 -0
  33. package/build/auth/storage/oauthStorageService.d.ts +8 -1
  34. package/build/auth/storage/oauthStorageService.d.ts.map +1 -1
  35. package/build/auth/storage/oauthStorageService.js +69 -47
  36. package/build/auth/storage/oauthStorageService.js.map +1 -1
  37. package/build/auth/storage/protectedRecordStorage.d.ts +129 -0
  38. package/build/auth/storage/protectedRecordStorage.d.ts.map +1 -0
  39. package/build/auth/storage/protectedRecordStorage.js +1139 -0
  40. package/build/auth/storage/protectedRecordStorage.js.map +1 -0
  41. package/build/auth/storage/sessionRepository.d.ts.map +1 -1
  42. package/build/auth/storage/sessionRepository.js +10 -0
  43. package/build/auth/storage/sessionRepository.js.map +1 -1
  44. package/build/auth/storage/upstreamOAuthStorage.d.ts +15 -0
  45. package/build/auth/storage/upstreamOAuthStorage.d.ts.map +1 -0
  46. package/build/auth/storage/upstreamOAuthStorage.js +25 -0
  47. package/build/auth/storage/upstreamOAuthStorage.js.map +1 -0
  48. package/build/auth/storage/upstreamOAuthStoragePath.d.ts +3 -0
  49. package/build/auth/storage/upstreamOAuthStoragePath.d.ts.map +1 -0
  50. package/build/auth/storage/upstreamOAuthStoragePath.js +8 -0
  51. package/build/auth/storage/upstreamOAuthStoragePath.js.map +1 -0
  52. package/build/commands/auth/exportOAuthCredentials.d.ts +9 -0
  53. package/build/commands/auth/exportOAuthCredentials.d.ts.map +1 -0
  54. package/build/commands/auth/exportOAuthCredentials.js +71 -0
  55. package/build/commands/auth/exportOAuthCredentials.js.map +1 -0
  56. package/build/commands/auth/exportUpstreamCredentials.d.ts +5 -0
  57. package/build/commands/auth/exportUpstreamCredentials.d.ts.map +1 -0
  58. package/build/commands/auth/exportUpstreamCredentials.js +6 -0
  59. package/build/commands/auth/exportUpstreamCredentials.js.map +1 -0
  60. package/build/commands/auth/index.d.ts.map +1 -1
  61. package/build/commands/auth/index.js +23 -1
  62. package/build/commands/auth/index.js.map +1 -1
  63. package/build/commands/inspect/inspectUtils.d.ts.map +1 -1
  64. package/build/commands/inspect/inspectUtils.js +2 -3
  65. package/build/commands/inspect/inspectUtils.js.map +1 -1
  66. package/build/commands/run/runUtils.js +2 -2
  67. package/build/commands/run/runUtils.js.map +1 -1
  68. package/build/commands/serve/index.d.ts +5 -0
  69. package/build/commands/serve/index.d.ts.map +1 -1
  70. package/build/commands/serve/index.js +5 -0
  71. package/build/commands/serve/index.js.map +1 -1
  72. package/build/commands/serve/serveBackground.d.ts.map +1 -1
  73. package/build/commands/serve/serveBackground.js +1 -0
  74. package/build/commands/serve/serveBackground.js.map +1 -1
  75. package/build/config/configLoader.d.ts.map +1 -1
  76. package/build/config/configLoader.js +13 -0
  77. package/build/config/configLoader.js.map +1 -1
  78. package/build/config/configManager.d.ts.map +1 -1
  79. package/build/config/configManager.js +44 -2
  80. package/build/config/configManager.js.map +1 -1
  81. package/build/config/configWatcher.d.ts.map +1 -1
  82. package/build/config/configWatcher.js +3 -1
  83. package/build/config/configWatcher.js.map +1 -1
  84. package/build/config/envProcessor.d.ts.map +1 -1
  85. package/build/config/envProcessor.js +3 -1
  86. package/build/config/envProcessor.js.map +1 -1
  87. package/build/config/mcpConfigManager.d.ts.map +1 -1
  88. package/build/config/mcpConfigManager.js +4 -1
  89. package/build/config/mcpConfigManager.js.map +1 -1
  90. package/build/config/projectConfigLoader.d.ts.map +1 -1
  91. package/build/config/projectConfigLoader.js +7 -0
  92. package/build/config/projectConfigLoader.js.map +1 -1
  93. package/build/constants/mcp.d.ts +1 -1
  94. package/build/constants/mcp.js +1 -1
  95. package/build/core/capabilities/asyncLoadingOrchestrator.d.ts.map +1 -1
  96. package/build/core/capabilities/asyncLoadingOrchestrator.js +31 -2
  97. package/build/core/capabilities/asyncLoadingOrchestrator.js.map +1 -1
  98. package/build/core/capabilities/capabilityAggregator.d.ts +3 -1
  99. package/build/core/capabilities/capabilityAggregator.d.ts.map +1 -1
  100. package/build/core/capabilities/capabilityAggregator.js +9 -2
  101. package/build/core/capabilities/capabilityAggregator.js.map +1 -1
  102. package/build/core/capabilities/capabilityCatalog.d.ts +24 -1
  103. package/build/core/capabilities/capabilityCatalog.d.ts.map +1 -1
  104. package/build/core/capabilities/capabilityCatalog.js +410 -39
  105. package/build/core/capabilities/capabilityCatalog.js.map +1 -1
  106. package/build/core/capabilities/capabilityPagination.d.ts +18 -1
  107. package/build/core/capabilities/capabilityPagination.d.ts.map +1 -1
  108. package/build/core/capabilities/capabilityPagination.js +101 -15
  109. package/build/core/capabilities/capabilityPagination.js.map +1 -1
  110. package/build/core/capabilities/capabilityVisibility.d.ts +13 -1
  111. package/build/core/capabilities/capabilityVisibility.d.ts.map +1 -1
  112. package/build/core/capabilities/capabilityVisibility.js +24 -1
  113. package/build/core/capabilities/capabilityVisibility.js.map +1 -1
  114. package/build/core/capabilities/catalogGeneration.d.ts.map +1 -1
  115. package/build/core/capabilities/catalogGeneration.js +20 -1
  116. package/build/core/capabilities/catalogGeneration.js.map +1 -1
  117. package/build/core/capabilities/configuredToolSnapshot.d.ts +1 -0
  118. package/build/core/capabilities/configuredToolSnapshot.d.ts.map +1 -1
  119. package/build/core/capabilities/configuredToolSnapshot.js +30 -4
  120. package/build/core/capabilities/configuredToolSnapshot.js.map +1 -1
  121. package/build/core/capabilities/lazyLoadingOrchestrator.d.ts +2 -0
  122. package/build/core/capabilities/lazyLoadingOrchestrator.d.ts.map +1 -1
  123. package/build/core/capabilities/lazyLoadingOrchestrator.js +20 -4
  124. package/build/core/capabilities/lazyLoadingOrchestrator.js.map +1 -1
  125. package/build/core/capabilities/metaToolProvider.d.ts +3 -1
  126. package/build/core/capabilities/metaToolProvider.d.ts.map +1 -1
  127. package/build/core/capabilities/metaToolProvider.js +42 -4
  128. package/build/core/capabilities/metaToolProvider.js.map +1 -1
  129. package/build/core/capabilities/runtimeCapabilityCatalog.d.ts +15 -2
  130. package/build/core/capabilities/runtimeCapabilityCatalog.d.ts.map +1 -1
  131. package/build/core/capabilities/runtimeCapabilityCatalog.js +153 -16
  132. package/build/core/capabilities/runtimeCapabilityCatalog.js.map +1 -1
  133. package/build/core/capabilities/schemaCache.d.ts.map +1 -1
  134. package/build/core/capabilities/schemaCache.js +41 -0
  135. package/build/core/capabilities/schemaCache.js.map +1 -1
  136. package/build/core/capabilities/schemas/metaToolSchemas.d.ts +1 -0
  137. package/build/core/capabilities/schemas/metaToolSchemas.d.ts.map +1 -1
  138. package/build/core/capabilities/schemas/metaToolSchemas.js +1 -0
  139. package/build/core/capabilities/schemas/metaToolSchemas.js.map +1 -1
  140. package/build/core/capabilities/toolRegistry.d.ts +7 -3
  141. package/build/core/capabilities/toolRegistry.d.ts.map +1 -1
  142. package/build/core/capabilities/toolRegistry.js +28 -9
  143. package/build/core/capabilities/toolRegistry.js.map +1 -1
  144. package/build/core/instructions/instructionAggregator.d.ts.map +1 -1
  145. package/build/core/instructions/instructionAggregator.js +3 -1
  146. package/build/core/instructions/instructionAggregator.js.map +1 -1
  147. package/build/core/instructions/templateTypes.d.ts +1 -1
  148. package/build/core/instructions/templateTypes.d.ts.map +1 -1
  149. package/build/core/instructions/templateTypes.js +3 -3
  150. package/build/core/loading/loadingStateTracker.d.ts.map +1 -1
  151. package/build/core/loading/loadingStateTracker.js +11 -2
  152. package/build/core/loading/loadingStateTracker.js.map +1 -1
  153. package/build/core/loading/mcpLoadingManager.d.ts.map +1 -1
  154. package/build/core/loading/mcpLoadingManager.js +6 -2
  155. package/build/core/loading/mcpLoadingManager.js.map +1 -1
  156. package/build/core/protocol/requestHandlerUtils.d.ts +2 -2
  157. package/build/core/protocol/requestHandlerUtils.d.ts.map +1 -1
  158. package/build/core/protocol/requestHandlerUtils.js +7 -4
  159. package/build/core/protocol/requestHandlerUtils.js.map +1 -1
  160. package/build/core/server/agentConfig.d.ts +1 -0
  161. package/build/core/server/agentConfig.d.ts.map +1 -1
  162. package/build/core/server/agentConfig.js +1 -0
  163. package/build/core/server/agentConfig.js.map +1 -1
  164. package/build/core/server/disabledTools.d.ts +1 -1
  165. package/build/core/server/disabledTools.d.ts.map +1 -1
  166. package/build/core/server/disabledTools.js +18 -25
  167. package/build/core/server/disabledTools.js.map +1 -1
  168. package/build/core/server/processIdentity.d.ts.map +1 -1
  169. package/build/core/server/processIdentity.js +67 -18
  170. package/build/core/server/processIdentity.js.map +1 -1
  171. package/build/core/server/runtimeLaunchIpc.d.ts +14 -1
  172. package/build/core/server/runtimeLaunchIpc.d.ts.map +1 -1
  173. package/build/core/server/runtimeReplacementConfig.d.ts +14 -1
  174. package/build/core/server/runtimeReplacementConfig.d.ts.map +1 -1
  175. package/build/core/server/toolDescriptionOverrides.d.ts +1 -0
  176. package/build/core/server/toolDescriptionOverrides.d.ts.map +1 -1
  177. package/build/core/server/toolDescriptionOverrides.js +30 -5
  178. package/build/core/server/toolDescriptionOverrides.js.map +1 -1
  179. package/build/core/tools/handlers/serverManagementHandler.d.ts +21 -0
  180. package/build/core/tools/handlers/serverManagementHandler.d.ts.map +1 -1
  181. package/build/core/tools/internal/adapters/helpers/configTransformers.d.ts +3 -0
  182. package/build/core/tools/internal/adapters/helpers/configTransformers.d.ts.map +1 -1
  183. package/build/core/tools/internal/schemas/discovery.d.ts +1 -1
  184. package/build/core/tools/internal/schemas/index.d.ts +1 -1
  185. package/build/core/types/transport.d.ts +25 -2
  186. package/build/core/types/transport.d.ts.map +1 -1
  187. package/build/core/types/transport.js +12 -0
  188. package/build/core/types/transport.js.map +1 -1
  189. package/build/domains/admin/configuredToolInventory.d.ts.map +1 -1
  190. package/build/domains/admin/configuredToolInventory.js +47 -9
  191. package/build/domains/admin/configuredToolInventory.js.map +1 -1
  192. package/build/domains/admin/runtimeConfiguredToolInspectionService.d.ts.map +1 -1
  193. package/build/domains/admin/runtimeConfiguredToolInspectionService.js +13 -3
  194. package/build/domains/admin/runtimeConfiguredToolInspectionService.js.map +1 -1
  195. package/build/gateway/adapters/modern/modernInboundEraAdapter.d.ts.map +1 -1
  196. package/build/gateway/adapters/modern/modernInboundEraAdapter.js +3 -3
  197. package/build/gateway/adapters/modern/modernInboundEraAdapter.js.map +1 -1
  198. package/build/gateway/adapters/modern/modernOutboundEraAdapter.d.ts.map +1 -1
  199. package/build/gateway/adapters/modern/modernOutboundEraAdapter.js +4 -0
  200. package/build/gateway/adapters/modern/modernOutboundEraAdapter.js.map +1 -1
  201. package/build/gateway/contracts/gatewayFailure.d.ts +39 -1
  202. package/build/gateway/contracts/gatewayFailure.d.ts.map +1 -1
  203. package/build/gateway/contracts/gatewayFailure.js +139 -0
  204. package/build/gateway/contracts/gatewayFailure.js.map +1 -1
  205. package/build/gateway/interactions/nativeInputResponses.d.ts +16 -0
  206. package/build/gateway/interactions/nativeInputResponses.d.ts.map +1 -0
  207. package/build/gateway/interactions/nativeInputResponses.js +76 -0
  208. package/build/gateway/interactions/nativeInputResponses.js.map +1 -0
  209. package/build/gateway/interactions/validateInteractionResponse.d.ts.map +1 -1
  210. package/build/gateway/interactions/validateInteractionResponse.js +20 -1
  211. package/build/gateway/interactions/validateInteractionResponse.js.map +1 -1
  212. package/build/gateway/ports/outboundEraAdapter.d.ts +2 -0
  213. package/build/gateway/ports/outboundEraAdapter.d.ts.map +1 -1
  214. package/build/logger/diagnosticRedaction.d.ts +3 -0
  215. package/build/logger/diagnosticRedaction.d.ts.map +1 -0
  216. package/build/logger/diagnosticRedaction.js +12 -0
  217. package/build/logger/diagnosticRedaction.js.map +1 -0
  218. package/build/logger/httpDiagnostics.d.ts +25 -0
  219. package/build/logger/httpDiagnostics.d.ts.map +1 -0
  220. package/build/logger/httpDiagnostics.js +125 -0
  221. package/build/logger/httpDiagnostics.js.map +1 -0
  222. package/build/logger/localDiagnosticRecord.d.ts +11 -0
  223. package/build/logger/localDiagnosticRecord.d.ts.map +1 -0
  224. package/build/logger/localDiagnosticRecord.js +9 -0
  225. package/build/logger/localDiagnosticRecord.js.map +1 -0
  226. package/build/logger/localDiagnostics.d.ts +5 -0
  227. package/build/logger/localDiagnostics.d.ts.map +1 -0
  228. package/build/logger/localDiagnostics.js +116 -0
  229. package/build/logger/localDiagnostics.js.map +1 -0
  230. package/build/logger/logger.d.ts +7 -0
  231. package/build/logger/logger.d.ts.map +1 -1
  232. package/build/logger/logger.js +14 -0
  233. package/build/logger/logger.js.map +1 -1
  234. package/build/observability/events/registry.d.ts +163 -49
  235. package/build/observability/events/registry.d.ts.map +1 -1
  236. package/build/observability/events/registry.js +136 -49
  237. package/build/observability/events/registry.js.map +1 -1
  238. package/build/observability/privacy/fields.d.ts +3 -1
  239. package/build/observability/privacy/fields.d.ts.map +1 -1
  240. package/build/observability/privacy/fields.js +23 -0
  241. package/build/observability/privacy/fields.js.map +1 -1
  242. package/build/sdk/contracts/catalogCoverageInvalidation.d.ts +4 -0
  243. package/build/sdk/contracts/catalogCoverageInvalidation.d.ts.map +1 -0
  244. package/build/sdk/contracts/catalogCoverageInvalidation.js +13 -0
  245. package/build/sdk/contracts/catalogCoverageInvalidation.js.map +1 -0
  246. package/build/sdk/contracts/mcpParamHeaders.d.ts +17 -0
  247. package/build/sdk/contracts/mcpParamHeaders.d.ts.map +1 -0
  248. package/build/sdk/contracts/mcpParamHeaders.js +134 -0
  249. package/build/sdk/contracts/mcpParamHeaders.js.map +1 -0
  250. package/build/sdk/contracts/requestProgress.d.ts +29 -0
  251. package/build/sdk/contracts/requestProgress.d.ts.map +1 -0
  252. package/build/sdk/contracts/requestProgress.js +126 -0
  253. package/build/sdk/contracts/requestProgress.js.map +1 -0
  254. package/build/sdk/legacy/auth/sdkOAuthClientProvider.d.ts +77 -84
  255. package/build/sdk/legacy/auth/sdkOAuthClientProvider.d.ts.map +1 -1
  256. package/build/sdk/legacy/auth/sdkOAuthClientProvider.js +632 -209
  257. package/build/sdk/legacy/auth/sdkOAuthClientProvider.js.map +1 -1
  258. package/build/sdk/legacy/auth/sdkOAuthServerProvider.d.ts.map +1 -1
  259. package/build/sdk/legacy/auth/sdkOAuthServerProvider.js +25 -7
  260. package/build/sdk/legacy/auth/sdkOAuthServerProvider.js.map +1 -1
  261. package/build/sdk/legacy/client/runtime/clientManager.d.ts +5 -1
  262. package/build/sdk/legacy/client/runtime/clientManager.d.ts.map +1 -1
  263. package/build/sdk/legacy/client/runtime/clientManager.js +213 -6
  264. package/build/sdk/legacy/client/runtime/clientManager.js.map +1 -1
  265. package/build/sdk/legacy/client/runtime/connectionHandler.d.ts.map +1 -1
  266. package/build/sdk/legacy/client/runtime/connectionHandler.js +70 -4
  267. package/build/sdk/legacy/client/runtime/connectionHandler.js.map +1 -1
  268. package/build/sdk/legacy/client/runtime/legacyInteractionLease.d.ts +2 -1
  269. package/build/sdk/legacy/client/runtime/legacyInteractionLease.d.ts.map +1 -1
  270. package/build/sdk/legacy/client/runtime/legacyInteractionLease.js +11 -2
  271. package/build/sdk/legacy/client/runtime/legacyInteractionLease.js.map +1 -1
  272. package/build/sdk/legacy/client/runtime/legacySdkClientAdapter.d.ts.map +1 -1
  273. package/build/sdk/legacy/client/runtime/legacySdkClientAdapter.js +28 -2
  274. package/build/sdk/legacy/client/runtime/legacySdkClientAdapter.js.map +1 -1
  275. package/build/sdk/legacy/client/runtime/mcpParamHeaders.d.ts +2 -0
  276. package/build/sdk/legacy/client/runtime/mcpParamHeaders.d.ts.map +1 -0
  277. package/build/sdk/legacy/client/runtime/mcpParamHeaders.js +2 -0
  278. package/build/sdk/legacy/client/runtime/mcpParamHeaders.js.map +1 -0
  279. package/build/sdk/legacy/client/runtime/modernSdkClientAdapter.d.ts +6 -0
  280. package/build/sdk/legacy/client/runtime/modernSdkClientAdapter.d.ts.map +1 -1
  281. package/build/sdk/legacy/client/runtime/modernSdkClientAdapter.js +117 -6
  282. package/build/sdk/legacy/client/runtime/modernSdkClientAdapter.js.map +1 -1
  283. package/build/sdk/legacy/client/runtime/oauthFlowHandler.d.ts +1 -1
  284. package/build/sdk/legacy/client/runtime/oauthFlowHandler.d.ts.map +1 -1
  285. package/build/sdk/legacy/client/runtime/oauthFlowHandler.js +68 -16
  286. package/build/sdk/legacy/client/runtime/oauthFlowHandler.js.map +1 -1
  287. package/build/sdk/legacy/commands/serve.d.ts +1 -0
  288. package/build/sdk/legacy/commands/serve.d.ts.map +1 -1
  289. package/build/sdk/legacy/commands/serve.js +28 -2
  290. package/build/sdk/legacy/commands/serve.js.map +1 -1
  291. package/build/sdk/legacy/server/protocol/notificationHandlers.d.ts.map +1 -1
  292. package/build/sdk/legacy/server/protocol/notificationHandlers.js +2 -6
  293. package/build/sdk/legacy/server/protocol/notificationHandlers.js.map +1 -1
  294. package/build/sdk/legacy/server/protocol/privateInteractionConnection.d.ts +1 -1
  295. package/build/sdk/legacy/server/protocol/privateInteractionConnection.d.ts.map +1 -1
  296. package/build/sdk/legacy/server/protocol/privateInteractionConnection.js +31 -11
  297. package/build/sdk/legacy/server/protocol/privateInteractionConnection.js.map +1 -1
  298. package/build/sdk/legacy/server/protocol/promptRequestHandlers.d.ts.map +1 -1
  299. package/build/sdk/legacy/server/protocol/promptRequestHandlers.js +4 -4
  300. package/build/sdk/legacy/server/protocol/promptRequestHandlers.js.map +1 -1
  301. package/build/sdk/legacy/server/protocol/requestInteractionScope.d.ts.map +1 -1
  302. package/build/sdk/legacy/server/protocol/requestInteractionScope.js +62 -10
  303. package/build/sdk/legacy/server/protocol/requestInteractionScope.js.map +1 -1
  304. package/build/sdk/legacy/server/protocol/requestProviderProgress.d.ts +8 -0
  305. package/build/sdk/legacy/server/protocol/requestProviderProgress.d.ts.map +1 -0
  306. package/build/sdk/legacy/server/protocol/requestProviderProgress.js +29 -0
  307. package/build/sdk/legacy/server/protocol/requestProviderProgress.js.map +1 -0
  308. package/build/sdk/legacy/server/protocol/resourceRequestHandlers.d.ts.map +1 -1
  309. package/build/sdk/legacy/server/protocol/resourceRequestHandlers.js +20 -2
  310. package/build/sdk/legacy/server/protocol/resourceRequestHandlers.js.map +1 -1
  311. package/build/sdk/legacy/server/protocol/toolRequestHandlers.d.ts.map +1 -1
  312. package/build/sdk/legacy/server/protocol/toolRequestHandlers.js +151 -60
  313. package/build/sdk/legacy/server/protocol/toolRequestHandlers.js.map +1 -1
  314. package/build/sdk/legacy/server/retained-sdk/LICENSE +21 -0
  315. package/build/sdk/legacy/server/retained-sdk/provenance.json +17 -0
  316. package/build/sdk/legacy/server/retained-sdk/streamableHttp.js +160 -0
  317. package/build/sdk/legacy/server/retained-sdk/webStandardStreamableHttp.js +950 -0
  318. package/build/sdk/legacy/server/runtime/clientInstancePool.d.ts.map +1 -1
  319. package/build/sdk/legacy/server/runtime/clientInstancePool.js +34 -6
  320. package/build/sdk/legacy/server/runtime/clientInstancePool.js.map +1 -1
  321. package/build/sdk/legacy/server/runtime/mcpLoggingEnhancer.d.ts.map +1 -1
  322. package/build/sdk/legacy/server/runtime/mcpLoggingEnhancer.js +4 -2
  323. package/build/sdk/legacy/server/runtime/mcpLoggingEnhancer.js.map +1 -1
  324. package/build/sdk/legacy/server/runtime/serverManager.d.ts.map +1 -1
  325. package/build/sdk/legacy/server/runtime/serverManager.js +3 -1
  326. package/build/sdk/legacy/server/runtime/serverManager.js.map +1 -1
  327. package/build/sdk/legacy/server/runtime/templateServerManager.d.ts.map +1 -1
  328. package/build/sdk/legacy/server/runtime/templateServerManager.js +32 -7
  329. package/build/sdk/legacy/server/runtime/templateServerManager.js.map +1 -1
  330. package/build/sdk/legacy/server/streamableHttp.js +1 -1
  331. package/build/sdk/legacy/shared/resourceTemplateRouting.d.ts.map +1 -1
  332. package/build/sdk/legacy/shared/resourceTemplateRouting.js +29 -11
  333. package/build/sdk/legacy/shared/resourceTemplateRouting.js.map +1 -1
  334. package/build/sdk/legacy/transport/http/middlewares/scopeAuthMiddleware.d.ts.map +1 -1
  335. package/build/sdk/legacy/transport/http/middlewares/scopeAuthMiddleware.js +12 -1
  336. package/build/sdk/legacy/transport/http/middlewares/scopeAuthMiddleware.js.map +1 -1
  337. package/build/sdk/legacy/transport/http/modernInboundLegacyBridge.d.ts +4 -0
  338. package/build/sdk/legacy/transport/http/modernInboundLegacyBridge.d.ts.map +1 -1
  339. package/build/sdk/legacy/transport/http/modernInboundLegacyBridge.js +11 -0
  340. package/build/sdk/legacy/transport/http/modernInboundLegacyBridge.js.map +1 -1
  341. package/build/sdk/legacy/transport/http/server.d.ts.map +1 -1
  342. package/build/sdk/legacy/transport/http/server.js +16 -2
  343. package/build/sdk/legacy/transport/http/server.js.map +1 -1
  344. package/build/sdk/legacy/transport/transportFactory.d.ts.map +1 -1
  345. package/build/sdk/legacy/transport/transportFactory.js +34 -12
  346. package/build/sdk/legacy/transport/transportFactory.js.map +1 -1
  347. package/build/transport/http/middlewares/httpRequestLogger.d.ts +4 -2
  348. package/build/transport/http/middlewares/httpRequestLogger.d.ts.map +1 -1
  349. package/build/transport/http/middlewares/httpRequestLogger.js +135 -16
  350. package/build/transport/http/middlewares/httpRequestLogger.js.map +1 -1
  351. package/build/transport/http/routes/cliTokenRoute.d.ts.map +1 -1
  352. package/build/transport/http/routes/cliTokenRoute.js +1 -0
  353. package/build/transport/http/routes/cliTokenRoute.js.map +1 -1
  354. package/build/transport/http/routes/healthRoutes.d.ts +11 -1
  355. package/build/transport/http/routes/healthRoutes.d.ts.map +1 -1
  356. package/build/transport/http/routes/healthRoutes.js +6 -2
  357. package/build/transport/http/routes/healthRoutes.js.map +1 -1
  358. package/build/transport/http/routes/inspectHelpers.d.ts.map +1 -1
  359. package/build/transport/http/routes/inspectHelpers.js +4 -3
  360. package/build/transport/http/routes/inspectHelpers.js.map +1 -1
  361. package/build/transport/http/routes/modernHttpRoutes.d.ts +4 -0
  362. package/build/transport/http/routes/modernHttpRoutes.d.ts.map +1 -1
  363. package/build/transport/http/routes/modernHttpRoutes.js +168 -24
  364. package/build/transport/http/routes/modernHttpRoutes.js.map +1 -1
  365. package/build/transport/http/routes/modernInteractionBinding.d.ts +2 -1
  366. package/build/transport/http/routes/modernInteractionBinding.d.ts.map +1 -1
  367. package/build/transport/http/routes/modernInteractionBinding.js +7 -4
  368. package/build/transport/http/routes/modernInteractionBinding.js.map +1 -1
  369. package/build/transport/http/routes/modernToolHeaderRegistry.d.ts +16 -0
  370. package/build/transport/http/routes/modernToolHeaderRegistry.d.ts.map +1 -0
  371. package/build/transport/http/routes/modernToolHeaderRegistry.js +161 -0
  372. package/build/transport/http/routes/modernToolHeaderRegistry.js.map +1 -0
  373. package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -1
  374. package/build/transport/http/routes/oauthRoutes.js +6 -3
  375. package/build/transport/http/routes/oauthRoutes.js.map +1 -1
  376. package/build/transport/http/routes/toolRoutes.d.ts.map +1 -1
  377. package/build/transport/http/routes/toolRoutes.js +18 -2
  378. package/build/transport/http/routes/toolRoutes.js.map +1 -1
  379. package/build/utils/core/parsing.d.ts +2 -0
  380. package/build/utils/core/parsing.d.ts.map +1 -1
  381. package/build/utils/core/parsing.js +19 -0
  382. package/build/utils/core/parsing.js.map +1 -1
  383. package/build/utils/core/resourceUris.d.ts +6 -0
  384. package/build/utils/core/resourceUris.d.ts.map +1 -0
  385. package/build/utils/core/resourceUris.js +104 -0
  386. package/build/utils/core/resourceUris.js.map +1 -0
  387. package/build/utils/core/toolNames.d.ts +8 -0
  388. package/build/utils/core/toolNames.d.ts.map +1 -0
  389. package/build/utils/core/toolNames.js +56 -0
  390. package/build/utils/core/toolNames.js.map +1 -0
  391. package/package.json +68 -64
@@ -1,243 +1,666 @@
1
- import { randomUUID } from 'node:crypto';
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { createHash, createHmac, randomBytes, randomUUID } from 'node:crypto';
3
+ import { authoritySlot, matchesAuthorityContext, OAUTH_ATTEMPT_TTL_MS, oauthAuthorityError, OAuthAuthorizationDeniedError, oauthDigest, sameAuthority, } from '../../../auth/oauthAuthority.js';
4
+ import { createOAuthEndpointFetch, validateOAuthEndpoint } from '../../../auth/oauthEndpointFetch.js';
2
5
  import { ClientSessionRepository } from '../../../auth/storage/clientSessionRepository.js';
3
- import { FileStorageService } from '../../../auth/storage/fileStorageService.js';
6
+ import { createUpstreamOAuthStorage } from '../../../auth/storage/upstreamOAuthStorage.js';
4
7
  import { AUTH_CONFIG } from '../../../constants.js';
5
- import logger from '../../../logger/logger.js';
6
- /**
7
- * SDK-compatible OAuth client provider that replaces the custom implementation.
8
- *
9
- * This provider implements the OAuth 2.1 Authorization Code Grant flow using
10
- * the SDK's OAuthClientProvider interface while maintaining compatibility with
11
- * the existing session storage system.
12
- */
8
+ import { AgentConfigManager } from '../../../core/server/agentConfig.js';
9
+ import { OAuthClientInformationFullSchema, OAuthTokensSchema, } from '../shared/auth.js';
10
+ /** Shared by the released modern and legacy SDK adapters. SDK cache objects are never authority. */
13
11
  export class SDKOAuthClientProvider {
14
- _clientMetadata;
15
- _clientInfo;
16
- _tokens;
17
- _codeVerifier;
18
- _state;
19
- sessionRepository;
20
- fileStorage;
21
12
  serverName;
22
13
  config;
23
- _authorizationUrl;
14
+ sessionRepository;
15
+ fileStorage;
16
+ context;
17
+ slot;
18
+ record;
19
+ verifiers = new Map();
20
+ callbacks = new AsyncLocalStorage();
21
+ authorizationAttempt;
22
+ callbackTail = Promise.resolve();
23
+ operations = new AsyncLocalStorage();
24
+ sseEndpoint;
25
+ tokenRequests = new WeakMap();
26
+ tokenResponses = new Map();
27
+ registrationResponses = new Map();
28
+ discoveryResponses = new Map();
29
+ // These tickets are process-local; a random key protects secret-bearing response correlation.
30
+ responseKey = randomBytes(32);
31
+ migration;
32
+ shutdownSignal = new AbortController();
33
+ claim;
34
+ fetch;
24
35
  constructor(serverName, config, sessionStoragePath) {
25
36
  this.serverName = serverName;
26
37
  this.config = config;
27
- // Create FileStorageService and ClientSessionRepository with 'client' subdirectory
28
- this.fileStorage = new FileStorageService(sessionStoragePath, AUTH_CONFIG.CLIENT.SESSION.SUBDIR);
38
+ const runtimeScope = AgentConfigManager.getInstance().get('runtimeScopeStoragePath');
39
+ this.fileStorage = createUpstreamOAuthStorage({
40
+ baseDir: sessionStoragePath,
41
+ runtimeScope: typeof runtimeScope === 'string' ? runtimeScope : undefined,
42
+ mode: AgentConfigManager.getInstance().get('auth').credentialStore ?? 'file',
43
+ });
29
44
  this.sessionRepository = new ClientSessionRepository(this.fileStorage);
30
- // Set up client metadata for registration with better defaults
31
- this._clientMetadata = {
32
- client_name: `1MCP Agent - ${serverName}`,
33
- redirect_uris: [config.redirectUrl || ''],
45
+ this.context = config.authority;
46
+ this.slot = this.context ? authoritySlot(this.context) : undefined;
47
+ const restore = () => {
48
+ if (this.slot && this.context) {
49
+ const stored = this.sessionRepository.getBound(this.slot);
50
+ if (stored && matchesAuthorityContext(stored.authority, this.context)) {
51
+ if (!config.issuer || config.issuer === stored.authority.issuer)
52
+ this.record = stored;
53
+ }
54
+ }
55
+ return this.slot ? (this.sessionRepository.getClaim(this.slot)?.generation ?? null) : null;
56
+ };
57
+ const alreadyReady = this.fileStorage.isReady();
58
+ const observed = alreadyReady ? restore() : null;
59
+ this.migration = this.fileStorage.ready().then(async () => {
60
+ const observedGeneration = alreadyReady ? observed : restore();
61
+ // Quarantine preserves unbound ownership: moving secrets never grants an authority.
62
+ await this.sessionRepository.quarantine(serverName);
63
+ if (this.slot && this.context)
64
+ this.claim = await this.sessionRepository.claimContext(this.slot, this.context, observedGeneration, this.shutdownSignal.signal);
65
+ });
66
+ void this.migration.catch(() => undefined);
67
+ this.fetch = createOAuthEndpointFetch({
68
+ resource: this.context?.route.url ?? 'https://invalid.invalid/',
69
+ issuer: this.config.issuer,
70
+ isResource: (url) => url.href === this.context?.route.url || url.href === this.sseEndpoint,
71
+ acceptSseEndpoint: this.context?.route.kind === 'sse'
72
+ ? (endpoint) => {
73
+ const configured = new URL(this.context.route.url);
74
+ const target = new URL(endpoint, configured);
75
+ if (target.origin !== configured.origin || target.username || target.password || target.hash)
76
+ throw oauthAuthorityError();
77
+ this.sseEndpoint = target.href;
78
+ }
79
+ : undefined,
80
+ beforeRequest: (url, init) => this.prepareFetch(url, init),
81
+ pinDestination: async (host, addresses, init) => {
82
+ await this.migration;
83
+ if (!this.slot || !this.claim)
84
+ throw oauthAuthorityError();
85
+ await this.sessionRepository.pinDestination(this.slot, this.tokenRequests.get(init)?.generation ?? this.claim, host, addresses);
86
+ },
87
+ onFailure: (resourceRequest) => {
88
+ const operation = this.operations.getStore();
89
+ if (!resourceRequest && operation)
90
+ operation.failed = true;
91
+ },
92
+ response: (value, _url, init) => {
93
+ const ticket = this.tokenRequests.get(init);
94
+ if (!ticket)
95
+ return;
96
+ if (ticket.kind === 'token') {
97
+ const tokens = { ...value };
98
+ if (tokens.refresh_token === undefined)
99
+ tokens.refresh_token = new URLSearchParams(String(init.body ?? '')).get('refresh_token') ?? undefined;
100
+ const key = this.responseDigest(OAuthTokensSchema.parse(tokens));
101
+ this.recordResponse(this.responseMap('token'), key, ticket);
102
+ }
103
+ else if (ticket.kind === 'registration') {
104
+ const key = this.responseDigest(OAuthClientInformationFullSchema.parse({ ...this.clientMetadata, ...value }));
105
+ this.recordResponse(this.responseMap('registration'), key, ticket);
106
+ }
107
+ },
108
+ metadata: (value, url, init) => {
109
+ const validated = this.validateMetadata(value, url);
110
+ const ticket = this.tokenRequests.get(init);
111
+ if (typeof value.issuer === 'string' && ticket)
112
+ this.recordResponse(this.responseMap('discovery'), this.discoveryKey(value), ticket);
113
+ return validated;
114
+ },
115
+ });
116
+ }
117
+ get redirectUrl() {
118
+ return this.config.redirectUrl || '';
119
+ }
120
+ get clientMetadataUrl() {
121
+ return this.config.clientMetadataUrl;
122
+ }
123
+ get clientMetadata() {
124
+ return {
125
+ client_name: `1MCP Agent - ${this.serverName}`,
126
+ redirect_uris: [this.redirectUrl],
34
127
  grant_types: ['authorization_code', 'refresh_token'],
35
128
  response_types: ['code'],
36
- token_endpoint_auth_method: config.clientSecret ? 'client_secret_post' : 'none',
37
- scope: config.scopes?.join(' ') || AUTH_CONFIG.CLIENT.OAUTH.DEFAULT_SCOPES.join(' '),
129
+ token_endpoint_auth_method: this.config.clientSecret ? 'client_secret_post' : 'none',
130
+ scope: this.config.scopes?.join(' ') ?? AUTH_CONFIG.CLIENT.OAUTH.DEFAULT_SCOPES.join(' '),
38
131
  };
39
- logger.debug('sdkOAuthClientProvider.oauth.client.configured.for.with.redirect.url.configured.f624fff1');
40
- // Load existing client info and tokens if available
41
- this.loadPersistedData();
42
- // Seed client info from a pre-registered clientId so the SDK skips Dynamic
43
- // Client Registration for servers without a registration_endpoint (e.g. Slack).
44
- // Guarded so persisted client info always wins.
45
- if (!this._clientInfo && config.clientId) {
46
- this._clientInfo = {
47
- ...this._clientMetadata,
48
- client_id: config.clientId,
49
- client_secret: config.clientSecret,
132
+ }
133
+ clientInformation(ctx) {
134
+ this.checkIssuer(ctx);
135
+ if (this.record)
136
+ this.requireCurrent();
137
+ if (this.config.clientId) {
138
+ return {
139
+ ...this.clientMetadata,
140
+ client_id: this.config.clientId,
141
+ client_secret: this.config.clientSecret,
142
+ ...(this.record ? { issuer: this.record.authority.issuer } : {}),
50
143
  };
51
144
  }
145
+ const record = this.current();
146
+ if (!record?.clientInfo)
147
+ return undefined;
148
+ try {
149
+ return {
150
+ ...OAuthClientInformationFullSchema.parse(JSON.parse(record.clientInfo)),
151
+ issuer: record.authority.issuer,
152
+ };
153
+ }
154
+ catch {
155
+ throw oauthAuthorityError();
156
+ }
52
157
  }
53
- get redirectUrl() {
54
- return this.config.redirectUrl || '';
158
+ async saveClientInformation(clientInfo, ctx) {
159
+ this.assertOperation();
160
+ this.checkIssuer(ctx);
161
+ const record = this.requireCurrent();
162
+ const stamped = clientInfo;
163
+ if (stamped.issuer && stamped.issuer !== record.authority.issuer)
164
+ throw oauthAuthorityError();
165
+ if (this.config.clientId)
166
+ return;
167
+ const parsed = OAuthClientInformationFullSchema.parse({ ...this.clientMetadata, ...clientInfo });
168
+ const key = this.responseDigest(parsed);
169
+ const ticket = this.responseMap('registration').get(key);
170
+ this.responseMap('registration').delete(key);
171
+ if (!ticket && parsed.client_id !== this.config.clientMetadataUrl)
172
+ throw oauthAuthorityError();
173
+ if (ticket && (ticket.ambiguous || ticket.generation !== record.generation))
174
+ throw oauthAuthorityError();
175
+ this.record = await this.sessionRepository.updateBound(this.slot, record.generation, (current) => {
176
+ if (ticket && current.revision !== ticket.revision)
177
+ throw oauthAuthorityError();
178
+ current.clientInfo = JSON.stringify(parsed);
179
+ current.revision++;
180
+ }, ticket?.requestVersion ?? this.operations.getStore()?.requestVersion);
181
+ this.advanceOperation();
182
+ }
183
+ tokens(ctx) {
184
+ this.checkIssuer(ctx);
185
+ const record = this.current();
186
+ if (!record?.tokens)
187
+ return undefined;
188
+ try {
189
+ return { ...OAuthTokensSchema.parse(JSON.parse(record.tokens)), issuer: record.authority.issuer };
190
+ }
191
+ catch {
192
+ throw oauthAuthorityError();
193
+ }
194
+ }
195
+ async saveTokens(tokens, ctx) {
196
+ this.assertOperation();
197
+ this.checkIssuer(ctx);
198
+ const record = this.requireCurrent();
199
+ const stamped = tokens;
200
+ if (stamped.issuer && stamped.issuer !== record.authority.issuer)
201
+ throw oauthAuthorityError();
202
+ const parsed = OAuthTokensSchema.parse(tokens);
203
+ if (this.config.scopes && parsed.scope?.split(' ').some((scope) => !this.config.scopes.includes(scope)))
204
+ throw oauthAuthorityError();
205
+ const responseKey = this.responseDigest(parsed);
206
+ const ticket = this.responseMap('token').get(responseKey);
207
+ this.responseMap('token').delete(responseKey);
208
+ if (!ticket || ticket.ambiguous || ticket.generation !== record.generation)
209
+ this.rejectOperation();
210
+ const expectedRevision = ticket.revision;
211
+ this.record = await this.sessionRepository.updateBound(this.slot, record.generation, (current) => {
212
+ if (current.revision !== expectedRevision)
213
+ throw oauthAuthorityError();
214
+ current.tokens = JSON.stringify(parsed);
215
+ current.revision++;
216
+ }, ticket.requestVersion);
217
+ this.authorizationAttempt = undefined;
218
+ }
219
+ async invalidateCredentials(scope) {
220
+ const record = this.current();
221
+ this.authorizationAttempt = undefined;
222
+ this.verifiers.clear();
223
+ if (!record)
224
+ return;
225
+ this.record = await this.sessionRepository.updateBound(this.slot, record.generation, (current) => {
226
+ current.generation = randomUUID();
227
+ current.revision++;
228
+ current.attempts = {};
229
+ if (scope !== 'verifier')
230
+ current.tokens = undefined;
231
+ if (scope === 'all' || scope === 'client' || scope === 'discovery')
232
+ current.clientInfo = undefined;
233
+ if (scope === 'all' || scope === 'discovery')
234
+ current.discovery = '';
235
+ });
236
+ this.claim = this.record.generation;
237
+ // In-flight work retains its old revision and cannot publish into this generation.
238
+ }
239
+ state() {
240
+ return randomUUID();
241
+ }
242
+ saveCodeVerifier(verifier) {
243
+ if (!/^[A-Za-z0-9._~-]{43,128}$/.test(verifier) || this.verifiers.size >= 32)
244
+ throw oauthAuthorityError();
245
+ this.verifiers.set(createHash('sha256').update(verifier).digest('base64url'), verifier);
246
+ }
247
+ codeVerifier() {
248
+ const callback = this.callbacks.getStore();
249
+ if (!callback || callback.generation !== this.requireCurrent().generation)
250
+ throw oauthAuthorityError();
251
+ return callback.verifier;
252
+ }
253
+ async redirectToAuthorization(url) {
254
+ this.assertOperation();
255
+ const record = this.requireCurrent();
256
+ const target = new URL(url);
257
+ const state = target.searchParams.get('state');
258
+ const challenge = target.searchParams.get('code_challenge');
259
+ const verifier = challenge ? this.verifiers.get(challenge) : undefined;
260
+ target.search = '';
261
+ const endpoint = new URL(record.authority.authorizationEndpoint);
262
+ endpoint.search = '';
263
+ if (target.href !== endpoint.href ||
264
+ !state ||
265
+ !verifier ||
266
+ url.searchParams.get('redirect_uri') !== this.redirectUrl ||
267
+ url.searchParams.get('resource') !== record.authority.resource)
268
+ throw oauthAuthorityError();
269
+ this.assertScopes(url.searchParams.get('scope'));
270
+ await this.sessionRepository.addAttempt(this.slot, record.generation, state, {
271
+ authority: record.authority,
272
+ generation: record.generation,
273
+ redirect: this.redirectUrl,
274
+ verifier,
275
+ createdAt: Date.now(),
276
+ expires: Date.now() + OAUTH_ATTEMPT_TTL_MS,
277
+ consumed: false,
278
+ });
279
+ this.verifiers.delete(challenge);
280
+ this.authorizationAttempt = { url: url.toString(), key: oauthDigest(state) };
55
281
  }
56
- get clientMetadata() {
57
- return this._clientMetadata;
58
- }
59
- /**
60
- * Returns current client registration information
61
- */
62
- clientInformation() {
63
- return this._clientInfo;
64
- }
65
- /**
66
- * Saves client registration information from dynamic registration
67
- */
68
- saveClientInformation(clientInfo) {
69
- this._clientInfo = clientInfo;
70
- this.persistAllData();
71
- logger.info('sdkOAuthClientProvider.oauth.client.registered.for.a7d64162');
72
- }
73
- /**
74
- * Returns current OAuth tokens
75
- */
76
- tokens() {
77
- return this._tokens;
78
- }
79
- /**
80
- * Saves OAuth tokens after successful authorization
81
- */
82
- saveTokens(tokens) {
83
- this._tokens = tokens;
84
- this.persistAllData();
85
- logger.info('sdkOAuthClientProvider.oauth.tokens.saved.for.22916b52');
86
- }
87
- /**
88
- * Invalidates persisted OAuth credentials as requested by the MCP SDK.
89
- */
90
- invalidateCredentials(scope) {
91
- switch (scope) {
92
- case 'all':
93
- this._clientInfo = undefined;
94
- this._tokens = undefined;
95
- this._codeVerifier = undefined;
96
- this._state = undefined;
97
- this._authorizationUrl = undefined;
98
- break;
99
- case 'client':
100
- this._clientInfo = undefined;
101
- break;
102
- case 'tokens':
103
- this._tokens = undefined;
104
- this._state = undefined;
105
- this._authorizationUrl = undefined;
106
- break;
107
- case 'verifier':
108
- this._codeVerifier = undefined;
109
- break;
110
- case 'discovery':
111
- return;
112
- }
113
- this.persistAllData();
114
- logger.info('sdkOAuthClientProvider.oauth.credentials.invalidated.for.a8274c9f');
115
- }
116
- /**
117
- * Stores authorization URL instead of prompting user in console
118
- */
119
- redirectToAuthorization(authorizationUrl) {
120
- this._authorizationUrl = authorizationUrl.toString();
121
- }
122
- /**
123
- * Gets the current authorization URL
124
- */
125
282
  getAuthorizationUrl() {
126
- return this._authorizationUrl;
283
+ return this.authorizationAttempt?.url;
284
+ }
285
+ /** Only a live, unconsumed attempt owned by this provider can be resumed. */
286
+ getPendingAuthorizationUrl() {
287
+ const authorization = this.authorizationAttempt;
288
+ if (!authorization)
289
+ return undefined;
290
+ const record = this.current();
291
+ if (!record)
292
+ return undefined;
293
+ // The durable key was bound to this URL at creation, before it was exposed
294
+ // through transport/provider APIs. Resumption never reinterprets a URL.
295
+ const attempt = record.attempts[authorization.key];
296
+ if (!attempt || attempt.consumed || attempt.expires <= Date.now())
297
+ return undefined;
298
+ if (attempt.generation !== record.generation || !sameAuthority(attempt.authority, record.authority))
299
+ return undefined;
300
+ if (attempt.redirect !== this.redirectUrl)
301
+ return undefined;
302
+ return this.authorizationAttempt?.url;
127
303
  }
128
- /**
129
- * Clears the stored authorization URL
130
- */
131
304
  clearAuthorizationUrl() {
132
- this._authorizationUrl = undefined;
133
- }
134
- /**
135
- * Saves PKCE code verifier for the authorization session
136
- */
137
- saveCodeVerifier(codeVerifier) {
138
- this._codeVerifier = codeVerifier;
139
- this.persistAllData();
140
- }
141
- /**
142
- * Returns the PKCE code verifier for token exchange
143
- */
144
- codeVerifier() {
145
- return this._codeVerifier || '';
305
+ this.authorizationAttempt = undefined;
146
306
  }
147
- /**
148
- * Returns the OAuth state parameter for CSRF protection
149
- */
150
- state() {
151
- if (!this._state) {
152
- this._state = randomUUID();
153
- this.persistAllData();
154
- }
155
- return this._state;
307
+ /** Validation and durable consumption happen before the SDK can see a code, for both eras. */
308
+ async withAuthorizationCallback(response, operation) {
309
+ const run = async () => {
310
+ await this.migration;
311
+ const record = this.requireCurrent();
312
+ for (const key of ['state', 'code', 'iss', 'error', 'redirect_uri']) {
313
+ if (response.getAll(key).length > 1)
314
+ throw oauthAuthorityError();
315
+ }
316
+ const state = response.get('state');
317
+ if (!state)
318
+ throw oauthAuthorityError();
319
+ const attempt = await this.sessionRepository.consumeAttempt(this.slot, record.generation, state, (candidate) => {
320
+ if (!sameAuthority(candidate.authority, record.authority) ||
321
+ candidate.generation !== record.generation ||
322
+ candidate.redirect !== this.redirectUrl)
323
+ throw oauthAuthorityError();
324
+ const redirect = response.get('redirect_uri');
325
+ if (redirect && redirect !== candidate.redirect)
326
+ throw oauthAuthorityError();
327
+ const issuer = response.get('iss');
328
+ if (candidate.authority.requireIssuer && !issuer)
329
+ throw oauthAuthorityError();
330
+ if (issuer !== null && issuer !== candidate.authority.issuer)
331
+ throw oauthAuthorityError();
332
+ if (!response.get('code') && !response.get('error'))
333
+ throw oauthAuthorityError();
334
+ });
335
+ if (response.has('error'))
336
+ throw new OAuthAuthorizationDeniedError(response.get('error') === 'access_denied' ? 'access_denied' : 'provider_error');
337
+ return this.callbacks.run({ verifier: attempt.verifier, generation: attempt.generation }, operation);
338
+ };
339
+ const pending = this.callbackTail.then(run, run);
340
+ this.callbackTail = pending.catch(() => undefined);
341
+ return pending;
342
+ }
343
+ async bindAdminReturn(state, origin) {
344
+ const record = this.requireCurrent();
345
+ await this.sessionRepository.updateBound(this.slot, record.generation, (current) => {
346
+ const attempt = current.attempts[oauthDigest(state)];
347
+ if (!attempt || attempt.consumed || attempt.expires <= Date.now())
348
+ throw oauthAuthorityError();
349
+ attempt.adminReturnOrigin = origin;
350
+ });
351
+ }
352
+ getAdminReturn(state) {
353
+ const attempt = this.current()?.attempts[oauthDigest(state)];
354
+ return attempt && attempt.consumed && attempt.expires > Date.now() ? attempt.adminReturnOrigin : undefined;
156
355
  }
157
- /**
158
- * Custom resource validation (optional)
159
- */
160
356
  async validateResourceURL(serverUrl, resource) {
161
- const url = typeof serverUrl === 'string' ? new URL(serverUrl) : serverUrl;
162
- // Basic validation - can be extended for specific requirements
163
- if (resource && !resource.startsWith(url.origin)) {
357
+ return this.selectResourceURL(serverUrl, resource);
358
+ }
359
+ selectResourceURL(serverUrl, resource) {
360
+ try {
361
+ const configured = new URL(this.context?.route.url ?? serverUrl);
362
+ configured.hash = '';
363
+ const requested = new URL(serverUrl);
364
+ requested.hash = '';
365
+ if (requested.href !== configured.href)
366
+ throw oauthAuthorityError();
367
+ if (resource === undefined)
368
+ return configured;
369
+ const advertised = new URL(resource);
370
+ if (advertised.username || advertised.password || resource.includes('#'))
371
+ throw oauthAuthorityError();
372
+ if (advertised.origin !== configured.origin || advertised.search !== configured.search)
373
+ throw oauthAuthorityError();
374
+ // Resource Indicators may describe a parent resource; the transport route remains exact.
375
+ const resourcePath = advertised.pathname.endsWith('/') ? advertised.pathname : advertised.pathname + '/';
376
+ const routePath = configured.pathname.endsWith('/') ? configured.pathname : configured.pathname + '/';
377
+ if (configured.pathname.length < advertised.pathname.length || !routePath.startsWith(resourcePath))
378
+ throw oauthAuthorityError();
379
+ return advertised;
380
+ }
381
+ catch {
382
+ throw oauthAuthorityError();
383
+ }
384
+ }
385
+ discoveryState() {
386
+ // A new SDK auth operation may retry transient transport failures. The failed
387
+ // operation itself remains blocked from inferred fallback or credential writes.
388
+ this.operations.enterWith({
389
+ failed: false,
390
+ responses: { token: new Map(), registration: new Map(), discovery: new Map() },
391
+ });
392
+ const current = this.current();
393
+ // Refresh/new authorization re-discovers current destinations. Only a validated
394
+ // callback resumes the exact discovery snapshot captured by its durable attempt.
395
+ if (!this.callbacks.getStore() || !current?.discovery)
396
+ return undefined;
397
+ try {
398
+ return JSON.parse(current.discovery);
399
+ }
400
+ catch {
401
+ throw oauthAuthorityError();
402
+ }
403
+ }
404
+ async saveDiscoveryState(state) {
405
+ await this.migration;
406
+ this.assertOperation();
407
+ if (!this.context || !this.slot)
408
+ throw oauthAuthorityError();
409
+ const metadata = state.authorizationServerMetadata;
410
+ let requestVersion = this.operations.getStore()?.requestVersion;
411
+ if (metadata) {
412
+ const key = this.discoveryKey(metadata);
413
+ const ticket = this.responseMap('discovery').get(key);
414
+ this.responseMap('discovery').delete(key);
415
+ if (ticket && (ticket.ambiguous || ticket.generation !== this.claim))
416
+ throw oauthAuthorityError();
417
+ if (ticket)
418
+ requestVersion = ticket.requestVersion;
419
+ }
420
+ const issuer = state.authorizationServerUrl;
421
+ if (this.config.issuer && this.config.issuer !== issuer)
422
+ throw oauthAuthorityError();
423
+ if (metadata?.issuer && metadata.issuer !== issuer)
424
+ throw oauthAuthorityError();
425
+ const approved = this.record?.authority.issuer;
426
+ const advertised = state.resourceMetadata?.authorization_servers;
427
+ if (advertised?.length) {
428
+ const selected = this.config.issuer ?? (approved && advertised.includes(approved) ? approved : undefined);
429
+ if (selected ? selected !== issuer : advertised.length !== 1 || advertised[0] !== issuer)
430
+ throw oauthAuthorityError();
431
+ }
432
+ else if (!this.config.legacy && !this.config.issuer) {
433
+ throw oauthAuthorityError();
434
+ }
435
+ const issuerUrl = validateOAuthEndpoint(issuer, this.context.route.url, undefined, this.config.issuer);
436
+ if (issuerUrl.search || issuerUrl.hash)
437
+ throw oauthAuthorityError();
438
+ const fallback = this.config.legacy && issuerUrl.origin === new URL(this.context.route.url).origin;
439
+ if (!metadata && !fallback)
440
+ throw oauthAuthorityError();
441
+ const resource = await this.validateResourceURL(this.context.route.url, state.resourceMetadata?.resource);
442
+ const endpoint = (value, pathname) => {
443
+ if (!value && !fallback)
444
+ throw oauthAuthorityError();
445
+ return validateOAuthEndpoint(value ?? new URL(pathname, issuerUrl).href, this.context.route.url, value ? undefined : issuerUrl.origin, this.config.issuer).href;
446
+ };
447
+ let registrationEndpoint;
448
+ if (metadata?.registration_endpoint)
449
+ registrationEndpoint = endpoint(metadata.registration_endpoint, '/register');
450
+ else if (!metadata && fallback)
451
+ registrationEndpoint = endpoint(undefined, '/register');
452
+ const authority = {
453
+ ...this.context,
454
+ version: 1,
455
+ issuer,
456
+ resource: resource.href,
457
+ authorizationEndpoint: endpoint(metadata?.authorization_endpoint, '/authorize'),
458
+ tokenEndpoint: endpoint(metadata?.token_endpoint, '/token'),
459
+ registrationEndpoint,
460
+ requireIssuer: metadata
461
+ ?.authorization_response_iss_parameter_supported === true,
462
+ };
463
+ this.record = await this.sessionRepository.activate(this.slot, authority, JSON.stringify(state), this.claim, requestVersion);
464
+ this.claim = this.record.generation;
465
+ this.advanceOperation();
466
+ }
467
+ current() {
468
+ if (!this.record || !this.slot || !this.context)
164
469
  return undefined;
470
+ const current = this.sessionRepository.getBound(this.slot);
471
+ if (this.sessionRepository.getClaim(this.slot)?.generation !== this.record.generation)
472
+ throw oauthAuthorityError();
473
+ if (!current ||
474
+ current.generation !== this.record.generation ||
475
+ !sameAuthority(current.authority, this.record.authority) ||
476
+ !matchesAuthorityContext(current.authority, this.context))
477
+ throw oauthAuthorityError();
478
+ return current;
479
+ }
480
+ requireCurrent() {
481
+ const current = this.current();
482
+ if (!current)
483
+ throw oauthAuthorityError();
484
+ return current;
485
+ }
486
+ checkIssuer(ctx) {
487
+ if (!ctx)
488
+ return;
489
+ const issuer = this.record?.authority.issuer ?? this.config.issuer;
490
+ if (!issuer || ctx.issuer !== issuer)
491
+ throw oauthAuthorityError();
492
+ }
493
+ assertScopes(scope) {
494
+ if (this.config.scopes && scope?.split(' ').some((item) => !this.config.scopes.includes(item)))
495
+ throw oauthAuthorityError();
496
+ }
497
+ validateMetadata(value, url) {
498
+ if (!this.context)
499
+ throw oauthAuthorityError();
500
+ if (Array.isArray(value.authorization_servers)) {
501
+ const issuers = value.authorization_servers;
502
+ if (!issuers.length || issuers.length > 16 || issuers.some((issuer) => typeof issuer !== 'string'))
503
+ throw oauthAuthorityError();
504
+ for (const issuer of issuers)
505
+ validateOAuthEndpoint(String(issuer), this.context.route.url, undefined, this.config.issuer);
506
+ const approved = this.config.issuer ?? this.record?.authority.issuer;
507
+ let selected;
508
+ if (approved && issuers.includes(approved))
509
+ selected = approved;
510
+ else if (issuers.length === 1)
511
+ selected = String(issuers[0]);
512
+ if (!selected || (this.config.issuer && selected !== this.config.issuer))
513
+ throw oauthAuthorityError();
514
+ if (typeof value.resource !== 'string')
515
+ throw oauthAuthorityError();
516
+ this.selectResourceURL(this.context.route.url, value.resource);
517
+ return {
518
+ ...value,
519
+ authorization_servers: [selected],
520
+ ...(this.config.scopes ? { scopes_supported: this.config.scopes } : {}),
521
+ };
165
522
  }
166
- return url;
167
- }
168
- /**
169
- * Load persisted OAuth data from unified client session storage
170
- */
171
- loadPersistedData() {
172
- const clientSession = this.sessionRepository.get(this.serverName);
173
- if (clientSession) {
174
- // Load client info
175
- if (clientSession.clientInfo) {
176
- this._clientInfo = JSON.parse(clientSession.clientInfo);
523
+ if (typeof value.issuer === 'string') {
524
+ const issuer = validateOAuthEndpoint(value.issuer, this.context.route.url, undefined, this.config.issuer);
525
+ if (issuer.origin !== url.origin || (this.config.issuer && value.issuer !== this.config.issuer))
526
+ throw oauthAuthorityError();
527
+ for (const key of ['authorization_endpoint', 'token_endpoint', 'registration_endpoint', 'jwks_uri']) {
528
+ if (value[key] !== undefined)
529
+ validateOAuthEndpoint(String(value[key]), this.context.route.url, undefined, this.config.issuer);
177
530
  }
178
- // Load tokens
179
- if (clientSession.tokens) {
180
- this._tokens = JSON.parse(clientSession.tokens);
181
- // Check if tokens are expired
182
- if (this._tokens && this.isTokenExpired(this._tokens)) {
183
- logger.warn('sdkOAuthClientProvider.oauth.tokens.expired.for.clearing.aa3cd964');
184
- this._tokens = undefined;
185
- this.persistAllData();
531
+ }
532
+ return value;
533
+ }
534
+ async prepareFetch(url, init) {
535
+ await this.migration;
536
+ if (!this.context)
537
+ throw oauthAuthorityError();
538
+ const resource = new URL(this.context.route.url);
539
+ const headers = new Headers(init.headers);
540
+ const isDiscovery = (init.method ?? 'GET') === 'GET' && url.href !== resource.href && url.href !== this.sseEndpoint;
541
+ if (isDiscovery) {
542
+ this.assertOperation();
543
+ const requestVersion = await this.reserveRequest();
544
+ if (url.search)
545
+ throw oauthAuthorityError();
546
+ const request = { ...init, headers: { accept: 'application/json' }, redirect: 'error' };
547
+ this.tokenRequests.set(request, {
548
+ generation: this.claim,
549
+ revision: this.record?.revision ?? 0,
550
+ kind: 'discovery',
551
+ requestVersion,
552
+ });
553
+ return request;
554
+ }
555
+ // Resource requests need the generation check in pinDestination, not credential loading.
556
+ if (url.href === resource.href || url.href === this.sseEndpoint)
557
+ return { ...init, redirect: 'error' };
558
+ const record = this.current();
559
+ const isToken = record?.authority.tokenEndpoint === url.href;
560
+ const isRegistration = record?.authority.registrationEndpoint === url.href;
561
+ if (isToken || isRegistration) {
562
+ this.assertOperation();
563
+ const requestVersion = await this.reserveRequest();
564
+ if ((init.method ?? 'GET') !== 'POST')
565
+ throw oauthAuthorityError();
566
+ const safeHeaders = new Headers();
567
+ safeHeaders.set('content-type', isToken ? 'application/x-www-form-urlencoded' : 'application/json');
568
+ if (isToken) {
569
+ const params = new URLSearchParams(String(init.body ?? ''));
570
+ if (params.get('resource') !== record.authority.resource)
571
+ throw oauthAuthorityError();
572
+ this.assertScopes(params.get('scope'));
573
+ if (params.get('grant_type') === 'authorization_code') {
574
+ if (this.callbacks.getStore()?.generation !== record.generation)
575
+ throw oauthAuthorityError();
186
576
  }
577
+ const client = this.clientInformation();
578
+ const authorization = headers.get('authorization');
579
+ if (authorization?.startsWith('Basic ') && client?.client_secret) {
580
+ const expected = `Basic ${Buffer.from(`${client.client_id}:${client.client_secret}`).toString('base64')}`;
581
+ if (authorization !== expected)
582
+ throw oauthAuthorityError();
583
+ safeHeaders.set('authorization', authorization);
584
+ }
585
+ if (params.has('client_id') && params.get('client_id') !== client?.client_id)
586
+ throw oauthAuthorityError();
587
+ if (params.has('client_secret') && params.get('client_secret') !== client?.client_secret)
588
+ throw oauthAuthorityError();
187
589
  }
188
- // Load code verifier
189
- if (clientSession.codeVerifier) {
190
- this._codeVerifier = clientSession.codeVerifier;
191
- }
192
- // Load state
193
- if (clientSession.state) {
194
- this._state = clientSession.state;
590
+ else {
591
+ const registration = JSON.parse(String(init.body ?? '{}'));
592
+ this.assertScopes(registration.scope ?? null);
593
+ if (this.config.clientId || this.config.autoRegister === false)
594
+ throw oauthAuthorityError();
195
595
  }
596
+ const request = { ...init, headers: safeHeaders, redirect: 'error' };
597
+ this.tokenRequests.set(request, {
598
+ generation: record.generation,
599
+ revision: record.revision,
600
+ kind: isToken ? 'token' : 'registration',
601
+ requestVersion,
602
+ });
603
+ return request;
196
604
  }
605
+ throw oauthAuthorityError();
197
606
  }
198
- /**
199
- * Persist all OAuth data to unified client session storage
200
- */
201
- persistAllData() {
202
- // Calculate the longest TTL based on the data we have
203
- let maxTtl = AUTH_CONFIG.CLIENT.OAUTH.TTL_MS; // Default to 30 days
204
- // If we have tokens, use their expiry time
205
- if (this._tokens && this._tokens.expires_in) {
206
- const tokenTtl = this._tokens.expires_in * 1000;
207
- maxTtl = Math.max(maxTtl, tokenTtl);
208
- }
209
- // Code verifier and state have shorter TTL, but we keep them for completeness
210
- const clientSessionData = {
211
- serverName: this.serverName,
212
- clientInfo: this._clientInfo ? JSON.stringify(this._clientInfo) : undefined,
213
- tokens: this._tokens ? JSON.stringify(this._tokens) : undefined,
214
- codeVerifier: this._codeVerifier,
215
- state: this._state,
216
- expires: Date.now() + maxTtl,
217
- createdAt: Date.now(),
218
- };
219
- this.sessionRepository.save(this.serverName, clientSessionData, maxTtl);
220
- }
221
- /**
222
- * Check if OAuth tokens are expired
223
- */
224
- isTokenExpired(tokens) {
225
- if (!tokens.expires_in) {
226
- return false; // No expiration info, assume valid
227
- }
228
- // This is a simple check - in practice, you might want to store the issued_at time
229
- // For now, we'll rely on the session storage TTL for expiration
230
- return false;
231
- }
232
- /**
233
- * Clean up resources
234
- */
235
- shutdown() {
236
- // Clean up temporary session data by clearing verifier and state
237
- this._codeVerifier = undefined;
238
- this._state = undefined;
239
- this.persistAllData();
607
+ responseMap(kind) {
608
+ const operation = this.operations.getStore();
609
+ if (operation)
610
+ return operation.responses[kind];
611
+ if (kind === 'token')
612
+ return this.tokenResponses;
613
+ if (kind === 'registration')
614
+ return this.registrationResponses;
615
+ return this.discoveryResponses;
616
+ }
617
+ advanceOperation() {
618
+ const operation = this.operations.getStore();
619
+ if (operation && this.slot)
620
+ operation.requestVersion = this.sessionRepository.getClaim(this.slot)?.requestVersion;
621
+ }
622
+ rejectOperation() {
623
+ const operation = this.operations.getStore();
624
+ if (operation)
625
+ operation.failed = true;
626
+ throw oauthAuthorityError();
627
+ }
628
+ assertOperation() {
629
+ if (this.operations.getStore()?.failed)
630
+ throw oauthAuthorityError();
631
+ }
632
+ async reserveRequest() {
633
+ const requestVersion = await this.sessionRepository.reserveRequest(this.slot, this.claim);
634
+ const operation = this.operations.getStore();
635
+ if (operation)
636
+ operation.requestVersion = requestVersion;
637
+ return requestVersion;
638
+ }
639
+ responseDigest(value) {
640
+ return createHmac('sha256', this.responseKey).update(JSON.stringify(value)).digest('hex');
641
+ }
642
+ discoveryKey(metadata) {
643
+ return this.responseDigest([
644
+ metadata.issuer,
645
+ metadata.authorization_endpoint,
646
+ metadata.token_endpoint,
647
+ metadata.registration_endpoint,
648
+ ]);
649
+ }
650
+ recordResponse(target, key, ticket) {
651
+ if (target.size >= 32 && !target.has(key))
652
+ throw oauthAuthorityError();
653
+ const previous = target.get(key);
654
+ if (previous) {
655
+ previous.ambiguous = true;
656
+ return;
657
+ }
658
+ target.set(key, ticket);
659
+ }
660
+ async shutdown() {
661
+ this.shutdownSignal.abort();
240
662
  this.fileStorage.shutdown();
663
+ await this.migration.catch(() => undefined);
241
664
  }
242
665
  }
243
666
  //# sourceMappingURL=sdkOAuthClientProvider.js.map