@frontmcp/sdk 0.5.1 → 0.6.1

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 (265) hide show
  1. package/README.md +1 -0
  2. package/package.json +12 -16
  3. package/src/adapter/adapter.instance.js +5 -0
  4. package/src/adapter/adapter.instance.js.map +1 -1
  5. package/src/auth/authorization/authorization.class.d.ts +1 -4
  6. package/src/auth/authorization/authorization.class.js +6 -13
  7. package/src/auth/authorization/authorization.class.js.map +1 -1
  8. package/src/auth/flows/session.verify.flow.d.ts +1 -0
  9. package/src/auth/flows/session.verify.flow.js +11 -1
  10. package/src/auth/flows/session.verify.flow.js.map +1 -1
  11. package/src/auth/flows/well-known.jwks.flow.js +2 -2
  12. package/src/auth/flows/well-known.jwks.flow.js.map +1 -1
  13. package/src/auth/jwks/dev-key-persistence.d.ts +63 -0
  14. package/src/auth/jwks/dev-key-persistence.js +219 -0
  15. package/src/auth/jwks/dev-key-persistence.js.map +1 -0
  16. package/src/auth/jwks/index.d.ts +1 -0
  17. package/src/auth/jwks/index.js +1 -0
  18. package/src/auth/jwks/index.js.map +1 -1
  19. package/src/auth/jwks/jwks.service.d.ts +7 -4
  20. package/src/auth/jwks/jwks.service.js +81 -12
  21. package/src/auth/jwks/jwks.service.js.map +1 -1
  22. package/src/auth/jwks/jwks.types.d.ts +7 -0
  23. package/src/auth/jwks/jwks.types.js.map +1 -1
  24. package/src/auth/machine-id.d.ts +5 -0
  25. package/src/auth/machine-id.js +32 -0
  26. package/src/auth/machine-id.js.map +1 -0
  27. package/src/auth/session/index.d.ts +2 -0
  28. package/src/auth/session/index.js +5 -1
  29. package/src/auth/session/index.js.map +1 -1
  30. package/src/auth/session/record/session.base.js +5 -3
  31. package/src/auth/session/record/session.base.js.map +1 -1
  32. package/src/auth/session/record/session.stateless.d.ts +2 -2
  33. package/src/auth/session/record/session.stateless.js +5 -3
  34. package/src/auth/session/record/session.stateless.js.map +1 -1
  35. package/src/auth/session/redis-session.store.d.ts +64 -0
  36. package/src/auth/session/redis-session.store.js +204 -0
  37. package/src/auth/session/redis-session.store.js.map +1 -0
  38. package/src/auth/session/session.service.d.ts +0 -2
  39. package/src/auth/session/session.service.js +1 -7
  40. package/src/auth/session/session.service.js.map +1 -1
  41. package/src/auth/session/transport-session.manager.js +3 -5
  42. package/src/auth/session/transport-session.manager.js.map +1 -1
  43. package/src/auth/session/transport-session.types.d.ts +4 -0
  44. package/src/auth/session/transport-session.types.js +4 -3
  45. package/src/auth/session/transport-session.types.js.map +1 -1
  46. package/src/auth/session/utils/session-id.utils.d.ts +12 -1
  47. package/src/auth/session/utils/session-id.utils.js +48 -9
  48. package/src/auth/session/utils/session-id.utils.js.map +1 -1
  49. package/src/auth/session/vercel-kv-session.store.d.ts +96 -0
  50. package/src/auth/session/vercel-kv-session.store.js +216 -0
  51. package/src/auth/session/vercel-kv-session.store.js.map +1 -0
  52. package/src/auth/ui/base-layout.d.ts +0 -8
  53. package/src/auth/ui/base-layout.js +1 -14
  54. package/src/auth/ui/base-layout.js.map +1 -1
  55. package/src/auth/ui/index.d.ts +3 -4
  56. package/src/auth/ui/index.js +10 -11
  57. package/src/auth/ui/index.js.map +1 -1
  58. package/src/auth/ui/{htmx-templates.d.ts → templates.d.ts} +5 -6
  59. package/src/auth/ui/{htmx-templates.js → templates.js} +8 -15
  60. package/src/auth/ui/templates.js.map +1 -0
  61. package/src/common/decorators/decorator-utils.js.map +1 -1
  62. package/src/common/decorators/front-mcp.decorator.js +26 -3
  63. package/src/common/decorators/front-mcp.decorator.js.map +1 -1
  64. package/src/common/index.d.ts +0 -1
  65. package/src/common/index.js +0 -1
  66. package/src/common/index.js.map +1 -1
  67. package/src/common/interfaces/adapter.interface.d.ts +6 -0
  68. package/src/common/interfaces/adapter.interface.js.map +1 -1
  69. package/src/common/interfaces/execution-context.interface.d.ts +52 -3
  70. package/src/common/interfaces/execution-context.interface.js +88 -3
  71. package/src/common/interfaces/execution-context.interface.js.map +1 -1
  72. package/src/common/interfaces/flow.interface.d.ts +13 -0
  73. package/src/common/interfaces/flow.interface.js +24 -0
  74. package/src/common/interfaces/flow.interface.js.map +1 -1
  75. package/src/common/interfaces/server.interface.d.ts +9 -0
  76. package/src/common/interfaces/server.interface.js.map +1 -1
  77. package/src/common/metadata/app.metadata.d.ts +108 -0
  78. package/src/common/metadata/front-mcp.metadata.d.ts +1341 -2
  79. package/src/common/metadata/front-mcp.metadata.js +4 -1
  80. package/src/common/metadata/front-mcp.metadata.js.map +1 -1
  81. package/src/common/metadata/prompt.metadata.d.ts +4 -0
  82. package/src/common/metadata/provider.metadata.d.ts +14 -0
  83. package/src/common/metadata/provider.metadata.js +18 -2
  84. package/src/common/metadata/provider.metadata.js.map +1 -1
  85. package/src/common/metadata/resource.metadata.d.ts +8 -0
  86. package/src/common/metadata/tool-ui.metadata.d.ts +2 -2
  87. package/src/common/metadata/tool-ui.metadata.js +1 -1
  88. package/src/common/metadata/tool-ui.metadata.js.map +1 -1
  89. package/src/common/metadata/tool.metadata.d.ts +5 -1
  90. package/src/common/metadata/tool.metadata.js.map +1 -1
  91. package/src/common/migrate/auth-transport.migrate.d.ts +62 -0
  92. package/src/common/migrate/auth-transport.migrate.js +140 -0
  93. package/src/common/migrate/auth-transport.migrate.js.map +1 -0
  94. package/src/common/migrate/index.d.ts +1 -0
  95. package/src/common/migrate/index.js +6 -0
  96. package/src/common/migrate/index.js.map +1 -0
  97. package/src/common/schemas/http-output.schema.d.ts +24 -6
  98. package/src/common/schemas/index.d.ts +1 -0
  99. package/src/common/schemas/index.js +1 -0
  100. package/src/common/schemas/index.js.map +1 -1
  101. package/src/common/schemas/session-header.schema.d.ts +16 -0
  102. package/src/common/schemas/session-header.schema.js +42 -0
  103. package/src/common/schemas/session-header.schema.js.map +1 -0
  104. package/src/common/tokens/front-mcp.tokens.js +4 -1
  105. package/src/common/tokens/front-mcp.tokens.js.map +1 -1
  106. package/src/common/types/options/auth.options.d.ts +233 -3
  107. package/src/common/types/options/auth.options.js +29 -40
  108. package/src/common/types/options/auth.options.js.map +1 -1
  109. package/src/common/types/options/index.d.ts +2 -0
  110. package/src/common/types/options/index.js +2 -0
  111. package/src/common/types/options/index.js.map +1 -1
  112. package/src/common/types/options/redis.options.d.ts +190 -0
  113. package/src/common/types/options/redis.options.js +191 -0
  114. package/src/common/types/options/redis.options.js.map +1 -0
  115. package/src/common/types/options/server-info.options.d.ts +4 -0
  116. package/src/common/types/options/transport.options.d.ts +148 -0
  117. package/src/common/types/options/transport.options.js +121 -0
  118. package/src/common/types/options/transport.options.js.map +1 -0
  119. package/src/common/utils/global-config.utils.d.ts +36 -0
  120. package/src/common/utils/global-config.utils.js +44 -0
  121. package/src/common/utils/global-config.utils.js.map +1 -0
  122. package/src/common/utils/index.d.ts +1 -0
  123. package/src/common/utils/index.js +1 -0
  124. package/src/common/utils/index.js.map +1 -1
  125. package/src/completion/flows/complete.flow.d.ts +6 -8
  126. package/src/context/frontmcp-context-storage.d.ts +94 -0
  127. package/src/context/frontmcp-context-storage.js +183 -0
  128. package/src/context/frontmcp-context-storage.js.map +1 -0
  129. package/src/context/frontmcp-context.d.ts +269 -0
  130. package/src/context/frontmcp-context.js +360 -0
  131. package/src/context/frontmcp-context.js.map +1 -0
  132. package/src/context/frontmcp-context.provider.d.ts +43 -0
  133. package/src/context/frontmcp-context.provider.js +61 -0
  134. package/src/context/frontmcp-context.provider.js.map +1 -0
  135. package/src/context/index.d.ts +34 -0
  136. package/src/context/index.js +64 -0
  137. package/src/context/index.js.map +1 -0
  138. package/src/context/request-context-storage.d.ts +89 -0
  139. package/src/context/request-context-storage.js +183 -0
  140. package/src/context/request-context-storage.js.map +1 -0
  141. package/src/context/request-context.d.ts +184 -0
  142. package/src/context/request-context.js +209 -0
  143. package/src/context/request-context.js.map +1 -0
  144. package/src/context/request-context.provider.d.ts +37 -0
  145. package/src/context/request-context.provider.js +51 -0
  146. package/src/context/request-context.provider.js.map +1 -0
  147. package/src/context/session-key.provider.d.ts +45 -0
  148. package/src/context/session-key.provider.js +65 -0
  149. package/src/context/session-key.provider.js.map +1 -0
  150. package/src/context/trace-context.d.ts +43 -0
  151. package/src/context/trace-context.js +142 -0
  152. package/src/context/trace-context.js.map +1 -0
  153. package/src/errors/index.d.ts +1 -1
  154. package/src/errors/index.js +4 -1
  155. package/src/errors/index.js.map +1 -1
  156. package/src/errors/mcp.error.d.ts +16 -0
  157. package/src/errors/mcp.error.js +29 -1
  158. package/src/errors/mcp.error.js.map +1 -1
  159. package/src/flows/flow.instance.d.ts +16 -0
  160. package/src/flows/flow.instance.js +166 -80
  161. package/src/flows/flow.instance.js.map +1 -1
  162. package/src/flows/flow.registry.d.ts +5 -0
  163. package/src/flows/flow.registry.js +45 -3
  164. package/src/flows/flow.registry.js.map +1 -1
  165. package/src/front-mcp/front-mcp.d.ts +12 -0
  166. package/src/front-mcp/front-mcp.js +22 -3
  167. package/src/front-mcp/front-mcp.js.map +1 -1
  168. package/src/front-mcp/front-mcp.providers.d.ts +474 -1
  169. package/src/front-mcp/front-mcp.providers.js +2 -1
  170. package/src/front-mcp/front-mcp.providers.js.map +1 -1
  171. package/src/front-mcp/index.d.ts +1 -0
  172. package/src/front-mcp/index.js +3 -0
  173. package/src/front-mcp/index.js.map +1 -1
  174. package/src/front-mcp/serverless-handler.d.ts +28 -0
  175. package/src/front-mcp/serverless-handler.js +61 -0
  176. package/src/front-mcp/serverless-handler.js.map +1 -0
  177. package/src/hooks/hooks.utils.d.ts +1 -1
  178. package/src/hooks/hooks.utils.js +10 -3
  179. package/src/hooks/hooks.utils.js.map +1 -1
  180. package/src/index.d.ts +9 -5
  181. package/src/index.js +21 -1
  182. package/src/index.js.map +1 -1
  183. package/src/logger/instances/instance.logger.js +0 -1
  184. package/src/logger/instances/instance.logger.js.map +1 -1
  185. package/src/logging/flows/set-level.flow.d.ts +6 -8
  186. package/src/notification/notification.service.js +5 -1
  187. package/src/notification/notification.service.js.map +1 -1
  188. package/src/prompt/flows/get-prompt.flow.d.ts +14 -8
  189. package/src/prompt/flows/prompts-list.flow.d.ts +8 -7
  190. package/src/provider/provider.registry.d.ts +97 -5
  191. package/src/provider/provider.registry.js +306 -9
  192. package/src/provider/provider.registry.js.map +1 -1
  193. package/src/provider/provider.types.d.ts +21 -3
  194. package/src/provider/provider.types.js.map +1 -1
  195. package/src/resource/flows/read-resource.flow.d.ts +8 -9
  196. package/src/resource/flows/resource-templates-list.flow.d.ts +8 -7
  197. package/src/resource/flows/resources-list.flow.d.ts +8 -7
  198. package/src/resource/flows/subscribe-resource.flow.d.ts +6 -8
  199. package/src/resource/flows/unsubscribe-resource.flow.d.ts +6 -8
  200. package/src/scope/flows/http.request.flow.js +43 -7
  201. package/src/scope/flows/http.request.flow.js.map +1 -1
  202. package/src/scope/scope.instance.js +12 -5
  203. package/src/scope/scope.instance.js.map +1 -1
  204. package/src/server/adapters/base.host.adapter.d.ts +9 -0
  205. package/src/server/adapters/base.host.adapter.js.map +1 -1
  206. package/src/server/adapters/express.host.adapter.d.ts +12 -0
  207. package/src/server/adapters/express.host.adapter.js +21 -1
  208. package/src/server/adapters/express.host.adapter.js.map +1 -1
  209. package/src/server/server.instance.d.ts +3 -0
  210. package/src/server/server.instance.js +14 -7
  211. package/src/server/server.instance.js.map +1 -1
  212. package/src/store/adapters/store.vercel-kv.adapter.d.ts +86 -0
  213. package/src/store/adapters/store.vercel-kv.adapter.js +155 -0
  214. package/src/store/adapters/store.vercel-kv.adapter.js.map +1 -0
  215. package/src/store/index.d.ts +2 -0
  216. package/src/store/index.js +2 -0
  217. package/src/store/index.js.map +1 -1
  218. package/src/store/store.factory.d.ts +86 -0
  219. package/src/store/store.factory.js +194 -0
  220. package/src/store/store.factory.js.map +1 -0
  221. package/src/tool/flows/call-tool.flow.d.ts +38 -19
  222. package/src/tool/flows/call-tool.flow.js +240 -194
  223. package/src/tool/flows/call-tool.flow.js.map +1 -1
  224. package/src/tool/flows/tools-list.flow.d.ts +14 -17
  225. package/src/tool/flows/tools-list.flow.js +84 -33
  226. package/src/tool/flows/tools-list.flow.js.map +1 -1
  227. package/src/tool/tool.instance.d.ts +1 -4
  228. package/src/tool/ui/index.d.ts +4 -4
  229. package/src/tool/ui/index.js +4 -4
  230. package/src/tool/ui/index.js.map +1 -1
  231. package/src/tool/ui/platform-adapters.d.ts +2 -2
  232. package/src/tool/ui/platform-adapters.js +3 -3
  233. package/src/tool/ui/platform-adapters.js.map +1 -1
  234. package/src/tool/ui/template-helpers.d.ts +5 -7
  235. package/src/tool/ui/template-helpers.js +9 -26
  236. package/src/tool/ui/template-helpers.js.map +1 -1
  237. package/src/tool/ui/ui-resource.handler.d.ts +1 -1
  238. package/src/tool/ui/ui-resource.handler.js +5 -5
  239. package/src/tool/ui/ui-resource.handler.js.map +1 -1
  240. package/src/transport/adapters/transport.streamable-http.adapter.js +1 -0
  241. package/src/transport/adapters/transport.streamable-http.adapter.js.map +1 -1
  242. package/src/transport/flows/handle.sse.flow.js +9 -2
  243. package/src/transport/flows/handle.sse.flow.js.map +1 -1
  244. package/src/transport/flows/handle.streamable-http.flow.js +63 -6
  245. package/src/transport/flows/handle.streamable-http.flow.js.map +1 -1
  246. package/src/transport/mcp-handlers/complete-request.handler.d.ts +4 -15
  247. package/src/transport/mcp-handlers/get-prompt-request.handler.d.ts +5 -15
  248. package/src/transport/mcp-handlers/index.d.ts +67 -195
  249. package/src/transport/mcp-handlers/initialize-request.handler.js +12 -2
  250. package/src/transport/mcp-handlers/initialize-request.handler.js.map +1 -1
  251. package/src/transport/mcp-handlers/list-prompts-request.handler.d.ts +5 -15
  252. package/src/transport/mcp-handlers/list-resource-templates-request.handler.d.ts +5 -15
  253. package/src/transport/mcp-handlers/list-resources-request.handler.d.ts +5 -15
  254. package/src/transport/mcp-handlers/list-tools-request.handler.d.ts +5 -15
  255. package/src/transport/mcp-handlers/logging-set-level-request.handler.d.ts +3 -14
  256. package/src/transport/mcp-handlers/read-resource-request.handler.d.ts +4 -15
  257. package/src/transport/mcp-handlers/subscribe-request.handler.d.ts +3 -14
  258. package/src/transport/mcp-handlers/unsubscribe-request.handler.d.ts +3 -14
  259. package/src/transport/transport.registry.d.ts +72 -4
  260. package/src/transport/transport.registry.js +342 -11
  261. package/src/transport/transport.registry.js.map +1 -1
  262. package/src/auth/ui/htmx-templates.js.map +0 -1
  263. package/src/common/providers/session.provider.d.ts +0 -13
  264. package/src/common/providers/session.provider.js +0 -27
  265. package/src/common/providers/session.provider.js.map +0 -1
