@frontmcp/sdk 0.4.0 → 0.5.0

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 (558) hide show
  1. package/README.md +30 -18
  2. package/package.json +20 -5
  3. package/src/app/app.registry.d.ts +3 -2
  4. package/src/app/app.registry.js +3 -1
  5. package/src/app/app.registry.js.map +1 -1
  6. package/src/app/instances/app.local.instance.js +2 -2
  7. package/src/app/instances/app.local.instance.js.map +1 -1
  8. package/src/auth/auth.registry.d.ts +34 -2
  9. package/src/auth/auth.registry.js +162 -24
  10. package/src/auth/auth.registry.js.map +1 -1
  11. package/src/auth/auth.utils.js +8 -9
  12. package/src/auth/auth.utils.js.map +1 -1
  13. package/src/auth/authorization/authorization.class.d.ts +125 -0
  14. package/src/auth/authorization/authorization.class.js +224 -0
  15. package/src/auth/authorization/authorization.class.js.map +1 -0
  16. package/src/auth/authorization/authorization.types.d.ts +300 -0
  17. package/src/auth/authorization/authorization.types.js +79 -0
  18. package/src/auth/authorization/authorization.types.js.map +1 -0
  19. package/src/auth/authorization/index.d.ts +5 -0
  20. package/src/auth/authorization/index.js +19 -0
  21. package/src/auth/authorization/index.js.map +1 -0
  22. package/src/auth/authorization/orchestrated.authorization.d.ts +242 -0
  23. package/src/auth/authorization/orchestrated.authorization.js +306 -0
  24. package/src/auth/authorization/orchestrated.authorization.js.map +1 -0
  25. package/src/auth/authorization/public.authorization.d.ts +91 -0
  26. package/src/auth/authorization/public.authorization.js +132 -0
  27. package/src/auth/authorization/public.authorization.js.map +1 -0
  28. package/src/auth/authorization/transparent.authorization.d.ts +130 -0
  29. package/src/auth/authorization/transparent.authorization.js +147 -0
  30. package/src/auth/authorization/transparent.authorization.js.map +1 -0
  31. package/src/auth/consent/consent.types.d.ts +111 -0
  32. package/src/auth/consent/consent.types.js +119 -0
  33. package/src/auth/consent/consent.types.js.map +1 -0
  34. package/src/auth/consent/index.d.ts +1 -0
  35. package/src/auth/consent/index.js +13 -0
  36. package/src/auth/consent/index.js.map +1 -0
  37. package/src/auth/detection/auth-provider-detection.d.ts +84 -0
  38. package/src/auth/detection/auth-provider-detection.js +230 -0
  39. package/src/auth/detection/auth-provider-detection.js.map +1 -0
  40. package/src/auth/detection/index.d.ts +1 -0
  41. package/src/auth/detection/index.js +15 -0
  42. package/src/auth/detection/index.js.map +1 -0
  43. package/src/auth/flows/auth.verify.flow.d.ts +110 -0
  44. package/src/auth/flows/auth.verify.flow.js +379 -0
  45. package/src/auth/flows/auth.verify.flow.js.map +1 -0
  46. package/src/auth/flows/oauth.authorize.flow.d.ts +118 -164
  47. package/src/auth/flows/oauth.authorize.flow.js +701 -33
  48. package/src/auth/flows/oauth.authorize.flow.js.map +1 -1
  49. package/src/auth/flows/oauth.callback.flow.d.ts +117 -0
  50. package/src/auth/flows/oauth.callback.flow.js +357 -0
  51. package/src/auth/flows/oauth.callback.flow.js.map +1 -0
  52. package/src/auth/flows/oauth.register.flow.d.ts +32 -125
  53. package/src/auth/flows/oauth.token.flow.d.ts +52 -154
  54. package/src/auth/flows/oauth.token.flow.js +193 -55
  55. package/src/auth/flows/oauth.token.flow.js.map +1 -1
  56. package/src/auth/flows/session.verify.flow.d.ts +66 -321
  57. package/src/auth/flows/session.verify.flow.js +107 -18
  58. package/src/auth/flows/session.verify.flow.js.map +1 -1
  59. package/src/auth/flows/well-known.jwks.flow.d.ts +34 -205
  60. package/src/auth/flows/well-known.jwks.flow.js +15 -8
  61. package/src/auth/flows/well-known.jwks.flow.js.map +1 -1
  62. package/src/auth/flows/well-known.oauth-authorization-server.flow.d.ts +48 -223
  63. package/src/auth/flows/well-known.oauth-authorization-server.flow.js +2 -3
  64. package/src/auth/flows/well-known.oauth-authorization-server.flow.js.map +1 -1
  65. package/src/auth/flows/well-known.prm.flow.d.ts +19 -120
  66. package/src/auth/flows/well-known.prm.flow.js +3 -4
  67. package/src/auth/flows/well-known.prm.flow.js.map +1 -1
  68. package/src/auth/instances/instance.local-primary-auth.d.ts +91 -4
  69. package/src/auth/instances/instance.local-primary-auth.js +236 -6
  70. package/src/auth/instances/instance.local-primary-auth.js.map +1 -1
  71. package/src/auth/instances/instance.remote-primary-auth.d.ts +4 -3
  72. package/src/auth/instances/instance.remote-primary-auth.js +2 -2
  73. package/src/auth/instances/instance.remote-primary-auth.js.map +1 -1
  74. package/src/auth/session/authorization-vault.d.ts +611 -0
  75. package/src/auth/session/authorization-vault.js +817 -0
  76. package/src/auth/session/authorization-vault.js.map +1 -0
  77. package/src/auth/session/authorization.store.d.ts +301 -0
  78. package/src/auth/session/authorization.store.js +323 -0
  79. package/src/auth/session/authorization.store.js.map +1 -0
  80. package/src/auth/session/encrypted-authorization-vault.d.ts +181 -0
  81. package/src/auth/session/encrypted-authorization-vault.js +493 -0
  82. package/src/auth/session/encrypted-authorization-vault.js.map +1 -0
  83. package/src/auth/session/index.d.ts +4 -4
  84. package/src/auth/session/index.js +11 -7
  85. package/src/auth/session/index.js.map +1 -1
  86. package/src/auth/session/session.schema.d.ts +1 -1
  87. package/src/auth/session/session.service.d.ts +1 -1
  88. package/src/auth/session/transport-session.manager.d.ts +101 -0
  89. package/src/auth/session/transport-session.manager.js +300 -0
  90. package/src/auth/session/transport-session.manager.js.map +1 -0
  91. package/src/auth/session/transport-session.types.d.ts +457 -0
  92. package/src/auth/session/transport-session.types.js +110 -0
  93. package/src/auth/session/transport-session.types.js.map +1 -0
  94. package/src/auth/session/utils/session-id.utils.d.ts +14 -2
  95. package/src/auth/session/utils/session-id.utils.js +68 -19
  96. package/src/auth/session/utils/session-id.utils.js.map +1 -1
  97. package/src/auth/session/vault-encryption.d.ts +189 -0
  98. package/src/auth/session/vault-encryption.js +263 -0
  99. package/src/auth/session/vault-encryption.js.map +1 -0
  100. package/src/auth/ui/base-layout.d.ts +188 -0
  101. package/src/auth/ui/base-layout.js +292 -0
  102. package/src/auth/ui/base-layout.js.map +1 -0
  103. package/src/auth/ui/htmx-templates.d.ts +135 -0
  104. package/src/auth/ui/htmx-templates.js +433 -0
  105. package/src/auth/ui/htmx-templates.js.map +1 -0
  106. package/src/auth/ui/index.d.ts +11 -0
  107. package/src/auth/ui/index.js +35 -0
  108. package/src/auth/ui/index.js.map +1 -0
  109. package/src/auth/utils/audience.validator.d.ts +129 -0
  110. package/src/auth/utils/audience.validator.js +196 -0
  111. package/src/auth/utils/audience.validator.js.map +1 -0
  112. package/src/auth/utils/index.d.ts +2 -0
  113. package/src/auth/utils/index.js +7 -0
  114. package/src/auth/utils/index.js.map +1 -0
  115. package/src/auth/utils/www-authenticate.utils.d.ts +97 -0
  116. package/src/auth/utils/www-authenticate.utils.js +183 -0
  117. package/src/auth/utils/www-authenticate.utils.js.map +1 -0
  118. package/src/common/common.schema.d.ts +2 -16
  119. package/src/common/constants.d.ts +3 -0
  120. package/src/common/constants.js +6 -1
  121. package/src/common/constants.js.map +1 -1
  122. package/src/common/decorators/decorator-utils.d.ts +131 -0
  123. package/src/common/decorators/decorator-utils.js +195 -0
  124. package/src/common/decorators/decorator-utils.js.map +1 -0
  125. package/src/common/decorators/front-mcp.decorator.js +3 -2
  126. package/src/common/decorators/front-mcp.decorator.js.map +1 -1
  127. package/src/common/decorators/hook.decorator.d.ts +58 -2
  128. package/src/common/decorators/hook.decorator.js +127 -17
  129. package/src/common/decorators/hook.decorator.js.map +1 -1
  130. package/src/common/decorators/plugin.decorator.d.ts +1 -1
  131. package/src/common/decorators/plugin.decorator.js +11 -10
  132. package/src/common/decorators/plugin.decorator.js.map +1 -1
  133. package/src/common/decorators/resource.decorator.d.ts +32 -3
  134. package/src/common/decorators/resource.decorator.js +46 -4
  135. package/src/common/decorators/resource.decorator.js.map +1 -1
  136. package/src/common/decorators/tool.decorator.d.ts +54 -5
  137. package/src/common/decorators/tool.decorator.js.map +1 -1
  138. package/src/common/dynamic/dynamic.plugin.d.ts +22 -11
  139. package/src/common/dynamic/dynamic.plugin.js +7 -1
  140. package/src/common/dynamic/dynamic.plugin.js.map +1 -1
  141. package/src/common/entries/prompt.entry.d.ts +46 -2
  142. package/src/common/entries/prompt.entry.js +10 -0
  143. package/src/common/entries/prompt.entry.js.map +1 -1
  144. package/src/common/entries/resource.entry.d.ts +69 -6
  145. package/src/common/entries/resource.entry.js +27 -3
  146. package/src/common/entries/resource.entry.js.map +1 -1
  147. package/src/common/entries/scope.entry.d.ts +5 -1
  148. package/src/common/entries/scope.entry.js +3 -3
  149. package/src/common/entries/scope.entry.js.map +1 -1
  150. package/src/common/flow/flow.utils.d.ts +56 -0
  151. package/src/common/flow/flow.utils.js +96 -0
  152. package/src/common/flow/flow.utils.js.map +1 -0
  153. package/src/common/index.d.ts +2 -2
  154. package/src/common/index.js +2 -2
  155. package/src/common/index.js.map +1 -1
  156. package/src/common/interfaces/execution-context.interface.d.ts +59 -0
  157. package/src/common/interfaces/execution-context.interface.js +81 -0
  158. package/src/common/interfaces/execution-context.interface.js.map +1 -0
  159. package/src/common/interfaces/flow.interface.d.ts +1 -1
  160. package/src/common/interfaces/flow.interface.js.map +1 -1
  161. package/src/common/interfaces/index.d.ts +1 -0
  162. package/src/common/interfaces/index.js +1 -0
  163. package/src/common/interfaces/index.js.map +1 -1
  164. package/src/common/interfaces/internal/primary-auth-provider.interface.d.ts +17 -2
  165. package/src/common/interfaces/internal/primary-auth-provider.interface.js +52 -4
  166. package/src/common/interfaces/internal/primary-auth-provider.interface.js.map +1 -1
  167. package/src/common/interfaces/internal/registry.interface.d.ts +16 -2
  168. package/src/common/interfaces/internal/registry.interface.js.map +1 -1
  169. package/src/common/interfaces/plugin.interface.js.map +1 -1
  170. package/src/common/interfaces/prompt.interface.d.ts +53 -4
  171. package/src/common/interfaces/prompt.interface.js +78 -0
  172. package/src/common/interfaces/prompt.interface.js.map +1 -1
  173. package/src/common/interfaces/resource.interface.d.ts +47 -17
  174. package/src/common/interfaces/resource.interface.js +53 -0
  175. package/src/common/interfaces/resource.interface.js.map +1 -1
  176. package/src/common/interfaces/tool.interface.d.ts +39 -22
  177. package/src/common/interfaces/tool.interface.js +61 -34
  178. package/src/common/interfaces/tool.interface.js.map +1 -1
  179. package/src/common/metadata/adapter.metadata.d.ts +1 -9
  180. package/src/common/metadata/app.metadata.d.ts +425 -730
  181. package/src/common/metadata/auth-provider.metadata.d.ts +2 -12
  182. package/src/common/metadata/flow.metadata.d.ts +10 -25
  183. package/src/common/metadata/front-mcp.metadata.d.ts +602 -1023
  184. package/src/common/metadata/front-mcp.metadata.js +6 -4
  185. package/src/common/metadata/front-mcp.metadata.js.map +1 -1
  186. package/src/common/metadata/hook.metadata.d.ts +1 -1
  187. package/src/common/metadata/hook.metadata.js.map +1 -1
  188. package/src/common/metadata/index.d.ts +1 -0
  189. package/src/common/metadata/index.js +1 -0
  190. package/src/common/metadata/index.js.map +1 -1
  191. package/src/common/metadata/logger.metadata.d.ts +1 -9
  192. package/src/common/metadata/plugin.metadata.d.ts +8 -30
  193. package/src/common/metadata/prompt.metadata.d.ts +4 -161
  194. package/src/common/metadata/provider.metadata.d.ts +2 -12
  195. package/src/common/metadata/resource.metadata.d.ts +6 -98
  196. package/src/common/metadata/resource.metadata.js +15 -6
  197. package/src/common/metadata/resource.metadata.js.map +1 -1
  198. package/src/common/metadata/tool-ui.metadata.d.ts +10 -0
  199. package/src/common/metadata/tool-ui.metadata.js +12 -0
  200. package/src/common/metadata/tool-ui.metadata.js.map +1 -0
  201. package/src/common/metadata/tool.metadata.d.ts +78 -199
  202. package/src/common/metadata/tool.metadata.js +11 -14
  203. package/src/common/metadata/tool.metadata.js.map +1 -1
  204. package/src/common/providers/base-config.provider.d.ts +84 -0
  205. package/src/common/providers/base-config.provider.js +128 -0
  206. package/src/common/providers/base-config.provider.js.map +1 -0
  207. package/src/common/records/plugin.record.d.ts +5 -6
  208. package/src/common/records/plugin.record.js.map +1 -1
  209. package/src/common/records/prompt.record.js.map +1 -1
  210. package/src/common/records/resource.record.d.ts +17 -1
  211. package/src/common/records/resource.record.js +12 -6
  212. package/src/common/records/resource.record.js.map +1 -1
  213. package/src/common/records/tool.record.js.map +1 -1
  214. package/src/common/schemas/annotated-class.schema.d.ts +9 -9
  215. package/src/common/schemas/annotated-class.schema.js +92 -27
  216. package/src/common/schemas/annotated-class.schema.js.map +1 -1
  217. package/src/common/schemas/http-input.schema.d.ts +6 -30
  218. package/src/common/schemas/http-output.schema.d.ts +326 -1630
  219. package/src/common/schemas/http-output.schema.js +39 -1
  220. package/src/common/schemas/http-output.schema.js.map +1 -1
  221. package/src/common/tokens/front-mcp.tokens.js +4 -1
  222. package/src/common/tokens/front-mcp.tokens.js.map +1 -1
  223. package/src/common/tokens/resource.tokens.d.ts +2 -0
  224. package/src/common/tokens/resource.tokens.js +4 -1
  225. package/src/common/tokens/resource.tokens.js.map +1 -1
  226. package/src/common/tokens/tool.tokens.d.ts +2 -0
  227. package/src/common/tokens/tool.tokens.js +2 -0
  228. package/src/common/tokens/tool.tokens.js.map +1 -1
  229. package/src/common/types/auth/jwt.types.d.ts +5 -31
  230. package/src/common/types/auth/session.types.d.ts +97 -192
  231. package/src/common/types/auth/session.types.js +24 -11
  232. package/src/common/types/auth/session.types.js.map +1 -1
  233. package/src/common/types/options/auth.options.d.ts +1013 -490
  234. package/src/common/types/options/auth.options.js +554 -36
  235. package/src/common/types/options/auth.options.js.map +1 -1
  236. package/src/common/types/options/http.options.d.ts +1 -9
  237. package/src/common/types/options/logging.options.d.ts +7 -13
  238. package/src/common/types/options/logging.options.js +4 -0
  239. package/src/common/types/options/logging.options.js.map +1 -1
  240. package/src/common/types/options/server-info.options.d.ts +3 -31
  241. package/src/common/types/options/session.options.d.ts +90 -10
  242. package/src/common/types/options/session.options.js +26 -3
  243. package/src/common/types/options/session.options.js.map +1 -1
  244. package/src/common/utils/decide-request-intent.utils.d.ts +8 -46
  245. package/src/common/utils/decide-request-intent.utils.js +88 -23
  246. package/src/common/utils/decide-request-intent.utils.js.map +1 -1
  247. package/src/completion/flows/complete.flow.d.ts +74 -0
  248. package/src/completion/flows/complete.flow.js +199 -0
  249. package/src/completion/flows/complete.flow.js.map +1 -0
  250. package/src/errors/authorization-required.error.d.ts +189 -0
  251. package/src/errors/authorization-required.error.js +274 -0
  252. package/src/errors/authorization-required.error.js.map +1 -0
  253. package/src/errors/index.d.ts +2 -1
  254. package/src/errors/index.js +17 -1
  255. package/src/errors/index.js.map +1 -1
  256. package/src/errors/mcp.error.d.ts +101 -1
  257. package/src/errors/mcp.error.js +147 -2
  258. package/src/errors/mcp.error.js.map +1 -1
  259. package/src/flows/flow.instance.js +4 -3
  260. package/src/flows/flow.instance.js.map +1 -1
  261. package/src/flows/flow.registry.js.map +1 -1
  262. package/src/flows/flow.stages.js +14 -11
  263. package/src/flows/flow.stages.js.map +1 -1
  264. package/src/front-mcp/front-mcp.providers.d.ts +464 -102
  265. package/src/front-mcp/front-mcp.providers.js +3 -5
  266. package/src/front-mcp/front-mcp.providers.js.map +1 -1
  267. package/src/hooks/hook.instance.d.ts +1 -1
  268. package/src/hooks/hook.instance.js +5 -2
  269. package/src/hooks/hook.instance.js.map +1 -1
  270. package/src/hooks/hook.registry.js +7 -5
  271. package/src/hooks/hook.registry.js.map +1 -1
  272. package/src/index.d.ts +28 -9
  273. package/src/index.js +5 -1
  274. package/src/index.js.map +1 -1
  275. package/src/logger/instances/instance.logger.js +3 -2
  276. package/src/logger/instances/instance.logger.js.map +1 -1
  277. package/src/logger/logger.registry.js +7 -2
  278. package/src/logger/logger.registry.js.map +1 -1
  279. package/src/logging/flows/set-level.flow.d.ts +62 -0
  280. package/src/logging/flows/set-level.flow.js +108 -0
  281. package/src/logging/flows/set-level.flow.js.map +1 -0
  282. package/src/mcp-apps/csp.d.ts +111 -0
  283. package/src/mcp-apps/csp.js +267 -0
  284. package/src/mcp-apps/csp.js.map +1 -0
  285. package/src/mcp-apps/index.d.ts +23 -0
  286. package/src/mcp-apps/index.js +91 -0
  287. package/src/mcp-apps/index.js.map +1 -0
  288. package/src/mcp-apps/schemas.d.ts +403 -0
  289. package/src/mcp-apps/schemas.js +345 -0
  290. package/src/mcp-apps/schemas.js.map +1 -0
  291. package/src/mcp-apps/template.d.ts +94 -0
  292. package/src/mcp-apps/template.js +419 -0
  293. package/src/mcp-apps/template.js.map +1 -0
  294. package/src/mcp-apps/types.d.ts +323 -0
  295. package/src/mcp-apps/types.js +59 -0
  296. package/src/mcp-apps/types.js.map +1 -0
  297. package/src/notification/index.d.ts +1 -0
  298. package/src/notification/index.js +13 -0
  299. package/src/notification/index.js.map +1 -0
  300. package/src/notification/notification.service.d.ts +378 -0
  301. package/src/notification/notification.service.js +727 -0
  302. package/src/notification/notification.service.js.map +1 -0
  303. package/src/plugin/plugin.registry.js +12 -9
  304. package/src/plugin/plugin.registry.js.map +1 -1
  305. package/src/prompt/flows/get-prompt.flow.d.ts +153 -0
  306. package/src/prompt/flows/get-prompt.flow.js +214 -0
  307. package/src/prompt/flows/get-prompt.flow.js.map +1 -0
  308. package/src/prompt/flows/prompts-list.flow.d.ts +67 -0
  309. package/src/prompt/flows/prompts-list.flow.js +176 -0
  310. package/src/prompt/flows/prompts-list.flow.js.map +1 -0
  311. package/src/prompt/index.d.ts +7 -0
  312. package/src/prompt/index.js +17 -0
  313. package/src/prompt/index.js.map +1 -0
  314. package/src/prompt/prompt.events.d.ts +17 -0
  315. package/src/prompt/prompt.events.js +25 -0
  316. package/src/prompt/prompt.events.js.map +1 -0
  317. package/src/prompt/prompt.instance.d.ts +30 -0
  318. package/src/prompt/prompt.instance.js +120 -0
  319. package/src/prompt/prompt.instance.js.map +1 -0
  320. package/src/prompt/prompt.registry.d.ts +79 -12
  321. package/src/prompt/prompt.registry.js +360 -15
  322. package/src/prompt/prompt.registry.js.map +1 -1
  323. package/src/prompt/prompt.types.d.ts +26 -0
  324. package/src/prompt/prompt.types.js +11 -0
  325. package/src/prompt/prompt.types.js.map +1 -0
  326. package/src/prompt/prompt.utils.d.ts +26 -0
  327. package/src/prompt/prompt.utils.js +136 -0
  328. package/src/prompt/prompt.utils.js.map +1 -0
  329. package/src/provider/provider.registry.d.ts +12 -5
  330. package/src/provider/provider.registry.js +30 -138
  331. package/src/provider/provider.registry.js.map +1 -1
  332. package/src/regsitry/registry.base.d.ts +1 -1
  333. package/src/regsitry/registry.base.js.map +1 -1
  334. package/src/resource/flows/read-resource.flow.d.ts +91 -0
  335. package/src/resource/flows/read-resource.flow.js +270 -0
  336. package/src/resource/flows/read-resource.flow.js.map +1 -0
  337. package/src/resource/flows/resource-templates-list.flow.d.ts +64 -0
  338. package/src/resource/flows/resource-templates-list.flow.js +191 -0
  339. package/src/resource/flows/resource-templates-list.flow.js.map +1 -0
  340. package/src/resource/flows/resources-list.flow.d.ts +64 -0
  341. package/src/resource/flows/resources-list.flow.js +196 -0
  342. package/src/resource/flows/resources-list.flow.js.map +1 -0
  343. package/src/resource/flows/subscribe-resource.flow.d.ts +45 -0
  344. package/src/resource/flows/subscribe-resource.flow.js +123 -0
  345. package/src/resource/flows/subscribe-resource.flow.js.map +1 -0
  346. package/src/resource/flows/unsubscribe-resource.flow.d.ts +44 -0
  347. package/src/resource/flows/unsubscribe-resource.flow.js +107 -0
  348. package/src/resource/flows/unsubscribe-resource.flow.js.map +1 -0
  349. package/src/resource/index.d.ts +8 -0
  350. package/src/resource/index.js +20 -0
  351. package/src/resource/index.js.map +1 -0
  352. package/src/resource/resource.events.d.ts +24 -0
  353. package/src/resource/resource.events.js +17 -0
  354. package/src/resource/resource.events.js.map +1 -0
  355. package/src/resource/resource.instance.d.ts +35 -0
  356. package/src/resource/resource.instance.js +163 -0
  357. package/src/resource/resource.instance.js.map +1 -0
  358. package/src/resource/resource.registry.d.ts +106 -12
  359. package/src/resource/resource.registry.js +449 -13
  360. package/src/resource/resource.registry.js.map +1 -1
  361. package/src/resource/resource.types.d.ts +35 -0
  362. package/src/resource/resource.types.js +11 -0
  363. package/src/resource/resource.types.js.map +1 -0
  364. package/src/resource/resource.utils.d.ts +30 -0
  365. package/src/resource/resource.utils.js +151 -0
  366. package/src/resource/resource.utils.js.map +1 -0
  367. package/src/scope/flows/http.request.flow.d.ts +48 -330
  368. package/src/scope/flows/http.request.flow.js +306 -78
  369. package/src/scope/flows/http.request.flow.js.map +1 -1
  370. package/src/scope/scope.instance.d.ts +12 -0
  371. package/src/scope/scope.instance.js +145 -15
  372. package/src/scope/scope.instance.js.map +1 -1
  373. package/src/tool/flows/call-tool.flow.d.ts +64 -1110
  374. package/src/tool/flows/call-tool.flow.js +303 -15
  375. package/src/tool/flows/call-tool.flow.js.map +1 -1
  376. package/src/tool/flows/tools-list.flow.d.ts +32 -473
  377. package/src/tool/flows/tools-list.flow.js +111 -10
  378. package/src/tool/flows/tools-list.flow.js.map +1 -1
  379. package/src/tool/tool.events.d.ts +8 -1
  380. package/src/tool/tool.events.js.map +1 -1
  381. package/src/tool/tool.instance.d.ts +3 -1
  382. package/src/tool/tool.instance.js +17 -3
  383. package/src/tool/tool.instance.js.map +1 -1
  384. package/src/tool/tool.registry.d.ts +7 -1
  385. package/src/tool/tool.registry.js +26 -10
  386. package/src/tool/tool.registry.js.map +1 -1
  387. package/src/tool/tool.types.d.ts +4 -4
  388. package/src/tool/tool.types.js.map +1 -1
  389. package/src/tool/tool.utils.d.ts +3 -12
  390. package/src/tool/tool.utils.js +39 -193
  391. package/src/tool/tool.utils.js.map +1 -1
  392. package/src/tool/ui/index.d.ts +22 -0
  393. package/src/tool/ui/index.js +63 -0
  394. package/src/tool/ui/index.js.map +1 -0
  395. package/src/tool/ui/platform-adapters.d.ts +10 -0
  396. package/src/tool/ui/platform-adapters.js +18 -0
  397. package/src/tool/ui/platform-adapters.js.map +1 -0
  398. package/src/tool/ui/template-helpers.d.ts +46 -0
  399. package/src/tool/ui/template-helpers.js +112 -0
  400. package/src/tool/ui/template-helpers.js.map +1 -0
  401. package/src/tool/ui/ui-resource-template.d.ts +34 -0
  402. package/src/tool/ui/ui-resource-template.js +64 -0
  403. package/src/tool/ui/ui-resource-template.js.map +1 -0
  404. package/src/tool/ui/ui-resource.handler.d.ts +74 -0
  405. package/src/tool/ui/ui-resource.handler.js +129 -0
  406. package/src/tool/ui/ui-resource.handler.js.map +1 -0
  407. package/src/transport/adapters/transport.local.adapter.d.ts +2 -2
  408. package/src/transport/adapters/transport.local.adapter.js +28 -7
  409. package/src/transport/adapters/transport.local.adapter.js.map +1 -1
  410. package/src/transport/adapters/transport.sse.adapter.d.ts +2 -2
  411. package/src/transport/adapters/transport.sse.adapter.js +4 -3
  412. package/src/transport/adapters/transport.sse.adapter.js.map +1 -1
  413. package/src/transport/adapters/transport.streamable-http.adapter.d.ts +10 -3
  414. package/src/transport/adapters/transport.streamable-http.adapter.js +54 -8
  415. package/src/transport/adapters/transport.streamable-http.adapter.js.map +1 -1
  416. package/src/transport/flows/handle.sse.flow.d.ts +29 -63
  417. package/src/transport/flows/handle.sse.flow.js +78 -10
  418. package/src/transport/flows/handle.sse.flow.js.map +1 -1
  419. package/src/transport/flows/handle.stateless-http.flow.d.ts +29 -0
  420. package/src/transport/flows/handle.stateless-http.flow.js +102 -0
  421. package/src/transport/flows/handle.stateless-http.flow.js.map +1 -0
  422. package/src/transport/flows/handle.streamable-http.flow.d.ts +32 -64
  423. package/src/transport/flows/handle.streamable-http.flow.js +158 -26
  424. package/src/transport/flows/handle.streamable-http.flow.js.map +1 -1
  425. package/src/transport/legacy/legacy.sse.tranporter.d.ts +9 -0
  426. package/src/transport/legacy/legacy.sse.tranporter.js +17 -2
  427. package/src/transport/legacy/legacy.sse.tranporter.js.map +1 -1
  428. package/src/transport/mcp-handlers/call-tool-request.handler.js +27 -1
  429. package/src/transport/mcp-handlers/call-tool-request.handler.js.map +1 -1
  430. package/src/transport/mcp-handlers/complete-request.handler.d.ts +69 -0
  431. package/src/transport/mcp-handlers/complete-request.handler.js +11 -0
  432. package/src/transport/mcp-handlers/complete-request.handler.js.map +1 -0
  433. package/src/transport/mcp-handlers/get-prompt-request.handler.d.ts +87 -0
  434. package/src/transport/mcp-handlers/get-prompt-request.handler.js +11 -0
  435. package/src/transport/mcp-handlers/get-prompt-request.handler.js.map +1 -0
  436. package/src/transport/mcp-handlers/index.d.ts +517 -208
  437. package/src/transport/mcp-handlers/index.js +39 -2
  438. package/src/transport/mcp-handlers/index.js.map +1 -1
  439. package/src/transport/mcp-handlers/initialize-request.handler.d.ts +1 -1
  440. package/src/transport/mcp-handlers/initialize-request.handler.js +73 -7
  441. package/src/transport/mcp-handlers/initialize-request.handler.js.map +1 -1
  442. package/src/transport/mcp-handlers/list-prompts-request.handler.d.ts +54 -0
  443. package/src/transport/mcp-handlers/list-prompts-request.handler.js +11 -0
  444. package/src/transport/mcp-handlers/list-prompts-request.handler.js.map +1 -0
  445. package/src/transport/mcp-handlers/list-resource-templates-request.handler.d.ts +51 -0
  446. package/src/transport/mcp-handlers/list-resource-templates-request.handler.js +12 -0
  447. package/src/transport/mcp-handlers/list-resource-templates-request.handler.js.map +1 -0
  448. package/src/transport/mcp-handlers/list-resources-request.handler.d.ts +51 -0
  449. package/src/transport/mcp-handlers/list-resources-request.handler.js +12 -0
  450. package/src/transport/mcp-handlers/list-resources-request.handler.js.map +1 -0
  451. package/src/transport/mcp-handlers/list-tools-request.handler.d.ts +19 -146
  452. package/src/transport/mcp-handlers/logging-set-level-request.handler.d.ts +46 -0
  453. package/src/transport/mcp-handlers/logging-set-level-request.handler.js +34 -0
  454. package/src/transport/mcp-handlers/logging-set-level-request.handler.js.map +1 -0
  455. package/src/transport/mcp-handlers/mcp-handlers.types.d.ts +3 -7
  456. package/src/transport/mcp-handlers/mcp-handlers.types.js.map +1 -1
  457. package/src/transport/mcp-handlers/read-resource-request.handler.d.ts +46 -0
  458. package/src/transport/mcp-handlers/read-resource-request.handler.js +12 -0
  459. package/src/transport/mcp-handlers/read-resource-request.handler.js.map +1 -0
  460. package/src/transport/mcp-handlers/roots-list-changed-notification.handler.d.ts +11 -0
  461. package/src/transport/mcp-handlers/roots-list-changed-notification.handler.js +26 -0
  462. package/src/transport/mcp-handlers/roots-list-changed-notification.handler.js.map +1 -0
  463. package/src/transport/mcp-handlers/subscribe-request.handler.d.ts +37 -0
  464. package/src/transport/mcp-handlers/subscribe-request.handler.js +34 -0
  465. package/src/transport/mcp-handlers/subscribe-request.handler.js.map +1 -0
  466. package/src/transport/mcp-handlers/unsubscribe-request.handler.d.ts +37 -0
  467. package/src/transport/mcp-handlers/unsubscribe-request.handler.js +34 -0
  468. package/src/transport/mcp-handlers/unsubscribe-request.handler.js.map +1 -0
  469. package/src/transport/transport.local.js +7 -2
  470. package/src/transport/transport.local.js.map +1 -1
  471. package/src/transport/transport.registry.d.ts +30 -0
  472. package/src/transport/transport.registry.js +84 -1
  473. package/src/transport/transport.registry.js.map +1 -1
  474. package/src/transport/transport.types.d.ts +3 -3
  475. package/src/transport/transport.types.js.map +1 -1
  476. package/src/utils/content.utils.d.ts +48 -0
  477. package/src/utils/content.utils.js +194 -0
  478. package/src/utils/content.utils.js.map +1 -0
  479. package/src/utils/index.d.ts +8 -0
  480. package/src/utils/index.js +55 -0
  481. package/src/utils/index.js.map +1 -0
  482. package/src/utils/lineage.utils.d.ts +40 -0
  483. package/src/utils/lineage.utils.js +82 -0
  484. package/src/utils/lineage.utils.js.map +1 -0
  485. package/src/utils/naming.utils.d.ts +46 -0
  486. package/src/utils/naming.utils.js +136 -0
  487. package/src/utils/naming.utils.js.map +1 -0
  488. package/src/utils/types.utils.d.ts +2 -2
  489. package/src/utils/types.utils.js.map +1 -1
  490. package/src/utils/uri-template.utils.d.ts +57 -0
  491. package/src/utils/uri-template.utils.js +113 -0
  492. package/src/utils/uri-template.utils.js.map +1 -0
  493. package/src/utils/uri-validation.utils.d.ts +40 -0
  494. package/src/utils/uri-validation.utils.js +76 -0
  495. package/src/utils/uri-validation.utils.js.map +1 -0
  496. package/src/__test-utils__/fixtures/hook.fixtures.d.ts +0 -46
  497. package/src/__test-utils__/fixtures/hook.fixtures.js +0 -114
  498. package/src/__test-utils__/fixtures/hook.fixtures.js.map +0 -1
  499. package/src/__test-utils__/fixtures/index.d.ts +0 -7
  500. package/src/__test-utils__/fixtures/index.js +0 -11
  501. package/src/__test-utils__/fixtures/index.js.map +0 -1
  502. package/src/__test-utils__/fixtures/plugin.fixtures.d.ts +0 -46
  503. package/src/__test-utils__/fixtures/plugin.fixtures.js +0 -127
  504. package/src/__test-utils__/fixtures/plugin.fixtures.js.map +0 -1
  505. package/src/__test-utils__/fixtures/provider.fixtures.d.ts +0 -69
  506. package/src/__test-utils__/fixtures/provider.fixtures.js +0 -131
  507. package/src/__test-utils__/fixtures/provider.fixtures.js.map +0 -1
  508. package/src/__test-utils__/fixtures/scope.fixtures.d.ts +0 -14
  509. package/src/__test-utils__/fixtures/scope.fixtures.js +0 -59
  510. package/src/__test-utils__/fixtures/scope.fixtures.js.map +0 -1
  511. package/src/__test-utils__/fixtures/tool.fixtures.d.ts +0 -36
  512. package/src/__test-utils__/fixtures/tool.fixtures.js +0 -91
  513. package/src/__test-utils__/fixtures/tool.fixtures.js.map +0 -1
  514. package/src/__test-utils__/helpers/assertion.helpers.d.ts +0 -45
  515. package/src/__test-utils__/helpers/assertion.helpers.js +0 -153
  516. package/src/__test-utils__/helpers/assertion.helpers.js.map +0 -1
  517. package/src/__test-utils__/helpers/async.helpers.d.ts +0 -48
  518. package/src/__test-utils__/helpers/async.helpers.js +0 -112
  519. package/src/__test-utils__/helpers/async.helpers.js.map +0 -1
  520. package/src/__test-utils__/helpers/index.d.ts +0 -6
  521. package/src/__test-utils__/helpers/index.js +0 -10
  522. package/src/__test-utils__/helpers/index.js.map +0 -1
  523. package/src/__test-utils__/helpers/setup.helpers.d.ts +0 -54
  524. package/src/__test-utils__/helpers/setup.helpers.js +0 -106
  525. package/src/__test-utils__/helpers/setup.helpers.js.map +0 -1
  526. package/src/__test-utils__/index.d.ts +0 -9
  527. package/src/__test-utils__/index.js +0 -14
  528. package/src/__test-utils__/index.js.map +0 -1
  529. package/src/__test-utils__/mocks/flow-instance.mock.d.ts +0 -50
  530. package/src/__test-utils__/mocks/flow-instance.mock.js +0 -72
  531. package/src/__test-utils__/mocks/flow-instance.mock.js.map +0 -1
  532. package/src/__test-utils__/mocks/hook-registry.mock.d.ts +0 -25
  533. package/src/__test-utils__/mocks/hook-registry.mock.js +0 -65
  534. package/src/__test-utils__/mocks/hook-registry.mock.js.map +0 -1
  535. package/src/__test-utils__/mocks/index.d.ts +0 -8
  536. package/src/__test-utils__/mocks/index.js +0 -12
  537. package/src/__test-utils__/mocks/index.js.map +0 -1
  538. package/src/__test-utils__/mocks/plugin-registry.mock.d.ts +0 -43
  539. package/src/__test-utils__/mocks/plugin-registry.mock.js +0 -70
  540. package/src/__test-utils__/mocks/plugin-registry.mock.js.map +0 -1
  541. package/src/__test-utils__/mocks/provider-registry.mock.d.ts +0 -39
  542. package/src/__test-utils__/mocks/provider-registry.mock.js +0 -72
  543. package/src/__test-utils__/mocks/provider-registry.mock.js.map +0 -1
  544. package/src/__test-utils__/mocks/tool-registry.mock.d.ts +0 -43
  545. package/src/__test-utils__/mocks/tool-registry.mock.js +0 -79
  546. package/src/__test-utils__/mocks/tool-registry.mock.js.map +0 -1
  547. package/src/auth/path.utils.d.ts +0 -20
  548. package/src/auth/path.utils.js +0 -71
  549. package/src/auth/path.utils.js.map +0 -1
  550. package/src/common/decorators-old/async-with.decorator.d.ts +0 -10
  551. package/src/common/decorators-old/async-with.decorator.js +0 -24
  552. package/src/common/decorators-old/async-with.decorator.js.map +0 -1
  553. package/src/common/decorators-old/auth-hook.decorator.d.ts +0 -14
  554. package/src/common/decorators-old/auth-hook.decorator.js +0 -27
  555. package/src/common/decorators-old/auth-hook.decorator.js.map +0 -1
  556. package/src/common/decorators-old/session-hook.decorator.d.ts +0 -14
  557. package/src/common/decorators-old/session-hook.decorator.js +0 -27
  558. package/src/common/decorators-old/session-hook.decorator.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"transport.local.adapter.js","sourceRoot":"","sources":["../../../../src/transport/adapters/transport.local.adapter.ts"],"names":[],"mappings":";;;AAEA,wEAA8E;AAC9E,iEAAkH;AAClH,oEAA4D;AAK5D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AG,CAAC,IAAI,GAAG;YACT,KAAK;YACL,IAAI;YACJ,SAAS,EAAE,OAAQ,CAAC,EAAE;YACtB,gBAAgB,EAAE,OAAQ,CAAC,OAAO;YAClC,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE;YACxB,SAAS;SACS,CAAC;QACrB,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,oBAAoB,CAAC,GAA+B;QAElD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACnB,MAAM,EAAC,IAAI,EAAE,OAAO,EAAC,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;YACvC,IAAI,IAAI,KAAK,CAAC,KAAK,IAAI,OAAO,KAAK,2BAA2B,EAAE,CAAC;gBAC/D,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC1C,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,MAAM,GAAG,6BAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC9D,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACxC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAzID,sDAyIC","sourcesContent":["import {AuthenticatedServerRequest} from '../../server/server.types';\nimport {TransportKey, TypedElicitResult} from '../transport.types';\nimport {Server as McpServer} from '@modelcontextprotocol/sdk/server/index.js';\nimport {EmptyResultSchema, ElicitResult, RequestId, ElicitResultSchema} from '@modelcontextprotocol/sdk/types.js';\nimport {InMemoryEventStore} from '../transport.event-store';\nimport {AuthInfo} from '@modelcontextprotocol/sdk/server/auth/types.js';\nimport {StreamableHTTPServerTransport} from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport {SSEServerTransport} from '../legacy/legacy.sse.tranporter';\nimport {ZodObject} from 'zod';\nimport {FrontMcpLogger, ServerRequestTokens, ServerResponse} from '../../common';\nimport {Scope} from '../../scope';\nimport {createMcpHandlers} from '../mcp-handlers';\n\nexport abstract class LocalTransportAdapter<T extends StreamableHTTPServerTransport | SSEServerTransport> {\n protected logger: FrontMcpLogger;\n protected transport: T;\n protected eventStore = new InMemoryEventStore();\n protected elicitHandler: { resolve: (result: ElicitResult) => void; reject: (err: unknown) => void } | undefined =\n undefined;\n #requestId = 1;\n ready: Promise<void>;\n server: McpServer;\n\n constructor(\n protected readonly scope: Scope,\n protected readonly key: TransportKey,\n protected readonly onDispose: () => void,\n res: ServerResponse,\n ) {\n this.logger = scope.logger.child('LocalTransportAdapter');\n this.transport = this.createTransport(key.sessionId, res);\n this.ready = this.connectServer();\n }\n\n abstract createTransport(sessionId: string, response: ServerResponse): T;\n\n abstract initialize(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void>;\n\n abstract sendElicitRequest<T extends ZodObject<any>>(\n relatedRequestId: RequestId,\n message: string,\n requestedSchema: T,\n ): Promise<TypedElicitResult<T>>;\n\n abstract handleRequest(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void>;\n\n connectServer() {\n const {info} = this.scope.metadata;\n\n // TODO: collect server options from scope\n const serverOptions = {\n instructions: '',\n capabilities: {\n tools: {\n subscribe: true,\n listChanged: true,\n },\n },\n serverInfo: info,\n };\n this.server = new McpServer(info, serverOptions);\n const handlers = createMcpHandlers({\n scope: this.scope,\n serverOptions,\n });\n\n for (const handler of handlers) {\n this.server.setRequestHandler(handler.requestSchema, handler.handler as any);\n }\n return this.server.connect(this.transport);\n }\n\n get newRequestId(): RequestId {\n return this.#requestId++;\n }\n\n async destroy(reason?: string): Promise<void> {\n console.log('destroying transporter, reason:', reason);\n\n try {\n // if(!this.transport.closed){\n // this.transport.close();\n // }\n } catch {\n /* empty */\n }\n if (reason) {\n console.warn(`Destroying transporter: ${reason}`);\n } else {\n try {\n this.onDispose?.();\n } catch {\n /* empty */\n }\n }\n }\n\n /**\n * Ping the connected client for this transport.\n * Returns true on success, false on timeout/error.\n */\n async ping(timeoutMs = 10_000): Promise<boolean> {\n try {\n await this.ready; // ensure server.connect(...) finished\n // Preferred if your SDK exposes it:\n // await this.server.ping({ timeout: timeoutMs });\n\n // Works on all versions (low-level request):\n await this.server.request({method: 'ping'}, EmptyResultSchema, {timeout: timeoutMs});\n return true;\n } catch {\n return false;\n }\n }\n\n protected ensureAuthInfo(req: AuthenticatedServerRequest, transport: LocalTransportAdapter<T>) {\n const {token, user, session} = req[ServerRequestTokens.auth];\n req.auth = {\n token,\n user,\n sessionId: session!.id,\n sessionIdPayload: session!.payload,\n scopes: [],\n clientId: user.sub ?? '',\n transport,\n } satisfies AuthInfo;\n return req.auth;\n }\n\n handleIfElicitResult(req: AuthenticatedServerRequest): boolean {\n\n if (!this.elicitHandler) {\n return false;\n }\n if (req.body.error) {\n const {code, message} = req.body.error;\n if (code === -32600 && message === 'Elicitation not supported') {\n this.elicitHandler.reject(req.body.error);\n return true;\n }\n return false;\n }\n\n const parsed = ElicitResultSchema.safeParse(req.body?.result);\n if (parsed.success) {\n this.elicitHandler.resolve(parsed.data);\n return true;\n }\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"transport.local.adapter.js","sourceRoot":"","sources":["../../../../src/transport/adapters/transport.local.adapter.ts"],"names":[],"mappings":";;;AAEA,wEAAgF;AAChF,iEAAoH;AACpH,oEAA8D;AAK9D,yCAAmF;AAEnF,kDAAoD;AAEpD,MAAsB,qBAAqB;IAWpB;IACA;IACA;IAZX,MAAM,CAAiB;IACvB,SAAS,CAAI;IACb,UAAU,GAAG,IAAI,0CAAkB,EAAE,CAAC;IACtC,aAAa,GACrB,S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ACxB,SAAS;SACS,CAAC;QACrB,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,oBAAoB,CAAC,GAA+B;QAClD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACnB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;YACzC,IAAI,IAAI,KAAK,CAAC,KAAK,IAAI,OAAO,KAAK,2BAA2B,EAAE,CAAC;gBAC/D,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC1C,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,MAAM,GAAG,6BAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC9D,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACxC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AArKD,sDAqKC","sourcesContent":["import { AuthenticatedServerRequest } from '../../server/server.types';\nimport { TransportKey, TypedElicitResult } from '../transport.types';\nimport { Server as McpServer } from '@modelcontextprotocol/sdk/server/index.js';\nimport { EmptyResultSchema, ElicitResult, RequestId, ElicitResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { InMemoryEventStore } from '../transport.event-store';\nimport { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport { SSEServerTransport } from '../legacy/legacy.sse.tranporter';\nimport { ZodType } from 'zod';\nimport { FrontMcpLogger, ServerRequestTokens, ServerResponse } from '../../common';\nimport { Scope } from '../../scope';\nimport { createMcpHandlers } from '../mcp-handlers';\n\nexport abstract class LocalTransportAdapter<T extends StreamableHTTPServerTransport | SSEServerTransport> {\n protected logger: FrontMcpLogger;\n protected transport: T;\n protected eventStore = new InMemoryEventStore();\n protected elicitHandler: { resolve: (result: ElicitResult) => void; reject: (err: unknown) => void } | undefined =\n undefined;\n #requestId = 1;\n ready: Promise<void>;\n server: McpServer;\n\n constructor(\n protected readonly scope: Scope,\n protected readonly key: TransportKey,\n protected readonly onDispose: () => void,\n res: ServerResponse,\n ) {\n this.logger = scope.logger.child('LocalTransportAdapter');\n this.transport = this.createTransport(key.sessionId, res);\n this.ready = this.connectServer();\n }\n\n abstract createTransport(sessionId: string, response: ServerResponse): T;\n\n abstract initialize(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void>;\n\n abstract sendElicitRequest<T extends ZodType>(\n relatedRequestId: RequestId,\n message: string,\n requestedSchema: T,\n ): Promise<TypedElicitResult<T>>;\n\n abstract handleRequest(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void>;\n\n connectServer() {\n const { info } = this.scope.metadata;\n\n // Check if completions capability should be enabled (when prompts or resources are present)\n const hasPrompts = this.scope.prompts.hasAny();\n const hasResources = this.scope.resources.hasAny();\n const hasTools = this.scope.tools.hasAny();\n const completionsCapability = hasPrompts || hasResources ? { completions: {} } : {};\n\n const serverOptions = {\n instructions: '',\n capabilities: {\n ...this.scope.tools.getCapabilities(),\n ...this.scope.resources.getCapabilities(),\n ...this.scope.prompts.getCapabilities(),\n ...completionsCapability,\n // MCP logging protocol support - allows clients to set log level via logging/setLevel\n logging: {},\n },\n serverInfo: info,\n };\n\n this.logger.info('connectServer: advertising capabilities', {\n hasTools,\n hasResources,\n hasPrompts,\n capabilities: JSON.stringify(serverOptions.capabilities),\n serverInfo: JSON.stringify(serverOptions.serverInfo),\n });\n\n this.server = new McpServer(info, serverOptions);\n const handlers = createMcpHandlers({\n scope: this.scope,\n serverOptions,\n });\n\n for (const handler of handlers) {\n this.server.setRequestHandler(handler.requestSchema, handler.handler as any);\n }\n\n // Register server with notification service for server→client notifications\n this.scope.notifications.registerServer(this.key.sessionId, this.server);\n\n return this.server.connect(this.transport);\n }\n\n get newRequestId(): RequestId {\n return this.#requestId++;\n }\n\n async destroy(reason?: string): Promise<void> {\n console.log('destroying transporter, reason:', reason);\n\n // Unregister server from notification service\n this.scope.notifications.unregisterServer(this.key.sessionId);\n\n try {\n // if(!this.transport.closed){\n // this.transport.close();\n // }\n } catch {\n /* empty */\n }\n if (reason) {\n console.warn(`Destroying transporter: ${reason}`);\n } else {\n try {\n this.onDispose?.();\n } catch {\n /* empty */\n }\n }\n }\n\n /**\n * Ping the connected client for this transport.\n * Returns true on success, false on timeout/error.\n */\n async ping(timeoutMs = 10_000): Promise<boolean> {\n try {\n await this.ready; // ensure server.connect(...) finished\n // Preferred if your SDK exposes it:\n // await this.server.ping({ timeout: timeoutMs });\n\n // Works on all versions (low-level request):\n await this.server.request({ method: 'ping' }, EmptyResultSchema, { timeout: timeoutMs });\n return true;\n } catch {\n return false;\n }\n }\n\n protected ensureAuthInfo(req: AuthenticatedServerRequest, transport: LocalTransportAdapter<T>) {\n const { token, user, session } = req[ServerRequestTokens.auth];\n\n // Session should always exist now (created in session.verify for public mode)\n // But add defensive fallback for safety in case session is undefined\n const sessionId = session?.id ?? `fallback:${Date.now()}`;\n const sessionPayload = session?.payload ?? { protocol: 'streamable-http' as const };\n\n req.auth = {\n token,\n user,\n sessionId,\n sessionIdPayload: sessionPayload,\n scopes: [],\n clientId: user.sub ?? '',\n transport,\n } satisfies AuthInfo;\n return req.auth;\n }\n\n handleIfElicitResult(req: AuthenticatedServerRequest): boolean {\n if (!this.elicitHandler) {\n return false;\n }\n if (req.body.error) {\n const { code, message } = req.body.error;\n if (code === -32600 && message === 'Elicitation not supported') {\n this.elicitHandler.reject(req.body.error);\n return true;\n }\n return false;\n }\n\n const parsed = ElicitResultSchema.safeParse(req.body?.result);\n if (parsed.success) {\n this.elicitHandler.resolve(parsed.data);\n return true;\n }\n return false;\n }\n}\n"]}
@@ -3,12 +3,12 @@ import { TypedElicitResult } from '../transport.types';
3
3
  import { SSEServerTransport } from '../legacy/legacy.sse.tranporter';
4
4
  import { LocalTransportAdapter } from './transport.local.adapter';
5
5
  import { RequestId } from '@modelcontextprotocol/sdk/types.js';
6
- import { ZodObject } from 'node_modules/zod/v3/types.cjs';
6
+ import { ZodType } from 'zod';
7
7
  import { ServerResponse } from '../../common';
8
8
  export declare class TransportSSEAdapter extends LocalTransportAdapter<SSEServerTransport> {
9
9
  sessionId: string;
10
10
  createTransport(sessionId: string, res: ServerResponse): SSEServerTransport;
11
11
  initialize(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void>;
12
12
  handleRequest(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void>;
13
- sendElicitRequest<T extends ZodObject<any>>(relatedRequestId: RequestId, message: string, requestedSchema: T): Promise<TypedElicitResult<T>>;
13
+ sendElicitRequest<T extends ZodType>(relatedRequestId: RequestId, message: string, requestedSchema: T): Promise<TypedElicitResult<T>>;
14
14
  }
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransportSSEAdapter = void 0;
4
4
  const legacy_sse_tranporter_1 = require("../legacy/legacy.sse.tranporter");
5
5
  const transport_local_adapter_1 = require("./transport.local.adapter");
6
+ const v4_1 = require("zod/v4");
6
7
  const transport_error_1 = require("../transport.error");
7
- const zod_to_json_schema_1 = require("zod-to-json-schema");
8
8
  class TransportSSEAdapter extends transport_local_adapter_1.LocalTransportAdapter {
9
9
  sessionId;
10
10
  createTransport(sessionId, res) {
@@ -15,7 +15,8 @@ class TransportSSEAdapter extends transport_local_adapter_1.LocalTransportAdapte
15
15
  sessionId: sessionId,
16
16
  });
17
17
  transport.onerror = (error) => {
18
- console.error('SSE error:', error);
18
+ // Use safe logging to avoid Node.js 24 util.inspect bug with Zod errors
19
+ console.error('SSE error:', error instanceof Error ? error.message : 'Unknown error');
19
20
  };
20
21
  transport.onclose = this.destroy.bind(this);
21
22
  return transport;
@@ -44,7 +45,7 @@ class TransportSSEAdapter extends transport_local_adapter_1.LocalTransportAdapte
44
45
  console.log('sendElicitRequest', { relatedRequestId });
45
46
  await this.transport.send((0, transport_error_1.rpcRequest)(this.newRequestId, 'elicitation/create', {
46
47
  message,
47
- requestedSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(requestedSchema),
48
+ requestedSchema: (0, v4_1.toJSONSchema)(requestedSchema),
48
49
  }));
49
50
  return new Promise((resolve, reject) => {
50
51
  this.elicitHandler = {
@@ -1 +1 @@
1
- {"version":3,"file":"transport.sse.adapter.js","sourceRoot":"","sources":["../../../../src/transport/adapters/transport.sse.adapter.ts"],"names":[],"mappings":";;;AAEA,2EAAqE;AACrE,uEAAkE;AAGlE,wDAAgD;AAChD,2DAAqD;AAGrD,MAAa,mBAAoB,SAAQ,+CAAyC;IAChF,SAAS,CAAS;IAET,eAAe,CAAC,SAAiB,EAAE,GAAmB;QAC7D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QACrE,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;QACtC,MAAM,SAAS,GAAG,IAAI,0CAAkB,CAAC,GAAG,SAAS,UAAU,EAAE,GAAG,EAAE;YACpE,SAAS,EAAE,SAAS;SACrB,CAAC,CAAC;QACH,SAAS,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE;YAC5B,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC,CAAC;QACF,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC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D,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACvB,IAAA,4BAAU,EAAC,IAAI,CAAC,YAAY,EAAE,oBAAoB,EAAE;YAClD,OAAO;YACP,eAAe,EAAE,IAAA,oCAAe,EAAC,eAAsB,CAAC;SACzD,CAAC,CACH,CAAC;QAEF,OAAO,IAAI,OAAO,CAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3D,IAAI,CAAC,aAAa,GAAG;gBACnB,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;oBAClB,OAAO,CAAC,MAA8B,CAAC,CAAC;oBACxC,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;gBACjC,CAAC;gBACD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;oBACd,MAAM,CAAC,GAAG,CAAC,CAAC;oBACZ,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;gBACjC,CAAC;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAjED,kDAiEC","sourcesContent":["import { AuthenticatedServerRequest } from '../../server/server.types';\nimport { TypedElicitResult } from '../transport.types';\nimport { SSEServerTransport } from '../legacy/legacy.sse.tranporter';\nimport { LocalTransportAdapter } from './transport.local.adapter';\nimport { RequestId } from '@modelcontextprotocol/sdk/types.js';\nimport { ZodObject } from 'node_modules/zod/v3/types.cjs';\nimport { rpcRequest } from '../transport.error';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport { ServerResponse } from '../../common';\n\nexport class TransportSSEAdapter extends LocalTransportAdapter<SSEServerTransport> {\n sessionId: string;\n\n override createTransport(sessionId: string, res: ServerResponse): SSEServerTransport {\n this.sessionId = sessionId;\n this.logger.info(`new transport session: ${sessionId.slice(0, 40)}`);\n const scopePath = this.scope.fullPath;\n const transport = new SSEServerTransport(`${scopePath}/message`, res, {\n sessionId: sessionId,\n });\n transport.onerror = (error) => {\n console.error('SSE error:', error);\n };\n transport.onclose = this.destroy.bind(this);\n return transport;\n }\n\n initialize(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void> {\n this.logger.verbose(`[${this.sessionId}] handle initialize request`);\n this.ensureAuthInfo(req, this);\n return Promise.resolve();\n }\n\n async handleRequest(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void> {\n const authInfo = this.ensureAuthInfo(req, this);\n\n if (this.handleIfElicitResult(req)) {\n this.logger.verbose(`[${this.sessionId}] handle get request`);\n return;\n }\n if (req.method === 'GET') {\n this.logger.verbose(`[${this.sessionId}] handle get request`);\n return this.transport.handleMessage(req.body, { requestInfo: req, authInfo });\n } else {\n this.logger.verbose(`[${this.sessionId}] handle post request`);\n return this.transport.handlePostMessage(req, res, req.body);\n }\n }\n\n async sendElicitRequest<T extends ZodObject<any>>(\n relatedRequestId: RequestId,\n message: string,\n requestedSchema: T,\n ): Promise<TypedElicitResult<T>> {\n console.log('sendElicitRequest', { relatedRequestId });\n await this.transport.send(\n rpcRequest(this.newRequestId, 'elicitation/create', {\n message,\n requestedSchema: zodToJsonSchema(requestedSchema as any),\n }),\n );\n\n return new Promise<TypedElicitResult<T>>((resolve, reject) => {\n this.elicitHandler = {\n resolve: (result) => {\n resolve(result as TypedElicitResult<T>);\n this.elicitHandler = undefined;\n },\n reject: (err) => {\n reject(err);\n this.elicitHandler = undefined;\n },\n };\n });\n }\n}\n"]}
1
+ {"version":3,"file":"transport.sse.adapter.js","sourceRoot":"","sources":["../../../../src/transport/adapters/transport.sse.adapter.ts"],"names":[],"mappings":";;;AAEA,2EAAqE;AACrE,uEAAkE;AAGlE,+BAAsC;AACtC,wDAAgD;AAGhD,MAAa,mBAAoB,SAAQ,+CAAyC;IAChF,SAAS,CAAS;IAET,eAAe,CAAC,SAAiB,EAAE,GAAmB;QAC7D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QACrE,MA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AAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;QAChF,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,SAAS,uBAAuB,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,gBAA2B,EAC3B,OAAe,EACf,eAAkB;QAElB,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACvD,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACvB,IAAA,4BAAU,EAAC,IAAI,CAAC,YAAY,EAAE,oBAAoB,EAAE;YAClD,OAAO;YACP,eAAe,EAAE,IAAA,iBAAY,EAAC,eAAsB,CAAC;SACtD,CAAC,CACH,CAAC;QAEF,OAAO,IAAI,OAAO,CAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3D,IAAI,CAAC,aAAa,GAAG;gBACnB,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;oBAClB,OAAO,CAAC,MAA8B,CAAC,CAAC;oBACxC,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;gBACjC,CAAC;gBACD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;oBACd,MAAM,CAAC,GAAG,CAAC,CAAC;oBACZ,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;gBACjC,CAAC;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlED,kDAkEC","sourcesContent":["import { AuthenticatedServerRequest } from '../../server/server.types';\nimport { TypedElicitResult } from '../transport.types';\nimport { SSEServerTransport } from '../legacy/legacy.sse.tranporter';\nimport { LocalTransportAdapter } from './transport.local.adapter';\nimport { RequestId } from '@modelcontextprotocol/sdk/types.js';\nimport { ZodType } from 'zod';\nimport { toJSONSchema } from 'zod/v4';\nimport { rpcRequest } from '../transport.error';\nimport { ServerResponse } from '../../common';\n\nexport class TransportSSEAdapter extends LocalTransportAdapter<SSEServerTransport> {\n sessionId: string;\n\n override createTransport(sessionId: string, res: ServerResponse): SSEServerTransport {\n this.sessionId = sessionId;\n this.logger.info(`new transport session: ${sessionId.slice(0, 40)}`);\n const scopePath = this.scope.fullPath;\n const transport = new SSEServerTransport(`${scopePath}/message`, res, {\n sessionId: sessionId,\n });\n transport.onerror = (error) => {\n // Use safe logging to avoid Node.js 24 util.inspect bug with Zod errors\n console.error('SSE error:', error instanceof Error ? error.message : 'Unknown error');\n };\n transport.onclose = this.destroy.bind(this);\n return transport;\n }\n\n initialize(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void> {\n this.logger.verbose(`[${this.sessionId}] handle initialize request`);\n this.ensureAuthInfo(req, this);\n return Promise.resolve();\n }\n\n async handleRequest(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void> {\n const authInfo = this.ensureAuthInfo(req, this);\n\n if (this.handleIfElicitResult(req)) {\n this.logger.verbose(`[${this.sessionId}] handle get request`);\n return;\n }\n if (req.method === 'GET') {\n this.logger.verbose(`[${this.sessionId}] handle get request`);\n return this.transport.handleMessage(req.body, { requestInfo: req, authInfo });\n } else {\n this.logger.verbose(`[${this.sessionId}] handle post request`);\n return this.transport.handlePostMessage(req, res, req.body);\n }\n }\n\n async sendElicitRequest<T extends ZodType>(\n relatedRequestId: RequestId,\n message: string,\n requestedSchema: T,\n ): Promise<TypedElicitResult<T>> {\n console.log('sendElicitRequest', { relatedRequestId });\n await this.transport.send(\n rpcRequest(this.newRequestId, 'elicitation/create', {\n message,\n requestedSchema: toJSONSchema(requestedSchema as any),\n }),\n );\n\n return new Promise<TypedElicitResult<T>>((resolve, reject) => {\n this.elicitHandler = {\n resolve: (result) => {\n resolve(result as TypedElicitResult<T>);\n this.elicitHandler = undefined;\n },\n reject: (err) => {\n reject(err);\n this.elicitHandler = undefined;\n },\n };\n });\n }\n}\n"]}
@@ -1,13 +1,20 @@
1
1
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
2
- import { TypedElicitResult } from '../transport.types';
2
+ import { TransportType, TypedElicitResult } from '../transport.types';
3
3
  import { AuthenticatedServerRequest } from '../../server/server.types';
4
4
  import { LocalTransportAdapter } from './transport.local.adapter';
5
5
  import { RequestId } from '@modelcontextprotocol/sdk/types.js';
6
- import { ZodObject } from 'zod';
6
+ import { ZodType } from 'zod';
7
7
  import { ServerResponse } from '../../common';
8
+ /**
9
+ * Stateless HTTP requests must be able to send multiple initialize calls without
10
+ * tripping the MCP transport's "already initialized" guard. The upstream SDK
11
+ * treats any transport with a session ID generator as stateful, so we disable
12
+ * session generation entirely for stateless transports.
13
+ */
14
+ export declare const resolveSessionIdGenerator: (transportType: TransportType, sessionId: string) => (() => string) | undefined;
8
15
  export declare class TransportStreamableHttpAdapter extends LocalTransportAdapter<StreamableHTTPServerTransport> {
9
16
  createTransport(sessionId: string, response: ServerResponse): StreamableHTTPServerTransport;
10
17
  initialize(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void>;
11
18
  handleRequest(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void>;
12
- sendElicitRequest<T extends ZodObject<any>>(relatedRequestId: RequestId, message: string, requestedSchema: T): Promise<TypedElicitResult<T>>;
19
+ sendElicitRequest<T extends ZodType>(relatedRequestId: RequestId, message: string, requestedSchema: T): Promise<TypedElicitResult<T>>;
13
20
  }
@@ -1,27 +1,73 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransportStreamableHttpAdapter = void 0;
3
+ exports.TransportStreamableHttpAdapter = exports.resolveSessionIdGenerator = void 0;
4
4
  const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
5
5
  const transport_local_adapter_1 = require("./transport.local.adapter");
6
- const zod_to_json_schema_1 = require("zod-to-json-schema");
6
+ const v4_1 = require("zod/v4");
7
7
  const transport_error_1 = require("../transport.error");
8
+ /**
9
+ * Stateless HTTP requests must be able to send multiple initialize calls without
10
+ * tripping the MCP transport's "already initialized" guard. The upstream SDK
11
+ * treats any transport with a session ID generator as stateful, so we disable
12
+ * session generation entirely for stateless transports.
13
+ */
14
+ const resolveSessionIdGenerator = (transportType, sessionId) => {
15
+ return transportType === 'stateless-http' ? undefined : () => sessionId;
16
+ };
17
+ exports.resolveSessionIdGenerator = resolveSessionIdGenerator;
8
18
  class TransportStreamableHttpAdapter extends transport_local_adapter_1.LocalTransportAdapter {
9
19
  createTransport(sessionId, response) {
20
+ const sessionIdGenerator = (0, exports.resolveSessionIdGenerator)(this.key.type, sessionId);
10
21
  return new streamableHttp_js_1.StreamableHTTPServerTransport({
11
- sessionIdGenerator: () => {
12
- return sessionId;
13
- },
22
+ sessionIdGenerator,
14
23
  onsessionclosed: () => {
15
24
  // this.destroy();
16
25
  },
17
26
  onsessioninitialized: (sessionId) => {
18
- console.log(`session initialized: ${sessionId.slice(0, 40)}`);
27
+ if (sessionId) {
28
+ console.log(`session initialized: ${sessionId.slice(0, 40)}`);
29
+ }
30
+ else {
31
+ console.log(`stateless session initialized`);
32
+ }
19
33
  },
20
- eventStore: this.eventStore,
34
+ // Disable eventStore to prevent priming events - Claude.ai's client doesn't handle them
35
+ // The priming event has empty data with no `event:` type, which violates MCP spec
36
+ // ("Event types MUST be message") and confuses some clients
37
+ eventStore: undefined,
21
38
  });
22
39
  }
23
40
  initialize(req, res) {
24
41
  this.ensureAuthInfo(req, this);
42
+ this.logger.info('[StreamableHttpAdapter] initialize() called', {
43
+ method: req.method,
44
+ sessionId: this.key.sessionId.slice(0, 30),
45
+ bodyMethod: req.body?.method,
46
+ });
47
+ // Intercept response to log what gets sent back to client
48
+ const originalWrite = res.write.bind(res);
49
+ const originalEnd = res.end.bind(res);
50
+ let responseBody = '';
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ res.write = function (chunk, encodingOrCb, cb) {
53
+ if (chunk) {
54
+ responseBody += typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : String(chunk);
55
+ }
56
+ return originalWrite.call(this, chunk, encodingOrCb, cb);
57
+ };
58
+ const adapter = this;
59
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
+ res.end = function (chunk, encodingOrCb, cb) {
61
+ if (chunk) {
62
+ responseBody += typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : String(chunk);
63
+ }
64
+ adapter.logger.info('[StreamableHttpAdapter] initialize response', {
65
+ statusCode: res.statusCode,
66
+ headers: res.getHeaders?.() ?? {},
67
+ bodyPreview: responseBody.slice(0, 1000),
68
+ });
69
+ return originalEnd.call(this, chunk, encodingOrCb, cb);
70
+ };
25
71
  return this.transport.handleRequest(req, res, req.body);
26
72
  }
27
73
  async handleRequest(req, res) {
@@ -45,7 +91,7 @@ class TransportStreamableHttpAdapter extends transport_local_adapter_1.LocalTran
45
91
  async sendElicitRequest(relatedRequestId, message, requestedSchema) {
46
92
  await this.transport.send((0, transport_error_1.rpcRequest)(this.newRequestId, 'elicitation/create', {
47
93
  message,
48
- requestedSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(requestedSchema),
94
+ requestedSchema: (0, v4_1.toJSONSchema)(requestedSchema),
49
95
  }), { relatedRequestId });
50
96
  return new Promise((resolve, reject) => {
51
97
  this.elicitHandler = {
@@ -1 +1 @@
1
- {"version":3,"file":"transport.streamable-http.adapter.js","sourceRoot":"","sources":["../../../../src/transport/adapters/transport.streamable-http.adapter.ts"],"names":[],"mappings":";;;AAAA,0FAAmG;AAGnG,uEAAkE;AAElE,2DAAqD;AAErD,wDAAgD;AAGhD,MAAa,8BAA+B,SAAQ,+CAAoD;IAE7F,eAAe,CAAC,SAAiB,EAAE,QAAwB;QAChE,OAAO,IAAI,iDAA6B,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C,IAAI,CACvB,IAAA,4BAAU,EAAC,IAAI,CAAC,YAAY,EAAE,oBAAoB,EAAE;YAClD,OAAO;YACP,eAAe,EAAE,IAAA,oCAAe,EAAC,eAAsB,CAAC;SACzD,CAAC,EACF,EAAE,gBAAgB,EAAE,CACrB,CAAC;QAEF,OAAO,IAAI,OAAO,CAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3D,IAAI,CAAC,aAAa,GAAG;gBACnB,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;oBAClB,OAAO,CAAC,MAA8B,CAAC,CAAC;oBACxC,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;gBACjC,CAAC;gBACD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;oBACd,MAAM,CAAC,GAAG,CAAC,CAAC;oBACZ,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;gBACjC,CAAC;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CAEF;AApED,wEAoEC","sourcesContent":["import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport { TypedElicitResult } from '../transport.types';\nimport { AuthenticatedServerRequest } from '../../server/server.types';\nimport { LocalTransportAdapter } from './transport.local.adapter';\nimport { RequestId } from '@modelcontextprotocol/sdk/types.js';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport { ZodObject } from 'zod';\nimport { rpcRequest } from '../transport.error';\nimport { ServerResponse } from '../../common';\n\nexport class TransportStreamableHttpAdapter extends LocalTransportAdapter<StreamableHTTPServerTransport> {\n\n override createTransport(sessionId: string, response: ServerResponse): StreamableHTTPServerTransport {\n return new StreamableHTTPServerTransport({\n sessionIdGenerator: () => {\n return sessionId\n },\n onsessionclosed: () => {\n // this.destroy();\n },\n onsessioninitialized: (sessionId) => {\n console.log(`session initialized: ${sessionId.slice(0, 40)}`);\n },\n eventStore: this.eventStore,\n })\n }\n\n initialize(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void> {\n this.ensureAuthInfo(req, this);\n return this.transport.handleRequest(req, res, req.body);\n }\n\n async handleRequest(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void> {\n this.ensureAuthInfo(req, this);\n //\n // if ((await this.isInitialized) && isInitializeRequest(req.body)) {\n // await this.transport.close();\n // this.isInitialized = this.connectStreamableTransport(req.authSession.session!.id);\n // await this.ready;\n // }\n\n if (req.method === 'GET') {\n return this.transport.handleRequest(req, res);\n } else {\n if (this.handleIfElicitResult(req)) {\n return;\n }\n return this.transport.handleRequest(req, res, req.body);\n }\n }\n\n async sendElicitRequest<T extends ZodObject<any>>(\n relatedRequestId: RequestId,\n message: string,\n requestedSchema: T,\n ): Promise<TypedElicitResult<T>> {\n await this.transport.send(\n rpcRequest(this.newRequestId, 'elicitation/create', {\n message,\n requestedSchema: zodToJsonSchema(requestedSchema as any),\n }),\n { relatedRequestId },\n );\n\n return new Promise<TypedElicitResult<T>>((resolve, reject) => {\n this.elicitHandler = {\n resolve: (result) => {\n resolve(result as TypedElicitResult<T>);\n this.elicitHandler = undefined;\n },\n reject: (err) => {\n reject(err);\n this.elicitHandler = undefined;\n },\n };\n });\n }\n\n}\n"]}
1
+ {"version":3,"file":"transport.streamable-http.adapter.js","sourceRoot":"","sources":["../../../../src/transport/adapters/transport.streamable-http.adapter.ts"],"names":[],"mappings":";;;AAAA,0FAAmG;AAGnG,uEAAkE;AAGlE,+BAAsC;AACtC,wDAAgD;AAGhD;;;;;GAKG;AACI,MAAM,yBAAyB,GAAG,CACvC,aAA4B,EAC5B,SAAiB,EACW,EAAE;IAC9B,OAAO,aAAa,KAAK,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;AAC1E,CAAC,CAAC;AALW,QAAA,yBAAyB,6BAKpC;AAEF,MAAa,8BAA+B,SAAQ,+CAAoD;IAC7F,eAAe,CAAC,SAAiB,EAAE,QAAwB;QAClE,MAAM,kBAAkB,GAAG,IAA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ourcesContent":["import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport { TransportType, TypedElicitResult } from '../transport.types';\nimport { AuthenticatedServerRequest } from '../../server/server.types';\nimport { LocalTransportAdapter } from './transport.local.adapter';\nimport { RequestId } from '@modelcontextprotocol/sdk/types.js';\nimport { ZodType } from 'zod';\nimport { toJSONSchema } from 'zod/v4';\nimport { rpcRequest } from '../transport.error';\nimport { ServerResponse } from '../../common';\n\n/**\n * Stateless HTTP requests must be able to send multiple initialize calls without\n * tripping the MCP transport's \"already initialized\" guard. The upstream SDK\n * treats any transport with a session ID generator as stateful, so we disable\n * session generation entirely for stateless transports.\n */\nexport const resolveSessionIdGenerator = (\n transportType: TransportType,\n sessionId: string,\n): (() => string) | undefined => {\n return transportType === 'stateless-http' ? undefined : () => sessionId;\n};\n\nexport class TransportStreamableHttpAdapter extends LocalTransportAdapter<StreamableHTTPServerTransport> {\n override createTransport(sessionId: string, response: ServerResponse): StreamableHTTPServerTransport {\n const sessionIdGenerator = resolveSessionIdGenerator(this.key.type, sessionId);\n\n return new StreamableHTTPServerTransport({\n sessionIdGenerator,\n onsessionclosed: () => {\n // this.destroy();\n },\n onsessioninitialized: (sessionId) => {\n if (sessionId) {\n console.log(`session initialized: ${sessionId.slice(0, 40)}`);\n } else {\n console.log(`stateless session initialized`);\n }\n },\n // Disable eventStore to prevent priming events - Claude.ai's client doesn't handle them\n // The priming event has empty data with no `event:` type, which violates MCP spec\n // (\"Event types MUST be message\") and confuses some clients\n eventStore: undefined,\n });\n }\n\n initialize(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void> {\n this.ensureAuthInfo(req, this);\n\n this.logger.info('[StreamableHttpAdapter] initialize() called', {\n method: req.method,\n sessionId: this.key.sessionId.slice(0, 30),\n bodyMethod: (req.body as { method?: string })?.method,\n });\n\n // Intercept response to log what gets sent back to client\n const originalWrite = res.write.bind(res) as typeof res.write;\n const originalEnd = res.end.bind(res) as typeof res.end;\n let responseBody = '';\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n res.write = function (this: ServerResponse, chunk: any, encodingOrCb?: any, cb?: any): boolean {\n if (chunk) {\n responseBody += typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : String(chunk);\n }\n return originalWrite.call(this, chunk, encodingOrCb, cb);\n } as typeof res.write;\n\n const adapter = this;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n res.end = function (this: ServerResponse, chunk?: any, encodingOrCb?: any, cb?: any): ServerResponse {\n if (chunk) {\n responseBody += typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : String(chunk);\n }\n adapter.logger.info('[StreamableHttpAdapter] initialize response', {\n statusCode: res.statusCode,\n headers: res.getHeaders?.() ?? {},\n bodyPreview: responseBody.slice(0, 1000),\n });\n return originalEnd.call(this, chunk, encodingOrCb, cb);\n } as typeof res.end;\n\n return this.transport.handleRequest(req, res, req.body);\n }\n\n async handleRequest(req: AuthenticatedServerRequest, res: ServerResponse): Promise<void> {\n this.ensureAuthInfo(req, this);\n //\n // if ((await this.isInitialized) && isInitializeRequest(req.body)) {\n // await this.transport.close();\n // this.isInitialized = this.connectStreamableTransport(req.authSession.session!.id);\n // await this.ready;\n // }\n\n if (req.method === 'GET') {\n return this.transport.handleRequest(req, res);\n } else {\n if (this.handleIfElicitResult(req)) {\n return;\n }\n return this.transport.handleRequest(req, res, req.body);\n }\n }\n\n async sendElicitRequest<T extends ZodType>(\n relatedRequestId: RequestId,\n message: string,\n requestedSchema: T,\n ): Promise<TypedElicitResult<T>> {\n await this.transport.send(\n rpcRequest(this.newRequestId, 'elicitation/create', {\n message,\n requestedSchema: toJSONSchema(requestedSchema as any),\n }),\n { relatedRequestId },\n );\n\n return new Promise<TypedElicitResult<T>>((resolve, reject) => {\n this.elicitHandler = {\n resolve: (result) => {\n resolve(result as TypedElicitResult<T>);\n this.elicitHandler = undefined;\n },\n reject: (err) => {\n reject(err);\n this.elicitHandler = undefined;\n },\n };\n });\n }\n}\n"]}
@@ -10,72 +10,38 @@ export declare const stateSchema: z.ZodObject<{
10
10
  token: z.ZodString;
11
11
  session: z.ZodObject<{
12
12
  id: z.ZodString;
13
- payload: z.ZodObject<{
13
+ payload: z.ZodOptional<z.ZodObject<{
14
14
  nodeId: z.ZodString;
15
15
  authSig: z.ZodString;
16
16
  uuid: z.ZodString;
17
17
  iat: z.ZodNumber;
18
- protocol: z.ZodEnum<["legacy-sse", "sse", "streamable-http", "stateful-http", "stateless-http"]>;
19
- }, "strip", z.ZodTypeAny, {
20
- uuid: string;
21
- nodeId: string;
22
- authSig: string;
23
- iat: number;
24
- protocol: "sse" | "legacy-sse" | "streamable-http" | "stateful-http" | "stateless-http";
25
- }, {
26
- uuid: string;
27
- nodeId: string;
28
- authSig: string;
29
- iat: number;
30
- protocol: "sse" | "legacy-sse" | "streamable-http" | "stateful-http" | "stateless-http";
31
- }>;
32
- }, "strip", z.ZodTypeAny, {
33
- id: string;
34
- payload: {
35
- uuid: string;
36
- nodeId: string;
37
- authSig: string;
38
- iat: number;
39
- protocol: "sse" | "legacy-sse" | "streamable-http" | "stateful-http" | "stateless-http";
40
- };
41
- }, {
42
- id: string;
43
- payload: {
44
- uuid: string;
45
- nodeId: string;
46
- authSig: string;
47
- iat: number;
48
- protocol: "sse" | "legacy-sse" | "streamable-http" | "stateful-http" | "stateless-http";
49
- };
50
- }>;
51
- requestType: z.ZodOptional<z.ZodEnum<["initialize", "message", "elicitResult"]>>;
52
- }, "strip", z.ZodTypeAny, {
53
- session: {
54
- id: string;
55
- payload: {
56
- uuid: string;
57
- nodeId: string;
58
- authSig: string;
59
- iat: number;
60
- protocol: "sse" | "legacy-sse" | "streamable-http" | "stateful-http" | "stateless-http";
61
- };
62
- };
63
- token: string;
64
- requestType?: "message" | "initialize" | "elicitResult" | undefined;
65
- }, {
66
- session: {
67
- id: string;
68
- payload: {
69
- uuid: string;
70
- nodeId: string;
71
- authSig: string;
72
- iat: number;
73
- protocol: "sse" | "legacy-sse" | "streamable-http" | "stateful-http" | "stateless-http";
74
- };
75
- };
76
- token: string;
77
- requestType?: "message" | "initialize" | "elicitResult" | undefined;
78
- }>;
18
+ protocol: z.ZodOptional<z.ZodEnum<{
19
+ "legacy-sse": "legacy-sse";
20
+ sse: "sse";
21
+ "streamable-http": "streamable-http";
22
+ "stateful-http": "stateful-http";
23
+ "stateless-http": "stateless-http";
24
+ }>>;
25
+ isPublic: z.ZodOptional<z.ZodBoolean>;
26
+ platformType: z.ZodOptional<z.ZodEnum<{
27
+ unknown: "unknown";
28
+ continue: "continue";
29
+ openai: "openai";
30
+ claude: "claude";
31
+ gemini: "gemini";
32
+ cursor: "cursor";
33
+ cody: "cody";
34
+ "generic-mcp": "generic-mcp";
35
+ "ext-apps": "ext-apps";
36
+ }>>;
37
+ }, z.core.$strip>>;
38
+ }, z.core.$strip>;
39
+ requestType: z.ZodOptional<z.ZodEnum<{
40
+ message: "message";
41
+ initialize: "initialize";
42
+ elicitResult: "elicitResult";
43
+ }>>;
44
+ }, z.core.$strip>;
79
45
  declare const name: "handle:legacy-sse";
80
46
  declare global {
81
47
  interface ExtendFlows {
@@ -83,7 +49,7 @@ declare global {
83
49
  }
84
50
  }
85
51
  export default class HandleSseFlow extends FlowBase<typeof name> {
86
- paseInput(): Promise<void>;
52
+ parseInput(): Promise<void>;
87
53
  router(): Promise<void>;
88
54
  onInitialize(): Promise<void>;
89
55
  onElicitResult(): Promise<void>;
@@ -11,22 +11,65 @@ exports.plan = {
11
11
  post: [],
12
12
  finalize: ['cleanup'],
13
13
  };
14
+ // Relaxed session schema for state - payload is optional when using mcp-session-id header directly
15
+ const stateSessionSchema = zod_1.z.object({
16
+ id: zod_1.z.string(),
17
+ payload: zod_1.z
18
+ .object({
19
+ nodeId: zod_1.z.string(),
20
+ authSig: zod_1.z.string(),
21
+ uuid: zod_1.z.string().uuid(),
22
+ iat: zod_1.z.number(),
23
+ protocol: zod_1.z.enum(['legacy-sse', 'sse', 'streamable-http', 'stateful-http', 'stateless-http']).optional(),
24
+ isPublic: zod_1.z.boolean().optional(),
25
+ platformType: zod_1.z
26
+ .enum(['openai', 'claude', 'gemini', 'cursor', 'continue', 'cody', 'generic-mcp', 'ext-apps', 'unknown'])
27
+ .optional(),
28
+ })
29
+ .optional(),
30
+ });
14
31
  exports.stateSchema = zod_1.z.object({
15
32
  token: zod_1.z.string(),
16
- session: common_1.sessionIdSchema,
33
+ session: stateSessionSchema,
17
34
  requestType: zod_1.z.enum(['initialize', 'message', 'elicitResult']).optional(),
18
35
  });
19
36
  const name = 'handle:legacy-sse';
20
37
  const { Stage } = (0, common_1.FlowHooksOf)(name);
21
38
  let HandleSseFlow = class HandleSseFlow extends common_1.FlowBase {
22
- async paseInput() {
39
+ async parseInput() {
23
40
  const { request } = this.rawInput;
24
41
  const authorization = request[common_1.ServerRequestTokens.auth];
25
42
  const { token } = authorization;
26
- let { session } = authorization;
27
- if (!session) {
28
- session = (0, session_id_utils_1.createSessionId)('legacy-sse', token);
29
- request[common_1.ServerRequestTokens.auth].session = session;
43
+ // CRITICAL: The mcp-session-id header is the client's reference to their session.
44
+ // We MUST use this exact ID for transport registry lookup.
45
+ //
46
+ // Priority 1: Use mcp-session-id header if present (client's session ID for lookup)
47
+ // This is the ID the client received from initialize and is referencing.
48
+ // Priority 2: Use session from authorization if header matches or is absent
49
+ // Priority 3: Create new session (first request - no header, no authorization.session)
50
+ const mcpSessionHeader = request.headers?.['mcp-session-id'];
51
+ let session;
52
+ if (mcpSessionHeader) {
53
+ // Client sent session ID - ALWAYS use it for transport lookup
54
+ // If authorization.session exists and matches, use its payload for protocol detection
55
+ // If authorization.session differs or is missing, still use header ID (payload may be undefined)
56
+ if (authorization.session?.id === mcpSessionHeader) {
57
+ session = authorization.session;
58
+ }
59
+ else {
60
+ session = { id: mcpSessionHeader };
61
+ }
62
+ }
63
+ else if (authorization.session) {
64
+ // No header but authorization has session - use it (shouldn't happen in normal flow)
65
+ session = authorization.session;
66
+ }
67
+ else {
68
+ // No session - create new one (initialize request)
69
+ session = (0, session_id_utils_1.createSessionId)('legacy-sse', token, {
70
+ userAgent: request.headers?.['user-agent'],
71
+ platformDetectionConfig: this.scope.metadata?.session?.platformDetection,
72
+ });
30
73
  }
31
74
  this.state.set(exports.stateSchema.parse({ token, session }));
32
75
  }
@@ -36,10 +79,11 @@ let HandleSseFlow = class HandleSseFlow extends common_1.FlowBase {
36
79
  const requestPath = (0, common_1.normalizeEntryPrefix)(request.path);
37
80
  const prefix = (0, common_1.normalizeEntryPrefix)(scope.entryPath);
38
81
  const scopePath = (0, common_1.normalizeScopeBase)(scope.routeBase);
39
- if (requestPath === `${prefix}${scopePath}`) {
82
+ const basePath = `${prefix}${scopePath}`;
83
+ if (requestPath === `${basePath}/sse`) {
40
84
  this.state.set('requestType', 'initialize');
41
85
  }
42
- else if (requestPath === `${prefix}${scopePath}/message`) {
86
+ else if (requestPath === `${basePath}/message`) {
43
87
  this.state.set('requestType', 'message');
44
88
  }
45
89
  }
@@ -62,11 +106,35 @@ let HandleSseFlow = class HandleSseFlow extends common_1.FlowBase {
62
106
  }
63
107
  async onMessage() {
64
108
  const transportService = this.scope.transportService;
109
+ const logger = this.scopeLogger.child('handle:legacy-sse:onMessage');
65
110
  const { request, response } = this.rawInput;
66
111
  const { token, session } = this.state.required;
67
112
  const transport = await transportService.getTransporter('sse', token, session.id);
68
113
  if (!transport) {
69
- this.respond(common_1.httpRespond.rpcError('session not initialized'));
114
+ // Check if session was ever created to differentiate error types per MCP Spec 2025-11-25
115
+ const wasCreated = transportService.wasSessionCreated('sse', token, session.id);
116
+ const body = request.body;
117
+ if (wasCreated) {
118
+ // Session existed but was terminated/evicted → HTTP 404 (client should re-initialize)
119
+ logger.info('Session expired - client should re-initialize', {
120
+ sessionId: session.id?.slice(0, 20),
121
+ tokenHash: token.slice(0, 8),
122
+ method: body?.['method'],
123
+ requestId: body?.['id'],
124
+ });
125
+ this.respond(common_1.httpRespond.sessionExpired('session expired'));
126
+ }
127
+ else {
128
+ // Session was never created → HTTP 404 (per user requirement: invalid/missing session = 404)
129
+ logger.warn('Session not initialized - client attempted request without initializing', {
130
+ sessionId: session.id?.slice(0, 20),
131
+ tokenHash: token.slice(0, 8),
132
+ method: body?.['method'],
133
+ requestId: body?.['id'],
134
+ userAgent: request.headers?.['user-agent']?.slice(0, 50),
135
+ });
136
+ this.respond(common_1.httpRespond.sessionNotFound('session not initialized'));
137
+ }
70
138
  return;
71
139
  }
72
140
  await transport.handleRequest(request, response);
@@ -78,7 +146,7 @@ tslib_1.__decorate([
78
146
  tslib_1.__metadata("design:type", Function),
79
147
  tslib_1.__metadata("design:paramtypes", []),
80
148
  tslib_1.__metadata("design:returntype", Promise)
81
- ], HandleSseFlow.prototype, "paseInput", null);
149
+ ], HandleSseFlow.prototype, "parseInput", null);
82
150
  tslib_1.__decorate([
83
151
  Stage('router'),
84
152
  tslib_1.__metadata("design:type", Function),
@@ -1 +1 @@
1
- {"version":3,"file":"handle.sse.flow.js","sourceRoot":"","sources":["../../../../src/transport/flows/handle.sse.flow.ts"],"names":[],"mappings":";;;;AAAA,yCAcsB;AACtB,6BAAwB;AAExB,gFAA4E;AAE/D,QAAA,IAAI,GAAG;IAClB,GAAG,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC;IAC7B,OAAO,EAAE,CAAC,cAAc,EAAE,WAAW,EAAE,gBAAgB,CAAC;IACxD,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE,CAAC,SAAS,CAAC;CACc,CAAC;AAEzB,QAAA,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAClC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;IACjB,OAAO,EAAE,wBAAe;IACxB,WAAW,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC1E,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG,mBAA4B,CAAC;AAC1C,MA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AS,EAAE,CAAC;YACf,IAAI,CAAC,OAAO,CAAC,oBAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC;YAC9D,OAAO;QACT,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjD,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;CACF,CAAA;AAtEO;IADL,KAAK,CAAC,YAAY,CAAC;;;;8CAanB;AAGK;IADL,KAAK,CAAC,QAAQ,CAAC;;;;2CAYf;AAKK;IAHL,KAAK,CAAC,cAAc,EAAE;QACrB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC,WAAW,KAAK,YAAY;KACrE,CAAC;;;;iDASD;AAKK;IAHL,KAAK,CAAC,gBAAgB,EAAE;QACvB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC,WAAW,KAAK,cAAc;KACvE,CAAC;;;;mDASD;AAKK;IAHL,KAAK,CAAC,WAAW,EAAE;QAClB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC,WAAW,KAAK,SAAS;KAClE,CAAC;;;;8CAaD;AAvEkB,aAAa;IAPjC,IAAA,aAAI,EAAC;QACJ,IAAI;QACJ,MAAM,EAAE,YAAY;QACpB,WAAW,EAAE,wBAAe;QAC5B,YAAY,EAAE,yBAAgB;QAC9B,IAAI,EAAJ,YAAI;KACL,CAAC;GACmB,aAAa,CAwEjC;kBAxEoB,aAAa","sourcesContent":["import {\n Flow,\n httpInputSchema,\n FlowRunOptions,\n httpOutputSchema,\n FlowPlan,\n FlowBase,\n FlowHooksOf,\n sessionIdSchema,\n httpRespond,\n ServerRequestTokens,\n Authorization,\n normalizeEntryPrefix,\n normalizeScopeBase,\n} from '../../common';\nimport { z } from 'zod';\nimport { Scope } from '../../scope';\nimport { createSessionId } from '../../auth/session/utils/session-id.utils';\n\nexport const plan = {\n pre: ['parseInput', 'router'],\n execute: ['onInitialize', 'onMessage', 'onElicitResult'],\n post: [],\n finalize: ['cleanup'],\n} as const satisfies FlowPlan<string>;\n\nexport const stateSchema = z.object({\n token: z.string(),\n session: sessionIdSchema,\n requestType: z.enum(['initialize', 'message', 'elicitResult']).optional(),\n});\n\nconst name = 'handle:legacy-sse' as const;\nconst { Stage } = FlowHooksOf(name);\n\ndeclare global {\n interface ExtendFlows {\n 'handle:legacy-sse': FlowRunOptions<\n HandleSseFlow,\n typeof plan,\n typeof httpInputSchema,\n typeof httpOutputSchema,\n typeof stateSchema\n >;\n }\n}\n\n@Flow({\n name,\n access: 'authorized',\n inputSchema: httpInputSchema,\n outputSchema: httpOutputSchema,\n plan,\n})\nexport default class HandleSseFlow extends FlowBase<typeof name> {\n @Stage('parseInput')\n async paseInput() {\n const { request } = this.rawInput;\n\n const authorization = request[ServerRequestTokens.auth] as Authorization;\n const { token } = authorization;\n let { session } = authorization;\n\n if (!session) {\n session = createSessionId('legacy-sse', token);\n request[ServerRequestTokens.auth].session = session;\n }\n this.state.set(stateSchema.parse({ token, session }));\n }\n\n @Stage('router')\n async router() {\n const { request } = this.rawInput;\n const scope = this.scope as Scope;\n const requestPath = normalizeEntryPrefix(request.path);\n const prefix = normalizeEntryPrefix(scope.entryPath);\n const scopePath = normalizeScopeBase(scope.routeBase);\n if (requestPath === `${prefix}${scopePath}`) {\n this.state.set('requestType', 'initialize');\n } else if (requestPath === `${prefix}${scopePath}/message`) {\n this.state.set('requestType', 'message');\n }\n }\n\n @Stage('onInitialize', {\n filter: ({ state: { requestType } }) => requestType === 'initialize',\n })\n async onInitialize() {\n const transportService = (this.scope as Scope).transportService;\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n const transport = await transportService.createTransporter('sse', token, session.id, response);\n await transport.initialize(request, response);\n this.handled();\n }\n\n @Stage('onElicitResult', {\n filter: ({ state: { requestType } }) => requestType === 'elicitResult',\n })\n async onElicitResult() {\n // const transport = await transportService.getTransporter('sse', token, session.id);\n // if (!transport) {\n // this.respond(httpRespond.rpcError('session not initialized'));\n // return;\n // }\n // await transport.handleRequest(request, response);\n this.fail(new Error('Not implemented'));\n }\n\n @Stage('onMessage', {\n filter: ({ state: { requestType } }) => requestType === 'message',\n })\n async onMessage() {\n const transportService = (this.scope as Scope).transportService;\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n const transport = await transportService.getTransporter('sse', token, session.id);\n if (!transport) {\n this.respond(httpRespond.rpcError('session not initialized'));\n return;\n }\n await transport.handleRequest(request, response);\n this.handled();\n }\n}\n"]}
1
+ {"version":3,"file":"handle.sse.flow.js","sourceRoot":"","sources":["../../../../src/transport/flows/handle.sse.flow.ts"],"names":[],"mappings":";;;;AAAA,yCAcsB;AACtB,6BAAwB;AAExB,gFAA4E;AAE/D,QAAA,IAAI,GAAG;IAClB,GAAG,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC;IAC7B,OAAO,EAAE,CAAC,cAAc,EAAE,WAAW,EAAE,gBAAgB,CAAC;IACxD,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE,CAAC,SAAS,CAAC;CACc,CAAC;AAEtC,mGAAmG;AACnG,MAAM,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;IACd,OAAO,EAAE,OAAC;SACP,MAAM,CAAC;QACN,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;QAClB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;QACnB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;QACvB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;QACf,QAAQ,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,CAAC,CAAC,CAAC,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AC,oBAAW,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAAC;YACvE,CAAC;YACD,OAAO;QACT,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjD,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;CACF,CAAA;AA1HO;IADL,KAAK,CAAC,YAAY,CAAC;;;;+CAuCnB;AAGK;IADL,KAAK,CAAC,QAAQ,CAAC;;;;2CAcf;AAKK;IAHL,KAAK,CAAC,cAAc,EAAE;QACrB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC,WAAW,KAAK,YAAY;KACrE,CAAC;;;;iDASD;AAKK;IAHL,KAAK,CAAC,gBAAgB,EAAE;QACvB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC,WAAW,KAAK,cAAc;KACvE,CAAC;;;;mDASD;AAKK;IAHL,KAAK,CAAC,WAAW,EAAE;QAClB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC,WAAW,KAAK,SAAS;KAClE,CAAC;;;;8CAqCD;AA3HkB,aAAa;IAPjC,IAAA,aAAI,EAAC;QACJ,IAAI;QACJ,MAAM,EAAE,YAAY;QACpB,WAAW,EAAE,wBAAe;QAC5B,YAAY,EAAE,yBAAgB;QAC9B,IAAI,EAAJ,YAAI;KACL,CAAC;GACmB,aAAa,CA4HjC;kBA5HoB,aAAa","sourcesContent":["import {\n Flow,\n httpInputSchema,\n FlowRunOptions,\n httpOutputSchema,\n FlowPlan,\n FlowBase,\n FlowHooksOf,\n sessionIdSchema,\n httpRespond,\n ServerRequestTokens,\n Authorization,\n normalizeEntryPrefix,\n normalizeScopeBase,\n} from '../../common';\nimport { z } from 'zod';\nimport { Scope } from '../../scope';\nimport { createSessionId } from '../../auth/session/utils/session-id.utils';\n\nexport const plan = {\n pre: ['parseInput', 'router'],\n execute: ['onInitialize', 'onMessage', 'onElicitResult'],\n post: [],\n finalize: ['cleanup'],\n} as const satisfies FlowPlan<string>;\n\n// Relaxed session schema for state - payload is optional when using mcp-session-id header directly\nconst stateSessionSchema = z.object({\n id: z.string(),\n payload: z\n .object({\n nodeId: z.string(),\n authSig: z.string(),\n uuid: z.string().uuid(),\n iat: z.number(),\n protocol: z.enum(['legacy-sse', 'sse', 'streamable-http', 'stateful-http', 'stateless-http']).optional(),\n isPublic: z.boolean().optional(),\n platformType: z\n .enum(['openai', 'claude', 'gemini', 'cursor', 'continue', 'cody', 'generic-mcp', 'ext-apps', 'unknown'])\n .optional(),\n })\n .optional(),\n});\n\nexport const stateSchema = z.object({\n token: z.string(),\n session: stateSessionSchema,\n requestType: z.enum(['initialize', 'message', 'elicitResult']).optional(),\n});\n\nconst name = 'handle:legacy-sse' as const;\nconst { Stage } = FlowHooksOf(name);\n\ndeclare global {\n interface ExtendFlows {\n 'handle:legacy-sse': FlowRunOptions<\n HandleSseFlow,\n typeof plan,\n typeof httpInputSchema,\n typeof httpOutputSchema,\n typeof stateSchema\n >;\n }\n}\n\n@Flow({\n name,\n access: 'authorized',\n inputSchema: httpInputSchema,\n outputSchema: httpOutputSchema,\n plan,\n})\nexport default class HandleSseFlow extends FlowBase<typeof name> {\n @Stage('parseInput')\n async parseInput() {\n const { request } = this.rawInput;\n\n const authorization = request[ServerRequestTokens.auth] as Authorization;\n const { token } = authorization;\n\n // CRITICAL: The mcp-session-id header is the client's reference to their session.\n // We MUST use this exact ID for transport registry lookup.\n //\n // Priority 1: Use mcp-session-id header if present (client's session ID for lookup)\n // This is the ID the client received from initialize and is referencing.\n // Priority 2: Use session from authorization if header matches or is absent\n // Priority 3: Create new session (first request - no header, no authorization.session)\n const mcpSessionHeader = request.headers?.['mcp-session-id'] as string | undefined;\n\n let session: { id: string; payload?: z.infer<typeof stateSchema>['session']['payload'] };\n\n if (mcpSessionHeader) {\n // Client sent session ID - ALWAYS use it for transport lookup\n // If authorization.session exists and matches, use its payload for protocol detection\n // If authorization.session differs or is missing, still use header ID (payload may be undefined)\n if (authorization.session?.id === mcpSessionHeader) {\n session = authorization.session;\n } else {\n session = { id: mcpSessionHeader };\n }\n } else if (authorization.session) {\n // No header but authorization has session - use it (shouldn't happen in normal flow)\n session = authorization.session;\n } else {\n // No session - create new one (initialize request)\n session = createSessionId('legacy-sse', token, {\n userAgent: request.headers?.['user-agent'] as string | undefined,\n platformDetectionConfig: (this.scope as Scope).metadata?.session?.platformDetection,\n });\n }\n\n this.state.set(stateSchema.parse({ token, session }));\n }\n\n @Stage('router')\n async router() {\n const { request } = this.rawInput;\n const scope = this.scope as Scope;\n const requestPath = normalizeEntryPrefix(request.path);\n const prefix = normalizeEntryPrefix(scope.entryPath);\n const scopePath = normalizeScopeBase(scope.routeBase);\n const basePath = `${prefix}${scopePath}`;\n\n if (requestPath === `${basePath}/sse`) {\n this.state.set('requestType', 'initialize');\n } else if (requestPath === `${basePath}/message`) {\n this.state.set('requestType', 'message');\n }\n }\n\n @Stage('onInitialize', {\n filter: ({ state: { requestType } }) => requestType === 'initialize',\n })\n async onInitialize() {\n const transportService = (this.scope as Scope).transportService;\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n const transport = await transportService.createTransporter('sse', token, session.id, response);\n await transport.initialize(request, response);\n this.handled();\n }\n\n @Stage('onElicitResult', {\n filter: ({ state: { requestType } }) => requestType === 'elicitResult',\n })\n async onElicitResult() {\n // const transport = await transportService.getTransporter('sse', token, session.id);\n // if (!transport) {\n // this.respond(httpRespond.rpcError('session not initialized'));\n // return;\n // }\n // await transport.handleRequest(request, response);\n this.fail(new Error('Not implemented'));\n }\n\n @Stage('onMessage', {\n filter: ({ state: { requestType } }) => requestType === 'message',\n })\n async onMessage() {\n const transportService = (this.scope as Scope).transportService;\n const logger = this.scopeLogger.child('handle:legacy-sse:onMessage');\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n const transport = await transportService.getTransporter('sse', token, session.id);\n if (!transport) {\n // Check if session was ever created to differentiate error types per MCP Spec 2025-11-25\n const wasCreated = transportService.wasSessionCreated('sse', token, session.id);\n const body = request.body as Record<string, unknown> | undefined;\n\n if (wasCreated) {\n // Session existed but was terminated/evicted → HTTP 404 (client should re-initialize)\n logger.info('Session expired - client should re-initialize', {\n sessionId: session.id?.slice(0, 20),\n tokenHash: token.slice(0, 8),\n method: body?.['method'],\n requestId: body?.['id'],\n });\n this.respond(httpRespond.sessionExpired('session expired'));\n } else {\n // Session was never created → HTTP 404 (per user requirement: invalid/missing session = 404)\n logger.warn('Session not initialized - client attempted request without initializing', {\n sessionId: session.id?.slice(0, 20),\n tokenHash: token.slice(0, 8),\n method: body?.['method'],\n requestId: body?.['id'],\n userAgent: (request.headers?.['user-agent'] as string | undefined)?.slice(0, 50),\n });\n this.respond(httpRespond.sessionNotFound('session not initialized'));\n }\n return;\n }\n await transport.handleRequest(request, response);\n this.handled();\n }\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import { httpInputSchema, FlowRunOptions, httpOutputSchema, FlowBase } from '../../common';
2
+ import { z } from 'zod';
3
+ export declare const plan: {
4
+ readonly pre: ["parseInput", "router"];
5
+ readonly execute: ["handleRequest"];
6
+ readonly post: [];
7
+ readonly finalize: ["cleanup"];
8
+ };
9
+ export declare const stateSchema: z.ZodObject<{
10
+ token: z.ZodOptional<z.ZodString>;
11
+ isAuthenticated: z.ZodBoolean;
12
+ requestType: z.ZodOptional<z.ZodEnum<{
13
+ message: "message";
14
+ initialize: "initialize";
15
+ }>>;
16
+ }, z.core.$strip>;
17
+ declare const name: "handle:stateless-http";
18
+ declare global {
19
+ interface ExtendFlows {
20
+ 'handle:stateless-http': FlowRunOptions<HandleStatelessHttpFlow, typeof plan, typeof httpInputSchema, typeof httpOutputSchema, typeof stateSchema>;
21
+ }
22
+ }
23
+ export default class HandleStatelessHttpFlow extends FlowBase<typeof name> {
24
+ name: "handle:stateless-http";
25
+ parseInput(): Promise<void>;
26
+ router(): Promise<void>;
27
+ handleRequest(): Promise<void>;
28
+ }
29
+ export {};