skybridge 0.0.0-dev.e9705ff → 0.0.0-dev.e9be772
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.
- package/LICENSE +21 -674
- package/README.md +86 -352
- package/bin/run.js +5 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +61 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.d.ts +4 -0
- package/dist/cli/header.js +6 -0
- package/dist/cli/header.js.map +1 -0
- package/dist/cli/run-command.d.ts +2 -0
- package/dist/cli/run-command.js +43 -0
- package/dist/cli/run-command.js.map +1 -0
- package/dist/cli/telemetry.d.ts +7 -0
- package/dist/cli/telemetry.js +123 -0
- package/dist/cli/telemetry.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +11 -0
- package/dist/cli/use-execute-steps.js +36 -0
- package/dist/cli/use-execute-steps.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +7 -0
- package/dist/cli/use-nodemon.js +76 -0
- package/dist/cli/use-nodemon.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +8 -0
- package/dist/cli/use-typescript-check.js +59 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +9 -0
- package/dist/commands/build.js +46 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/dev.d.ts +9 -0
- package/dist/commands/dev.js +36 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +9 -0
- package/dist/commands/start.js +52 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +14 -0
- package/dist/commands/telemetry/disable.js.map +1 -0
- package/dist/commands/telemetry/enable.d.ts +5 -0
- package/dist/commands/telemetry/enable.js +14 -0
- package/dist/commands/telemetry/enable.js.map +1 -0
- package/dist/commands/telemetry/status.d.ts +5 -0
- package/dist/commands/telemetry/status.js +14 -0
- package/dist/commands/telemetry/status.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
- package/dist/server/asset-base-url-transform-plugin.js +34 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +56 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/express.d.ts +11 -0
- package/dist/server/express.js +72 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.js +80 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js.map +1 -0
- package/dist/{src/server → server}/inferUtilityTypes.d.ts +10 -0
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/server/middleware.d.ts +124 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.js +383 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +147 -0
- package/dist/server/server.js +275 -0
- package/dist/server/server.js.map +1 -0
- package/dist/{src/server → server}/templateHelper.d.ts +3 -0
- package/dist/{src/server → server}/templateHelper.js +5 -4
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates/development.hbs +12 -0
- package/dist/{src/server → server}/templates/production.hbs +1 -1
- package/dist/{src/server → server}/widgetsDevServer.d.ts +3 -2
- package/dist/server/widgetsDevServer.js +57 -0
- package/dist/server/widgetsDevServer.js.map +1 -0
- package/dist/{src/test → test}/utils.d.ts +54 -8
- package/dist/{src/test → test}/utils.js +86 -8
- package/dist/test/utils.js.map +1 -0
- package/dist/test/widget.test.js +263 -0
- package/dist/test/widget.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +22 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +75 -0
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +10 -0
- package/dist/web/bridges/apps-sdk/bridge.js +46 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
- package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
- package/dist/web/bridges/apps-sdk/index.js +5 -0
- package/dist/web/bridges/apps-sdk/index.js.map +1 -0
- package/dist/{src/web → web/bridges/apps-sdk}/types.d.ts +37 -49
- package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
- package/dist/web/bridges/apps-sdk/types.js.map +1 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +7 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
- package/dist/web/bridges/get-adaptor.d.ts +2 -0
- package/dist/web/bridges/get-adaptor.js +8 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -0
- package/dist/web/bridges/index.d.ts +5 -0
- package/dist/web/bridges/index.js +6 -0
- package/dist/web/bridges/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/adaptor.d.ts +38 -0
- package/dist/web/bridges/mcp-app/adaptor.js +184 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +26 -0
- package/dist/web/bridges/mcp-app/bridge.js +102 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +4 -0
- package/dist/web/bridges/mcp-app/index.js +4 -0
- package/dist/web/bridges/mcp-app/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/types.d.ts +8 -0
- package/dist/web/bridges/mcp-app/types.js +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +7 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +7 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +26 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +102 -0
- package/dist/web/bridges/types.js +2 -0
- package/dist/web/bridges/types.js.map +1 -0
- package/dist/web/bridges/use-host-context.d.ts +2 -0
- package/dist/web/bridges/use-host-context.js +8 -0
- package/dist/web/bridges/use-host-context.js.map +1 -0
- package/dist/web/components/modal-provider.d.ts +4 -0
- package/dist/web/components/modal-provider.js +47 -0
- package/dist/web/components/modal-provider.js.map +1 -0
- package/dist/web/create-store.js +24 -0
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.js +131 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/{src/web → web}/data-llm.js +11 -7
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.js +142 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.d.ts +11 -8
- package/dist/{src/web → web}/generate-helpers.js +5 -3
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test-d.js +59 -3
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test.js +1 -1
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/{src/web → web}/helpers/state.js +14 -9
- package/dist/web/helpers/state.js.map +1 -0
- package/dist/{src/web → web}/helpers/state.test.js +19 -12
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/web/hooks/index.d.ts +11 -0
- package/dist/{src/web → web}/hooks/index.js +3 -4
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +16 -0
- package/dist/web/hooks/test/utils.js +64 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.d.ts +3 -2
- package/dist/{src/web → web}/hooks/use-call-tool.js +12 -4
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test.js +35 -16
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +4 -0
- package/dist/web/hooks/use-display-mode.js +9 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-display-mode.test.js +3 -2
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +6 -0
- package/dist/web/hooks/use-files.js +9 -0
- package/dist/web/hooks/use-files.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-files.test.js +11 -6
- package/dist/web/hooks/use-files.test.js.map +1 -0
- package/dist/web/hooks/use-layout.d.ts +22 -0
- package/dist/web/hooks/use-layout.js +23 -0
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.js +96 -0
- package/dist/web/hooks/use-layout.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.d.ts +3 -0
- package/dist/web/hooks/use-open-external.js +8 -0
- package/dist/web/hooks/use-open-external.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.js +65 -0
- package/dist/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +9 -0
- package/dist/web/hooks/use-request-modal.js +16 -0
- package/dist/web/hooks/use-request-modal.js.map +1 -0
- package/dist/web/hooks/use-request-modal.test.js +57 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.js +8 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +8 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js +43 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.d.ts +13 -2
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +40 -5
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/web/hooks/use-tool-info.test.js +130 -0
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/web/hooks/use-user.d.ts +18 -0
- package/dist/web/hooks/use-user.js +19 -0
- package/dist/web/hooks/use-user.js.map +1 -0
- package/dist/web/hooks/use-user.test.d.ts +1 -0
- package/dist/web/hooks/use-user.test.js +94 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-widget-state.js +11 -11
- package/dist/web/hooks/use-widget-state.js.map +1 -0
- package/dist/web/hooks/use-widget-state.test.d.ts +1 -0
- package/dist/{src/web → web}/hooks/use-widget-state.test.js +12 -8
- package/dist/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/{src/web → web}/index.d.ts +5 -4
- package/dist/{src/web → web}/index.js +5 -4
- package/dist/web/index.js.map +1 -0
- package/dist/{src/web → web}/mount-widget.js +9 -1
- package/dist/web/mount-widget.js.map +1 -0
- package/dist/web/plugin/data-llm.test.d.ts +1 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -0
- package/dist/web/plugin/plugin.js +54 -0
- package/dist/web/plugin/plugin.js.map +1 -0
- package/dist/{src/web → web}/plugin/transform-data-llm.js +6 -3
- package/dist/web/plugin/transform-data-llm.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.test.d.ts +1 -0
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
- package/dist/web/plugin/validate-widget.d.ts +5 -0
- package/dist/web/plugin/validate-widget.js +27 -0
- package/dist/web/plugin/validate-widget.js.map +1 -0
- package/dist/web/plugin/validate-widget.test.d.ts +1 -0
- package/dist/web/plugin/validate-widget.test.js +42 -0
- package/dist/web/plugin/validate-widget.test.js.map +1 -0
- package/dist/{src/web → web}/proxy.js +6 -2
- package/dist/web/proxy.js.map +1 -0
- package/dist/web/types.d.ts +16 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +67 -36
- package/tsconfig.base.json +28 -0
- package/dist/src/server/index.d.ts +0 -4
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/inferUtilityTypes.js.map +0 -1
- package/dist/src/server/server.d.ts +0 -48
- package/dist/src/server/server.js +0 -62
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -12
- package/dist/src/server/widgetsDevServer.js +0 -39
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -90
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/create-store.js +0 -25
- package/dist/src/web/create-store.js.map +0 -1
- package/dist/src/web/create-store.test.js +0 -70
- package/dist/src/web/create-store.test.js.map +0 -1
- package/dist/src/web/data-llm.js.map +0 -1
- package/dist/src/web/data-llm.test.js +0 -76
- package/dist/src/web/data-llm.test.js.map +0 -1
- package/dist/src/web/generate-helpers.js.map +0 -1
- package/dist/src/web/generate-helpers.test-d.js.map +0 -1
- package/dist/src/web/generate-helpers.test.js.map +0 -1
- package/dist/src/web/helpers/state.js.map +0 -1
- package/dist/src/web/helpers/state.test.js.map +0 -1
- package/dist/src/web/hooks/index.d.ts +0 -12
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.d.ts +0 -4
- package/dist/src/web/hooks/use-display-mode.js +0 -7
- package/dist/src/web/hooks/use-display-mode.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
- package/dist/src/web/hooks/use-files.d.ts +0 -10
- package/dist/src/web/hooks/use-files.js +0 -7
- package/dist/src/web/hooks/use-files.js.map +0 -1
- package/dist/src/web/hooks/use-files.test.js.map +0 -1
- package/dist/src/web/hooks/use-locale.d.ts +0 -1
- package/dist/src/web/hooks/use-locale.js +0 -5
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -21
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.d.ts +0 -1
- package/dist/src/web/hooks/use-open-external.js +0 -6
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js +0 -24
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -2
- package/dist/src/web/hooks/use-openai-global.js +0 -23
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -6
- package/dist/src/web/hooks/use-request-modal.js +0 -9
- package/dist/src/web/hooks/use-request-modal.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.test.js +0 -24
- package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -5
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -26
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.js +0 -22
- package/dist/src/web/hooks/use-tool-info.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test.js +0 -59
- package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.js +0 -5
- package/dist/src/web/hooks/use-user-agent.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.test.js +0 -31
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/src/web/index.js.map +0 -1
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/plugin/data-llm.test.js.map +0 -1
- package/dist/src/web/plugin/plugin.js +0 -33
- package/dist/src/web/plugin/plugin.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/src/web/proxy.js.map +0 -1
- package/dist/src/web/types.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -8
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/test/widget.test.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/web/create-store.test.d.ts → server/express.test.d.ts} +0 -0
- /package/dist/{src/server → server}/index.js +0 -0
- /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
- /package/dist/{src/web/data-llm.test.d.ts → server/middleware.test-d.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test-d.d.ts → server/middleware.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test.d.ts → test/widget.test.d.ts} +0 -0
- /package/dist/{src/web/helpers/state.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
- /package/dist/{src/web → web}/create-store.d.ts +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → web/create-store.test.d.ts} +0 -0
- /package/dist/{src/web → web}/data-llm.d.ts +0 -0
- /package/dist/{src/web/plugin → web}/data-llm.test.d.ts +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → web/generate-helpers.test.d.ts} +0 -0
- /package/dist/{src/web → web}/helpers/state.d.ts +0 -0
- /package/dist/{src/web/hooks/use-files.test.d.ts → web/helpers/state.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-locale.test.d.ts → web/hooks/use-call-tool.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-open-external.test.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/hooks/use-display-mode.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-theme.test.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → web/hooks/use-files.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/hooks/use-layout.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-user-agent.test.d.ts → web/hooks/use-open-external.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/hooks/use-request-modal.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
- /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → web/hooks/use-set-open-in-app-url.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-widget-state.d.ts +0 -0
- /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/data-llm.test.js +0 -0
- /package/dist/{src/web → web}/plugin/plugin.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.test.js +0 -0
- /package/dist/{src/web → web}/pro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CAAC;AAEH,IAAI,CAAC,mDAAmD,EAAE,GAAG,EAAE;IAC7D,YAAY,EAA8B,CAAC,aAAa,EAAmB,CAAC;IAC5E,YAAY,EAA8B,CAAC,aAAa,EAAkB,CAAC;IAC3E,YAAY,EAET,CAAC,aAAa,EAAa,CAAC;AACjC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,gEAAgE,EAAE,GAAG,EAAE;IAC1E,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QAC/D,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAC5B,YAAY,CAAC,MAAM,CAAC,CAAC,aAAa,EAAoC,CAAC;QACvE,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mEAAmE,EAAE,GAAG,EAAE;IAC7E,YAAY,EAA2B,CAAC,aAAa,EAElD,CAAC;AACN,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0DAA0D,EAAE,GAAG,EAAE;IACpE,MAAM,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC7C,YAAY,CAAC,KAAK,CAAC,CAAC,aAAa,EAAwB,CAAC;QAC1D,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,aAAa,EAA2B,CAAC;QACvE,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { buildMiddlewareChain, getHandlerMaps, matchesFilter, } from "./middleware.js";
|
|
6
|
+
import { McpServer } from "./server.js";
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// matchesFilter
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
describe("matchesFilter", () => {
|
|
11
|
+
it("matches exact method", () => {
|
|
12
|
+
expect(matchesFilter("tools/call", "tools/call", false)).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
it("rejects non-matching exact method", () => {
|
|
15
|
+
expect(matchesFilter("tools/list", "tools/call", false)).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
it("matches wildcard", () => {
|
|
18
|
+
expect(matchesFilter("tools/call", "tools/*", false)).toBe(true);
|
|
19
|
+
expect(matchesFilter("tools/list", "tools/*", false)).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
it("rejects non-matching wildcard", () => {
|
|
22
|
+
expect(matchesFilter("resources/read", "tools/*", false)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
it('category "request" matches when isNotification=false', () => {
|
|
25
|
+
expect(matchesFilter("tools/call", "request", false)).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it('category "request" rejects when isNotification=true', () => {
|
|
28
|
+
expect(matchesFilter("notifications/initialized", "request", true)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
it('category "notification" matches when isNotification=true', () => {
|
|
31
|
+
expect(matchesFilter("notifications/initialized", "notification", true)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
it('category "notification" rejects when isNotification=false', () => {
|
|
34
|
+
expect(matchesFilter("tools/call", "notification", false)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// buildMiddlewareChain
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
describe("buildMiddlewareChain", () => {
|
|
41
|
+
const fakeExtra = {};
|
|
42
|
+
const makeHandler = (returnValue) => vi.fn(async () => returnValue);
|
|
43
|
+
const makeEntry = (filter, handler) => ({ filter, handler });
|
|
44
|
+
it("returns original handler when no middleware applies", () => {
|
|
45
|
+
const original = makeHandler("result");
|
|
46
|
+
const chain = buildMiddlewareChain("tools/call", false, original, [
|
|
47
|
+
makeEntry("resources/*", async (_req, _extra, next) => next()),
|
|
48
|
+
]);
|
|
49
|
+
expect(chain).toBe(original);
|
|
50
|
+
});
|
|
51
|
+
it("catch-all middleware runs for any method", async () => {
|
|
52
|
+
const original = makeHandler("ok");
|
|
53
|
+
const spy = vi.fn();
|
|
54
|
+
const chain = buildMiddlewareChain("tools/call", false, original, [
|
|
55
|
+
makeEntry(null, async (request, _extra, next) => {
|
|
56
|
+
spy(request.method);
|
|
57
|
+
return next();
|
|
58
|
+
}),
|
|
59
|
+
]);
|
|
60
|
+
const result = await chain({ method: "tools/call", params: {} }, fakeExtra);
|
|
61
|
+
expect(spy).toHaveBeenCalledWith("tools/call");
|
|
62
|
+
expect(result).toBe("ok");
|
|
63
|
+
});
|
|
64
|
+
it("method-scoped middleware only runs for matching methods", async () => {
|
|
65
|
+
const original = makeHandler("ok");
|
|
66
|
+
const spy = vi.fn();
|
|
67
|
+
const entries = [
|
|
68
|
+
makeEntry("tools/call", async (_req, _extra, next) => {
|
|
69
|
+
spy("tools/call");
|
|
70
|
+
return next();
|
|
71
|
+
}),
|
|
72
|
+
];
|
|
73
|
+
// Matching
|
|
74
|
+
const chain1 = buildMiddlewareChain("tools/call", false, original, entries);
|
|
75
|
+
await chain1({ method: "tools/call", params: {} }, fakeExtra);
|
|
76
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
77
|
+
// Non-matching — returns original handler directly
|
|
78
|
+
const chain2 = buildMiddlewareChain("tools/list", false, original, entries);
|
|
79
|
+
expect(chain2).toBe(original);
|
|
80
|
+
});
|
|
81
|
+
it("executes middleware in registration order (onion model)", async () => {
|
|
82
|
+
const calls = [];
|
|
83
|
+
const original = makeHandler("result");
|
|
84
|
+
const chain = buildMiddlewareChain("tools/call", false, original, [
|
|
85
|
+
makeEntry(null, async (_req, _extra, next) => {
|
|
86
|
+
calls.push("A:before");
|
|
87
|
+
const result = await next();
|
|
88
|
+
calls.push("A:after");
|
|
89
|
+
return result;
|
|
90
|
+
}),
|
|
91
|
+
makeEntry(null, async (_req, _extra, next) => {
|
|
92
|
+
calls.push("B:before");
|
|
93
|
+
const result = await next();
|
|
94
|
+
calls.push("B:after");
|
|
95
|
+
return result;
|
|
96
|
+
}),
|
|
97
|
+
]);
|
|
98
|
+
await chain({ method: "tools/call", params: {} }, fakeExtra);
|
|
99
|
+
expect(calls).toEqual(["A:before", "B:before", "B:after", "A:after"]);
|
|
100
|
+
});
|
|
101
|
+
it("short-circuit (no next() call) skips handler", async () => {
|
|
102
|
+
const original = makeHandler("original");
|
|
103
|
+
const chain = buildMiddlewareChain("tools/call", false, original, [
|
|
104
|
+
makeEntry(null, async () => "short-circuited"),
|
|
105
|
+
]);
|
|
106
|
+
const result = await chain({ method: "tools/call", params: {} }, fakeExtra);
|
|
107
|
+
expect(result).toBe("short-circuited");
|
|
108
|
+
expect(original).not.toHaveBeenCalled();
|
|
109
|
+
});
|
|
110
|
+
it("middleware can modify result post-next()", async () => {
|
|
111
|
+
const original = makeHandler({ value: 1 });
|
|
112
|
+
const chain = buildMiddlewareChain("tools/call", false, original, [
|
|
113
|
+
makeEntry(null, async (_req, _extra, next) => {
|
|
114
|
+
const result = (await next());
|
|
115
|
+
return { value: result.value + 10 };
|
|
116
|
+
}),
|
|
117
|
+
]);
|
|
118
|
+
const result = await chain({ method: "tools/call", params: {} }, fakeExtra);
|
|
119
|
+
expect(result).toEqual({ value: 11 });
|
|
120
|
+
});
|
|
121
|
+
it("throws on double next() call", async () => {
|
|
122
|
+
const original = makeHandler("ok");
|
|
123
|
+
const chain = buildMiddlewareChain("tools/call", false, original, [
|
|
124
|
+
makeEntry(null, async (_req, _extra, next) => {
|
|
125
|
+
await next();
|
|
126
|
+
return next(); // double call
|
|
127
|
+
}),
|
|
128
|
+
]);
|
|
129
|
+
await expect(chain({ method: "tools/call", params: {} }, fakeExtra)).rejects.toThrow("next() called multiple times");
|
|
130
|
+
});
|
|
131
|
+
it("propagates errors from handler and middleware", async () => {
|
|
132
|
+
// Error from original handler bubbles through middleware
|
|
133
|
+
const failingHandler = vi.fn(async () => {
|
|
134
|
+
throw new Error("handler boom");
|
|
135
|
+
});
|
|
136
|
+
const chain1 = buildMiddlewareChain("tools/call", false, failingHandler, [
|
|
137
|
+
makeEntry(null, async (_req, _extra, next) => next()),
|
|
138
|
+
]);
|
|
139
|
+
await expect(chain1({ method: "tools/call", params: {} }, fakeExtra)).rejects.toThrow("handler boom");
|
|
140
|
+
// Error thrown inside middleware propagates
|
|
141
|
+
const chain2 = buildMiddlewareChain("tools/call", false, makeHandler("ok"), [
|
|
142
|
+
makeEntry(null, async () => {
|
|
143
|
+
throw new Error("middleware boom");
|
|
144
|
+
}),
|
|
145
|
+
]);
|
|
146
|
+
await expect(chain2({ method: "tools/call", params: {} }, fakeExtra)).rejects.toThrow("middleware boom");
|
|
147
|
+
});
|
|
148
|
+
it("passes extra as undefined for notifications (isNotification=true)", async () => {
|
|
149
|
+
const original = makeHandler(undefined);
|
|
150
|
+
let capturedExtra = {};
|
|
151
|
+
const chain = buildMiddlewareChain("notifications/initialized", true, original, [
|
|
152
|
+
makeEntry(null, async (_req, extra, next) => {
|
|
153
|
+
capturedExtra = extra;
|
|
154
|
+
return next();
|
|
155
|
+
}),
|
|
156
|
+
]);
|
|
157
|
+
await chain({ method: "notifications/initialized" });
|
|
158
|
+
expect(capturedExtra).toBeUndefined();
|
|
159
|
+
});
|
|
160
|
+
it("defaults params to empty object when rawRequest has no params", async () => {
|
|
161
|
+
const original = makeHandler("ok");
|
|
162
|
+
let capturedParams;
|
|
163
|
+
const chain = buildMiddlewareChain("tools/call", false, original, [
|
|
164
|
+
makeEntry(null, async (request, _extra, next) => {
|
|
165
|
+
capturedParams = request.params;
|
|
166
|
+
return next();
|
|
167
|
+
}),
|
|
168
|
+
]);
|
|
169
|
+
await chain({ method: "tools/call" }, fakeExtra);
|
|
170
|
+
expect(capturedParams).toEqual({});
|
|
171
|
+
});
|
|
172
|
+
it("propagates in-place param mutation to original handler", async () => {
|
|
173
|
+
let handlerReceivedName = "";
|
|
174
|
+
const original = vi.fn(async (rawReq) => {
|
|
175
|
+
handlerReceivedName = rawReq.params.name;
|
|
176
|
+
return "ok";
|
|
177
|
+
});
|
|
178
|
+
const chain = buildMiddlewareChain("tools/call", false, original, [
|
|
179
|
+
makeEntry(null, async (request, _extra, next) => {
|
|
180
|
+
request.params.name = "mutated";
|
|
181
|
+
return next();
|
|
182
|
+
}),
|
|
183
|
+
]);
|
|
184
|
+
await chain({ params: { name: "original" } }, fakeExtra);
|
|
185
|
+
expect(handlerReceivedName).toBe("mutated");
|
|
186
|
+
});
|
|
187
|
+
it("propagates full param replacement to original handler", async () => {
|
|
188
|
+
let handlerReceivedParams = {};
|
|
189
|
+
const original = vi.fn(async (rawReq) => {
|
|
190
|
+
handlerReceivedParams = rawReq.params;
|
|
191
|
+
return "ok";
|
|
192
|
+
});
|
|
193
|
+
const chain = buildMiddlewareChain("tools/call", false, original, [
|
|
194
|
+
makeEntry(null, async (request, _extra, next) => {
|
|
195
|
+
request.params = { replaced: true };
|
|
196
|
+
return next();
|
|
197
|
+
}),
|
|
198
|
+
]);
|
|
199
|
+
await chain({ params: { original: true } }, fakeExtra);
|
|
200
|
+
expect(handlerReceivedParams).toEqual({ replaced: true });
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
// McpServer.mcpMiddleware() integration tests
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
describe("McpServer.mcpMiddleware()", () => {
|
|
207
|
+
function createClient() {
|
|
208
|
+
return new Client({ name: "test-client", version: "1.0.0" });
|
|
209
|
+
}
|
|
210
|
+
it("returns this for chaining", () => {
|
|
211
|
+
const server = new McpServer({ name: "test", version: "1.0.0" });
|
|
212
|
+
const result = server.mcpMiddleware(async (_req, _extra, next) => next());
|
|
213
|
+
expect(result).toBe(server);
|
|
214
|
+
});
|
|
215
|
+
it("intercepts tools/call and exposes request params", async () => {
|
|
216
|
+
let capturedMethod = "";
|
|
217
|
+
let capturedParams = {};
|
|
218
|
+
const server = new McpServer({ name: "test", version: "1.0.0" });
|
|
219
|
+
server.registerTool("greet", {
|
|
220
|
+
description: "greet",
|
|
221
|
+
inputSchema: { name: z.string() },
|
|
222
|
+
}, (args) => ({
|
|
223
|
+
content: [{ type: "text", text: `hi ${args.name}` }],
|
|
224
|
+
}));
|
|
225
|
+
server.mcpMiddleware("tools/call", async (request, _extra, next) => {
|
|
226
|
+
capturedMethod = request.method;
|
|
227
|
+
capturedParams = request.params;
|
|
228
|
+
return next();
|
|
229
|
+
});
|
|
230
|
+
const client = createClient();
|
|
231
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
232
|
+
await server.connect(serverTransport);
|
|
233
|
+
await client.connect(clientTransport);
|
|
234
|
+
const result = await client.callTool({
|
|
235
|
+
name: "greet",
|
|
236
|
+
arguments: { name: "World" },
|
|
237
|
+
});
|
|
238
|
+
expect(capturedMethod).toBe("tools/call");
|
|
239
|
+
expect(capturedParams).toMatchObject({
|
|
240
|
+
name: "greet",
|
|
241
|
+
arguments: { name: "World" },
|
|
242
|
+
});
|
|
243
|
+
expect(result.content).toEqual([{ type: "text", text: "hi World" }]);
|
|
244
|
+
await client.close();
|
|
245
|
+
await server.close();
|
|
246
|
+
});
|
|
247
|
+
it("array filter works", async () => {
|
|
248
|
+
const matchedMethods = [];
|
|
249
|
+
const server = new McpServer({ name: "test", version: "1.0.0" });
|
|
250
|
+
server.registerTool("t1", { description: "t1" }, () => ({
|
|
251
|
+
content: [{ type: "text", text: "ok" }],
|
|
252
|
+
}));
|
|
253
|
+
server.mcpMiddleware(["tools/call", "tools/list"], async (request, _extra, next) => {
|
|
254
|
+
matchedMethods.push(request.method);
|
|
255
|
+
return next();
|
|
256
|
+
});
|
|
257
|
+
const client = createClient();
|
|
258
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
259
|
+
await server.connect(serverTransport);
|
|
260
|
+
await client.connect(clientTransport);
|
|
261
|
+
await client.listTools();
|
|
262
|
+
await client.callTool({ name: "t1" });
|
|
263
|
+
expect(matchedMethods).toEqual(["tools/list", "tools/call"]);
|
|
264
|
+
await client.close();
|
|
265
|
+
await server.close();
|
|
266
|
+
});
|
|
267
|
+
it("throws if registered after connect()", async () => {
|
|
268
|
+
const server = new McpServer({ name: "test", version: "1.0.0" });
|
|
269
|
+
const [_clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
270
|
+
await server.connect(serverTransport);
|
|
271
|
+
expect(() => server.mcpMiddleware(async (_req, _extra, next) => next())).toThrow("Cannot register MCP middleware after run() or connect()");
|
|
272
|
+
await server.close();
|
|
273
|
+
});
|
|
274
|
+
it("throws when filter provided without handler", () => {
|
|
275
|
+
const server = new McpServer({ name: "test", version: "1.0.0" });
|
|
276
|
+
expect(() =>
|
|
277
|
+
// @ts-expect-error intentionally passing filter without handler
|
|
278
|
+
server.mcpMiddleware("tools/call")).toThrow("mcpMiddleware requires a handler function");
|
|
279
|
+
});
|
|
280
|
+
it("catch-all middleware + filtered middleware stack correctly", async () => {
|
|
281
|
+
const calls = [];
|
|
282
|
+
const server = new McpServer({ name: "test", version: "1.0.0" });
|
|
283
|
+
server.registerTool("t1", { description: "t1" }, () => ({
|
|
284
|
+
content: [{ type: "text", text: "ok" }],
|
|
285
|
+
}));
|
|
286
|
+
server
|
|
287
|
+
.mcpMiddleware(async (request, _extra, next) => {
|
|
288
|
+
calls.push(`global:${request.method}`);
|
|
289
|
+
return next();
|
|
290
|
+
})
|
|
291
|
+
.mcpMiddleware("tools/call", async (_req, _extra, next) => {
|
|
292
|
+
calls.push("tools-only");
|
|
293
|
+
return next();
|
|
294
|
+
});
|
|
295
|
+
const client = createClient();
|
|
296
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
297
|
+
await server.connect(serverTransport);
|
|
298
|
+
await client.connect(clientTransport);
|
|
299
|
+
await client.listTools();
|
|
300
|
+
await client.callTool({ name: "t1" });
|
|
301
|
+
// Catch-all also intercepts initialize + notifications/initialized from handshake.
|
|
302
|
+
// tools/list: only global middleware runs
|
|
303
|
+
// tools/call: global + tools-only both run
|
|
304
|
+
expect(calls).toContain("global:tools/list");
|
|
305
|
+
expect(calls).toContain("global:tools/call");
|
|
306
|
+
expect(calls).toContain("tools-only");
|
|
307
|
+
// "tools-only" must come right after "global:tools/call"
|
|
308
|
+
const toolsCallIdx = calls.indexOf("global:tools/call");
|
|
309
|
+
expect(calls[toolsCallIdx + 1]).toBe("tools-only");
|
|
310
|
+
await client.close();
|
|
311
|
+
await server.close();
|
|
312
|
+
});
|
|
313
|
+
it("notification middleware receives extra as undefined", async () => {
|
|
314
|
+
let capturedExtra = "sentinel";
|
|
315
|
+
const server = new McpServer({ name: "test", version: "1.0.0" });
|
|
316
|
+
server.registerTool("t1", { description: "t1" }, () => ({
|
|
317
|
+
content: [{ type: "text", text: "ok" }],
|
|
318
|
+
}));
|
|
319
|
+
server.mcpMiddleware("notification", async (_request, extra, next) => {
|
|
320
|
+
capturedExtra = extra;
|
|
321
|
+
return next();
|
|
322
|
+
});
|
|
323
|
+
const client = createClient();
|
|
324
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
325
|
+
await server.connect(serverTransport);
|
|
326
|
+
await client.connect(clientTransport);
|
|
327
|
+
// The client sends notifications/initialized automatically on connect.
|
|
328
|
+
await client.listTools();
|
|
329
|
+
expect(capturedExtra).toBeUndefined();
|
|
330
|
+
await client.close();
|
|
331
|
+
await server.close();
|
|
332
|
+
});
|
|
333
|
+
it("category 'request' filter matches requests but not notifications", async () => {
|
|
334
|
+
const matchedMethods = [];
|
|
335
|
+
const server = new McpServer({ name: "test", version: "1.0.0" });
|
|
336
|
+
server.registerTool("t1", { description: "t1" }, () => ({
|
|
337
|
+
content: [{ type: "text", text: "ok" }],
|
|
338
|
+
}));
|
|
339
|
+
server.mcpMiddleware("request", async (request, _extra, next) => {
|
|
340
|
+
matchedMethods.push(request.method);
|
|
341
|
+
return next();
|
|
342
|
+
});
|
|
343
|
+
const client = createClient();
|
|
344
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
345
|
+
await server.connect(serverTransport);
|
|
346
|
+
await client.connect(clientTransport);
|
|
347
|
+
await client.listTools();
|
|
348
|
+
await client.callTool({ name: "t1" });
|
|
349
|
+
expect(matchedMethods).toContain("tools/list");
|
|
350
|
+
expect(matchedMethods).toContain("tools/call");
|
|
351
|
+
expect(matchedMethods).not.toContain("notifications/initialized");
|
|
352
|
+
await client.close();
|
|
353
|
+
await server.close();
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
// ---------------------------------------------------------------------------
|
|
357
|
+
// getHandlerMaps
|
|
358
|
+
// ---------------------------------------------------------------------------
|
|
359
|
+
describe("getHandlerMaps", () => {
|
|
360
|
+
it("throws for incompatible server objects", () => {
|
|
361
|
+
// Empty object
|
|
362
|
+
expect(() => getHandlerMaps({})).toThrow("Incompatible MCP SDK version");
|
|
363
|
+
// Only _requestHandlers (missing _notificationHandlers)
|
|
364
|
+
expect(() => getHandlerMaps({ _requestHandlers: new Map() })).toThrow("Incompatible MCP SDK version");
|
|
365
|
+
// Non-Map values
|
|
366
|
+
expect(() => getHandlerMaps({
|
|
367
|
+
_requestHandlers: {},
|
|
368
|
+
_notificationHandlers: {},
|
|
369
|
+
})).toThrow("Incompatible MCP SDK version");
|
|
370
|
+
});
|
|
371
|
+
it("returns handler maps from valid server", () => {
|
|
372
|
+
const reqMap = new Map();
|
|
373
|
+
const notifMap = new Map();
|
|
374
|
+
const fake = {
|
|
375
|
+
_requestHandlers: reqMap,
|
|
376
|
+
_notificationHandlers: notifMap,
|
|
377
|
+
};
|
|
378
|
+
const result = getHandlerMaps(fake);
|
|
379
|
+
expect(result.requestHandlers).toBe(reqMap);
|
|
380
|
+
expect(result.notificationHandlers).toBe(notifMap);
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
//# sourceMappingURL=middleware.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.test.js","sourceRoot":"","sources":["../../src/server/middleware.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,oBAAoB,EACpB,cAAc,EAId,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAC9E,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,sBAAsB,EAAE,GAAG,EAAE;QAC9B,MAAM,CAAC,aAAa,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,CAAC,aAAa,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC1B,MAAM,CAAC,aAAa,CAAC,YAAY,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,MAAM,CAAC,aAAa,CAAC,YAAY,EAAE,SAAS,EAAE,KAAK,CAA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AAgB,EAAE,IAAI,GAAG,EAAE,EAAW,CAAC,CACzD,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC;QAC1C,iBAAiB;QACjB,MAAM,CAAC,GAAG,EAAE,CACV,cAAc,CAAC;YACb,gBAAgB,EAAE,EAAE;YACpB,qBAAqB,EAAE,EAAE;SACjB,CAAC,CACZ,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG;YACX,gBAAgB,EAAE,MAAM;YACxB,qBAAqB,EAAE,QAAQ;SAChC,CAAC;QACF,MAAM,MAAM,GAAG,cAAc,CAAC,IAAa,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5C,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { McpUiResourceMeta } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import { McpServer as McpServerBase, type RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
4
|
+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
5
|
+
import type { CallToolResult, Resource, ServerNotification, ServerRequest, ServerResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import type { RequestHandler } from "express";
|
|
7
|
+
import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
|
|
8
|
+
export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
|
|
9
|
+
input: TInput;
|
|
10
|
+
output: TOutput;
|
|
11
|
+
responseMetadata: TResponseMetadata;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Extended MCP Apps CSP with upcoming fields from ext-apps PR #158
|
|
15
|
+
* and Skybridge-specific fields for OpenAI compatibility
|
|
16
|
+
* @see https://github.com/modelcontextprotocol/ext-apps/pull/158
|
|
17
|
+
*/
|
|
18
|
+
type ExtendedMcpUiResourceCsp = McpUiResourceMeta["csp"] & {
|
|
19
|
+
/**
|
|
20
|
+
* Origins that can receive openExternal redirects without safe-link modal (OpenAI-specific)
|
|
21
|
+
* @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields
|
|
22
|
+
*/
|
|
23
|
+
redirectDomains?: string[];
|
|
24
|
+
};
|
|
25
|
+
/** Extended MCP Apps resource metadata with upcoming CSP fields */
|
|
26
|
+
type ExtendedMcpUiResourceMeta = Omit<McpUiResourceMeta, "csp"> & {
|
|
27
|
+
csp?: ExtendedMcpUiResourceCsp;
|
|
28
|
+
};
|
|
29
|
+
/** User-provided resource configuration with optional CSP override */
|
|
30
|
+
export type WidgetResourceMeta = {
|
|
31
|
+
ui?: ExtendedMcpUiResourceMeta;
|
|
32
|
+
} & Resource["_meta"];
|
|
33
|
+
export type WidgetHostType = "apps-sdk" | "mcp-app";
|
|
34
|
+
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType" | "_meta"> & {
|
|
35
|
+
_meta?: WidgetResourceMeta;
|
|
36
|
+
/** Restrict host types to a specific subset */
|
|
37
|
+
hosts?: WidgetHostType[];
|
|
38
|
+
};
|
|
39
|
+
type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
|
|
40
|
+
type Simplify<T> = {
|
|
41
|
+
[K in keyof T]: T[K];
|
|
42
|
+
};
|
|
43
|
+
type ExtractStructuredContent<T> = T extends {
|
|
44
|
+
structuredContent: infer SC;
|
|
45
|
+
} ? Simplify<SC> : never;
|
|
46
|
+
type ExtractMeta<T> = [Extract<T, {
|
|
47
|
+
_meta: unknown;
|
|
48
|
+
}>] extends [never] ? unknown : Extract<T, {
|
|
49
|
+
_meta: unknown;
|
|
50
|
+
}> extends {
|
|
51
|
+
_meta: infer M;
|
|
52
|
+
} ? Simplify<M> : unknown;
|
|
53
|
+
/**
|
|
54
|
+
* Type-level marker interface for cross-package type inference.
|
|
55
|
+
* This enables TypeScript to infer tool types across package boundaries
|
|
56
|
+
* using structural typing on the $types property, rather than relying on
|
|
57
|
+
* class generic inference which fails when McpServer comes from different
|
|
58
|
+
* package installations.
|
|
59
|
+
*
|
|
60
|
+
* Inspired by tRPC's _def pattern and Hono's type markers.
|
|
61
|
+
*/
|
|
62
|
+
export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
|
|
63
|
+
readonly tools: TTools;
|
|
64
|
+
}
|
|
65
|
+
type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
66
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
67
|
+
} & {
|
|
68
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
69
|
+
}>;
|
|
70
|
+
type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
|
|
71
|
+
[K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
|
|
72
|
+
}>;
|
|
73
|
+
type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
|
|
74
|
+
title?: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
inputSchema?: TInput;
|
|
77
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
78
|
+
annotations?: ToolAnnotations;
|
|
79
|
+
_meta?: Record<string, unknown>;
|
|
80
|
+
};
|
|
81
|
+
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
|
|
82
|
+
content: CallToolResult["content"];
|
|
83
|
+
} = CallToolResult> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
|
|
84
|
+
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBase {
|
|
85
|
+
readonly $types: McpServerTypes<TTools>;
|
|
86
|
+
private express?;
|
|
87
|
+
private customMiddleware;
|
|
88
|
+
private mcpMiddlewareEntries;
|
|
89
|
+
private mcpMiddlewareApplied;
|
|
90
|
+
use(...handlers: RequestHandler[]): this;
|
|
91
|
+
use(path: string, ...handlers: RequestHandler[]): this;
|
|
92
|
+
/**
|
|
93
|
+
* Register MCP protocol-level middleware (catch-all).
|
|
94
|
+
*/
|
|
95
|
+
mcpMiddleware(handler: McpMiddlewareFn): this;
|
|
96
|
+
/**
|
|
97
|
+
* Register MCP protocol-level middleware for all requests (`extra` is `McpExtra`).
|
|
98
|
+
*/
|
|
99
|
+
mcpMiddleware(filter: "request", handler: (request: {
|
|
100
|
+
method: string;
|
|
101
|
+
params: Record<string, unknown>;
|
|
102
|
+
}, extra: McpExtra, next: () => Promise<ServerResult>) => Promise<unknown> | unknown): this;
|
|
103
|
+
/**
|
|
104
|
+
* Register MCP protocol-level middleware for all notifications (`extra` is `undefined`).
|
|
105
|
+
*/
|
|
106
|
+
mcpMiddleware(filter: "notification", handler: (request: {
|
|
107
|
+
method: string;
|
|
108
|
+
params: Record<string, unknown>;
|
|
109
|
+
}, extra: undefined, next: () => Promise<undefined>) => Promise<unknown> | unknown): this;
|
|
110
|
+
/**
|
|
111
|
+
* Register MCP protocol-level middleware for an exact method.
|
|
112
|
+
* Narrows `params`, `extra`, and `next()` result based on the method string.
|
|
113
|
+
*/
|
|
114
|
+
mcpMiddleware<M extends McpMethodString>(filter: M, handler: McpTypedMiddlewareFn<M>): this;
|
|
115
|
+
/**
|
|
116
|
+
* Register MCP protocol-level middleware for a wildcard pattern (e.g. `"tools/*"`).
|
|
117
|
+
* `next()` returns the union of result types for matching methods.
|
|
118
|
+
*/
|
|
119
|
+
mcpMiddleware<W extends McpWildcard>(filter: W, handler: (request: {
|
|
120
|
+
method: string;
|
|
121
|
+
params: Record<string, unknown>;
|
|
122
|
+
}, extra: McpExtraFor<W>, next: () => Promise<McpResultFor<W>>) => Promise<unknown> | unknown): this;
|
|
123
|
+
/**
|
|
124
|
+
* Register MCP protocol-level middleware with a method filter.
|
|
125
|
+
* Filter can be an exact method (`"tools/call"`), wildcard (`"tools/*"`),
|
|
126
|
+
* category (`"request"` | `"notification"`), or an array of those.
|
|
127
|
+
*/
|
|
128
|
+
mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;
|
|
129
|
+
private applyMcpMiddleware;
|
|
130
|
+
connect(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
131
|
+
run(): Promise<void>;
|
|
132
|
+
registerWidget<TName extends string, TInput extends ZodRawShapeCompat, TReturn extends {
|
|
133
|
+
content: CallToolResult["content"];
|
|
134
|
+
}>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
|
|
135
|
+
inputSchema?: TInput;
|
|
136
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
137
|
+
}, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
138
|
+
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
139
|
+
content: CallToolResult["content"];
|
|
140
|
+
}>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
141
|
+
registerTool<InputArgs extends ZodRawShapeCompat>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
|
|
142
|
+
private registerWidgetResource;
|
|
143
|
+
private lookupDistFile;
|
|
144
|
+
private lookupDistFileWithIndexFallback;
|
|
145
|
+
private readManifest;
|
|
146
|
+
}
|
|
147
|
+
export {};
|