@@ -10,15 +10,15 @@
10
10
  * - **static**: Static widget is pre-compiled at startup, client fetches via resources/read
11
11
  * - **hybrid**: Shell (React + renderer) cached at startup, component + data in response
12
12
  *
13
- * NOTE: Core Tool UI functionality has moved to @frontmcp/ui/registry for standalone usage.
14
- * This module re-exports from @frontmcp/ui/registry for backwards compatibility.
13
+ * NOTE: Core Tool UI functionality is in @frontmcp/uipack/registry for standalone usage.
14
+ * This module re-exports from @frontmcp/uipack for backwards compatibility.
15
15
  */
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.StaticWidgetResourceTemplate = exports.createUIResourceHandler = exports.handleUIResourceRead = exports.resetIdCounter = exports.createTemplateHelpers = exports.jsonEmbed = exports.uniqueId = exports.formatCurrency = exports.formatDate = exports.escapeHtml = exports.buildUIMeta = exports.getUIResourceMimeType = exports.buildStaticWidgetUri = exports.parseWidgetUri = exports.isStaticWidgetUri = exports.isUIResourceUri = exports.UI_RESOURCE_SCHEME = exports.containsMdxSyntax = exports.isReactComponent = exports.hasUIConfig = exports.renderToolTemplate = exports.renderToolTemplateAsync = exports.ToolUIRegistry = void 0;
18
18
  // ============================================
