skybridge 0.0.0-dev.fe23f20 → 0.0.0-dev.fe35f75

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 (293) hide show
  1. package/README.md +153 -0
  2. package/bin/run.js +0 -4
  3. package/dist/cli/detect-port.d.ts +18 -0
  4. package/dist/cli/detect-port.js +61 -0
  5. package/dist/cli/detect-port.js.map +1 -0
  6. package/dist/cli/header.js +1 -1
  7. package/dist/cli/header.js.map +1 -1
  8. package/dist/cli/run-command.js.map +1 -1
  9. package/dist/cli/telemetry.d.ts +7 -0
  10. package/dist/cli/telemetry.js +123 -0
  11. package/dist/cli/telemetry.js.map +1 -0
  12. package/dist/cli/tunnel-control-server.d.ts +9 -0
  13. package/dist/cli/tunnel-control-server.js +31 -0
  14. package/dist/cli/tunnel-control-server.js.map +1 -0
  15. package/dist/cli/tunnel-control-server.test.js +39 -0
  16. package/dist/cli/tunnel-control-server.test.js.map +1 -0
  17. package/dist/cli/tunnel-handler.d.ts +3 -0
  18. package/dist/cli/tunnel-handler.js +48 -0
  19. package/dist/cli/tunnel-handler.js.map +1 -0
  20. package/dist/cli/tunnel-handler.test.js +105 -0
  21. package/dist/cli/tunnel-handler.test.js.map +1 -0
  22. package/dist/cli/tunnel.d.ts +57 -0
  23. package/dist/cli/tunnel.js +154 -0
  24. package/dist/cli/tunnel.js.map +1 -0
  25. package/dist/cli/tunnel.test.d.ts +1 -0
  26. package/dist/cli/tunnel.test.js +190 -0
  27. package/dist/cli/tunnel.test.js.map +1 -0
  28. package/dist/cli/types.d.ts +5 -0
  29. package/dist/cli/types.js +2 -0
  30. package/dist/cli/types.js.map +1 -0
  31. package/dist/cli/use-execute-steps.d.ts +3 -2
  32. package/dist/cli/use-execute-steps.js +6 -1
  33. package/dist/cli/use-execute-steps.js.map +1 -1
  34. package/dist/cli/use-messages.d.ts +3 -0
  35. package/dist/cli/use-messages.js +11 -0
  36. package/dist/cli/use-messages.js.map +1 -0
  37. package/dist/cli/use-nodemon.d.ts +2 -0
  38. package/dist/cli/use-nodemon.js +73 -0
  39. package/dist/cli/use-nodemon.js.map +1 -0
  40. package/dist/cli/use-open-browser.d.ts +1 -0
  41. package/dist/cli/use-open-browser.js +44 -0
  42. package/dist/cli/use-open-browser.js.map +1 -0
  43. package/dist/cli/use-tunnel.d.ts +14 -0
  44. package/dist/cli/use-tunnel.js +131 -0
  45. package/dist/cli/use-tunnel.js.map +1 -0
  46. package/dist/cli/use-typescript-check.d.ts +9 -0
  47. package/dist/cli/use-typescript-check.js +94 -0
  48. package/dist/cli/use-typescript-check.js.map +1 -0
  49. package/dist/commands/build.js +64 -6
  50. package/dist/commands/build.js.map +1 -1
  51. package/dist/commands/dev.d.ts +6 -1
  52. package/dist/commands/dev.js +69 -9
  53. package/dist/commands/dev.js.map +1 -1
  54. package/dist/commands/start.d.ts +3 -1
  55. package/dist/commands/start.js +31 -15
  56. package/dist/commands/start.js.map +1 -1
  57. package/dist/commands/telemetry/disable.d.ts +5 -0
  58. package/dist/commands/telemetry/disable.js +14 -0
  59. package/dist/commands/telemetry/disable.js.map +1 -0
  60. package/dist/commands/telemetry/enable.d.ts +5 -0
  61. package/dist/commands/telemetry/enable.js +14 -0
  62. package/dist/commands/telemetry/enable.js.map +1 -0
  63. package/dist/commands/telemetry/status.d.ts +5 -0
  64. package/dist/commands/telemetry/status.js +14 -0
  65. package/dist/commands/telemetry/status.js.map +1 -0
  66. package/dist/server/asset-base-url-transform-plugin.d.ts +10 -0
  67. package/dist/server/asset-base-url-transform-plugin.js +33 -0
  68. package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
  69. package/dist/server/asset-base-url-transform-plugin.test.d.ts +1 -0
  70. package/dist/server/asset-base-url-transform-plugin.test.js +84 -0
  71. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
  72. package/dist/server/content-helpers.d.ts +27 -0
  73. package/dist/server/content-helpers.js +46 -0
  74. package/dist/server/content-helpers.js.map +1 -0
  75. package/dist/server/content-helpers.test.d.ts +1 -0
  76. package/dist/server/content-helpers.test.js +70 -0
  77. package/dist/server/content-helpers.test.js.map +1 -0
  78. package/dist/server/express.d.ts +11 -0
  79. package/dist/server/express.js +101 -0
  80. package/dist/server/express.js.map +1 -0
  81. package/dist/server/express.test.d.ts +1 -0
  82. package/dist/server/express.test.js +430 -0
  83. package/dist/server/express.test.js.map +1 -0
  84. package/dist/server/index.d.ts +5 -3
  85. package/dist/server/index.js +3 -2
  86. package/dist/server/index.js.map +1 -1
  87. package/dist/server/inferUtilityTypes.d.ts +6 -6
  88. package/dist/server/inferUtilityTypes.js.map +1 -1
  89. package/dist/server/metric.d.ts +14 -0
  90. package/dist/server/metric.js +62 -0
  91. package/dist/server/metric.js.map +1 -0
  92. package/dist/server/middleware.d.ts +124 -0
  93. package/dist/server/middleware.js +93 -0
  94. package/dist/server/middleware.js.map +1 -0
  95. package/dist/server/middleware.test-d.d.ts +1 -0
  96. package/dist/server/middleware.test-d.js +75 -0
  97. package/dist/server/middleware.test-d.js.map +1 -0
  98. package/dist/server/middleware.test.d.ts +1 -0
  99. package/dist/server/middleware.test.js +493 -0
  100. package/dist/server/middleware.test.js.map +1 -0
  101. package/dist/server/server.d.ts +160 -63
  102. package/dist/server/server.js +393 -63
  103. package/dist/server/server.js.map +1 -1
  104. package/dist/server/templateHelper.d.ts +5 -7
  105. package/dist/server/templateHelper.js +3 -22
  106. package/dist/server/templateHelper.js.map +1 -1
  107. package/dist/server/templates.generated.d.ts +4 -0
  108. package/dist/server/templates.generated.js +47 -0
  109. package/dist/server/templates.generated.js.map +1 -0
  110. package/dist/server/tunnel-proxy-router.d.ts +7 -0
  111. package/dist/server/tunnel-proxy-router.js +110 -0
  112. package/dist/server/tunnel-proxy-router.js.map +1 -0
  113. package/dist/server/tunnel-proxy-router.test.d.ts +1 -0
  114. package/dist/server/tunnel-proxy-router.test.js +229 -0
  115. package/dist/server/tunnel-proxy-router.test.js.map +1 -0
  116. package/dist/server/viewsDevServer.d.ts +14 -0
  117. package/dist/server/viewsDevServer.js +45 -0
  118. package/dist/server/viewsDevServer.js.map +1 -0
  119. package/dist/test/utils.d.ts +13 -21
  120. package/dist/test/utils.js +42 -37
  121. package/dist/test/utils.js.map +1 -1
  122. package/dist/test/view.test.d.ts +1 -0
  123. package/dist/test/view.test.js +523 -0
  124. package/dist/test/view.test.js.map +1 -0
  125. package/dist/version.d.ts +1 -0
  126. package/dist/version.js +3 -0
  127. package/dist/version.js.map +1 -0
  128. package/dist/web/bridges/apps-sdk/adaptor.d.ts +18 -6
  129. package/dist/web/bridges/apps-sdk/adaptor.js +71 -8
  130. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
  131. package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -1
  132. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  133. package/dist/web/bridges/apps-sdk/index.d.ts +1 -1
  134. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  135. package/dist/web/bridges/apps-sdk/types.d.ts +39 -27
  136. package/dist/web/bridges/apps-sdk/types.js.map +1 -1
  137. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  138. package/dist/web/bridges/get-adaptor.js.map +1 -1
  139. package/dist/web/bridges/index.js.map +1 -1
  140. package/dist/web/bridges/mcp-app/adaptor.d.ts +39 -8
  141. package/dist/web/bridges/mcp-app/adaptor.js +182 -56
  142. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
  143. package/dist/web/bridges/mcp-app/bridge.d.ts +13 -30
  144. package/dist/web/bridges/mcp-app/bridge.js +43 -196
  145. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  146. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  147. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  148. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +5 -3
  149. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +2 -2
  150. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  151. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -41
  152. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  153. package/dist/web/bridges/types.d.ts +55 -12
  154. package/dist/web/bridges/types.js.map +1 -1
  155. package/dist/web/bridges/use-host-context.js.map +1 -1
  156. package/dist/web/components/modal-provider.d.ts +4 -0
  157. package/dist/web/components/modal-provider.js +45 -0
  158. package/dist/web/components/modal-provider.js.map +1 -0
  159. package/dist/web/create-store.js +17 -3
  160. package/dist/web/create-store.js.map +1 -1
  161. package/dist/web/create-store.test.js +23 -20
  162. package/dist/web/create-store.test.js.map +1 -1
  163. package/dist/web/data-llm.d.ts +1 -1
  164. package/dist/web/data-llm.js +3 -3
  165. package/dist/web/data-llm.js.map +1 -1
  166. package/dist/web/data-llm.test.js +33 -30
  167. package/dist/web/data-llm.test.js.map +1 -1
  168. package/dist/web/generate-helpers.d.ts +20 -18
  169. package/dist/web/generate-helpers.js +20 -18
  170. package/dist/web/generate-helpers.js.map +1 -1
  171. package/dist/web/generate-helpers.test-d.js +26 -26
  172. package/dist/web/generate-helpers.test-d.js.map +1 -1
  173. package/dist/web/generate-helpers.test.js.map +1 -1
  174. package/dist/web/helpers/state.d.ts +2 -2
  175. package/dist/web/helpers/state.js +11 -11
  176. package/dist/web/helpers/state.js.map +1 -1
  177. package/dist/web/helpers/state.test.js +9 -9
  178. package/dist/web/helpers/state.test.js.map +1 -1
  179. package/dist/web/hooks/index.d.ts +5 -2
  180. package/dist/web/hooks/index.js +4 -1
  181. package/dist/web/hooks/index.js.map +1 -1
  182. package/dist/web/hooks/test/utils.js +4 -0
  183. package/dist/web/hooks/test/utils.js.map +1 -1
  184. package/dist/web/hooks/use-call-tool.js.map +1 -1
  185. package/dist/web/hooks/use-call-tool.test-d.js.map +1 -1
  186. package/dist/web/hooks/use-call-tool.test.js +0 -4
  187. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  188. package/dist/web/hooks/use-display-mode.d.ts +3 -3
  189. package/dist/web/hooks/use-display-mode.js.map +1 -1
  190. package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
  191. package/dist/web/hooks/use-display-mode.test-d.js +8 -0
  192. package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
  193. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  194. package/dist/web/hooks/use-files.d.ts +3 -6
  195. package/dist/web/hooks/use-files.js +5 -2
  196. package/dist/web/hooks/use-files.js.map +1 -1
  197. package/dist/web/hooks/use-files.test.js +28 -3
  198. package/dist/web/hooks/use-files.test.js.map +1 -1
  199. package/dist/web/hooks/use-layout.d.ts +1 -1
  200. package/dist/web/hooks/use-layout.js.map +1 -1
  201. package/dist/web/hooks/use-layout.test.js +3 -3
  202. package/dist/web/hooks/use-layout.test.js.map +1 -1
  203. package/dist/web/hooks/use-open-external.d.ts +3 -1
  204. package/dist/web/hooks/use-open-external.js +1 -1
  205. package/dist/web/hooks/use-open-external.js.map +1 -1
  206. package/dist/web/hooks/use-open-external.test.js +26 -11
  207. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  208. package/dist/web/hooks/use-request-close.d.ts +2 -0
  209. package/dist/web/hooks/use-request-close.js +8 -0
  210. package/dist/web/hooks/use-request-close.js.map +1 -0
  211. package/dist/web/hooks/use-request-close.test.d.ts +1 -0
  212. package/dist/web/hooks/use-request-close.test.js +52 -0
  213. package/dist/web/hooks/use-request-close.test.js.map +1 -0
  214. package/dist/web/hooks/use-request-modal.d.ts +3 -3
  215. package/dist/web/hooks/use-request-modal.js +10 -8
  216. package/dist/web/hooks/use-request-modal.js.map +1 -1
  217. package/dist/web/hooks/use-request-modal.test.js +5 -1
  218. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  219. package/dist/web/hooks/use-request-size.d.ts +3 -0
  220. package/dist/web/hooks/use-request-size.js +8 -0
  221. package/dist/web/hooks/use-request-size.js.map +1 -0
  222. package/dist/web/hooks/use-request-size.test.d.ts +1 -0
  223. package/dist/web/hooks/use-request-size.test.js +65 -0
  224. package/dist/web/hooks/use-request-size.test.js.map +1 -0
  225. package/dist/web/hooks/use-send-follow-up-message.d.ts +2 -1
  226. package/dist/web/hooks/use-send-follow-up-message.js +2 -2
  227. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  228. package/dist/web/hooks/use-set-open-in-app-url.d.ts +1 -0
  229. package/dist/web/hooks/use-set-open-in-app-url.js +8 -0
  230. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
  231. package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
  232. package/dist/web/hooks/use-set-open-in-app-url.test.js +43 -0
  233. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
  234. package/dist/web/hooks/use-tool-info.js.map +1 -1
  235. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  236. package/dist/web/hooks/use-tool-info.test.js +1 -1
  237. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  238. package/dist/web/hooks/use-user.js +18 -2
  239. package/dist/web/hooks/use-user.js.map +1 -1
  240. package/dist/web/hooks/use-user.test.js +29 -1
  241. package/dist/web/hooks/use-user.test.js.map +1 -1
  242. package/dist/web/hooks/use-view-state.d.ts +4 -0
  243. package/dist/web/hooks/use-view-state.js +32 -0
  244. package/dist/web/hooks/use-view-state.js.map +1 -0
  245. package/dist/web/hooks/use-view-state.test.d.ts +1 -0
  246. package/dist/web/hooks/use-view-state.test.js +177 -0
  247. package/dist/web/hooks/use-view-state.test.js.map +1 -0
  248. package/dist/web/index.d.ts +1 -2
  249. package/dist/web/index.js +1 -2
  250. package/dist/web/index.js.map +1 -1
  251. package/dist/web/mount-view.d.ts +1 -0
  252. package/dist/web/{mount-widget.js → mount-view.js} +11 -3
  253. package/dist/web/mount-view.js.map +1 -0
  254. package/dist/web/plugin/data-llm.test.js.map +1 -1
  255. package/dist/web/plugin/plugin.d.ts +4 -1
  256. package/dist/web/plugin/plugin.js +135 -18
  257. package/dist/web/plugin/plugin.js.map +1 -1
  258. package/dist/web/plugin/scan-views.d.ts +16 -0
  259. package/dist/web/plugin/scan-views.js +88 -0
  260. package/dist/web/plugin/scan-views.js.map +1 -0
  261. package/dist/web/plugin/scan-views.test.d.ts +1 -0
  262. package/dist/web/plugin/scan-views.test.js +99 -0
  263. package/dist/web/plugin/scan-views.test.js.map +1 -0
  264. package/dist/web/plugin/transform-data-llm.js +1 -1
  265. package/dist/web/plugin/transform-data-llm.js.map +1 -1
  266. package/dist/web/plugin/transform-data-llm.test.js.map +1 -1
  267. package/dist/web/plugin/validate-view.d.ts +1 -0
  268. package/dist/web/plugin/validate-view.js +9 -0
  269. package/dist/web/plugin/validate-view.js.map +1 -0
  270. package/dist/web/plugin/validate-view.test.d.ts +1 -0
  271. package/dist/web/plugin/validate-view.test.js +24 -0
  272. package/dist/web/plugin/validate-view.test.js.map +1 -0
  273. package/dist/web/proxy.js +0 -1
  274. package/dist/web/proxy.js.map +1 -1
  275. package/dist/web/types.js.map +1 -1
  276. package/package.json +51 -30
  277. package/tsconfig.base.json +33 -0
  278. package/dist/server/templates/development.hbs +0 -66
  279. package/dist/server/templates/production.hbs +0 -7
  280. package/dist/server/widgetsDevServer.d.ts +0 -12
  281. package/dist/server/widgetsDevServer.js +0 -47
  282. package/dist/server/widgetsDevServer.js.map +0 -1
  283. package/dist/test/widget.test.js +0 -255
  284. package/dist/test/widget.test.js.map +0 -1
  285. package/dist/web/hooks/use-widget-state.d.ts +0 -4
  286. package/dist/web/hooks/use-widget-state.js +0 -32
  287. package/dist/web/hooks/use-widget-state.js.map +0 -1
  288. package/dist/web/hooks/use-widget-state.test.js +0 -61
  289. package/dist/web/hooks/use-widget-state.test.js.map +0 -1
  290. package/dist/web/mount-widget.d.ts +0 -1
  291. package/dist/web/mount-widget.js.map +0 -1
  292. /package/dist/{test/widget.test.d.ts → cli/tunnel-control-server.test.d.ts} +0 -0
  293. /package/dist/{web/hooks/use-widget-state.test.d.ts → cli/tunnel-handler.test.d.ts} +0 -0
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AqB,EAAE;gBACrE,MAAM,EAAE,MAAM;aACf,CAAC,CAAC;YACH,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC;YAC/B,EAAE,CAAC,YAAY,EAAE,CAAC;QACpB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import http from \"node:http\";\nimport type { ErrorRequestHandler, RequestHandler } from \"express\";\nimport { afterEach, describe, expect, it, vi } from \"vitest\";\nimport { McpServer } from \"./server.js\";\n\nvi.mock(\"@skybridge/devtools\", () => ({\n devtoolsStaticServer: () =>\n ((_req: unknown, _res: unknown, next: () => void) =>\n next()) as RequestHandler,\n}));\n\nvi.mock(\"./viewsDevServer.js\", () => ({\n viewsDevServer: (_httpServer: unknown) =>\n ((_req: unknown, _res: unknown, next: () => void) =>\n next()) as RequestHandler,\n}));\n\nasync function listen(app: Parameters<typeof http.createServer>[1]) {\n const server = http.createServer(app);\n await new Promise<void>((resolve) => server.listen(0, resolve));\n const port = (server.address() as { port: number }).port;\n return { port, server };\n}\n\nlet openServer: http.Server | undefined;\nafterEach(() => openServer?.close());\n\nasync function postMcp(port: number) {\n return fetch(`http://localhost:${port}/mcp`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ jsonrpc: \"2.0\", method: \"initialize\", id: 1 }),\n });\n}\n\nasync function postApi(port: number) {\n return fetch(`http://localhost:${port}/api/test`, { method: \"POST\" });\n}\n\ndescribe(\"McpServer.express\", () => {\n it(\"exposes a ready Express app immediately after construction\", () => {\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n expect(server.express).toBeDefined();\n expect(typeof server.express.use).toBe(\"function\");\n expect(typeof server.express.get).toBe(\"function\");\n });\n\n it(\"server.express.get registers a route reachable alongside /mcp\", async () => {\n const { createApp } = await import(\"./express.js\");\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n server.express.get(\"/health\", (_req, res) => {\n res.json({ status: \"ok\" });\n });\n\n const httpServer = http.createServer();\n await createApp({ mcpServer: server, httpServer });\n const { port, server: listening } = await listen(server.express);\n openServer = listening;\n\n const health = await fetch(`http://localhost:${port}/health`);\n expect(health.status).toBe(200);\n expect(await health.json()).toEqual({ status: \"ok\" });\n\n // /mcp still works (POST returns 200/4xx, not 404)\n const mcp = await postMcp(port);\n expect(mcp.status).not.toBe(404);\n });\n\n it(\"server.use and server.express.use produce the same registration order\", async () => {\n const { createApp } = await import(\"./express.js\");\n const callsA: string[] = [];\n const callsB: string[] = [];\n\n const buildServer = () => new McpServer({ name: \"t\", version: \"0.0.0\" });\n\n const sA = buildServer();\n sA.use((_req, _res, next) => {\n callsA.push(\"first\");\n next();\n });\n sA.express.use((_req, _res, next) => {\n callsA.push(\"second\");\n next();\n });\n\n const sB = buildServer();\n sB.express.use((_req, _res, next) => {\n callsB.push(\"first\");\n next();\n });\n sB.use((_req, _res, next) => {\n callsB.push(\"second\");\n next();\n });\n\n for (const s of [sA, sB]) {\n s.express.get(\"/probe\", (_req, res) => res.json({ ok: true }));\n const httpServer = http.createServer();\n await createApp({ mcpServer: s, httpServer });\n const { port, server: listening } = await listen(s.express);\n openServer = listening;\n await fetch(`http://localhost:${port}/probe`);\n listening.close();\n }\n\n expect(callsA).toEqual([\"first\", \"second\"]);\n expect(callsB).toEqual([\"first\", \"second\"]);\n });\n\n it(\"useOnError still wraps thrown /mcp errors after the route is mounted\", async () => {\n const { createApp } = await import(\"./express.js\");\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n // Register the error handler BEFORE createApp — useOnError should still\n // apply it after /mcp, so /mcp errors hit it.\n const seen: string[] = [];\n server.useOnError((_err, _req, res, _next) => {\n seen.push(\"useOnError\");\n res.status(503).json({ from: \"useOnError\" });\n });\n\n // Force the /mcp handler to throw so the error pipeline runs.\n vi.spyOn(server, \"connectStatelessTransport\").mockRejectedValue(\n new Error(\"boom\"),\n );\n\n const httpServer = http.createServer();\n await createApp({\n mcpServer: server,\n httpServer,\n // Mirror what run() does: forward the McpServer's useOnError handlers\n // to createApp so they get applied after /mcp.\n // biome-ignore lint/complexity/useLiteralKeys: test mirrors run() internals to verify useOnError ordering\n errorMiddleware: server[\"customErrorMiddleware\"],\n });\n const { port, server: listening } = await listen(server.express);\n openServer = listening;\n\n const res = await postMcp(port);\n expect(seen).toEqual([\"useOnError\"]);\n expect(res.status).toBe(503);\n expect(await res.json()).toEqual({ from: \"useOnError\" });\n });\n});\n\ndescribe(\"createApp\", () => {\n it(\"runs global custom middleware before the /mcp handler\", async () => {\n const { createApp } = await import(\"./express.js\");\n const calls: string[] = [];\n\n const mw: RequestHandler = (_req, _res, next) => {\n calls.push(\"custom\");\n next();\n };\n\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n server.use(mw);\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer: server, httpServer });\n\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n await postMcp(port);\n expect(calls).toEqual([\"custom\"]);\n });\n\n it(\"runs path-scoped middleware on /mcp\", async () => {\n const { createApp } = await import(\"./express.js\");\n const calls: string[] = [];\n\n const mw: RequestHandler = (_req, _res, next) => {\n calls.push(\"auth\");\n next();\n };\n\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n server.use(\"/mcp\", mw);\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer: server, httpServer });\n\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n await postMcp(port);\n expect(calls).toEqual([\"auth\"]);\n });\n\n it(\"allows middleware to short-circuit with 401\", async () => {\n const { createApp } = await import(\"./express.js\");\n const calls: string[] = [];\n\n const reject: RequestHandler = (_req, res) => {\n calls.push(\"reject\");\n res.status(401).json({ error: \"Unauthorized\" });\n };\n\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n server.use(\"/mcp\", reject);\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer: server, httpServer });\n\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n const res = await postMcp(port);\n expect(calls).toEqual([\"reject\"]);\n expect(res.status).toBe(401);\n expect(await res.json()).toEqual({ error: \"Unauthorized\" });\n });\n\n it(\"runs multiple global middleware in registration order\", async () => {\n const { createApp } = await import(\"./express.js\");\n const calls: string[] = [];\n\n const mwA: RequestHandler = (_req, _res, next) => {\n calls.push(\"A\");\n next();\n };\n const mwB: RequestHandler = (_req, _res, next) => {\n calls.push(\"B\");\n next();\n };\n\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n server.use(mwA);\n server.use(mwB);\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer: server, httpServer });\n\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n await postMcp(port);\n expect(calls).toEqual([\"A\", \"B\"]);\n });\n\n it(\"path-scoped middleware does not run on non-matching paths\", async () => {\n const { createApp } = await import(\"./express.js\");\n const calls: string[] = [];\n\n const apiMw: RequestHandler = (_req, _res, next) => {\n calls.push(\"api\");\n next();\n };\n\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n server.use(\"/api\", apiMw);\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer: server, httpServer });\n\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n // Hit /mcp — the /api middleware should NOT fire\n await postMcp(port);\n expect(calls).toEqual([]);\n });\n\n it(\"supports Express Router via custom middleware\", async () => {\n const { createApp } = await import(\"./express.js\");\n const { Router } = await import(\"express\");\n\n const router = Router();\n router.get(\"/health\", (_req, res) => {\n res.json({ status: \"ok\" });\n });\n\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n server.use(router as RequestHandler);\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer: server, httpServer });\n\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n const res = await fetch(`http://localhost:${port}/health`);\n expect(res.status).toBe(200);\n expect(await res.json()).toEqual({ status: \"ok\" });\n });\n\n it(\"supports path-prefixed Router\", async () => {\n const { createApp } = await import(\"./express.js\");\n const { Router } = await import(\"express\");\n\n const router = Router();\n router.get(\"/data\", (_req, res) => {\n res.json({ value: 42 });\n });\n\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n server.use(\"/api\", router as RequestHandler);\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer: server, httpServer });\n\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n const res = await fetch(`http://localhost:${port}/api/data`);\n expect(res.status).toBe(200);\n expect(await res.json()).toEqual({ value: 42 });\n });\n\n it(\"server survives middleware errors without crashing\", async () => {\n const { createApp } = await import(\"./express.js\");\n\n const throwing: RequestHandler = () => {\n throw new Error(\"boom\");\n };\n\n const server = new McpServer({ name: \"t\", version: \"0.0.0\" });\n server.use(\"/explode\", throwing);\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer: server, httpServer });\n\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n const res = await fetch(`http://localhost:${port}/explode`);\n expect(res.status).toBe(500);\n\n // Server process did not crash — it still accepts connections\n const followUp = await fetch(`http://localhost:${port}/explode`);\n expect(followUp.status).toBe(500);\n });\n\n it(\"returns 500 JSON-RPC error when the MCP handler throws and no error middleware is registered\", async () => {\n const { createApp } = await import(\"./express.js\");\n const consoleSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n\n const mcpServer = new McpServer({ name: \"t\", version: \"0.0.0\" });\n // Force the express-level error path: make connectStatelessTransport\n // reject so the request handler hits its try/catch and calls next(error),\n // which lands in the default /mcp error handler.\n vi.spyOn(mcpServer, \"connectStatelessTransport\").mockRejectedValue(\n new Error(\"boom\"),\n );\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer, httpServer });\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n const res = await postMcp(port);\n expect(res.status).toBe(500);\n expect(await res.json()).toEqual({\n jsonrpc: \"2.0\",\n error: { code: -32603, message: \"Internal server error\" },\n id: null,\n });\n expect(consoleSpy).toHaveBeenCalledWith(\n \"Error handling MCP request:\",\n expect.any(Error),\n );\n consoleSpy.mockRestore();\n });\n\n it(\"invokes a custom error handler when the MCP handler throws\", async () => {\n const { createApp } = await import(\"./express.js\");\n const calls: string[] = [];\n\n const errorHandler: ErrorRequestHandler = (_err, _req, res, _next) => {\n calls.push(\"error-handler\");\n res.status(503).json({ custom: true });\n };\n\n const mcpServer = new McpServer({ name: \"t\", version: \"0.0.0\" });\n vi.spyOn(mcpServer, \"connectStatelessTransport\").mockRejectedValue(\n new Error(\"boom\"),\n );\n\n const httpServer = http.createServer();\n const app = await createApp({\n mcpServer,\n httpServer,\n errorMiddleware: [{ handlers: [errorHandler] }],\n });\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n const res = await postMcp(port);\n expect(calls).toEqual([\"error-handler\"]);\n expect(res.status).toBe(503);\n expect(await res.json()).toEqual({ custom: true });\n });\n\n it(\"invokes a path-scoped error handler only for matching routes\", async () => {\n const { createApp } = await import(\"./express.js\");\n const calls: string[] = [];\n\n const mcpErrorHandler: ErrorRequestHandler = (_err, _req, res, _next) => {\n calls.push(\"mcp-error-handler\");\n res.status(503).json({ from: \"mcp-error-handler\" });\n };\n\n const throwingApiRoute: RequestHandler = (_req, _res, next) => {\n next(new Error(\"api error\"));\n };\n\n const mcpServer = new McpServer({ name: \"t\", version: \"0.0.0\" });\n vi.spyOn(mcpServer, \"connectStatelessTransport\").mockRejectedValue(\n new Error(\"boom\"),\n );\n mcpServer.use(\"/api/test\", throwingApiRoute);\n\n const httpServer = http.createServer();\n const app = await createApp({\n mcpServer,\n httpServer,\n errorMiddleware: [{ path: \"/mcp\", handlers: [mcpErrorHandler] }],\n });\n const { port, server: httpListening } = await listen(app);\n openServer = httpListening;\n\n const mcpRes = await postMcp(port);\n expect(calls).toEqual([\"mcp-error-handler\"]);\n expect(mcpRes.status).toBe(503);\n expect(await mcpRes.json()).toEqual({ from: \"mcp-error-handler\" });\n\n const consoleSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n const apiRes = await postApi(port);\n expect(calls).toEqual([\"mcp-error-handler\"]);\n expect(apiRes.status).toBe(500);\n consoleSpy.mockRestore();\n });\n\n it(\"handles concurrent /mcp requests without 'Already connected to a transport'\", async () => {\n const { createApp } = await import(\"./express.js\");\n\n const mcpServer = new McpServer({\n name: \"concurrent-test\",\n version: \"0.0.0\",\n });\n // Slow tool: keeps the underlying transport bound long enough to overlap\n // with concurrent requests, exposing the shared-McpServer race.\n mcpServer.registerTool({ name: \"slow\", description: \"slow\" }, async () => {\n await new Promise((r) => setTimeout(r, 50));\n return { content: [{ type: \"text\" as const, text: \"done\" }] };\n });\n\n const consoleSpy = vi.spyOn(console, \"error\").mockImplementation(() => {});\n\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer, httpServer });\n const { port, server } = await listen(app);\n openServer = server;\n\n const callBody = (id: number) =>\n JSON.stringify({\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n id,\n params: { name: \"slow\", arguments: {} },\n });\n\n const N = 10;\n const responses = await Promise.all(\n Array.from({ length: N }, (_, i) =>\n fetch(`http://localhost:${port}/mcp`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json, text/event-stream\",\n },\n body: callBody(i + 1),\n }),\n ),\n );\n\n expect(responses.map((r) => r.status)).toEqual(Array(N).fill(200));\n expect(consoleSpy).not.toHaveBeenCalledWith(\n \"Error handling MCP request:\",\n expect.any(Error),\n );\n consoleSpy.mockRestore();\n });\n});\n\ndescribe(\"createApp tunnel routes\", () => {\n it(\"proxies POST /__skybridge/tunnel to the cli control server in dev mode\", async () => {\n // Stand up a fake control listener that returns a known JSON body.\n const control = http.createServer((_req, res) => {\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end('{\"status\":\"idle\"}');\n });\n await new Promise<void>((resolve) =>\n control.listen(0, \"127.0.0.1\", resolve),\n );\n const controlAddr = control.address();\n if (typeof controlAddr === \"string\" || controlAddr === null) {\n control.close();\n throw new Error(\"control server has no address\");\n }\n const controlPort = controlAddr.port;\n\n const prev = process.env.__TUNNEL_CONTROL_PORT;\n process.env.__TUNNEL_CONTROL_PORT = String(controlPort);\n try {\n const { createApp } = await import(\"./express.js\");\n const mcpServer = new McpServer({ name: \"t\", version: \"0.0.0\" });\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer, httpServer });\n const { port, server } = await listen(app);\n openServer = server;\n\n const res = await fetch(`http://localhost:${port}/__skybridge/tunnel`, {\n method: \"POST\",\n });\n expect(res.status).toBe(200);\n expect(await res.json()).toEqual({ status: \"idle\" });\n } finally {\n if (prev === undefined) {\n delete process.env.__TUNNEL_CONTROL_PORT;\n } else {\n process.env.__TUNNEL_CONTROL_PORT = prev;\n }\n await new Promise<void>((resolve) => control.close(() => resolve()));\n }\n });\n\n it(\"does not expose /__skybridge/tunnel in production mode\", async () => {\n const prevEnv = process.env.NODE_ENV;\n process.env.NODE_ENV = \"production\";\n try {\n vi.resetModules();\n const { createApp } = await import(\"./express.js\");\n const { McpServer: ReloadedMcpServer } = await import(\"./server.js\");\n const mcpServer = new ReloadedMcpServer({ name: \"t\", version: \"0.0.0\" });\n const httpServer = http.createServer();\n const app = await createApp({ mcpServer, httpServer });\n const { port, server } = await listen(app);\n openServer = server;\n\n const res = await fetch(`http://localhost:${port}/__skybridge/tunnel`, {\n method: \"POST\",\n });\n expect(res.status).toBe(404);\n } finally {\n process.env.NODE_ENV = prevEnv;\n vi.resetModules();\n }\n });\n});\n"]}
@@ -1,4 +1,6 @@
1
+ export { audio, embeddedResource, image, resourceLink, text, } from "./content-helpers.js";
1
2
  export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
