@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
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stateSchema = exports.plan = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("../../common");
6
+ const zod_1 = require("zod");
7
+ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
8
+ exports.plan = {
9
+ pre: ['parseInput', 'router'],
10
+ execute: ['handleRequest'],
11
+ post: [],
12
+ finalize: ['cleanup'],
13
+ };
14
+ exports.stateSchema = zod_1.z.object({
15
+ token: zod_1.z.string().optional(),
16
+ isAuthenticated: zod_1.z.boolean(),
17
+ requestType: zod_1.z.enum(['initialize', 'message']).optional(),
18
+ });
19
+ const name = 'handle:stateless-http';
20
+ const { Stage } = (0, common_1.FlowHooksOf)(name);
21
+ let HandleStatelessHttpFlow = class HandleStatelessHttpFlow extends common_1.FlowBase {
22
+ name = name;
23
+ async parseInput() {
24
+ const { request } = this.rawInput;
25
+ // Check if we have auth info
26
+ const auth = request[common_1.ServerRequestTokens.auth];
27
+ const token = auth?.token;
28
+ const isAuthenticated = !!token && token.length > 0;
29
+ this.state.set(exports.stateSchema.parse({
30
+ token: token || undefined,
31
+ isAuthenticated,
32
+ }));
33
+ }
34
+ async router() {
35
+ const { request } = this.rawInput;
36
+ const body = request.body;
37
+ const method = body?.method;
38
+ // Use method-based detection for routing (more permissive than strict schema)
39
+ // The actual schema validation happens in the MCP SDK's transport layer
40
+ if (method === 'initialize') {
41
+ this.state.set('requestType', 'initialize');
42
+ }
43
+ else if (method && types_js_1.RequestSchema.safeParse(request.body).success) {
44
+ this.state.set('requestType', 'message');
45
+ }
46
+ else {
47
+ this.respond(common_1.httpRespond.rpcError('Invalid Request'));
48
+ }
49
+ }
50
+ async handleRequest() {
51
+ const transportService = this.scope.transportService;
52
+ const { request, response } = this.rawInput;
53
+ const { token, isAuthenticated, requestType } = this.state;
54
+ // Get or create the stateless transport
55
+ // For anonymous: shared singleton transport
56
+ // For authenticated: singleton per token
57
+ const transport = isAuthenticated && token
58
+ ? await transportService.getOrCreateAuthenticatedStatelessTransport('stateless-http', token, response)
59
+ : await transportService.getOrCreateAnonymousStatelessTransport('stateless-http', response);
60
+ // For stateless mode, inject the well-known session ID
61
+ // This satisfies the MCP SDK's session header requirement while keeping requests stateless
62
+ if (!request.headers['mcp-session-id']) {
63
+ request.headers['mcp-session-id'] = '__stateless__';
64
+ }
65
+ if (requestType === 'initialize') {
66
+ await transport.initialize(request, response);
67
+ }
68
+ else {
69
+ await transport.handleRequest(request, response);
70
+ }
71
+ this.handled();
72
+ }
73
+ };
74
+ tslib_1.__decorate([
75
+ Stage('parseInput'),
76
+ tslib_1.__metadata("design:type", Function),
77
+ tslib_1.__metadata("design:paramtypes", []),
78
+ tslib_1.__metadata("design:returntype", Promise)
79
+ ], HandleStatelessHttpFlow.prototype, "parseInput", null);
80
+ tslib_1.__decorate([
81
+ Stage('router'),
82
+ tslib_1.__metadata("design:type", Function),
83
+ tslib_1.__metadata("design:paramtypes", []),
84
+ tslib_1.__metadata("design:returntype", Promise)
85
+ ], HandleStatelessHttpFlow.prototype, "router", null);
86
+ tslib_1.__decorate([
87
+ Stage('handleRequest'),
88
+ tslib_1.__metadata("design:type", Function),
89
+ tslib_1.__metadata("design:paramtypes", []),
90
+ tslib_1.__metadata("design:returntype", Promise)
91
+ ], HandleStatelessHttpFlow.prototype, "handleRequest", null);
92
+ HandleStatelessHttpFlow = tslib_1.__decorate([
93
+ (0, common_1.Flow)({
94
+ name,
95
+ plan: exports.plan,
96
+ access: 'public', // Can be accessed without full auth
97
+ inputSchema: common_1.httpInputSchema,
98
+ outputSchema: common_1.httpOutputSchema,
99
+ })
100
+ ], HandleStatelessHttpFlow);
101
+ exports.default = HandleStatelessHttpFlow;
102
+ //# sourceMappingURL=handle.stateless-http.flow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.stateless-http.flow.js","sourceRoot":"","sources":["../../../../src/transport/flows/handle.stateless-http.flow.ts"],"names":[],"mappings":";;;;AAAA,yCAWsB;AACtB,6BAAwB;AACxB,iEAAmE;AAGtD,QAAA,IAAI,GAAG;IAClB,GAAG,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC;IAC7B,OAAO,EAAE,CAAC,eAAe,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AC;QAChD,CAAC;aAAM,CAAC;YACN,MAAM,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACnD,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;CACF,CAAA;AA7DO;IADL,KAAK,CAAC,YAAY,CAAC;;;;yDAenB;AAGK;IADL,KAAK,CAAC,QAAQ,CAAC;;;;qDAef;AAGK;IADL,KAAK,CAAC,eAAe,CAAC;;;;4DA2BtB;AAhEkB,uBAAuB;IAP3C,IAAA,aAAI,EAAC;QACJ,IAAI;QACJ,IAAI,EAAJ,YAAI;QACJ,MAAM,EAAE,QAAQ,EAAE,oCAAoC;QACtD,WAAW,EAAE,wBAAe;QAC5B,YAAY,EAAE,yBAAgB;KAC/B,CAAC;GACmB,uBAAuB,CAiE3C;kBAjEoB,uBAAuB","sourcesContent":["import {\n Flow,\n httpInputSchema,\n FlowRunOptions,\n httpOutputSchema,\n FlowPlan,\n FlowBase,\n FlowHooksOf,\n httpRespond,\n ServerRequestTokens,\n Authorization,\n} from '../../common';\nimport { z } from 'zod';\nimport { RequestSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { Scope } from '../../scope';\n\nexport const plan = {\n pre: ['parseInput', 'router'],\n execute: ['handleRequest'],\n post: [],\n finalize: ['cleanup'],\n} as const satisfies FlowPlan<string>;\n\nexport const stateSchema = z.object({\n token: z.string().optional(),\n isAuthenticated: z.boolean(),\n requestType: z.enum(['initialize', 'message']).optional(),\n});\n\nconst name = 'handle:stateless-http' as const;\nconst { Stage } = FlowHooksOf(name);\n\ndeclare global {\n interface ExtendFlows {\n 'handle:stateless-http': FlowRunOptions<\n HandleStatelessHttpFlow,\n typeof plan,\n typeof httpInputSchema,\n typeof httpOutputSchema,\n typeof stateSchema\n >;\n }\n}\n\n@Flow({\n name,\n plan,\n access: 'public', // Can be accessed without full auth\n inputSchema: httpInputSchema,\n outputSchema: httpOutputSchema,\n})\nexport default class HandleStatelessHttpFlow extends FlowBase<typeof name> {\n name = name;\n\n @Stage('parseInput')\n async parseInput() {\n const { request } = this.rawInput;\n\n // Check if we have auth info\n const auth = request[ServerRequestTokens.auth] as Authorization | undefined;\n const token = auth?.token;\n const isAuthenticated = !!token && token.length > 0;\n\n this.state.set(\n stateSchema.parse({\n token: token || undefined,\n isAuthenticated,\n }),\n );\n }\n\n @Stage('router')\n async router() {\n const { request } = this.rawInput;\n const body = request.body as { method?: string } | undefined;\n const method = body?.method;\n\n // Use method-based detection for routing (more permissive than strict schema)\n // The actual schema validation happens in the MCP SDK's transport layer\n if (method === 'initialize') {\n this.state.set('requestType', 'initialize');\n } else if (method && RequestSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'message');\n } else {\n this.respond(httpRespond.rpcError('Invalid Request'));\n }\n }\n\n @Stage('handleRequest')\n async handleRequest() {\n const transportService = (this.scope as Scope).transportService;\n const { request, response } = this.rawInput;\n const { token, isAuthenticated, requestType } = this.state;\n\n // Get or create the stateless transport\n // For anonymous: shared singleton transport\n // For authenticated: singleton per token\n const transport =\n isAuthenticated && token\n ? await transportService.getOrCreateAuthenticatedStatelessTransport('stateless-http', token, response)\n : await transportService.getOrCreateAnonymousStatelessTransport('stateless-http', response);\n\n // For stateless mode, inject the well-known session ID\n // This satisfies the MCP SDK's session header requirement while keeping requests stateless\n if (!request.headers['mcp-session-id']) {\n request.headers['mcp-session-id'] = '__stateless__';\n }\n\n if (requestType === 'initialize') {\n await transport.initialize(request, response);\n } else {\n await transport.handleRequest(request, response);\n }\n\n this.handled();\n }\n}\n"]}
@@ -2,7 +2,7 @@ import { httpInputSchema, FlowRunOptions, httpOutputSchema, FlowBase } from '../
2
2
  import { z } from 'zod';