19
- // Core Registry (from @frontmcp/ui/registry)
19
+ // Core Registry (from @frontmcp/uipack/registry)
20
20
  // ============================================
21
- var registry_1 = require("@frontmcp/ui/registry");
21
+ var registry_1 = require("@frontmcp/uipack/registry");
22
22
  // Registry
23
23
  Object.defineProperty(exports, "ToolUIRegistry", { enumerable: true, get: function () { return registry_1.ToolUIRegistry; } });
24
24
  // Template rendering
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/tool/ui/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,+CAA+C;AAC/C,6CAA6C;AAC7C,+CAA+C;AAC/C,kDAgB+B;AAf7B,WAAW;AACX,0GAAA,cAAc,OAAA;AACd,qBAAqB;AACrB,mHAAA,uBAAuB,OAAA;AACvB,8GAAA,kBAAkB,OAAA;AAClB,uGAAA,WAAW,OAAA;AACX,4GAAA,gBAAgB,OAAA;AAChB,6GAAA,iBAAiB,OAAA;AACjB,gBAAgB;AAChB,8GAAA,kBAAkB,OAAA;AAClB,2GAAA,eAAe,OAAA;AACf,6GAAA,iBAAiB,OAAA;AACjB,0GAAA,cAAc,OAAA;AACd,gHAAA,oBAAoB,OAAA;AACpB,iHAAA,qBAAqB,OAAA;AAgBvB,+CAA+C;AAC/C,iDAAiD;AACjD,+CAA+C;AAC/C,yDAAkD;AAAzC,gHAAA,WAAW,OAAA;AAGpB,+CAA+C;AAC/C,+CAA+C;AAC/C,+CAA+C;AAC/C,uDAQ4B;AAP1B,8GAAA,UAAU,OAAA;AACV,8GAAA,UAAU,OAAA;AACV,kHAAA,cAAc,OAAA;AACd,4GAAA,QAAQ,OAAA;AACR,6GAAA,SAAS,OAAA;AACT,yHAAA,qBAAqB,OAAA;AACrB,kHAAA,cAAc,OAAA;AAGhB,+CAA+C;AAC/C,iCAAiC;AACjC,+CAA+C;AAC/C,yEAAyE;AACzE,6DAAsF;AAA7E,2HAAA,oBAAoB,OAAA;AAAE,8HAAA,uBAAuB,OAAA;AAGtD,uDAAuD;AACvD,+DAAsE;AAA7D,oIAAA,4BAA4B,OAAA","sourcesContent":["/**\n * Tool UI Module\n *\n * Provides UI template rendering and platform-specific metadata generation\n * for MCP tool responses.\n *\n * Three serving modes:\n * - **inline**: HTML is rendered per-request and embedded in _meta['ui/html']\n * - **static**: Static widget is pre-compiled at startup, client fetches via resources/read\n * - **hybrid**: Shell (React + renderer) cached at startup, component + data in response\n *\n * NOTE: Core Tool UI functionality has moved to @frontmcp/ui/registry for standalone usage.\n * This module re-exports from @frontmcp/ui/registry for backwards compatibility.\n */\n\n// ============================================\n// Core Registry (from @frontmcp/ui/registry)\n// ============================================\nexport {\n // Registry\n ToolUIRegistry,\n // Template rendering\n renderToolTemplateAsync,\n renderToolTemplate,\n hasUIConfig,\n isReactComponent,\n containsMdxSyntax,\n // URI utilities\n UI_RESOURCE_SCHEME,\n isUIResourceUri,\n isStaticWidgetUri,\n parseWidgetUri,\n buildStaticWidgetUri,\n getUIResourceMimeType,\n} from '@frontmcp/ui/registry';\n\nexport type {\n // Registry types\n RenderOptions,\n UIRenderResult,\n CompileStaticWidgetOptions,\n HybridComponentPayload,\n BuildHybridComponentPayloadOptions,\n // Template types\n RenderTemplateOptions,\n // URI types\n ParsedWidgetUri,\n} from '@frontmcp/ui/registry';\n\n// ============================================\n// Platform Adapters (from @frontmcp/ui/adapters)\n// ============================================\nexport { buildUIMeta } from './platform-adapters';\nexport type { UIMetadata, BuildUIMetaOptions } from './platform-adapters';\n\n// ============================================\n// Template Helpers (from @frontmcp/ui/runtime)\n// ============================================\nexport {\n escapeHtml,\n formatDate,\n formatCurrency,\n uniqueId,\n jsonEmbed,\n createTemplateHelpers,\n resetIdCounter,\n} from './template-helpers';\n\n// ============================================\n// SDK-Specific (MCP Integration)\n// ============================================\n// UI Resource Handler - SDK-specific functions for MCP resource handling\nexport { handleUIResourceRead, createUIResourceHandler } from './ui-resource.handler';\nexport type { UIResourceHandleResult, UIResourceHandlerOptions, HandleUIResourceOptions } from './ui-resource.handler';\n\n// UI Resource Templates (for capability advertisement)\nexport { StaticWidgetResourceTemplate } from './ui-resource-template';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/tool/ui/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,+CAA+C;AAC/C,iDAAiD;AACjD,+CAA+C;AAC/C,sDAgBmC;AAfjC,WAAW;AACX,0GAAA,cAAc,OAAA;AACd,qBAAqB;AACrB,mHAAA,uBAAuB,OAAA;AACvB,8GAAA,kBAAkB,OAAA;AAClB,uGAAA,WAAW,OAAA;AACX,4GAAA,gBAAgB,OAAA;AAChB,6GAAA,iBAAiB,OAAA;AACjB,gBAAgB;AAChB,8GAAA,kBAAkB,OAAA;AAClB,2GAAA,eAAe,OAAA;AACf,6GAAA,iBAAiB,OAAA;AACjB,0GAAA,cAAc,OAAA;AACd,gHAAA,oBAAoB,OAAA;AACpB,iHAAA,qBAAqB,OAAA;AAgBvB,+CAA+C;AAC/C,iDAAiD;AACjD,+CAA+C;AAC/C,yDAAkD;AAAzC,gHAAA,WAAW,OAAA;AAGpB,+CAA+C;AAC/C,+CAA+C;AAC/C,+CAA+C;AAC/C,uDAQ4B;AAP1B,8GAAA,UAAU,OAAA;AACV,8GAAA,UAAU,OAAA;AACV,kHAAA,cAAc,OAAA;AACd,4GAAA,QAAQ,OAAA;AACR,6GAAA,SAAS,OAAA;AACT,yHAAA,qBAAqB,OAAA;AACrB,kHAAA,cAAc,OAAA;AAGhB,+CAA+C;AAC/C,iCAAiC;AACjC,+CAA+C;AAC/C,yEAAyE;AACzE,6DAAsF;AAA7E,2HAAA,oBAAoB,OAAA;AAAE,8HAAA,uBAAuB,OAAA;AAGtD,uDAAuD;AACvD,+DAAsE;AAA7D,oIAAA,4BAA4B,OAAA","sourcesContent":["/**\n * Tool UI Module\n *\n * Provides UI template rendering and platform-specific metadata generation\n * for MCP tool responses.\n *\n * Three serving modes:\n * - **inline**: HTML is rendered per-request and embedded in _meta['ui/html']\n * - **static**: Static widget is pre-compiled at startup, client fetches via resources/read\n * - **hybrid**: Shell (React + renderer) cached at startup, component + data in response\n *\n * NOTE: Core Tool UI functionality is in @frontmcp/uipack/registry for standalone usage.\n * This module re-exports from @frontmcp/uipack for backwards compatibility.\n */\n\n// ============================================\n// Core Registry (from @frontmcp/uipack/registry)\n// ============================================\nexport {\n // Registry\n ToolUIRegistry,\n // Template rendering\n renderToolTemplateAsync,\n renderToolTemplate,\n hasUIConfig,\n isReactComponent,\n containsMdxSyntax,\n // URI utilities\n UI_RESOURCE_SCHEME,\n isUIResourceUri,\n isStaticWidgetUri,\n parseWidgetUri,\n buildStaticWidgetUri,\n getUIResourceMimeType,\n} from '@frontmcp/uipack/registry';\n\nexport type {\n // Registry types\n RenderOptions,\n UIRenderResult,\n CompileStaticWidgetOptions,\n HybridComponentPayload,\n BuildHybridComponentPayloadOptions,\n // Template types\n RenderTemplateOptions,\n // URI types\n ParsedWidgetUri,\n} from '@frontmcp/uipack/registry';\n\n// ============================================\n// Platform Adapters (from @frontmcp/ui/adapters)\n// ============================================\nexport { buildUIMeta } from './platform-adapters';\nexport type { UIMetadata, BuildUIMetaOptions } from './platform-adapters';\n\n// ============================================\n// Template Helpers (from @frontmcp/ui/runtime)\n// ============================================\nexport {\n escapeHtml,\n formatDate,\n formatCurrency,\n uniqueId,\n jsonEmbed,\n createTemplateHelpers,\n resetIdCounter,\n} from './template-helpers';\n\n// ============================================\n// SDK-Specific (MCP Integration)\n// ============================================\n// UI Resource Handler - SDK-specific functions for MCP resource handling\nexport { handleUIResourceRead, createUIResourceHandler } from './ui-resource.handler';\nexport type { UIResourceHandleResult, UIResourceHandlerOptions, HandleUIResourceOptions } from './ui-resource.handler';\n\n// UI Resource Templates (for capability advertisement)\nexport { StaticWidgetResourceTemplate } from './ui-resource-template';\n"]}
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Platform Adapters
3
3
  *