2
- export type { McpServerTypes, ToolDef, WidgetHostType } from "./server.js";
3
- export { McpServer } from "./server.js";
4
- export { widgetsDevServer } from "./widgetsDevServer.js";
3
+ export type { McpExtra, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard, } from "./middleware.js";
4
+ export type { HandlerContent, KnownToolMeta, McpServerTypes, ToolDef, ToolMeta, ViewConfig, ViewCsp, ViewHostType, ViewName, ViewNameRegistry, } from "./server.js";
5
+ export { McpServer, normalizeContent, } from "./server.js";
6
+ export { viewsDevServer } from "./viewsDevServer.js";
@@ -1,3 +1,4 @@
1
- export { McpServer } from "./server.js";
2
- export { widgetsDevServer } from "./widgetsDevServer.js";
1
+ export { audio, embeddedResource, image, resourceLink, text, } from "./content-helpers.js";
2
+ export { McpServer, normalizeContent, } from "./server.js";
3
+ export { viewsDevServer } from "./viewsDevServer.js";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,YAAY,EACZ,IAAI,GACL,MAAM,sBAAsB,CAAC;AA8B9B,OAAO,EACL,SAAS,EACT,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n audio,\n embeddedResource,\n image,\n resourceLink,\n text,\n} from \"./content-helpers.js\";\nexport type {\n AnyToolRegistry,\n InferTools,\n ToolInput,\n ToolNames,\n ToolOutput,\n ToolResponseMetadata,\n} from \"./inferUtilityTypes.js\";\nexport type {\n McpExtra,\n McpMethodString,\n McpMiddlewareFilter,\n McpMiddlewareFn,\n McpResultFor,\n McpTypedMiddlewareFn,\n McpWildcard,\n} from \"./middleware.js\";\nexport type {\n HandlerContent,\n KnownToolMeta,\n McpServerTypes,\n ToolDef,\n ToolMeta,\n ViewConfig,\n ViewCsp,\n ViewHostType,\n ViewName,\n ViewNameRegistry,\n} from \"./server.js\";\nexport {\n McpServer,\n normalizeContent,\n} from \"./server.js\";\nexport { viewsDevServer } from \"./viewsDevServer.js\";\n"]}
@@ -1,12 +1,12 @@
1
1
  import type { McpServerTypes, ToolDef } from "./server.js";