3
3
  export declare const plan: {
4
4
  readonly pre: ["parseInput", "router"];
5
- readonly execute: ["onInitialize", "onMessage", "onElicitResult"];
5
+ readonly execute: ["onInitialize", "onMessage", "onElicitResult", "onSseListener"];
6
6
  readonly post: [];
7
7
  readonly finalize: ["cleanup"];
8
8
  };
@@ -10,72 +10,39 @@ 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
+ sseListener: "sseListener";
44
+ }>>;
45
+ }, z.core.$strip>;
79
46
  declare const name: "handle:streamable-http";
80
47
  declare global {
81
48
  interface ExtendFlows {
@@ -84,10 +51,11 @@ declare global {
84
51
  }
85
52
  export default class HandleStreamableHttpFlow extends FlowBase<typeof name> {
86
53
  name: "handle:streamable-http";
87
- paseInput(): Promise<void>;
54
+ parseInput(): Promise<void>;
88
55
  router(): Promise<void>;
89
56
  onInitialize(): Promise<void>;
90
57
  onElicitResult(): Promise<void>;
91
58
  onMessage(): Promise<void>;
59
+ onSseListener(): Promise<void>;
92
60
  }
93
61
  export {};
@@ -7,47 +7,94 @@ const zod_1 = require("zod");
7
7
  const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
8
8
  const session_id_utils_1 = require("../../auth/session/utils/session-id.utils");
9
9
  exports.plan = {
10
- pre: [
11
- 'parseInput',
12
- 'router',
13
- ],
14
- execute: [
15
- 'onInitialize',
16
- 'onMessage',
17
- 'onElicitResult',
18
- ],
10
+ pre: ['parseInput', 'router'],
11
+ execute: ['onInitialize', 'onMessage', 'onElicitResult', 'onSseListener'],
19
12
  post: [],
20
- finalize: [
21
- 'cleanup',
22
- ],
13
+ finalize: ['cleanup'],
23
14
  };
15
+ // Relaxed session schema for state - payload is optional when using mcp-session-id header directly
16
+ const stateSessionSchema = zod_1.z.object({
17
+ id: zod_1.z.string(),
18
+ payload: zod_1.z
19
+ .object({
20
+ nodeId: zod_1.z.string(),
21
+ authSig: zod_1.z.string(),
22
+ uuid: zod_1.z.string().uuid(),
23
+ iat: zod_1.z.number(),
24
+ protocol: zod_1.z.enum(['legacy-sse', 'sse', 'streamable-http', 'stateful-http', 'stateless-http']).optional(),
25
+ isPublic: zod_1.z.boolean().optional(),
26
+ platformType: zod_1.z
27
+ .enum(['openai', 'claude', 'gemini', 'cursor', 'continue', 'cody', 'generic-mcp', 'ext-apps', 'unknown'])
28
+ .optional(),
29
+ })
30
+ .optional(),
31
+ });
24
32
  exports.stateSchema = zod_1.z.object({
25
33
  token: zod_1.z.string(),
26
- session: common_1.sessionIdSchema,
27
- requestType: zod_1.z.enum(['initialize', 'message', 'elicitResult']).optional(),
34
+ session: stateSessionSchema,
35
+ requestType: zod_1.z.enum(['initialize', 'message', 'elicitResult', 'sseListener']).optional(),
28
36
  });
29
37
  const name = 'handle:streamable-http';
30
38
  const { Stage } = (0, common_1.FlowHooksOf)(name);
31
39
  let HandleStreamableHttpFlow = class HandleStreamableHttpFlow extends common_1.FlowBase {
32
40
  name = name;
33
- async paseInput() {
41
+ async parseInput() {
34
42
  const { request } = this.rawInput;
35
- let { token, session } = request[common_1.ServerRequestTokens.auth];
36
- if (!session) {
37
- session = (0, session_id_utils_1.createSessionId)('streamable-http', token);
38
- request[common_1.ServerRequestTokens.auth].session = session;
43
+ const authorization = request[common_1.ServerRequestTokens.auth];
44
+ const { token } = authorization;
45
+ // CRITICAL: The mcp-session-id header is the client's reference to their session.
46
+ // We MUST use this exact ID for transport registry lookup.
47
+ //
48
+ // Priority 1: Use mcp-session-id header if present (client's session ID for lookup)
49
+ // This is the ID the client received from initialize and is referencing.
50
+ // Priority 2: Use session from authorization if header matches or is absent
51
+ // Priority 3: Create new session (first request - no header, no authorization.session)
52
+ const mcpSessionHeader = request.headers?.['mcp-session-id'];
53
+ let session;
54
+ if (mcpSessionHeader) {
55
+ // Client sent session ID - ALWAYS use it for transport lookup
56
+ // If authorization.session exists and matches, use its payload for protocol detection
57
+ // If authorization.session differs or is missing, still use header ID (payload may be undefined)
58
+ if (authorization.session?.id === mcpSessionHeader) {
59
+ session = authorization.session;
60
+ }
61
+ else {
62
+ session = { id: mcpSessionHeader };
63
+ }
64
+ }
65
+ else if (authorization.session) {
66
+ // No header but authorization has session - use it (shouldn't happen in normal flow)
67
+ session = authorization.session;
68
+ }
69
+ else {
70
+ // No session - create new one (initialize request)
71
+ session = (0, session_id_utils_1.createSessionId)('streamable-http', token, {
72
+ userAgent: request.headers?.['user-agent'],
73
+ platformDetectionConfig: this.scope.metadata?.session?.platformDetection,
74
+ });
39
75
  }
40
76
  this.state.set(exports.stateSchema.parse({ token, session }));
41
77
  }
42
78
  async router() {
43
79
  const { request } = this.rawInput;
44
- if (types_js_1.InitializeRequestSchema.safeParse(request.body).success) {
80
+ // GET requests are SSE listener streams - no body expected
81
+ // Per MCP spec, clients can open SSE stream with GET + Accept: text/event-stream
82
+ if (request.method.toUpperCase() === 'GET') {
83
+ this.state.set('requestType', 'sseListener');
84
+ return;
85
+ }
86
+ // POST requests have MCP JSON-RPC body
87
+ const body = request.body;
88
+ const method = body?.method;
89
+ // Use method-based detection for routing (more permissive than strict schema)
90
+ // The actual schema validation happens in the MCP SDK's transport layer
91
+ if (method === 'initialize') {
45
92
  this.state.set('requestType', 'initialize');
46
93
  }
47
94
  else if (types_js_1.ElicitResultSchema.safeParse(request.body).success) {
48
95
  this.state.set('requestType', 'elicitResult');
49
96
  }
50
- else if (types_js_1.RequestSchema.safeParse(request.body).success) {
97
+ else if (method && types_js_1.RequestSchema.safeParse(request.body).success) {
51
98
  this.state.set('requestType', 'message');
52
99
  }
53
100
  else {
@@ -56,25 +103,102 @@ let HandleStreamableHttpFlow = class HandleStreamableHttpFlow extends common_1.F
56
103
  }
57
104
  async onInitialize() {
58
105
  const transportService = this.scope.transportService;
106
+ const logger = this.scope.logger.child('handle:streamable-http:onInitialize');
59
107
  const { request, response } = this.rawInput;
60
108
  const { token, session } = this.state.required;
61
- const transport = await transportService.createTransporter('streamable-http', token, session.id, response);
62
- await transport.initialize(request, response);
63
- this.handled();
109
+ logger.info('onInitialize: creating transport', {
110
+ sessionId: session.id.slice(0, 30),
111
+ hasToken: !!token,
112
+ tokenPrefix: token?.slice(0, 10),
113
+ });
114
+ try {
115
+ const transport = await transportService.createTransporter('streamable-http', token, session.id, response);
116
+ logger.info('onInitialize: transport created, calling initialize');
117
+ await transport.initialize(request, response);
118
+ logger.info('onInitialize: completed successfully');
119
+ this.handled();
120
+ }
121
+ catch (error) {
122
+ // FlowControl is expected control flow (from this.handled()), not an error
123
+ if (error instanceof common_1.FlowControl) {
124
+ throw error;
125
+ }
126
+ logger.error('onInitialize: failed', {
127
+ error: error instanceof Error ? error.message : String(error),
128
+ stack: error instanceof Error ? error.stack : undefined,
129
+ });
130
+ throw error;
131
+ }
64
132
  }
65
133
  async onElicitResult() {
66
134
  this.fail(new Error('Not implemented'));
67
135
  }
68
136
  async onMessage() {
137
+ const transportService = this.scope.transportService;
138
+ const logger = this.scopeLogger.child('handle:streamable-http:onMessage');
139
+ const { request, response } = this.rawInput;
140
+ const { token, session } = this.state.required;
141
+ const transport = await transportService.getTransporter('streamable-http', token, session.id);
142
+ if (!transport) {
143
+ // Check if session was ever created to differentiate error types per MCP Spec 2025-11-25
144
+ const wasCreated = transportService.wasSessionCreated('streamable-http', token, session.id);
145
+ const body = request.body;
146
+ if (wasCreated) {
147
+ // Session existed but was terminated/evicted → HTTP 404 (client should re-initialize)
148
+ logger.info('Session expired - client should re-initialize', {
149
+ sessionId: session.id?.slice(0, 20),
150
+ tokenHash: token.slice(0, 8),
151
+ method: body?.['method'],
152
+ requestId: body?.['id'],
153
+ mcpSessionId: request.headers?.['mcp-session-id'],
154
+ });
155
+ this.respond(common_1.httpRespond.sessionExpired('session expired'));
156
+ }
157
+ else {
158
+ // Session was never created → HTTP 404 (per user requirement: invalid/missing session = 404)
159
+ logger.warn('Session not initialized - client attempted request without initializing', {
160
+ sessionId: session.id?.slice(0, 20),
161
+ tokenHash: token.slice(0, 8),
162
+ method: body?.['method'],
163
+ requestId: body?.['id'],
164
+ mcpSessionId: request.headers?.['mcp-session-id'],
165
+ userAgent: request.headers?.['user-agent']?.slice(0, 50),
166
+ });
167
+ this.respond(common_1.httpRespond.sessionNotFound('session not initialized'));
168
+ }
169
+ return;
170
+ }
171
+ try {
172
+ await transport.handleRequest(request, response);
173
+ this.handled();
174
+ }
175
+ catch (error) {
176
+ // FlowControl is expected control flow, not an error
177
+ if (!(error instanceof common_1.FlowControl)) {
178
+ const body = request.body;
179
+ logger.error('handleRequest failed', {
180
+ error: error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : error,
181
+ method: body?.['method'],
182
+ id: body?.['id'],
183
+ sessionId: session.id?.slice(0, 20),
184
+ });
185
+ }
186
+ throw error;
187
+ }
188
+ }
189
+ async onSseListener() {
69
190
  const transportService = this.scope.transportService;
70
191
  const { request, response } = this.rawInput;
71
192
  const { token, session } = this.state.required;
193
+ // Get existing transport for this session - SSE listener requires existing session
72
194
  const transport = await transportService.getTransporter('streamable-http', token, session.id);
73
195
  if (!transport) {
74
- this.respond(common_1.httpRespond.rpcError('session not initialized'));
196
+ this.respond(common_1.httpRespond.notFound('Session not found'));
75
197
  return;
76
198
  }
199
+ // Forward GET request to transport (opens SSE stream for server→client notifications)
77
200
  await transport.handleRequest(request, response);
201
+ this.handled();
78
202
  }
79
203
  };
80
204
  tslib_1.__decorate([
@@ -82,7 +206,7 @@ tslib_1.__decorate([
82
206
  tslib_1.__metadata("design:type", Function),
83
207
  tslib_1.__metadata("design:paramtypes", []),
84
208
  tslib_1.__metadata("design:returntype", Promise)
85
- ], HandleStreamableHttpFlow.prototype, "paseInput", null);
209
+ ], HandleStreamableHttpFlow.prototype, "parseInput", null);
86
210
  tslib_1.__decorate([
87
211
  Stage('router'),
88
212
  tslib_1.__metadata("design:type", Function),
@@ -113,6 +237,14 @@ tslib_1.__decorate([
113
237
  tslib_1.__metadata("design:paramtypes", []),
114
238
  tslib_1.__metadata("design:returntype", Promise)
115
239
  ], HandleStreamableHttpFlow.prototype, "onMessage", null);
240
+ tslib_1.__decorate([
241
+ Stage('onSseListener', {
242
+ filter: ({ state: { requestType } }) => requestType === 'sseListener',
243
+ }),
244
+ tslib_1.__metadata("design:type", Function),
245
+ tslib_1.__metadata("design:paramtypes", []),
246
+ tslib_1.__metadata("design:returntype", Promise)
247
+ ], HandleStreamableHttpFlow.prototype, "onSseListener", null);
116
248
  HandleStreamableHttpFlow = tslib_1.__decorate([
117
249
  (0, common_1.Flow)({
118
250
  name,
@@ -1 +1 @@
1
- {"version":3,"file":"handle.streamable-http.flow.js","sourceRoot":"","sources":["../../../../src/transport/flows/handle.streamable-http.flow.ts"],"names":[],"mappings":";;;;AAAA,yCAGsB;AACtB,6BAAsB;AACtB,iEAA8G;AAE9G,gFAA0E;AAE7D,QAAA,IAAI,GAAG;IAClB,GAAG,EAAE;QACH,YAAY;QACZ,QAAQ;KACT;IACD,OAAO,EAAE;QACP,cAAc;QACd,WAAW;QACX,gBAAgB;KACjB;IACD,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE;QACR,SAAS;KACV;CACkC,CAAC;AAGzB,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;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ACf,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;IACnD,CAAC;CAGF,CAAA;AAhEO;IADL,KAAK,CAAC,YAAY,CAAC;;;;yDAWnB;AAGK;IADL,KAAK,CAAC,QAAQ,CAAC;;;;sDAaf;AAKK;IAHL,KAAK,CAAC,cAAc,EAAE;QACrB,MAAM,EAAE,CAAC,EAAC,KAAK,EAAE,EAAC,WAAW,EAAC,EAAC,EAAE,EAAE,CAAC,WAAW,KAAK,YAAY;KACjE,CAAC;;;;4DASD;AAKK;IAHL,KAAK,CAAC,gBAAgB,EAAE;QACvB,MAAM,EAAE,CAAC,EAAC,KAAK,EAAE,EAAC,WAAW,EAAC,EAAC,EAAE,EAAE,CAAC,WAAW,KAAK,cAAc;KACnE,CAAC;;;;8DAGD;AAKK;IAHL,KAAK,CAAC,WAAW,EAAE;QAClB,MAAM,EAAE,CAAC,EAAC,KAAK,EAAE,EAAC,WAAW,EAAC,EAAC,EAAE,EAAE,CAAC,WAAW,KAAK,SAAS;KAC9D,CAAC;;;;yDAYD;AAjEkB,wBAAwB;IAP5C,IAAA,aAAI,EAAC;QACJ,IAAI;QACJ,IAAI,EAAJ,YAAI;QACJ,MAAM,EAAE,YAAY;QACpB,WAAW,EAAE,wBAAe;QAC5B,YAAY,EAAE,yBAAgB;KAC/B,CAAC;GACmB,wBAAwB,CAoE5C;kBApEoB,wBAAwB","sourcesContent":["import {\n Flow, httpInputSchema, FlowRunOptions, httpOutputSchema, FlowPlan,\n FlowBase, FlowHooksOf, sessionIdSchema, httpRespond, ServerRequestTokens, Authorization,\n} from '../../common';\nimport {z} from 'zod';\nimport {ElicitResultSchema, InitializeRequestSchema, RequestSchema} from '@modelcontextprotocol/sdk/types.js';\nimport {Scope} from '../../scope';\nimport {createSessionId} from '../../auth/session/utils/session-id.utils';\n\nexport const plan = {\n pre: [\n 'parseInput',\n 'router',\n ],\n execute: [\n 'onInitialize',\n 'onMessage',\n 'onElicitResult',\n ],\n post: [],\n finalize: [\n 'cleanup',\n ],\n} as const satisfies FlowPlan<string>;\n\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:streamable-http' as const;\nconst {Stage} = FlowHooksOf(name);\n\n\ndeclare global {\n interface ExtendFlows {\n 'handle:streamable-http': FlowRunOptions<\n HandleStreamableHttpFlow,\n typeof plan,\n typeof httpInputSchema,\n typeof httpOutputSchema,\n typeof stateSchema\n >;\n }\n}\n\n@Flow({\n name,\n plan,\n access: 'authorized',\n inputSchema: httpInputSchema,\n outputSchema: httpOutputSchema,\n})\nexport default class HandleStreamableHttpFlow extends FlowBase<typeof name> {\n name = name;\n\n @Stage('parseInput')\n async paseInput() {\n const {request} = this.rawInput;\n\n let {token, session} = request[ServerRequestTokens.auth] as Authorization;\n\n if (!session) {\n session = createSessionId('streamable-http', 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\n if (InitializeRequestSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'initialize');\n } else if (ElicitResultSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'elicitResult');\n } else if (RequestSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'message');\n } else {\n this.respond(httpRespond.rpcError('Invalid Request'));\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('streamable-http', 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 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('streamable-http', token, session.id);\n if (!transport) {\n this.respond(httpRespond.rpcError('session not initialized'));\n return;\n }\n await transport.handleRequest(request, response);\n }\n\n\n}\n"]}
1
+ {"version":3,"file":"handle.streamable-http.flow.js","sourceRoot":"","sources":["../../../../src/transport/flows/handle.streamable-http.flow.ts"],"names":[],"mappings":";;;;AAAA,yCAasB;AACtB,6BAAwB;AACxB,iEAAuF;AAEvF,gFAA4E;AAE/D,QAAA,IAAI,GAAG;IAClB,GAAG,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC;IAC7B,OAAO,EAAE,CAAC,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,CAAC;IACzE,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,QAAQ,EAAE;QACxG,QAAQ,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAChC,YAAY,E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AwB,CAgM5C;kBAhMoB,wBAAwB","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 FlowControl,\n} from '../../common';\nimport { z } from 'zod';\nimport { ElicitResultSchema, RequestSchema } from '@modelcontextprotocol/sdk/types.js';\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', 'onSseListener'],\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', 'sseListener']).optional(),\n});\n\nconst name = 'handle:streamable-http' as const;\nconst { Stage } = FlowHooksOf(name);\n\ndeclare global {\n interface ExtendFlows {\n 'handle:streamable-http': FlowRunOptions<\n HandleStreamableHttpFlow,\n typeof plan,\n typeof httpInputSchema,\n typeof httpOutputSchema,\n typeof stateSchema\n >;\n }\n}\n\n@Flow({\n name,\n plan,\n access: 'authorized',\n inputSchema: httpInputSchema,\n outputSchema: httpOutputSchema,\n})\nexport default class HandleStreamableHttpFlow extends FlowBase<typeof name> {\n name = name;\n\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('streamable-http', 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\n // GET requests are SSE listener streams - no body expected\n // Per MCP spec, clients can open SSE stream with GET + Accept: text/event-stream\n if (request.method.toUpperCase() === 'GET') {\n this.state.set('requestType', 'sseListener');\n return;\n }\n\n // POST requests have MCP JSON-RPC body\n const body = request.body as { method?: string } | undefined;\n const method = body?.method;\n\n // Use method-based detection for routing (more permissive than strict schema)\n // The actual schema validation happens in the MCP SDK's transport layer\n if (method === 'initialize') {\n this.state.set('requestType', 'initialize');\n } else if (ElicitResultSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'elicitResult');\n } else if (method && RequestSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'message');\n } else {\n this.respond(httpRespond.rpcError('Invalid Request'));\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 const logger = (this.scope as Scope).logger.child('handle:streamable-http:onInitialize');\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n\n logger.info('onInitialize: creating transport', {\n sessionId: session.id.slice(0, 30),\n hasToken: !!token,\n tokenPrefix: token?.slice(0, 10),\n });\n\n try {\n const transport = await transportService.createTransporter('streamable-http', token, session.id, response);\n logger.info('onInitialize: transport created, calling initialize');\n await transport.initialize(request, response);\n logger.info('onInitialize: completed successfully');\n this.handled();\n } catch (error) {\n // FlowControl is expected control flow (from this.handled()), not an error\n if (error instanceof FlowControl) {\n throw error;\n }\n logger.error('onInitialize: failed', {\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n });\n throw error;\n }\n }\n\n @Stage('onElicitResult', {\n filter: ({ state: { requestType } }) => requestType === 'elicitResult',\n })\n async onElicitResult() {\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:streamable-http:onMessage');\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n const transport = await transportService.getTransporter('streamable-http', 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('streamable-http', 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 mcpSessionId: request.headers?.['mcp-session-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 mcpSessionId: request.headers?.['mcp-session-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\n try {\n await transport.handleRequest(request, response);\n this.handled();\n } catch (error) {\n // FlowControl is expected control flow, not an error\n if (!(error instanceof FlowControl)) {\n const body = request.body as Record<string, unknown> | undefined;\n logger.error('handleRequest failed', {\n error: error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : error,\n method: body?.['method'],\n id: body?.['id'],\n sessionId: session.id?.slice(0, 20),\n });\n }\n throw error;\n }\n }\n\n @Stage('onSseListener', {\n filter: ({ state: { requestType } }) => requestType === 'sseListener',\n })\n async onSseListener() {\n const transportService = (this.scope as Scope).transportService;\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n\n // Get existing transport for this session - SSE listener requires existing session\n const transport = await transportService.getTransporter('streamable-http', token, session.id);\n if (!transport) {\n this.respond(httpRespond.notFound('Session not found'));\n return;\n }\n\n // Forward GET request to transport (opens SSE stream for server→client notifications)\n await transport.handleRequest(request, response);\n this.handled();\n }\n}\n"]}
@@ -34,6 +34,8 @@ export declare class SSEServerTransport implements Transport {
34
34
  private _sseResponse?;
35
35
  private _sessionId;
36
36
  private _options;
37
+ /** Incrementing event ID counter for SSE events (MCP 2025-11-25 spec compliance) */
38
+ private _eventIdCounter;
37
39
  onclose?: () => void;
38
40
  onerror?: (error: Error) => void;
39
41
  onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
@@ -72,4 +74,11 @@ export declare class SSEServerTransport implements Transport {
72
74
  * This can be used to route incoming POST requests.
73
75
  */
74
76
  get sessionId(): string;
77
+ /**
78
+ * Returns the current event ID counter value.
79
+ *
80
+ * This is the ID that was used for the last sent event.
81
+ * Useful for testing and debugging reconnection scenarios.
82
+ */
83
+ get lastEventId(): number;
75
84
  }
@@ -19,6 +19,8 @@ class SSEServerTransport {
19
19
  _sseResponse;
20
20
  _sessionId;
21
21
  _options;
22
+ /** Incrementing event ID counter for SSE events (MCP 2025-11-25 spec compliance) */
23
+ _eventIdCounter = 0;
22
24
  onclose;
23
25
  onerror;
24
26
  onmessage;
@@ -78,7 +80,9 @@ class SSEServerTransport {
78
80
  endpointUrl.searchParams.set('sessionId', this._sessionId);
79
81
  // Reconstruct the relative URL string (pathname + search + hash)
80
82
  const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash;
81
- this.res.write(`event: endpoint\ndata: ${relativeUrlWithSession}\n\n`);
83
+ // Include event ID per MCP 2025-11-25 spec for client reconnection support
84
+ const eventId = ++this._eventIdCounter;
85
+ this.res.write(`id: ${eventId}\nevent: endpoint\ndata: ${relativeUrlWithSession}\n\n`);
82
86
  this._sseResponse = this.res;
83
87
  this.res.on('close', () => {
84
88
  this._sseResponse = undefined;
@@ -155,7 +159,9 @@ class SSEServerTransport {
155
159
  if (!this._sseResponse) {
156
160
  throw new Error('Not connected');
157
161
  }
158
- this._sseResponse.write(`event: message\ndata: ${JSON.stringify(message)}\n\n`);
162
+ // Include event ID per MCP 2025-11-25 spec for client reconnection support
163
+ const eventId = ++this._eventIdCounter;
164
+ this._sseResponse.write(`id: ${eventId}\nevent: message\ndata: ${JSON.stringify(message)}\n\n`);
159
165
  }
160
166
  /**
161
167
  * Returns the session ID for this transport.
@@ -165,6 +171,15 @@ class SSEServerTransport {
165
171
  get sessionId() {
166
172
  return this._sessionId;
167
173
  }
174
+ /**
175
+ * Returns the current event ID counter value.
176
+ *
177
+ * This is the ID that was used for the last sent event.
178
+ * Useful for testing and debugging reconnection scenarios.
179
+ */
180
+ get lastEventId() {
181
+ return this._eventIdCounter;
182
+ }
168
183
  }
169
184
  exports.SSEServerTransport = SSEServerTransport;
170
185
  //# sourceMappingURL=legacy.sse.tranporter.js.map