4
- * Re-exports platform adapter functions from @frontmcp/ui/adapters for SDK consumers.
4
+ * Re-exports platform adapter functions from @frontmcp/uipack/adapters for SDK consumers.
5
5
  * This provides a single source of truth for platform-specific metadata building
6
6
  * while maintaining backwards compatibility.
7
7
  *
8
8
  * @see {@link https://docs.agentfront.dev/docs/servers/tools#tool-ui | Tool UI Documentation}
9
9
  */
10
- export { type AIPlatformType, type UIMetadata, type BuildUIMetaOptions, type BuildToolDiscoveryMetaOptions, buildUIMeta, buildToolDiscoveryMeta, buildOpenAICSP, } from '@frontmcp/ui/adapters';
10
+ export { type AIPlatformType, type UIMetadata, type BuildUIMetaOptions, type BuildToolDiscoveryMetaOptions, buildUIMeta, buildToolDiscoveryMeta, buildOpenAICSP, } from '@frontmcp/uipack/adapters';
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Platform Adapters
4
4
  *
5
- * Re-exports platform adapter functions from @frontmcp/ui/adapters for SDK consumers.
5
+ * Re-exports platform adapter functions from @frontmcp/uipack/adapters for SDK consumers.
6
6
  * This provides a single source of truth for platform-specific metadata building
7
7
  * while maintaining backwards compatibility.
8
8
  *
@@ -10,8 +10,8 @@
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.buildOpenAICSP = exports.buildToolDiscoveryMeta = exports.buildUIMeta = void 0;
13
- // Re-export platform adapter types and functions from @frontmcp/ui
14
- var adapters_1 = require("@frontmcp/ui/adapters");
13
+ // Re-export platform adapter types and functions from @frontmcp/uipack
14
+ var adapters_1 = require("@frontmcp/uipack/adapters");
15
15
  Object.defineProperty(exports, "buildUIMeta", { enumerable: true, get: function () { return adapters_1.buildUIMeta; } });
16
16
  Object.defineProperty(exports, "buildToolDiscoveryMeta", { enumerable: true, get: function () { return adapters_1.buildToolDiscoveryMeta; } });
17
17
  Object.defineProperty(exports, "buildOpenAICSP", { enumerable: true, get: function () { return adapters_1.buildOpenAICSP; } });
@@ -1 +1 @@
1
- {"version":3,"file":"platform-adapters.js","sourceRoot":"","sources":["../../../../src/tool/ui/platform-adapters.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEH,mEAAmE;AACnE,kDAQ+B;AAH7B,uGAAA,WAAW,OAAA;AACX,kHAAA,sBAAsB,OAAA;AACtB,0GAAA,cAAc,OAAA","sourcesContent":["/**\n * Platform Adapters\n *\n * Re-exports platform adapter functions from @frontmcp/ui/adapters for SDK consumers.\n * This provides a single source of truth for platform-specific metadata building\n * while maintaining backwards compatibility.\n *\n * @see {@link https://docs.agentfront.dev/docs/servers/tools#tool-ui | Tool UI Documentation}\n */\n\n// Re-export platform adapter types and functions from @frontmcp/ui\nexport {\n type AIPlatformType,\n type UIMetadata,\n type BuildUIMetaOptions,\n type BuildToolDiscoveryMetaOptions,\n buildUIMeta,\n buildToolDiscoveryMeta,\n buildOpenAICSP,\n} from '@frontmcp/ui/adapters';\n"]}
1
+ {"version":3,"file":"platform-adapters.js","sourceRoot":"","sources":["../../../../src/tool/ui/platform-adapters.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEH,uEAAuE;AACvE,sDAQmC;AAHjC,uGAAA,WAAW,OAAA;AACX,kHAAA,sBAAsB,OAAA;AACtB,0GAAA,cAAc,OAAA","sourcesContent":["/**\n * Platform Adapters\n *\n * Re-exports platform adapter functions from @frontmcp/uipack/adapters for SDK consumers.\n * This provides a single source of truth for platform-specific metadata building\n * while maintaining backwards compatibility.\n *\n * @see {@link https://docs.agentfront.dev/docs/servers/tools#tool-ui | Tool UI Documentation}\n */\n\n// Re-export platform adapter types and functions from @frontmcp/uipack\nexport {\n type AIPlatformType,\n type UIMetadata,\n type BuildUIMetaOptions,\n type BuildToolDiscoveryMetaOptions,\n buildUIMeta,\n buildToolDiscoveryMeta,\n buildOpenAICSP,\n} from '@frontmcp/uipack/adapters';\n"]}
@@ -1,17 +1,15 @@
1
1
  /**
2
2
  * Template Helpers
3
3
  *
4
- * Re-exports template helper utilities from @frontmcp/ui/runtime.
4
+ * Re-exports template helper utilities from @frontmcp/ui.
5
5
  * Also provides individual helper functions for backwards compatibility.
6
6
  *
7
7
  * @see {@link https://docs.agentfront.dev/docs/servers/tools#tool-ui | Tool UI Documentation}
8
8
  */
9
9
  import type { TemplateHelpers } from '../../common/metadata/tool-ui.metadata';
10
- export { createTemplateHelpers } from '@frontmcp/ui/runtime';
11
- /**
12
- * Escape HTML special characters to prevent XSS.
13
- */
14
- export declare function escapeHtml(str: string): string;
10
+ import { escapeHtml } from '@frontmcp/uipack/utils';
11
+ export { createTemplateHelpers } from '@frontmcp/uipack/runtime';
12
+ export { escapeHtml };
15
13
  /**
16
14
  * Format a date for display.
17
15
  * @param date - Date object or ISO string
@@ -36,7 +34,7 @@ export declare function uniqueId(prefix?: string): string;
36
34
  export declare function jsonEmbed(data: unknown): string;
37
35
  /**
38
36
  * Create a TemplateHelpers object with all helper functions.
39
- * @deprecated Use createTemplateHelpers from @frontmcp/ui/runtime instead
37
+ * @deprecated Use createTemplateHelpers from @frontmcp/uipack/runtime instead
40
38
  */
41
39
  export declare function createTemplateHelpersLocal(): TemplateHelpers;
42
40
  /**
@@ -2,43 +2,26 @@
2
2
  /**
3
3
  * Template Helpers
4
4
  *
5
- * Re-exports template helper utilities from @frontmcp/ui/runtime.
5
+ * Re-exports template helper utilities from @frontmcp/ui.
6
6
  * Also provides individual helper functions for backwards compatibility.
7
7
  *
8
8
  * @see {@link https://docs.agentfront.dev/docs/servers/tools#tool-ui | Tool UI Documentation}
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.createTemplateHelpers = void 0;
12
- exports.escapeHtml = escapeHtml;
11
+ exports.escapeHtml = exports.createTemplateHelpers = void 0;
13
12
  exports.formatDate = formatDate;
14
13
  exports.formatCurrency = formatCurrency;
15
14
  exports.uniqueId = uniqueId;
16
15
  exports.jsonEmbed = jsonEmbed;
17
16
  exports.createTemplateHelpersLocal = createTemplateHelpersLocal;
18
17
  exports.resetIdCounter = resetIdCounter;
19
- // Re-export createTemplateHelpers from @frontmcp/ui
20
- var runtime_1 = require("@frontmcp/ui/runtime");
18
+ // Import escapeHtml from @frontmcp/uipack/utils - single source of truth (no React needed)
19
+ const utils_1 = require("@frontmcp/uipack/utils");
20
+ Object.defineProperty(exports, "escapeHtml", { enumerable: true, get: function () { return utils_1.escapeHtml; } });
21
+ // Re-export createTemplateHelpers from @frontmcp/uipack (no React needed)
22
+ var runtime_1 = require("@frontmcp/uipack/runtime");
21
23
  Object.defineProperty(exports, "createTemplateHelpers", { enumerable: true, get: function () { return runtime_1.createTemplateHelpers; } });
22
- // ============================================
23
- // Individual Helper Functions (Backwards Compatibility)
24
- // ============================================
25
- // These are exported individually for SDK consumers who import them directly.
26
- // For new code, prefer using createTemplateHelpers() instead.
27
24
  let idCounter = 0;
28
- /**
29
- * Escape HTML special characters to prevent XSS.
30
- */
31
- function escapeHtml(str) {
32
- if (typeof str !== 'string') {
33
- return String(str ?? '');
34
- }
35
- return str
36
- .replace(/&/g, '&')
37
- .replace(/</g, '&lt;')
38
- .replace(/>/g, '&gt;')
39
- .replace(/"/g, '&quot;')
40
- .replace(/'/g, '&#039;');
41
- }
42
25
  /**
43
26
  * Format a date for display.
44
27
  * @param date - Date object or ISO string
@@ -91,11 +74,11 @@ function jsonEmbed(data) {
91
74
  }
92
75
  /**
93
76
  * Create a TemplateHelpers object with all helper functions.
94
- * @deprecated Use createTemplateHelpers from @frontmcp/ui/runtime instead
77
+ * @deprecated Use createTemplateHelpers from @frontmcp/uipack/runtime instead
95
78
  */
96
79
  function createTemplateHelpersLocal() {
97
80
  return {
98
- escapeHtml,
81
+ escapeHtml: utils_1.escapeHtml,
99
82
  formatDate,
100
83
  formatCurrency,
101
84
  uniqueId,
@@ -1 +1 @@
1
- {"version":3,"file":"template-helpers.js","sourceRoot":"","sources":["../../../../src/tool/ui/template-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAkBH,gCAUC;AAOD,gCAgBC;AAOD,wCAKC;AAMD,4BAEC;AAMD,8BAMC;AAMD,gEAQC;AAMD,wCAEC;AArGD,oDAAoD;AACpD,gDAA6D;AAApD,gHAAA,qBAAqB,OAAA;AAE9B,+CAA+C;AAC/C,wDAAwD;AACxD,+CAA+C;AAC/C,8EAA8E;AAC9E,8DAA8D;AAE9D,IAAI,SAAS,GAAG,CAAC,CAAC;AAElB;;GAEG;AACH,SAAgB,UAAU,CAAC,GAAW;IACpC,IAAI,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,GAAG,MAAM,IAAI,EAAE,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,IAAa;IACrC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,SAAgB,0BAA0B;IACxC,OAAO;QACL,UAAU;QACV,UAAU;QACV,cAAc;QACd,QAAQ;QACR,SAAS;KACV,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,cAAc;IAC5B,SAAS,GAAG,CAAC,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Template Helpers\n *\n * Re-exports template helper utilities from @frontmcp/ui/runtime.\n * Also provides individual helper functions for backwards compatibility.\n *\n * @see {@link https://docs.agentfront.dev/docs/servers/tools#tool-ui | Tool UI Documentation}\n */\n\nimport type { TemplateHelpers } from '../../common/metadata/tool-ui.metadata';\n\n// Re-export createTemplateHelpers from @frontmcp/ui\nexport { createTemplateHelpers } from '@frontmcp/ui/runtime';\n\n// ============================================\n// Individual Helper Functions (Backwards Compatibility)\n// ============================================\n// These are exported individually for SDK consumers who import them directly.\n// For new code, prefer using createTemplateHelpers() instead.\n\nlet idCounter = 0;\n\n/**\n * Escape HTML special characters to prevent XSS.\n */\nexport function escapeHtml(str: string): string {\n if (typeof str !== 'string') {\n return String(str ?? '');\n }\n return str\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#039;');\n}\n\n/**\n * Format a date for display.\n * @param date - Date object or ISO string\n * @param format - Optional format: 'iso', 'time', 'datetime', or default (localized date)\n */\nexport function formatDate(date: Date | string, format?: string): string {\n const d = typeof date === 'string' ? new Date(date) : date;\n if (isNaN(d.getTime())) {\n return String(date);\n }\n\n switch (format) {\n case 'iso':\n return d.toISOString();\n case 'time':\n return d.toLocaleTimeString();\n case 'datetime':\n return d.toLocaleString();\n default:\n return d.toLocaleDateString();\n }\n}\n\n/**\n * Format a number as currency.\n * @param amount - The numeric amount\n * @param currency - ISO 4217 currency code (default: 'USD')\n */\nexport function formatCurrency(amount: number, currency = 'USD'): string {\n return new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency,\n }).format(amount);\n}\n\n/**\n * Generate a unique ID for DOM elements.\n * @param prefix - Optional prefix for the ID\n */\nexport function uniqueId(prefix = 'mcp'): string {\n return `${prefix}-${++idCounter}-${Date.now().toString(36)}`;\n}\n\n/**\n * Safely embed JSON data in HTML.\n * Escapes characters that could break out of script tags or HTML.\n */\nexport function jsonEmbed(data: unknown): string {\n return JSON.stringify(data)\n .replace(/</g, '\\\\u003c')\n .replace(/>/g, '\\\\u003e')\n .replace(/&/g, '\\\\u0026')\n .replace(/'/g, '\\\\u0027');\n}\n\n/**\n * Create a TemplateHelpers object with all helper functions.\n * @deprecated Use createTemplateHelpers from @frontmcp/ui/runtime instead\n */\nexport function createTemplateHelpersLocal(): TemplateHelpers {\n return {\n escapeHtml,\n formatDate,\n formatCurrency,\n uniqueId,\n jsonEmbed,\n };\n}\n\n/**\n * Reset the ID counter (useful for testing).\n * @internal\n */\nexport function resetIdCounter(): void {\n idCounter = 0;\n}\n"]}
1
+ {"version":3,"file":"template-helpers.js","sourceRoot":"","sources":["../../../../src/tool/ui/template-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAyBH,gCAgBC;AAOD,wCAKC;AAMD,4BAEC;AAMD,8BAMC;AAMD,gEAQC;AAMD,wCAEC;AA5FD,2FAA2F;AAC3F,kDAAoD;AAY3C,2FAZA,kBAAU,OAYA;AAVnB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O,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,SAAgB,0BAA0B;IACxC,OAAO;QACL,UAAU,EAAV,kBAAU;QACV,UAAU;QACV,cAAc;QACd,QAAQ;QACR,SAAS;KACV,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,cAAc;IAC5B,SAAS,GAAG,CAAC,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Template Helpers\n *\n * Re-exports template helper utilities from @frontmcp/ui.\n * Also provides individual helper functions for backwards compatibility.\n *\n * @see {@link https://docs.agentfront.dev/docs/servers/tools#tool-ui | Tool UI Documentation}\n */\n\nimport type { TemplateHelpers } from '../../common/metadata/tool-ui.metadata';\n// Import escapeHtml from @frontmcp/uipack/utils - single source of truth (no React needed)\nimport { escapeHtml } from '@frontmcp/uipack/utils';\n\n// Re-export createTemplateHelpers from @frontmcp/uipack (no React needed)\nexport { createTemplateHelpers } from '@frontmcp/uipack/runtime';\n\n// ============================================\n// Individual Helper Functions (Backwards Compatibility)\n// ============================================\n// These are exported individually for SDK consumers who import them directly.\n// For new code, prefer using createTemplateHelpers() instead.\n\n// Re-export escapeHtml for backwards compatibility\nexport { escapeHtml };\n\nlet idCounter = 0;\n\n/**\n * Format a date for display.\n * @param date - Date object or ISO string\n * @param format - Optional format: 'iso', 'time', 'datetime', or default (localized date)\n */\nexport function formatDate(date: Date | string, format?: string): string {\n const d = typeof date === 'string' ? new Date(date) : date;\n if (isNaN(d.getTime())) {\n return String(date);\n }\n\n switch (format) {\n case 'iso':\n return d.toISOString();\n case 'time':\n return d.toLocaleTimeString();\n case 'datetime':\n return d.toLocaleString();\n default:\n return d.toLocaleDateString();\n }\n}\n\n/**\n * Format a number as currency.\n * @param amount - The numeric amount\n * @param currency - ISO 4217 currency code (default: 'USD')\n */\nexport function formatCurrency(amount: number, currency = 'USD'): string {\n return new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency,\n }).format(amount);\n}\n\n/**\n * Generate a unique ID for DOM elements.\n * @param prefix - Optional prefix for the ID\n */\nexport function uniqueId(prefix = 'mcp'): string {\n return `${prefix}-${++idCounter}-${Date.now().toString(36)}`;\n}\n\n/**\n * Safely embed JSON data in HTML.\n * Escapes characters that could break out of script tags or HTML.\n */\nexport function jsonEmbed(data: unknown): string {\n return JSON.stringify(data)\n .replace(/</g, '\\\\u003c')\n .replace(/>/g, '\\\\u003e')\n .replace(/&/g, '\\\\u0026')\n .replace(/'/g, '\\\\u0027');\n}\n\n/**\n * Create a TemplateHelpers object with all helper functions.\n * @deprecated Use createTemplateHelpers from @frontmcp/uipack/runtime instead\n */\nexport function createTemplateHelpersLocal(): TemplateHelpers {\n return {\n escapeHtml,\n formatDate,\n formatCurrency,\n uniqueId,\n jsonEmbed,\n };\n}\n\n/**\n * Reset the ID counter (useful for testing).\n * @internal\n */\nexport function resetIdCounter(): void {\n idCounter = 0;\n}\n"]}
@@ -24,7 +24,7 @@
24
24
  */
25
25
  import type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
26
26
  import type { AIPlatformType } from '../../notification/notification.service';
27
- import { type ToolUIRegistry } from '@frontmcp/ui/registry';
27
+ import { type ToolUIRegistry } from '@frontmcp/uipack/registry';
28
28
  /**
29
29
  * Result of handling a UI resource request
30
30
  */
@@ -26,16 +26,16 @@
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.handleUIResourceRead = handleUIResourceRead;
28
28
  exports.createUIResourceHandler = createUIResourceHandler;
29
- const ui_1 = require("@frontmcp/ui");
30
- const registry_1 = require("@frontmcp/ui/registry");
29
+ const base_template_1 = require("@frontmcp/uipack/base-template");
30
+ const registry_1 = require("@frontmcp/uipack/registry");
31
31
  /**
32
32
  * Generate a placeholder widget HTML that reads from window.openai.toolOutput.
33
33
  *
34
- * Delegates to @frontmcp/ui's createDefaultBaseTemplate which provides:
34
+ * Delegates to @frontmcp/uipack's createDefaultBaseTemplate which provides:
35
35
  * - Tailwind CSS with @theme configuration
36
36
  * - Platform polyfills (callTool, detectMcpSession, getToolOutput)
37
37
  * - Polling for toolOutput injection
38
- * - Default JSON renderer (data-type-specific renderers are in @frontmcp/ui)
38
+ * - Default JSON renderer (data-type-specific renderers are in @frontmcp/uipack)
39
39
  *
40
40
  * This is returned when the static widget URI is fetched before the tool is called.
41
41
  * OpenAI caches this HTML, so it must be dynamic (read toolOutput at runtime).
@@ -44,7 +44,7 @@ const registry_1 = require("@frontmcp/ui/registry");
44
44
  * @returns HTML string with a dynamic widget that renders toolOutput
45
45
  */
46
46
  function generatePlaceholderWidget(toolName) {
47
- return (0, ui_1.createDefaultBaseTemplate)({ toolName });
47
+ return (0, base_template_1.createDefaultBaseTemplate)({ toolName });
48
48
  }
49
49
  /**
50
50
  * Handle a UI resource read request
@@ -1 +1 @@
1
- {"version":3,"file":"ui-resource.handler.js","sourceRoot":"","sources":["../../../../src/tool/ui/ui-resource.handler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAkEH,oDAgEC;AAkBD,0DAYC;AA5JD,qCAAyD;AACzD,oDAQ+B;AA0B/B;;;;;;;;;;;;;;GAcG;AACH,SAAS,yBAAyB,CAAC,QAAgB;IACjD,OAAO,IAAA,8BAAyB,EAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,GAAW,EACX,QAAwB,EACxB,YAA6B;IAE7B,qCAAqC;IACrC,IAAI,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,yCAAyC;IACzC,MAAM,QAAQ,GAAG,IAAA,gCAAqB,EAAC,YAAY,CAAC,CAAC;IAErD,sDAAsD;IACtD,2CAA2C;I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CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * UI Resource Handler\n *\n * Handles resources/read requests for ui:// URIs, serving widget HTML\n * from the ToolUIRegistry.\n *\n * Supported URI format:\n * - ui://widget/{toolName}.html - Static widget HTML (pre-compiled at startup)\n *\n * The static widget is registered at server startup for tools with\n * `servingMode: 'static'`. The widget HTML includes the FrontMCP Bridge\n * which reads tool output from the platform context at runtime.\n *\n * @example\n * ```typescript\n * // Client requests widget HTML (OpenAI discovery)\n * const result = await client.readResource({\n * uri: 'ui://widget/get_weather.html'\n * });\n *\n * // Returns pre-compiled widget with FrontMCP Bridge\n * // Widget reads tool output from window.openai.toolOutput at runtime\n * ```\n */\n\nimport type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';\nimport type { AIPlatformType } from '../../notification/notification.service';\nimport { createDefaultBaseTemplate } from '@frontmcp/ui';\nimport {\n type ToolUIRegistry,\n UI_RESOURCE_SCHEME,\n isUIResourceUri,\n isStaticWidgetUri,\n parseWidgetUri,\n getUIResourceMimeType,\n type ParsedWidgetUri,\n} from '@frontmcp/ui/registry';\n\n/**\n * Result of handling a UI resource request\n */\nexport interface UIResourceHandleResult {\n /** Whether the URI was handled */\n handled: boolean;\n /** The resource result if handled successfully */\n result?: ReadResourceResult;\n /** Error message if handling failed */\n error?: string;\n}\n\n/**\n * Options for handling a UI resource read request\n */\nexport interface HandleUIResourceOptions {\n /** The UI resource URI */\n uri: string;\n /** The ToolUIRegistry containing cached HTML */\n registry: ToolUIRegistry;\n /** Platform type of the connected client */\n platformType?: AIPlatformType;\n}\n\n/**\n * Generate a placeholder widget HTML that reads from window.openai.toolOutput.\n *\n * Delegates to @frontmcp/ui's createDefaultBaseTemplate which provides:\n * - Tailwind CSS with @theme configuration\n * - Platform polyfills (callTool, detectMcpSession, getToolOutput)\n * - Polling for toolOutput injection\n * - Default JSON renderer (data-type-specific renderers are in @frontmcp/ui)\n *\n * This is returned when the static widget URI is fetched before the tool is called.\n * OpenAI caches this HTML, so it must be dynamic (read toolOutput at runtime).\n *\n * @param toolName - The name of the tool\n * @returns HTML string with a dynamic widget that renders toolOutput\n */\nfunction generatePlaceholderWidget(toolName: string): string {\n return createDefaultBaseTemplate({ toolName });\n}\n\n/**\n * Handle a UI resource read request\n *\n * @param uri - The UI resource URI\n * @param registry - The ToolUIRegistry containing cached HTML\n * @param platformType - Optional platform type for dynamic MIME type selection\n * @returns Handle result with content or error\n */\nexport function handleUIResourceRead(\n uri: string,\n registry: ToolUIRegistry,\n platformType?: AIPlatformType,\n): UIResourceHandleResult {\n // Check if this is a UI resource URI\n if (!isUIResourceUri(uri)) {\n return { handled: false };\n }\n\n // Get the platform-appropriate MIME type\n const mimeType = getUIResourceMimeType(platformType);\n\n // Try static widget URI (ui://widget/{toolName}.html)\n // This is used by OpenAI at discovery time\n const widgetParsed = parseWidgetUri(uri);\n if (widgetParsed) {\n // Check for pre-compiled static widget from the developer's template\n // Static widgets are compiled at server startup for tools with servingMode: 'static'\n const cachedWidget = registry.getStaticWidget(widgetParsed.toolName);\n if (cachedWidget) {\n // Return the developer's actual template (SSR'd React/MDX component)\n // This template includes the FrontMCP Bridge for runtime data access\n return {\n handled: true,\n result: {\n contents: [\n {\n uri,\n mimeType,\n text: cachedWidget,\n },\n ],\n },\n };\n }\n\n // Fallback to dynamic placeholder widget if no pre-compiled template.\n // This is returned when the tool doesn't have a UI template configured\n // or uses a different serving mode.\n //\n // OpenAI caches widget HTML from outputTemplate URI, so we must return\n // a template that reads from window.openai.toolOutput at runtime.\n const html = generatePlaceholderWidget(widgetParsed.toolName);\n\n return {\n handled: true,\n result: {\n contents: [\n {\n uri,\n mimeType,\n text: html,\n },\n ],\n },\n };\n }\n\n // Unknown UI resource URI format\n return {\n handled: true,\n error: `Invalid UI resource URI format: ${uri}. Expected: ui://widget/{toolName}.html`,\n };\n}\n\n/**\n * Options for creating a UI resource handler\n */\nexport interface UIResourceHandlerOptions {\n /** ToolUIRegistry instance */\n registry: ToolUIRegistry;\n /** Optional custom error handler */\n onError?: (error: string, uri: string) => void;\n}\n\n/**\n * Create a UI resource handler function\n *\n * @param options - Handler options\n * @returns Handler function that can be used in the read-resource flow\n */\nexport function createUIResourceHandler(options: UIResourceHandlerOptions) {\n const { registry, onError } = options;\n\n return function handleUIResource(uri: string): UIResourceHandleResult {\n const result = handleUIResourceRead(uri, registry);\n\n if (result.handled && result.error && onError) {\n onError(result.error, uri);\n }\n\n return result;\n };\n}\n"]}
1
+ {"version":3,"file":"ui-resource.handler.js","sourceRoot":"","sources":["../../../../src/tool/ui/ui-resource.handler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAkEH,oDAgEC;AAkBD,0DAYC;AA5JD,kEAA2E;AAC3E,wDAQmC;AA0BnC;;;;;;;;;;;;;;GAcG;AACH,SAAS,yBAAyB,CAAC,QAAgB;IACjD,OAAO,IAAA,yCAAyB,EAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,GAAW,EACX,QAAwB,EACxB,YAA6B;IAE7B,qCAAqC;IACrC,IAAI,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,yCAAyC;IACzC,MAAM,QAAQ,GAAG,IAAA,gCAAqB,EAAC,YAAY,CAAC,CAAC;IAErD,sDAAsD;IACtD,2CAA2C;IAC3C,MAAM,YAAY,GAAG,IAAA,yBAAc,EAAC,GAAG,CAAC,CAAC;IACzC,IAAI,YAAY,EAAE,CAAC;QACjB,qEAAqE;QACrE,qFAAqF;QACrF,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACrE,IAAI,YAAY,EAAE,CAAC;YACjB,qEAAqE;YACrE,qEAAqE;YACrE,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,QAAQ,EAAE;wBACR;4BACE,GAAG;4BACH,QAAQ;4BACR,IAAI,EAAE,YAAY;yBACnB;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;QAED,sEAAsE;QACtE,uEAAuE;QACvE,oCAAoC;QACpC,EAAE;QACF,uEAAuE;QACvE,kEAAkE;QAClE,MAAM,IAAI,GAAG,yBAAyB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAE9D,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE;gBACN,QAAQ,EAAE;oBACR;wBACE,GAAG;wBACH,QAAQ;wBACR,IAAI,EAAE,IAAI;qBACX;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IAED,iCAAiC;IACjC,OAAO;QACL,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,mCAAmC,GAAG,yCAAyC;KACvF,CAAC;AACJ,CAAC;AAYD;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,OAAiC;IACvE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEtC,OAAO,SAAS,gBAAgB,CAAC,GAAW;QAC1C,MAAM,MAAM,GAAG,oBAAoB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAEnD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,IAAI,OAAO,EAAE,CAAC;YAC9C,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC7B,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * UI Resource Handler\n *\n * Handles resources/read requests for ui:// URIs, serving widget HTML\n * from the ToolUIRegistry.\n *\n * Supported URI format:\n * - ui://widget/{toolName}.html - Static widget HTML (pre-compiled at startup)\n *\n * The static widget is registered at server startup for tools with\n * `servingMode: 'static'`. The widget HTML includes the FrontMCP Bridge\n * which reads tool output from the platform context at runtime.\n *\n * @example\n * ```typescript\n * // Client requests widget HTML (OpenAI discovery)\n * const result = await client.readResource({\n * uri: 'ui://widget/get_weather.html'\n * });\n *\n * // Returns pre-compiled widget with FrontMCP Bridge\n * // Widget reads tool output from window.openai.toolOutput at runtime\n * ```\n */\n\nimport type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';\nimport type { AIPlatformType } from '../../notification/notification.service';\nimport { createDefaultBaseTemplate } from '@frontmcp/uipack/base-template';\nimport {\n type ToolUIRegistry,\n UI_RESOURCE_SCHEME,\n isUIResourceUri,\n isStaticWidgetUri,\n parseWidgetUri,\n getUIResourceMimeType,\n type ParsedWidgetUri,\n} from '@frontmcp/uipack/registry';\n\n/**\n * Result of handling a UI resource request\n */\nexport interface UIResourceHandleResult {\n /** Whether the URI was handled */\n handled: boolean;\n /** The resource result if handled successfully */\n result?: ReadResourceResult;\n /** Error message if handling failed */\n error?: string;\n}\n\n/**\n * Options for handling a UI resource read request\n */\nexport interface HandleUIResourceOptions {\n /** The UI resource URI */\n uri: string;\n /** The ToolUIRegistry containing cached HTML */\n registry: ToolUIRegistry;\n /** Platform type of the connected client */\n platformType?: AIPlatformType;\n}\n\n/**\n * Generate a placeholder widget HTML that reads from window.openai.toolOutput.\n *\n * Delegates to @frontmcp/uipack's createDefaultBaseTemplate which provides:\n * - Tailwind CSS with @theme configuration\n * - Platform polyfills (callTool, detectMcpSession, getToolOutput)\n * - Polling for toolOutput injection\n * - Default JSON renderer (data-type-specific renderers are in @frontmcp/uipack)\n *\n * This is returned when the static widget URI is fetched before the tool is called.\n * OpenAI caches this HTML, so it must be dynamic (read toolOutput at runtime).\n *\n * @param toolName - The name of the tool\n * @returns HTML string with a dynamic widget that renders toolOutput\n */\nfunction generatePlaceholderWidget(toolName: string): string {\n return createDefaultBaseTemplate({ toolName });\n}\n\n/**\n * Handle a UI resource read request\n *\n * @param uri - The UI resource URI\n * @param registry - The ToolUIRegistry containing cached HTML\n * @param platformType - Optional platform type for dynamic MIME type selection\n * @returns Handle result with content or error\n */\nexport function handleUIResourceRead(\n uri: string,\n registry: ToolUIRegistry,\n platformType?: AIPlatformType,\n): UIResourceHandleResult {\n // Check if this is a UI resource URI\n if (!isUIResourceUri(uri)) {\n return { handled: false };\n }\n\n // Get the platform-appropriate MIME type\n const mimeType = getUIResourceMimeType(platformType);\n\n // Try static widget URI (ui://widget/{toolName}.html)\n // This is used by OpenAI at discovery time\n const widgetParsed = parseWidgetUri(uri);\n if (widgetParsed) {\n // Check for pre-compiled static widget from the developer's template\n // Static widgets are compiled at server startup for tools with servingMode: 'static'\n const cachedWidget = registry.getStaticWidget(widgetParsed.toolName);\n if (cachedWidget) {\n // Return the developer's actual template (SSR'd React/MDX component)\n // This template includes the FrontMCP Bridge for runtime data access\n return {\n handled: true,\n result: {\n contents: [\n {\n uri,\n mimeType,\n text: cachedWidget,\n },\n ],\n },\n };\n }\n\n // Fallback to dynamic placeholder widget if no pre-compiled template.\n // This is returned when the tool doesn't have a UI template configured\n // or uses a different serving mode.\n //\n // OpenAI caches widget HTML from outputTemplate URI, so we must return\n // a template that reads from window.openai.toolOutput at runtime.\n const html = generatePlaceholderWidget(widgetParsed.toolName);\n\n return {\n handled: true,\n result: {\n contents: [\n {\n uri,\n mimeType,\n text: html,\n },\n ],\n },\n };\n }\n\n // Unknown UI resource URI format\n return {\n handled: true,\n error: `Invalid UI resource URI format: ${uri}. Expected: ui://widget/{toolName}.html`,\n };\n}\n\n/**\n * Options for creating a UI resource handler\n */\nexport interface UIResourceHandlerOptions {\n /** ToolUIRegistry instance */\n registry: ToolUIRegistry;\n /** Optional custom error handler */\n onError?: (error: string, uri: string) => void;\n}\n\n/**\n * Create a UI resource handler function\n *\n * @param options - Handler options\n * @returns Handler function that can be used in the read-resource flow\n */\nexport function createUIResourceHandler(options: UIResourceHandlerOptions) {\n const { registry, onError } = options;\n\n return function handleUIResource(uri: string): UIResourceHandleResult {\n const result = handleUIResourceRead(uri, registry);\n\n if (result.handled && result.error && onError) {\n onError(result.error, uri);\n }\n\n return result;\n };\n}\n"]}
@@ -55,6 +55,7 @@ class TransportStreamableHttpAdapter extends transport_local_adapter_1.LocalTran
55
55
  }
56
56
  return originalWrite.call(this, chunk, encodingOrCb, cb);
57
57
  };
58
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
58
59
  const adapter = this;
59
60
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
61
  res.end = function (chunk, encodingOrCb, cb) {
@@ -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;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,IAAA,iCAAyB,EAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAE/E,OAAO,IAAI,iDAA6B,CAAC;YACvC,kBAAkB;YAClB,eAAe,EAAE,GAAG,EAAE;gBACpB,kBAAkB;YACpB,CAAC;YACD,oBAAoB,EAAE,CAAC,SAAS,EAAE,EAAE;gBAClC,IAAI,SAAS,EAAE,CAAC;oBACd,OAAO,CAAC,GAAG,CAAC,wBAAwB,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;gBAChE,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,GAAG,CAAC,+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,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,gBAA2B,EAC3B,OAAe,EACf,eAAkB;QAElB,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,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;CACF;AA3GD,wEA2GC","sourcesContent":["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"]}
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,yBAA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AC,CAAC;oBACZ,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;gBACjC,CAAC;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA5GD,wEA4GC","sourcesContent":["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 // eslint-disable-next-line @typescript-eslint/no-this-alias\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"]}
@@ -47,7 +47,14 @@ let HandleSseFlow = class HandleSseFlow extends common_1.FlowBase {
47
47
  // This is the ID the client received from initialize and is referencing.
48
48
  // Priority 2: Use session from authorization if header matches or is absent
49
49
  // Priority 3: Create new session (first request - no header, no authorization.session)
50
- const mcpSessionHeader = request.headers?.['mcp-session-id'];
50
+ const raw = request.headers?.['mcp-session-id'];
51
+ const rawMcpSessionHeader = typeof raw === 'string' ? raw : undefined;
52
+ const mcpSessionHeader = (0, common_1.validateMcpSessionHeader)(rawMcpSessionHeader);
53
+ // If client sent a header but validation failed, return 404
54
+ if (raw !== undefined && !mcpSessionHeader) {
55
+ this.respond(common_1.httpRespond.sessionNotFound('invalid session id'));
56
+ return;
57
+ }
51
58
  let session;
52
59
  if (mcpSessionHeader) {
53
60
  // Client sent session ID - ALWAYS use it for transport lookup
@@ -68,7 +75,7 @@ let HandleSseFlow = class HandleSseFlow extends common_1.FlowBase {
68
75
  // No session - create new one (initialize request)
69
76
  session = (0, session_id_utils_1.createSessionId)('legacy-sse', token, {
70
77
  userAgent: request.headers?.['user-agent'],
71
- platformDetectionConfig: this.scope.metadata?.session?.platformDetection,
78
+ platformDetectionConfig: this.scope.metadata.transport?.platformDetection,
72
79
  });
73
80
  }
74
81
  this.state.set(exports.stateSchema.parse({ token, session }));
@@ -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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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"]}
1
+ {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CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjD,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;CACF,CAAA;AAlIO;IADL,KAAK,CAAC,YAAY,CAAC;;;;+CA+CnB;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;AAnIkB,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,CAoIjC;kBApIoB,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 validateMcpSessionHeader,\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 raw = request.headers?.['mcp-session-id'];\n const rawMcpSessionHeader = typeof raw === 'string' ? raw : undefined;\n const mcpSessionHeader = validateMcpSessionHeader(rawMcpSessionHeader);\n\n // If client sent a header but validation failed, return 404\n if (raw !== undefined && !mcpSessionHeader) {\n this.respond(httpRespond.sessionNotFound('invalid session id'));\n return;\n }\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.transport?.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"]}
@@ -40,7 +40,15 @@ let HandleStreamableHttpFlow = class HandleStreamableHttpFlow extends common_1.F
40
40
  name = name;
41
41
  async parseInput() {
42
42
  const { request } = this.rawInput;
43
+ console.log('[DEBUG] parseInput: starting');
43
44
  const authorization = request[common_1.ServerRequestTokens.auth];
45
+ console.log('[DEBUG] parseInput: authorization =', authorization
46
+ ? {
47
+ hasToken: !!authorization.token,
48
+ hasSession: !!authorization.session,
49
+ sessionId: authorization.session?.id?.slice(0, 30),
50
+ }
51
+ : 'undefined');
44
52
  const { token } = authorization;
45
53
  // CRITICAL: The mcp-session-id header is the client's reference to their session.
46
54
  // We MUST use this exact ID for transport registry lookup.
@@ -49,7 +57,14 @@ let HandleStreamableHttpFlow = class HandleStreamableHttpFlow extends common_1.F
49
57
  // This is the ID the client received from initialize and is referencing.
50
58
  // Priority 2: Use session from authorization if header matches or is absent
51
59
  // Priority 3: Create new session (first request - no header, no authorization.session)
52
- const mcpSessionHeader = request.headers?.['mcp-session-id'];
60
+ const raw = request.headers?.['mcp-session-id'];
61
+ const rawMcpSessionHeader = typeof raw === 'string' ? raw : undefined;
62
+ const mcpSessionHeader = (0, common_1.validateMcpSessionHeader)(rawMcpSessionHeader);
63
+ // If client sent a header but validation failed, return 404
64
+ if (raw !== undefined && !mcpSessionHeader) {
65
+ this.respond(common_1.httpRespond.sessionNotFound('invalid session id'));
66
+ return;
67
+ }
53
68
  let session;
54
69
  if (mcpSessionHeader) {
55
70
  // Client sent session ID - ALWAYS use it for transport lookup
@@ -70,7 +85,7 @@ let HandleStreamableHttpFlow = class HandleStreamableHttpFlow extends common_1.F
70
85
  // No session - create new one (initialize request)
71
86
  session = (0, session_id_utils_1.createSessionId)('streamable-http', token, {
72
87
  userAgent: request.headers?.['user-agent'],
73
- platformDetectionConfig: this.scope.metadata?.session?.platformDetection,
88
+ platformDetectionConfig: this.scope.metadata.transport?.platformDetection,
74
89
  });
75
90
  }
76
91
  this.state.set(exports.stateSchema.parse({ token, session }));
@@ -138,10 +153,31 @@ let HandleStreamableHttpFlow = class HandleStreamableHttpFlow extends common_1.F
138
153
  const logger = this.scopeLogger.child('handle:streamable-http:onMessage');
139
154
  const { request, response } = this.rawInput;
140
155
  const { token, session } = this.state.required;
141
- const transport = await transportService.getTransporter('streamable-http', token, session.id);
156
+ // 1. Try to get existing transport from memory
157
+ let transport = await transportService.getTransporter('streamable-http', token, session.id);
158
+ // 2. If not in memory, check if session exists in Redis and recreate
159
+ if (!transport) {
160
+ try {
161
+ const storedSession = await transportService.getStoredSession('streamable-http', token, session.id);
162
+ if (storedSession) {
163
+ logger.info('Recreating transport from Redis session', {
164
+ sessionId: session.id?.slice(0, 20),
165
+ createdAt: storedSession.createdAt,
166
+ });
167
+ transport = await transportService.recreateTransporter('streamable-http', token, session.id, storedSession, response);
168
+ }
169
+ }
170
+ catch (error) {
171
+ // Log and fall through to 404 logic - transport remains undefined
172
+ logger.warn('Failed to recreate transport from stored session', {
173
+ sessionId: session.id?.slice(0, 20),
174
+ error: error instanceof Error ? error.message : String(error),
175
+ });
176
+ }
177
+ }
142
178
  if (!transport) {
143
179
  // 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);
180
+ const wasCreated = await transportService.wasSessionCreatedAsync('streamable-http', token, session.id);
145
181
  const body = request.body;
146
182
  if (wasCreated) {
147
183
  // Session existed but was terminated/evicted → HTTP 404 (client should re-initialize)
@@ -188,10 +224,31 @@ let HandleStreamableHttpFlow = class HandleStreamableHttpFlow extends common_1.F
188
224
  }
189
225
  async onSseListener() {
190
226
  const transportService = this.scope.transportService;
227
+ const logger = this.scopeLogger.child('handle:streamable-http:onSseListener');
191
228
  const { request, response } = this.rawInput;
192
229
  const { token, session } = this.state.required;
193
- // Get existing transport for this session - SSE listener requires existing session
194
- const transport = await transportService.getTransporter('streamable-http', token, session.id);
230
+ // 1. Try to get existing transport from memory
231
+ let transport = await transportService.getTransporter('streamable-http', token, session.id);
232
+ // 2. If not in memory, check if session exists in Redis and recreate
233
+ if (!transport) {
234
+ try {
235
+ const storedSession = await transportService.getStoredSession('streamable-http', token, session.id);
236
+ if (storedSession) {
237
+ logger.info('Recreating transport from Redis session for SSE listener', {
238
+ sessionId: session.id?.slice(0, 20),
239
+ createdAt: storedSession.createdAt,
240
+ });
241
+ transport = await transportService.recreateTransporter('streamable-http', token, session.id, storedSession, response);
242
+ }
243
+ }
244
+ catch (error) {
245
+ // Log and fall through to 404 logic - transport remains undefined
246
+ logger.warn('Failed to recreate transport from stored session for SSE listener', {
247
+ sessionId: session.id?.slice(0, 20),
248
+ error: error instanceof Error ? error.message : String(error),
249
+ });
250
+ }
251
+ }
195
252
  if (!transport) {
196
253
  this.respond(common_1.httpRespond.notFound('Session not found'));
197
254
  return;