2
2
  /**
3
- * Any tool registry shape (includes both widgets and regular tools).
3
+ * Any tool registry shape (includes both views and regular tools).
4
4
  * Used as a constraint for type parameters that accept tool registries.
5
5
  */
6
6
  export type AnyToolRegistry = Record<string, ToolDef>;
7
7
  /**
8
8
  * Extract the tool registry type from an McpServer instance.
9
- * This includes both widgets (registered via widget()) and regular tools (registered via registerTool()).
9
+ * This includes both views (registered via view()) and regular tools (registered via registerTool()).
10
10
  *
11
11
  * Uses the `$types` property pattern for cross-package type inference.
12
12
  * This works across package boundaries because TypeScript uses structural typing
@@ -24,7 +24,7 @@ export type InferTools<ServerType> = ServerType extends {
24
24
  type ExtractTool<ServerType, K extends ToolNames<ServerType>> = InferTools<ServerType>[K];
25
25
  /**
26
26
  * Get a union of all tool names from an McpServer instance.
27
- * This includes both widgets and regular tools.
27
+ * This includes both views and regular tools.
28
28
  *
29
29
  * @example
30
30
  * ```ts
@@ -34,7 +34,7 @@ type ExtractTool<ServerType, K extends ToolNames<ServerType>> = InferTools<Serve
34
34
  */
35
35
  export type ToolNames<ServerType> = keyof InferTools<ServerType> & string;
36
36
  /**
37
- * Get the input type for a specific tool (widget or regular tool).
37
+ * Get the input type for a specific tool (view or regular tool).
38
38
  *
39
39
  * @example
40
40
  * ```ts
@@ -43,7 +43,7 @@ export type ToolNames<ServerType> = keyof InferTools<ServerType> & string;
43
43
  */
44
44
  export type ToolInput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["input"];
45
45
  /**
46
- * Get the output type for a specific tool (widget or regular tool).
46
+ * Get the output type for a specific tool (view or regular tool).
47
47
  *
48
48
  * @example
49
49
  * ```ts
@@ -52,7 +52,7 @@ export type ToolInput<ServerType, ToolName extends ToolNames<ServerType>> = Extr
52
52
  */
53
53
  export type ToolOutput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["output"];
54
54
  /**
55
- * Get the responseMetadata type for a specific tool (widget or regular tool).
55
+ * Get the responseMetadata type for a specific tool (view or regular tool).
56
56
  * This is inferred from the `_meta` property of the tool callback's return value.
57
57
  *
58
58
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"inferUtilityTypes.js","sourceRoot":"","sources":["../../src/server/inferUtilityTypes.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"inferUtilityTypes.js","sourceRoot":"","sources":["../../src/server/inferUtilityTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { McpServerTypes, ToolDef } from \"./server.js\";\n\n/**\n * Any tool registry shape (includes both views and regular tools).\n * Used as a constraint for type parameters that accept tool registries.\n */\nexport type AnyToolRegistry = Record<string, ToolDef>;\n\n/**\n * Extract the tool registry type from an McpServer instance.\n * This includes both views (registered via view()) and regular tools (registered via registerTool()).\n *\n * Uses the `$types` property pattern for cross-package type inference.\n * This works across package boundaries because TypeScript uses structural typing\n * on the shape of `$types`, rather than nominal typing on the McpServer class itself.\n *\n * @example\n * ```ts\n * type MyTools = InferTools<MyServer>;\n * // { \"search\": ToolDef<...>, \"calculate\": ToolDef<...> }\n * ```\n */\nexport type InferTools<ServerType> = ServerType extends {\n $types: McpServerTypes<infer W>;\n}\n ? W\n : never;\ntype ExtractTool<\n ServerType,\n K extends ToolNames<ServerType>,\n> = InferTools<ServerType>[K];\n\n/**\n * Get a union of all tool names from an McpServer instance.\n * This includes both views and regular tools.\n *\n * @example\n * ```ts\n * type Names = ToolNames<MyServer>;\n * // \"search\" | \"calculate\" | \"details\"\n * ```\n */\nexport type ToolNames<ServerType> = keyof InferTools<ServerType> & string;\n\n/**\n * Get the input type for a specific tool (view or regular tool).\n *\n * @example\n * ```ts\n * type SearchInput = ToolInput<MyServer, \"search\">;\n * ```\n */\nexport type ToolInput<\n ServerType,\n ToolName extends ToolNames<ServerType>,\n> = ExtractTool<ServerType, ToolName>[\"input\"];\n\n/**\n * Get the output type for a specific tool (view or regular tool).\n *\n * @example\n * ```ts\n * type SearchOutput = ToolOutput<MyServer, \"search\">;\n * ```\n */\nexport type ToolOutput<\n ServerType,\n ToolName extends ToolNames<ServerType>,\n> = ExtractTool<ServerType, ToolName>[\"output\"];\n\n/**\n * Get the responseMetadata type for a specific tool (view or regular tool).\n * This is inferred from the `_meta` property of the tool callback's return value.\n *\n * @example\n * ```ts\n * type SearchMeta = ToolResponseMetadata<MyServer, \"search\">;\n * ```\n */\nexport type ToolResponseMetadata<\n ServerType,\n ToolName extends ToolNames<ServerType>,\n> = ExtractTool<ServerType, ToolName>[\"responseMetadata\"];\n"]}
@@ -0,0 +1,14 @@
1
+ import type { McpMiddlewareEntry } from "./middleware.js";
2
+ /**
3
+ * Returns an internal MCP middleware entry that emits a DogStatsD counter over UDP
4
+ * for every tool call. Enabled by default; respects the existing telemetry
5
+ * opt-out (SKYBRIDGE_TELEMETRY_DISABLED, DO_NOT_TRACK, or `skybridge telemetry disable`).
6
+ *
7
+ * Returns `null` when the version string contains "-dev" (e.g. development
8
+ * builds) or when the version cannot be parsed into major.minor, so that
9
+ * malformed data does not pollute production metrics.
10
+ *
11
+ * Metric (DogStatsD counter format with tags):
12
+ * Requests:1|c|#version:<major>.<minor> — every tools/call
13
+ */
14
+ export declare function createMiddlewareEntry(): McpMiddlewareEntry | null;
@@ -0,0 +1,62 @@
1
+ import { createSocket } from "node:dgram";
2
+ import { isEnabled } from "../cli/telemetry.js";
3
+ import { VERSION } from "../version.js";
4
+ function parseMajorMinor(version) {
5
+ const parts = version.split(".");
6
+ if (parts.length < 2) {
7
+ return null;
8
+ }
9
+ return `${parts[0]}.${parts[1]}`;
10
+ }
11
+ const isDev = VERSION.includes("-dev");
12
+ const versionTag = parseMajorMinor(VERSION);
13
+ const STATSD_HOST = "18.208.242.161";
14
+ const STATSD_PORT = 8125;
15
+ let socket = null;
16
+ function getSocket() {
17
+ if (!socket) {
18
+ socket = createSocket("udp4");
19
+ socket.unref();
20
+ }
21
+ return socket;
22
+ }
23
+ function sendMetric(metric) {
24
+ if (!STATSD_HOST) {
25
+ return;
26
+ }
27
+ const payload = Buffer.from(metric);
28
+ getSocket().send(payload, STATSD_PORT, STATSD_HOST, () => {
29
+ // fire-and-forget: errors are intentionally silenced
30
+ });
31
+ }
32
+ /**
33
+ * Returns an internal MCP middleware entry that emits a DogStatsD counter over UDP
34
+ * for every tool call. Enabled by default; respects the existing telemetry
35
+ * opt-out (SKYBRIDGE_TELEMETRY_DISABLED, DO_NOT_TRACK, or `skybridge telemetry disable`).
36
+ *
37
+ * Returns `null` when the version string contains "-dev" (e.g. development
38
+ * builds) or when the version cannot be parsed into major.minor, so that
39
+ * malformed data does not pollute production metrics.
40
+ *
41
+ * Metric (DogStatsD counter format with tags):
42
+ * Requests:1|c|#version:<major>.<minor> — every tools/call
43
+ */
44
+ export function createMiddlewareEntry() {
45
+ if (isDev || !versionTag) {
46
+ return null;
47
+ }
48
+ const handler = async (_req, _extra, next) => {
49
+ // Check on every call so opt-out takes effect immediately without restart.
50
+ if (!isEnabled()) {
51
+ return next();
52
+ }
53
+ try {
54
+ return await next();
55
+ }
56
+ finally {
57
+ sendMetric(`Requests:1|c|#version:${versionTag}`);
58
+ }
59
+ };
60
+ return { filter: "tools/call", handler };
61
+ }
62
+ //# sourceMappingURL=metric.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metric.js","sourceRoot":"","sources":["../../src/server/metric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAA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C3E,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;YACjB,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,EAAE,CAAC;QACtB,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,yBAAyB,UAAU,EAAE,CAAC,CAAC;QACpD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import { createSocket } from \"node:dgram\";\nimport { isEnabled } from \"../cli/telemetry.js\";\nimport { VERSION } from \"../version.js\";\nimport type { McpMiddlewareEntry, McpMiddlewareFn } from \"./middleware.js\";\n\nfunction parseMajorMinor(version: string): string | null {\n const parts = version.split(\".\");\n if (parts.length < 2) {\n return null;\n }\n return `${parts[0]}.${parts[1]}`;\n}\n\nconst isDev = VERSION.includes(\"-dev\");\nconst versionTag = parseMajorMinor(VERSION);\n\nconst STATSD_HOST = \"18.208.242.161\";\nconst STATSD_PORT = 8125;\n\nlet socket: ReturnType<typeof createSocket> | null = null;\n\nfunction getSocket() {\n if (!socket) {\n socket = createSocket(\"udp4\");\n socket.unref();\n }\n return socket;\n}\n\nfunction sendMetric(metric: string): void {\n if (!STATSD_HOST) {\n return;\n }\n const payload = Buffer.from(metric);\n getSocket().send(payload, STATSD_PORT, STATSD_HOST, () => {\n // fire-and-forget: errors are intentionally silenced\n });\n}\n\n/**\n * Returns an internal MCP middleware entry that emits a DogStatsD counter over UDP\n * for every tool call. Enabled by default; respects the existing telemetry\n * opt-out (SKYBRIDGE_TELEMETRY_DISABLED, DO_NOT_TRACK, or `skybridge telemetry disable`).\n *\n * Returns `null` when the version string contains \"-dev\" (e.g. development\n * builds) or when the version cannot be parsed into major.minor, so that\n * malformed data does not pollute production metrics.\n *\n * Metric (DogStatsD counter format with tags):\n * Requests:1|c|#version:<major>.<minor> — every tools/call\n */\nexport function createMiddlewareEntry(): McpMiddlewareEntry | null {\n if (isDev || !versionTag) {\n return null;\n }\n\n const handler: McpMiddlewareFn = async (_req, _extra, next) => {\n // Check on every call so opt-out takes effect immediately without restart.\n if (!isEnabled()) {\n return next();\n }\n\n try {\n return await next();\n } finally {\n sendMetric(`Requests:1|c|#version:${versionTag}`);\n }\n };\n\n return { filter: \"tools/call\", handler };\n}\n"]}
@@ -0,0 +1,124 @@
1
+ import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
3
+ import type { CallToolResult, CancelTaskResult, ClientNotification, ClientRequest, CompleteResult, EmptyResult, GetPromptResult, GetTaskPayloadResult, GetTaskResult, InitializeResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, ListTasksResult, ListToolsResult, ReadResourceResult, ServerNotification, ServerRequest, ServerResult } from "@modelcontextprotocol/sdk/types.js";
4
+ /**
5
+ * The `extra` context object provided by the MCP SDK to request handlers.
6
+ */
7
+ export type McpExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;
8
+ /**
9
+ * A single MCP middleware function following the onion model.
10
+ * Call `next()` to invoke the next middleware or the final handler.
11
+ * For notifications, `extra` is `undefined` (SDK does not provide extra context)
12
+ * and `next()` resolves to `undefined`.
13
+ */
14
+ export type McpMiddlewareFn = (request: {
15
+ method: string;
16
+ params: Record<string, unknown>;
17
+ }, extra: McpExtra | undefined, next: () => Promise<unknown>) => Promise<unknown> | unknown;
18
+ /**
19
+ * MCP methods the server handles (incoming from client).
20
+ */
21
+ export type McpMethodString = ClientRequest["method"] | ClientNotification["method"];
22
+ /** Extract params type for a specific MCP method from SDK unions. */
23
+ export type McpRequestParams<M extends string> = Extract<ClientRequest, {
24
+ method: M;
25
+ }> extends {
26
+ params: infer P;
27
+ } ? P : Extract<ClientNotification, {
28
+ method: M;
29
+ }> extends {
30
+ params: infer P;
31
+ } ? P : Record<string, unknown>;
32
+ /** Resolve extra type: McpExtra for requests, undefined for notifications. */
33
+ export type McpExtraFor<M extends string> = M extends ClientRequest["method"] ? McpExtra : M extends ClientNotification["method"] ? undefined : McpExtra | undefined;
34
+ /** Maps each MCP request method to its SDK result type. */
35
+ interface McpResultMap {
36
+ ping: EmptyResult;
37
+ initialize: InitializeResult;
38
+ "tools/list": ListToolsResult;
39
+ "tools/call": CallToolResult;
40
+ "resources/list": ListResourcesResult;
41
+ "resources/templates/list": ListResourceTemplatesResult;
42
+ "resources/read": ReadResourceResult;
43
+ "resources/subscribe": EmptyResult;
44
+ "resources/unsubscribe": EmptyResult;
45
+ "prompts/list": ListPromptsResult;
46
+ "prompts/get": GetPromptResult;
47
+ "completion/complete": CompleteResult;
48
+ "logging/setLevel": EmptyResult;
49
+ "tasks/get": GetTaskResult;
50
+ "tasks/result": GetTaskPayloadResult;
51
+ "tasks/list": ListTasksResult;
52
+ "tasks/cancel": CancelTaskResult;
53
+ }
54
+ /**
55
+ * Map an MCP method string to its corresponding result type.
56
+ * For request methods, resolves to the specific SDK result type.
57
+ * For wildcard patterns (e.g. `"tools/*"`), resolves to the union of matching result types.
58
+ * For notification methods, resolves to `undefined`.
59
+ * For unknown/unmatched methods, falls back to `ServerResult`.
60
+ */
61
+ export type McpResultFor<M extends string> = M extends keyof McpResultMap ? McpResultMap[M] : M extends `${infer Prefix}/*` ? [McpResultMap[keyof McpResultMap & `${Prefix}/${string}`]] extends [never] ? M extends ToWildcard<ClientNotification["method"]> ? undefined : ServerResult : McpResultMap[keyof McpResultMap & `${Prefix}/${string}`] : M extends ClientNotification["method"] ? undefined : ServerResult;
62
+ /** Typed middleware fn for a specific method — narrows params, extra, and next() result. */
63
+ export type McpTypedMiddlewareFn<M extends string> = (request: {
64
+ method: M;
65
+ params: McpRequestParams<M>;
66
+ }, extra: McpExtraFor<M>, next: () => Promise<McpResultFor<M>>) => Promise<unknown> | unknown;
67
+ /** Extracts `"prefix/*"` from `"prefix/anything"` — distributive over unions. */
68
+ type ToWildcard<T extends string> = T extends `${infer Prefix}/${string}` ? `${Prefix}/*` : never;
69
+ /** Wildcard prefixes derived from method strings (e.g. `"tools/*"` from `"tools/call"`). */
70
+ export type McpWildcard = ToWildcard<McpMethodString>;
71
+ /** Category keywords matching all requests or all notifications. */
72
+ type McpCategory = "request" | "notification";
73
+ /**
74
+ * A single filter pattern for MCP middleware:
75
+ * - Exact method: `"tools/call"`
76
+ * - Wildcard: `"tools/*"`
77
+ * - Category: `"request"` | `"notification"`
78
+ * - Escape hatch: arbitrary string via `string & {}`
79
+ */
80
+ type McpMiddlewareFilterPattern = McpMethodString | McpWildcard | McpCategory | (string & {});
81
+ /**
82
+ * Filter determining which MCP methods a middleware applies to.
83
+ * A single pattern or an array of patterns (OR logic).
84
+ */
85
+ export type McpMiddlewareFilter = McpMiddlewareFilterPattern | McpMiddlewareFilterPattern[];
86
+ /**
87
+ * Internal entry stored for each registered middleware.
88
+ * `filter: null` means catch-all (matches everything).
89
+ */
90
+ export type McpMiddlewareEntry = {
91
+ filter: McpMiddlewareFilter | null;
92
+ handler: McpMiddlewareFn;
93
+ };
94
+ type HandlerMap = Map<string, (...args: unknown[]) => Promise<unknown>>;
95
+ /**
96
+ * Extract the TS-private `_requestHandlers` and `_notificationHandlers` maps
97
+ * from the SDK's `Server` (extends `Protocol`). These are runtime-accessible
98
+ * but declared `private` in TypeScript.
99
+ *
100
+ * Validates with `instanceof Map` so an incompatible SDK version fails fast
101
+ * instead of silently breaking.
102
+ */
103
+ export declare function getHandlerMaps(server: Server): {
104
+ requestHandlers: HandlerMap;
105
+ notificationHandlers: HandlerMap;
106
+ };
107
+ /**
108
+ * Check if a single filter pattern matches a given method.
109
+ *
110
+ * - Exact: `"tools/call"` matches only `"tools/call"`
111
+ * - Wildcard: `"tools/*"` matches any method starting with `"tools/"`
112
+ * - Category `"request"`: matches when `isNotification` is false
113
+ * - Category `"notification"`: matches when `isNotification` is true
114
+ */
115
+ export declare function matchesFilter(method: string, filter: string, isNotification: boolean): boolean;
116
+ /**
117
+ * Build an onion-model middleware chain for a specific method.
118
+ *
119
+ * Filters `entries` to those matching `method`, then composes them
120
+ * so the first registered middleware is the outermost layer.
121
+ * `next()` is guarded against multiple calls within a single middleware.
122
+ */
123
+ export declare function buildMiddlewareChain(method: string, isNotification: boolean, originalHandler: (...args: unknown[]) => Promise<unknown>, entries: McpMiddlewareEntry[]): (...args: unknown[]) => Promise<unknown>;
124
+ export {};
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Extract the TS-private `_requestHandlers` and `_notificationHandlers` maps
3
+ * from the SDK's `Server` (extends `Protocol`). These are runtime-accessible
4
+ * but declared `private` in TypeScript.
5
+ *
6
+ * Validates with `instanceof Map` so an incompatible SDK version fails fast
7
+ * instead of silently breaking.
8
+ */
9
+ export function getHandlerMaps(server) {
10
+ const obj = server;
11
+ if (!("_requestHandlers" in obj && obj._requestHandlers instanceof Map) ||
12
+ !("_notificationHandlers" in obj && obj._notificationHandlers instanceof Map)) {
13
+ throw new Error("Incompatible MCP SDK version: expected _requestHandlers and _notificationHandlers on Server");
14
+ }
15
+ return {
16
+ requestHandlers: obj._requestHandlers,
17
+ notificationHandlers: obj._notificationHandlers,
18
+ };
19
+ }
20
+ /**
21
+ * Check if a single filter pattern matches a given method.
22
+ *
23
+ * - Exact: `"tools/call"` matches only `"tools/call"`
24
+ * - Wildcard: `"tools/*"` matches any method starting with `"tools/"`
25
+ * - Category `"request"`: matches when `isNotification` is false
26
+ * - Category `"notification"`: matches when `isNotification` is true
27
+ */
28
+ export function matchesFilter(method, filter, isNotification) {
29
+ if (filter === "request") {
30
+ return !isNotification;
31
+ }
32
+ if (filter === "notification") {
33
+ return isNotification;
34
+ }
35
+ if (filter.endsWith("/*")) {
36
+ const prefix = filter.slice(0, -1); // "tools/*" → "tools/"
37
+ return method.startsWith(prefix);
38
+ }
39
+ return method === filter;
40
+ }
41
+ function matchesAnyFilter(method, filter, isNotification) {
42
+ if (filter === null) {
43
+ return true;
44
+ }
45
+ if (typeof filter === "string") {
46
+ return matchesFilter(method, filter, isNotification);
47
+ }
48
+ return filter.some((pattern) => matchesFilter(method, pattern, isNotification));
49
+ }
50
+ /**
51
+ * Build an onion-model middleware chain for a specific method.
52
+ *
53
+ * Filters `entries` to those matching `method`, then composes them
54
+ * so the first registered middleware is the outermost layer.
55
+ * `next()` is guarded against multiple calls within a single middleware.
56
+ */
57
+ export function buildMiddlewareChain(method, isNotification, originalHandler, entries) {
58
+ const applicable = entries.filter((entry) => matchesAnyFilter(method, entry.filter, isNotification));
59
+ if (applicable.length === 0) {
60
+ return originalHandler;
61
+ }
62
+ return (...args) => {
63
+ const rawRequest = args[0];
64
+ // SDK calls request handlers as handler(request, extra) but
65
+ // notification handlers as handler(notification) — no extra arg.
66
+ const extra = isNotification ? undefined : args[1];
67
+ const mcpRequest = {
68
+ method,
69
+ params: rawRequest?.params ?? {},
70
+ };
71
+ let index = 0;
72
+ const executeLayer = () => {
73
+ const entry = applicable[index++];
74
+ if (!entry) {
75
+ if (rawRequest) {
76
+ rawRequest.params = mcpRequest.params;
77
+ }
78
+ return originalHandler(...args);
79
+ }
80
+ let nextCalled = false;
81
+ const next = () => {
82
+ if (nextCalled) {
83
+ throw new Error(`next() called multiple times in middleware for "${method}"`);
84
+ }
85
+ nextCalled = true;
86
+ return executeLayer();
87
+ };
88
+ return Promise.resolve(entry.handler(mcpRequest, extra, next));
89
+ };
90
+ return executeLayer();
91
+ };
92
+ }
93
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/server/middleware.ts"],"names":[],"mappings":"AAyJA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,MAAM,GAAG,GAAW,MAAM,CAAC;IAE3B,IACE,CAAC,CAAC,kBAAkB,IAAI,GAAG,IAAI,GAAG,CAAC,gBAAgB,YAAY,GAAG,CAAC;QACnE,CAAC,CACC,uBAAuB,IAAI,GAAG,IAAI,GAAG,CAAC,qBAAqB,YAAY,GAA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,CAAC,CAAC;QACjE,CAAC,CAAC;QAEF,OAAO,YAAY,EAAE,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport type {\n CallToolResult,\n CancelTaskResult,\n ClientNotification,\n ClientRequest,\n CompleteResult,\n EmptyResult,\n GetPromptResult,\n GetTaskPayloadResult,\n GetTaskResult,\n InitializeResult,\n ListPromptsResult,\n ListResourcesResult,\n ListResourceTemplatesResult,\n ListTasksResult,\n ListToolsResult,\n ReadResourceResult,\n ServerNotification,\n ServerRequest,\n ServerResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\n\n/**\n * The `extra` context object provided by the MCP SDK to request handlers.\n */\nexport type McpExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;\n\n/**\n * A single MCP middleware function following the onion model.\n * Call `next()` to invoke the next middleware or the final handler.\n * For notifications, `extra` is `undefined` (SDK does not provide extra context)\n * and `next()` resolves to `undefined`.\n */\nexport type McpMiddlewareFn = (\n request: { method: string; params: Record<string, unknown> },\n extra: McpExtra | undefined,\n next: () => Promise<unknown>,\n) => Promise<unknown> | unknown;\n\n/**\n * MCP methods the server handles (incoming from client).\n */\nexport type McpMethodString =\n | ClientRequest[\"method\"]\n | ClientNotification[\"method\"];\n\n/** Extract params type for a specific MCP method from SDK unions. */\nexport type McpRequestParams<M extends string> =\n Extract<ClientRequest, { method: M }> extends { params: infer P }\n ? P\n : Extract<ClientNotification, { method: M }> extends { params: infer P }\n ? P\n : Record<string, unknown>;\n\n/** Resolve extra type: McpExtra for requests, undefined for notifications. */\nexport type McpExtraFor<M extends string> = M extends ClientRequest[\"method\"]\n ? McpExtra\n : M extends ClientNotification[\"method\"]\n ? undefined\n : McpExtra | undefined;\n\n/** Maps each MCP request method to its SDK result type. */\ninterface McpResultMap {\n ping: EmptyResult;\n initialize: InitializeResult;\n \"tools/list\": ListToolsResult;\n \"tools/call\": CallToolResult;\n \"resources/list\": ListResourcesResult;\n \"resources/templates/list\": ListResourceTemplatesResult;\n \"resources/read\": ReadResourceResult;\n \"resources/subscribe\": EmptyResult;\n \"resources/unsubscribe\": EmptyResult;\n \"prompts/list\": ListPromptsResult;\n \"prompts/get\": GetPromptResult;\n \"completion/complete\": CompleteResult;\n \"logging/setLevel\": EmptyResult;\n \"tasks/get\": GetTaskResult;\n \"tasks/result\": GetTaskPayloadResult;\n \"tasks/list\": ListTasksResult;\n \"tasks/cancel\": CancelTaskResult;\n}\n\n/**\n * Map an MCP method string to its corresponding result type.\n * For request methods, resolves to the specific SDK result type.\n * For wildcard patterns (e.g. `\"tools/*\"`), resolves to the union of matching result types.\n * For notification methods, resolves to `undefined`.\n * For unknown/unmatched methods, falls back to `ServerResult`.\n */\nexport type McpResultFor<M extends string> = M extends keyof McpResultMap\n ? McpResultMap[M]\n : M extends `${infer Prefix}/*`\n ? [McpResultMap[keyof McpResultMap & `${Prefix}/${string}`]] extends [never]\n ? M extends ToWildcard<ClientNotification[\"method\"]>\n ? undefined\n : ServerResult\n : McpResultMap[keyof McpResultMap & `${Prefix}/${string}`]\n : M extends ClientNotification[\"method\"]\n ? undefined\n : ServerResult;\n\n/** Typed middleware fn for a specific method — narrows params, extra, and next() result. */\nexport type McpTypedMiddlewareFn<M extends string> = (\n request: { method: M; params: McpRequestParams<M> },\n extra: McpExtraFor<M>,\n next: () => Promise<McpResultFor<M>>,\n) => Promise<unknown> | unknown;\n\n/** Extracts `\"prefix/*\"` from `\"prefix/anything\"` — distributive over unions. */\ntype ToWildcard<T extends string> = T extends `${infer Prefix}/${string}`\n ? `${Prefix}/*`\n : never;\n\n/** Wildcard prefixes derived from method strings (e.g. `\"tools/*\"` from `\"tools/call\"`). */\nexport type McpWildcard = ToWildcard<McpMethodString>;\n\n/** Category keywords matching all requests or all notifications. */\ntype McpCategory = \"request\" | \"notification\";\n\n/**\n * A single filter pattern for MCP middleware:\n * - Exact method: `\"tools/call\"`\n * - Wildcard: `\"tools/*\"`\n * - Category: `\"request\"` | `\"notification\"`\n * - Escape hatch: arbitrary string via `string & {}`\n */\ntype McpMiddlewareFilterPattern =\n | McpMethodString\n | McpWildcard\n | McpCategory\n | (string & {});\n\n/**\n * Filter determining which MCP methods a middleware applies to.\n * A single pattern or an array of patterns (OR logic).\n */\nexport type McpMiddlewareFilter =\n | McpMiddlewareFilterPattern\n | McpMiddlewareFilterPattern[];\n\n/**\n * Internal entry stored for each registered middleware.\n * `filter: null` means catch-all (matches everything).\n */\nexport type McpMiddlewareEntry = {\n filter: McpMiddlewareFilter | null;\n handler: McpMiddlewareFn;\n};\n\ntype HandlerMap = Map<string, (...args: unknown[]) => Promise<unknown>>;\n\n/**\n * Extract the TS-private `_requestHandlers` and `_notificationHandlers` maps\n * from the SDK's `Server` (extends `Protocol`). These are runtime-accessible\n * but declared `private` in TypeScript.\n *\n * Validates with `instanceof Map` so an incompatible SDK version fails fast\n * instead of silently breaking.\n */\nexport function getHandlerMaps(server: Server) {\n const obj: object = server;\n\n if (\n !(\"_requestHandlers\" in obj && obj._requestHandlers instanceof Map) ||\n !(\n \"_notificationHandlers\" in obj && obj._notificationHandlers instanceof Map\n )\n ) {\n throw new Error(\n \"Incompatible MCP SDK version: expected _requestHandlers and _notificationHandlers on Server\",\n );\n }\n\n return {\n requestHandlers: obj._requestHandlers as HandlerMap,\n notificationHandlers: obj._notificationHandlers as HandlerMap,\n };\n}\n\n/**\n * Check if a single filter pattern matches a given method.\n *\n * - Exact: `\"tools/call\"` matches only `\"tools/call\"`\n * - Wildcard: `\"tools/*\"` matches any method starting with `\"tools/\"`\n * - Category `\"request\"`: matches when `isNotification` is false\n * - Category `\"notification\"`: matches when `isNotification` is true\n */\nexport function matchesFilter(\n method: string,\n filter: string,\n isNotification: boolean,\n): boolean {\n if (filter === \"request\") {\n return !isNotification;\n }\n if (filter === \"notification\") {\n return isNotification;\n }\n if (filter.endsWith(\"/*\")) {\n const prefix = filter.slice(0, -1); // \"tools/*\" → \"tools/\"\n return method.startsWith(prefix);\n }\n return method === filter;\n}\n\nfunction matchesAnyFilter(\n method: string,\n filter: McpMiddlewareFilter | null,\n isNotification: boolean,\n): boolean {\n if (filter === null) {\n return true;\n }\n if (typeof filter === \"string\") {\n return matchesFilter(method, filter, isNotification);\n }\n return filter.some((pattern) =>\n matchesFilter(method, pattern, isNotification),\n );\n}\n\n/**\n * Build an onion-model middleware chain for a specific method.\n *\n * Filters `entries` to those matching `method`, then composes them\n * so the first registered middleware is the outermost layer.\n * `next()` is guarded against multiple calls within a single middleware.\n */\nexport function buildMiddlewareChain(\n method: string,\n isNotification: boolean,\n originalHandler: (...args: unknown[]) => Promise<unknown>,\n entries: McpMiddlewareEntry[],\n) {\n const applicable = entries.filter((entry) =>\n matchesAnyFilter(method, entry.filter, isNotification),\n );\n\n if (applicable.length === 0) {\n return originalHandler;\n }\n\n return (...args: unknown[]) => {\n const rawRequest = args[0] as Record<string, unknown> | undefined;\n // SDK calls request handlers as handler(request, extra) but\n // notification handlers as handler(notification) — no extra arg.\n const extra = isNotification ? undefined : (args[1] as McpExtra);\n const mcpRequest = {\n method,\n params: (rawRequest?.params as Record<string, unknown>) ?? {},\n };\n\n let index = 0;\n\n const executeLayer = (): Promise<unknown> => {\n const entry = applicable[index++];\n if (!entry) {\n if (rawRequest) {\n rawRequest.params = mcpRequest.params;\n }\n return originalHandler(...args);\n }\n\n let nextCalled = false;\n\n const next = (): Promise<unknown> => {\n if (nextCalled) {\n throw new Error(\n `next() called multiple times in middleware for \"${method}\"`,\n );\n }\n nextCalled = true;\n return executeLayer();\n };\n\n return Promise.resolve(entry.handler(mcpRequest, extra, next));\n };\n\n return executeLayer();\n };\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ import { expectTypeOf, test } from "vitest";
2
+ const server = null;
3
+ test("request category narrows extra and next() result", () => {
4
+ server.mcpMiddleware("request", async (_request, extra, next) => {
5
+ expectTypeOf(extra).toEqualTypeOf();
6
+ extra.signal;
7
+ const result = await next();
8
+ expectTypeOf(result).toEqualTypeOf();
9
+ return result;
10
+ });
11
+ });
12
+ test("notification category narrows extra and next() result", () => {
13
+ server.mcpMiddleware("notification", async (_request, extra, next) => {
14
+ expectTypeOf(extra).toEqualTypeOf();
15
+ // @ts-expect-error extra is undefined, cannot access .signal
16
+ extra.signal;
17
+ const result = await next();
18
+ expectTypeOf(result).toEqualTypeOf();
19
+ });
20
+ });
21
+ test("exact method tools/call narrows params, extra, and next() result", () => {
22
+ server.mcpMiddleware("tools/call", async (request, extra, next) => {
23
+ expectTypeOf(request.params.name).toBeString();
24
+ expectTypeOf(extra).toEqualTypeOf();
25
+ const result = await next();
26
+ expectTypeOf(result).toEqualTypeOf();
27
+ return result;
28
+ });
29
+ });
30
+ test("exact method tools/list narrows next() to ListToolsResult", () => {
31
+ server.mcpMiddleware("tools/list", async (_request, _extra, next) => {
32
+ const result = await next();
33
+ expectTypeOf(result).toEqualTypeOf();
34
+ return result;
35
+ });
36
+ });
37
+ test("exact notification method narrows extra and next() result", () => {
38
+ server.mcpMiddleware("notifications/initialized", async (_request, extra, next) => {
39
+ expectTypeOf(extra).toEqualTypeOf();
40
+ // @ts-expect-error extra is undefined
41
+ extra.signal;
42
+ const result = await next();
43
+ expectTypeOf(result).toEqualTypeOf();
44
+ });
45
+ });
46
+ test("McpTypedMiddlewareFn narrows params, extra, and next() per method", () => {
47
+ expectTypeOf().toBeString();
48
+ expectTypeOf().toEqualTypeOf();
49
+ expectTypeOf().toEqualTypeOf();
50
+ expectTypeOf().toEqualTypeOf();
51
+ expectTypeOf().toEqualTypeOf();
52
+ });
53
+ test("McpResultFor maps methods to correct result types", () => {
54
+ expectTypeOf().toEqualTypeOf();
55
+ expectTypeOf().toEqualTypeOf();
56
+ expectTypeOf().toEqualTypeOf();
57
+ });
58
+ test("wildcard tools/* narrows next() to union of tools result types", () => {
59
+ server.mcpMiddleware("tools/*", async (_request, _extra, next) => {
60
+ const result = await next();
61
+ expectTypeOf(result).toEqualTypeOf();
62
+ return result;
63
+ });
64
+ });
65
+ test("McpResultFor resolves wildcards to union of matching result types", () => {
66
+ expectTypeOf().toEqualTypeOf();
67
+ });
68
+ test("catch-all middleware has no narrowing on extra or params", () => {
69
+ server.mcpMiddleware((_request, extra, next) => {
70
+ expectTypeOf(extra).toEqualTypeOf();
71
+ expectTypeOf(_request.params).toEqualTypeOf();
72
+ return next();
73
+ });
74
+ });
75
+ //# sourceMappingURL=middleware.test-d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.test-d.js","sourceRoot":"","sources":["../../src/server/middleware.test-d.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAQ5C,MAAM,MAAM,GAAG,IAA4B,CAAC;AAE5C,IAAI,CAAC,kDAAkD,EAAE,GAAG,EAAE;IAC5D,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC9D,YAAY,CAAC,KAAK,CAAC,CAAC,aAAa,EAAY,CAAC;QAC9C,KAAK,CAAC,MAAM,CAAC;QACb,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAC5B,YAAY,CAAC,MAAM,CAAC,CAAC,aAAa,EAAgB,CAAC;QACnD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uDAAuD,EAAE,GAAG,EAAE;IACjE,MAAM,CAAC,aAAa,CAAC,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACnE,YAAY,CAAC,KAAK,CAAC,CAAC,aAAa,EAAa,CAAC;QAC/C,6DAA6D;QAC7D,KAAK,CAAC,MAAM,CAAC;QACb,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAC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B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import type {\n CallToolResult,\n ListToolsResult,\n ServerResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { expectTypeOf, test } from \"vitest\";\nimport type {\n McpExtra,\n McpResultFor,\n McpTypedMiddlewareFn,\n} from \"./middleware.js\";\nimport type { McpServer } from \"./server.js\";\n\nconst server = null as unknown as McpServer;\n\ntest(\"request category narrows extra and next() result\", () => {\n server.mcpMiddleware(\"request\", async (_request, extra, next) => {\n expectTypeOf(extra).toEqualTypeOf<McpExtra>();\n extra.signal;\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<ServerResult>();\n return result;\n });\n});\n\ntest(\"notification category narrows extra and next() result\", () => {\n server.mcpMiddleware(\"notification\", async (_request, extra, next) => {\n expectTypeOf(extra).toEqualTypeOf<undefined>();\n // @ts-expect-error extra is undefined, cannot access .signal\n extra.signal;\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<undefined>();\n });\n});\n\ntest(\"exact method tools/call narrows params, extra, and next() result\", () => {\n server.mcpMiddleware(\"tools/call\", async (request, extra, next) => {\n expectTypeOf(request.params.name).toBeString();\n expectTypeOf(extra).toEqualTypeOf<McpExtra>();\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<CallToolResult>();\n return result;\n });\n});\n\ntest(\"exact method tools/list narrows next() to ListToolsResult\", () => {\n server.mcpMiddleware(\"tools/list\", async (_request, _extra, next) => {\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<ListToolsResult>();\n return result;\n });\n});\n\ntest(\"exact notification method narrows extra and next() result\", () => {\n server.mcpMiddleware(\n \"notifications/initialized\",\n async (_request, extra, next) => {\n expectTypeOf(extra).toEqualTypeOf<undefined>();\n // @ts-expect-error extra is undefined\n extra.signal;\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<undefined>();\n },\n );\n});\n\ntest(\"McpTypedMiddlewareFn narrows params, extra, and next() per method\", () => {\n expectTypeOf<\n Parameters<McpTypedMiddlewareFn<\"tools/call\">>[0][\"params\"][\"name\"]\n >().toBeString();\n expectTypeOf<\n Parameters<McpTypedMiddlewareFn<\"tools/call\">>[1]\n >().toEqualTypeOf<McpExtra>();\n expectTypeOf<\n Parameters<McpTypedMiddlewareFn<\"notifications/initialized\">>[1]\n >().toEqualTypeOf<undefined>();\n expectTypeOf<\n ReturnType<Parameters<McpTypedMiddlewareFn<\"tools/list\">>[2]>\n >().toEqualTypeOf<Promise<ListToolsResult>>();\n expectTypeOf<\n ReturnType<Parameters<McpTypedMiddlewareFn<\"notifications/initialized\">>[2]>\n >().toEqualTypeOf<Promise<undefined>>();\n});\n\ntest(\"McpResultFor maps methods to correct result types\", () => {\n expectTypeOf<McpResultFor<\"tools/list\">>().toEqualTypeOf<ListToolsResult>();\n expectTypeOf<McpResultFor<\"tools/call\">>().toEqualTypeOf<CallToolResult>();\n expectTypeOf<\n McpResultFor<\"notifications/initialized\">\n >().toEqualTypeOf<undefined>();\n});\n\ntest(\"wildcard tools/* narrows next() to union of tools result types\", () => {\n server.mcpMiddleware(\"tools/*\", async (_request, _extra, next) => {\n const result = await next();\n expectTypeOf(result).toEqualTypeOf<ListToolsResult | CallToolResult>();\n return result;\n });\n});\n\ntest(\"McpResultFor resolves wildcards to union of matching result types\", () => {\n expectTypeOf<McpResultFor<\"tools/*\">>().toEqualTypeOf<\n ListToolsResult | CallToolResult\n >();\n});\n\ntest(\"catch-all middleware has no narrowing on extra or params\", () => {\n server.mcpMiddleware((_request, extra, next) => {\n expectTypeOf(extra).toEqualTypeOf<McpExtra | undefined>();\n expectTypeOf(_request.params).toEqualTypeOf<Record<string, unknown>>();\n return next();\n });\n});\n"]}
@@ -0,0 +1 @@
1
+ export {};