@frontmcp/sdk 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -18
- package/package.json +20 -5
- package/src/app/app.registry.d.ts +3 -2
- package/src/app/app.registry.js +3 -1
- package/src/app/app.registry.js.map +1 -1
- package/src/app/instances/app.local.instance.js +2 -2
- package/src/app/instances/app.local.instance.js.map +1 -1
- package/src/auth/auth.registry.d.ts +34 -2
- package/src/auth/auth.registry.js +162 -24
- package/src/auth/auth.registry.js.map +1 -1
- package/src/auth/auth.utils.js +8 -9
- package/src/auth/auth.utils.js.map +1 -1
- package/src/auth/authorization/authorization.class.d.ts +125 -0
- package/src/auth/authorization/authorization.class.js +224 -0
- package/src/auth/authorization/authorization.class.js.map +1 -0
- package/src/auth/authorization/authorization.types.d.ts +300 -0
- package/src/auth/authorization/authorization.types.js +79 -0
- package/src/auth/authorization/authorization.types.js.map +1 -0
- package/src/auth/authorization/index.d.ts +5 -0
- package/src/auth/authorization/index.js +19 -0
- package/src/auth/authorization/index.js.map +1 -0
- package/src/auth/authorization/orchestrated.authorization.d.ts +242 -0
- package/src/auth/authorization/orchestrated.authorization.js +306 -0
- package/src/auth/authorization/orchestrated.authorization.js.map +1 -0
- package/src/auth/authorization/public.authorization.d.ts +91 -0
- package/src/auth/authorization/public.authorization.js +132 -0
- package/src/auth/authorization/public.authorization.js.map +1 -0
- package/src/auth/authorization/transparent.authorization.d.ts +130 -0
- package/src/auth/authorization/transparent.authorization.js +147 -0
- package/src/auth/authorization/transparent.authorization.js.map +1 -0
- package/src/auth/consent/consent.types.d.ts +111 -0
- package/src/auth/consent/consent.types.js +119 -0
- package/src/auth/consent/consent.types.js.map +1 -0
- package/src/auth/consent/index.d.ts +1 -0
- package/src/auth/consent/index.js +13 -0
- package/src/auth/consent/index.js.map +1 -0
- package/src/auth/detection/auth-provider-detection.d.ts +84 -0
- package/src/auth/detection/auth-provider-detection.js +230 -0
- package/src/auth/detection/auth-provider-detection.js.map +1 -0
- package/src/auth/detection/index.d.ts +1 -0
- package/src/auth/detection/index.js +15 -0
- package/src/auth/detection/index.js.map +1 -0
- package/src/auth/flows/auth.verify.flow.d.ts +110 -0
- package/src/auth/flows/auth.verify.flow.js +379 -0
- package/src/auth/flows/auth.verify.flow.js.map +1 -0
- package/src/auth/flows/oauth.authorize.flow.d.ts +118 -164
- package/src/auth/flows/oauth.authorize.flow.js +701 -33
- package/src/auth/flows/oauth.authorize.flow.js.map +1 -1
- package/src/auth/flows/oauth.callback.flow.d.ts +117 -0
- package/src/auth/flows/oauth.callback.flow.js +357 -0
- package/src/auth/flows/oauth.callback.flow.js.map +1 -0
- package/src/auth/flows/oauth.register.flow.d.ts +32 -125
- package/src/auth/flows/oauth.token.flow.d.ts +52 -154
- package/src/auth/flows/oauth.token.flow.js +193 -55
- package/src/auth/flows/oauth.token.flow.js.map +1 -1
- package/src/auth/flows/session.verify.flow.d.ts +66 -321
- package/src/auth/flows/session.verify.flow.js +107 -18
- package/src/auth/flows/session.verify.flow.js.map +1 -1
- package/src/auth/flows/well-known.jwks.flow.d.ts +34 -205
- package/src/auth/flows/well-known.jwks.flow.js +15 -8
- package/src/auth/flows/well-known.jwks.flow.js.map +1 -1
- package/src/auth/flows/well-known.oauth-authorization-server.flow.d.ts +48 -223
- package/src/auth/flows/well-known.oauth-authorization-server.flow.js +2 -3
- package/src/auth/flows/well-known.oauth-authorization-server.flow.js.map +1 -1
- package/src/auth/flows/well-known.prm.flow.d.ts +19 -120
- package/src/auth/flows/well-known.prm.flow.js +3 -4
- package/src/auth/flows/well-known.prm.flow.js.map +1 -1
- package/src/auth/instances/instance.local-primary-auth.d.ts +91 -4
- package/src/auth/instances/instance.local-primary-auth.js +236 -6
- package/src/auth/instances/instance.local-primary-auth.js.map +1 -1
- package/src/auth/instances/instance.remote-primary-auth.d.ts +4 -3
- package/src/auth/instances/instance.remote-primary-auth.js +2 -2
- package/src/auth/instances/instance.remote-primary-auth.js.map +1 -1
- package/src/auth/session/authorization-vault.d.ts +611 -0
- package/src/auth/session/authorization-vault.js +817 -0
- package/src/auth/session/authorization-vault.js.map +1 -0
- package/src/auth/session/authorization.store.d.ts +301 -0
- package/src/auth/session/authorization.store.js +323 -0
- package/src/auth/session/authorization.store.js.map +1 -0
- package/src/auth/session/encrypted-authorization-vault.d.ts +181 -0
- package/src/auth/session/encrypted-authorization-vault.js +493 -0
- package/src/auth/session/encrypted-authorization-vault.js.map +1 -0
- package/src/auth/session/index.d.ts +4 -4
- package/src/auth/session/index.js +11 -7
- package/src/auth/session/index.js.map +1 -1
- package/src/auth/session/session.schema.d.ts +1 -1
- package/src/auth/session/session.service.d.ts +1 -1
- package/src/auth/session/transport-session.manager.d.ts +101 -0
- package/src/auth/session/transport-session.manager.js +300 -0
- package/src/auth/session/transport-session.manager.js.map +1 -0
- package/src/auth/session/transport-session.types.d.ts +457 -0
- package/src/auth/session/transport-session.types.js +110 -0
- package/src/auth/session/transport-session.types.js.map +1 -0
- package/src/auth/session/utils/session-id.utils.d.ts +14 -2
- package/src/auth/session/utils/session-id.utils.js +68 -19
- package/src/auth/session/utils/session-id.utils.js.map +1 -1
- package/src/auth/session/vault-encryption.d.ts +189 -0
- package/src/auth/session/vault-encryption.js +263 -0
- package/src/auth/session/vault-encryption.js.map +1 -0
- package/src/auth/ui/base-layout.d.ts +188 -0
- package/src/auth/ui/base-layout.js +292 -0
- package/src/auth/ui/base-layout.js.map +1 -0
- package/src/auth/ui/htmx-templates.d.ts +135 -0
- package/src/auth/ui/htmx-templates.js +433 -0
- package/src/auth/ui/htmx-templates.js.map +1 -0
- package/src/auth/ui/index.d.ts +11 -0
- package/src/auth/ui/index.js +35 -0
- package/src/auth/ui/index.js.map +1 -0
- package/src/auth/utils/audience.validator.d.ts +129 -0
- package/src/auth/utils/audience.validator.js +196 -0
- package/src/auth/utils/audience.validator.js.map +1 -0
- package/src/auth/utils/index.d.ts +2 -0
- package/src/auth/utils/index.js +7 -0
- package/src/auth/utils/index.js.map +1 -0
- package/src/auth/utils/www-authenticate.utils.d.ts +97 -0
- package/src/auth/utils/www-authenticate.utils.js +183 -0
- package/src/auth/utils/www-authenticate.utils.js.map +1 -0
- package/src/common/common.schema.d.ts +2 -16
- package/src/common/constants.d.ts +3 -0
- package/src/common/constants.js +6 -1
- package/src/common/constants.js.map +1 -1
- package/src/common/decorators/decorator-utils.d.ts +131 -0
- package/src/common/decorators/decorator-utils.js +195 -0
- package/src/common/decorators/decorator-utils.js.map +1 -0
- package/src/common/decorators/front-mcp.decorator.js +3 -2
- package/src/common/decorators/front-mcp.decorator.js.map +1 -1
- package/src/common/decorators/hook.decorator.d.ts +58 -2
- package/src/common/decorators/hook.decorator.js +127 -17
- package/src/common/decorators/hook.decorator.js.map +1 -1
- package/src/common/decorators/plugin.decorator.d.ts +1 -1
- package/src/common/decorators/plugin.decorator.js +11 -10
- package/src/common/decorators/plugin.decorator.js.map +1 -1
- package/src/common/decorators/resource.decorator.d.ts +32 -3
- package/src/common/decorators/resource.decorator.js +46 -4
- package/src/common/decorators/resource.decorator.js.map +1 -1
- package/src/common/decorators/tool.decorator.d.ts +54 -5
- package/src/common/decorators/tool.decorator.js.map +1 -1
- package/src/common/dynamic/dynamic.plugin.d.ts +22 -11
- package/src/common/dynamic/dynamic.plugin.js +7 -1
- package/src/common/dynamic/dynamic.plugin.js.map +1 -1
- package/src/common/entries/prompt.entry.d.ts +46 -2
- package/src/common/entries/prompt.entry.js +10 -0
- package/src/common/entries/prompt.entry.js.map +1 -1
- package/src/common/entries/resource.entry.d.ts +69 -6
- package/src/common/entries/resource.entry.js +27 -3
- package/src/common/entries/resource.entry.js.map +1 -1
- package/src/common/entries/scope.entry.d.ts +5 -1
- package/src/common/entries/scope.entry.js +3 -3
- package/src/common/entries/scope.entry.js.map +1 -1
- package/src/common/flow/flow.utils.d.ts +56 -0
- package/src/common/flow/flow.utils.js +96 -0
- package/src/common/flow/flow.utils.js.map +1 -0
- package/src/common/index.d.ts +2 -2
- package/src/common/index.js +2 -2
- package/src/common/index.js.map +1 -1
- package/src/common/interfaces/execution-context.interface.d.ts +59 -0
- package/src/common/interfaces/execution-context.interface.js +81 -0
- package/src/common/interfaces/execution-context.interface.js.map +1 -0
- package/src/common/interfaces/flow.interface.d.ts +1 -1
- package/src/common/interfaces/flow.interface.js.map +1 -1
- package/src/common/interfaces/index.d.ts +1 -0
- package/src/common/interfaces/index.js +1 -0
- package/src/common/interfaces/index.js.map +1 -1
- package/src/common/interfaces/internal/primary-auth-provider.interface.d.ts +17 -2
- package/src/common/interfaces/internal/primary-auth-provider.interface.js +52 -4
- package/src/common/interfaces/internal/primary-auth-provider.interface.js.map +1 -1
- package/src/common/interfaces/internal/registry.interface.d.ts +16 -2
- package/src/common/interfaces/internal/registry.interface.js.map +1 -1
- package/src/common/interfaces/plugin.interface.js.map +1 -1
- package/src/common/interfaces/prompt.interface.d.ts +53 -4
- package/src/common/interfaces/prompt.interface.js +78 -0
- package/src/common/interfaces/prompt.interface.js.map +1 -1
- package/src/common/interfaces/resource.interface.d.ts +47 -17
- package/src/common/interfaces/resource.interface.js +53 -0
- package/src/common/interfaces/resource.interface.js.map +1 -1
- package/src/common/interfaces/tool.interface.d.ts +39 -22
- package/src/common/interfaces/tool.interface.js +61 -34
- package/src/common/interfaces/tool.interface.js.map +1 -1
- package/src/common/metadata/adapter.metadata.d.ts +1 -9
- package/src/common/metadata/app.metadata.d.ts +425 -730
- package/src/common/metadata/auth-provider.metadata.d.ts +2 -12
- package/src/common/metadata/flow.metadata.d.ts +10 -25
- package/src/common/metadata/front-mcp.metadata.d.ts +602 -1023
- package/src/common/metadata/front-mcp.metadata.js +6 -4
- package/src/common/metadata/front-mcp.metadata.js.map +1 -1
- package/src/common/metadata/hook.metadata.d.ts +1 -1
- package/src/common/metadata/hook.metadata.js.map +1 -1
- package/src/common/metadata/index.d.ts +1 -0
- package/src/common/metadata/index.js +1 -0
- package/src/common/metadata/index.js.map +1 -1
- package/src/common/metadata/logger.metadata.d.ts +1 -9
- package/src/common/metadata/plugin.metadata.d.ts +8 -30
- package/src/common/metadata/prompt.metadata.d.ts +4 -161
- package/src/common/metadata/provider.metadata.d.ts +2 -12
- package/src/common/metadata/resource.metadata.d.ts +6 -98
- package/src/common/metadata/resource.metadata.js +15 -6
- package/src/common/metadata/resource.metadata.js.map +1 -1
- package/src/common/metadata/tool-ui.metadata.d.ts +10 -0
- package/src/common/metadata/tool-ui.metadata.js +12 -0
- package/src/common/metadata/tool-ui.metadata.js.map +1 -0
- package/src/common/metadata/tool.metadata.d.ts +78 -199
- package/src/common/metadata/tool.metadata.js +11 -14
- package/src/common/metadata/tool.metadata.js.map +1 -1
- package/src/common/providers/base-config.provider.d.ts +84 -0
- package/src/common/providers/base-config.provider.js +128 -0
- package/src/common/providers/base-config.provider.js.map +1 -0
- package/src/common/records/plugin.record.d.ts +5 -6
- package/src/common/records/plugin.record.js.map +1 -1
- package/src/common/records/prompt.record.js.map +1 -1
- package/src/common/records/resource.record.d.ts +17 -1
- package/src/common/records/resource.record.js +12 -6
- package/src/common/records/resource.record.js.map +1 -1
- package/src/common/records/tool.record.js.map +1 -1
- package/src/common/schemas/annotated-class.schema.d.ts +9 -9
- package/src/common/schemas/annotated-class.schema.js +92 -27
- package/src/common/schemas/annotated-class.schema.js.map +1 -1
- package/src/common/schemas/http-input.schema.d.ts +6 -30
- package/src/common/schemas/http-output.schema.d.ts +326 -1630
- package/src/common/schemas/http-output.schema.js +39 -1
- package/src/common/schemas/http-output.schema.js.map +1 -1
- package/src/common/tokens/front-mcp.tokens.js +4 -1
- package/src/common/tokens/front-mcp.tokens.js.map +1 -1
- package/src/common/tokens/resource.tokens.d.ts +2 -0
- package/src/common/tokens/resource.tokens.js +4 -1
- package/src/common/tokens/resource.tokens.js.map +1 -1
- package/src/common/tokens/tool.tokens.d.ts +2 -0
- package/src/common/tokens/tool.tokens.js +2 -0
- package/src/common/tokens/tool.tokens.js.map +1 -1
- package/src/common/types/auth/jwt.types.d.ts +5 -31
- package/src/common/types/auth/session.types.d.ts +97 -192
- package/src/common/types/auth/session.types.js +24 -11
- package/src/common/types/auth/session.types.js.map +1 -1
- package/src/common/types/options/auth.options.d.ts +1013 -490
- package/src/common/types/options/auth.options.js +554 -36
- package/src/common/types/options/auth.options.js.map +1 -1
- package/src/common/types/options/http.options.d.ts +1 -9
- package/src/common/types/options/logging.options.d.ts +7 -13
- package/src/common/types/options/logging.options.js +4 -0
- package/src/common/types/options/logging.options.js.map +1 -1
- package/src/common/types/options/server-info.options.d.ts +3 -31
- package/src/common/types/options/session.options.d.ts +90 -10
- package/src/common/types/options/session.options.js +26 -3
- package/src/common/types/options/session.options.js.map +1 -1
- package/src/common/utils/decide-request-intent.utils.d.ts +8 -46
- package/src/common/utils/decide-request-intent.utils.js +88 -23
- package/src/common/utils/decide-request-intent.utils.js.map +1 -1
- package/src/completion/flows/complete.flow.d.ts +74 -0
- package/src/completion/flows/complete.flow.js +199 -0
- package/src/completion/flows/complete.flow.js.map +1 -0
- package/src/errors/authorization-required.error.d.ts +189 -0
- package/src/errors/authorization-required.error.js +274 -0
- package/src/errors/authorization-required.error.js.map +1 -0
- package/src/errors/index.d.ts +2 -1
- package/src/errors/index.js +17 -1
- package/src/errors/index.js.map +1 -1
- package/src/errors/mcp.error.d.ts +101 -1
- package/src/errors/mcp.error.js +147 -2
- package/src/errors/mcp.error.js.map +1 -1
- package/src/flows/flow.instance.js +4 -3
- package/src/flows/flow.instance.js.map +1 -1
- package/src/flows/flow.registry.js.map +1 -1
- package/src/flows/flow.stages.js +14 -11
- package/src/flows/flow.stages.js.map +1 -1
- package/src/front-mcp/front-mcp.providers.d.ts +464 -102
- package/src/front-mcp/front-mcp.providers.js +3 -5
- package/src/front-mcp/front-mcp.providers.js.map +1 -1
- package/src/hooks/hook.instance.d.ts +1 -1
- package/src/hooks/hook.instance.js +5 -2
- package/src/hooks/hook.instance.js.map +1 -1
- package/src/hooks/hook.registry.js +7 -5
- package/src/hooks/hook.registry.js.map +1 -1
- package/src/index.d.ts +28 -9
- package/src/index.js +5 -1
- package/src/index.js.map +1 -1
- package/src/logger/instances/instance.logger.js +3 -2
- package/src/logger/instances/instance.logger.js.map +1 -1
- package/src/logger/logger.registry.js +7 -2
- package/src/logger/logger.registry.js.map +1 -1
- package/src/logging/flows/set-level.flow.d.ts +62 -0
- package/src/logging/flows/set-level.flow.js +108 -0
- package/src/logging/flows/set-level.flow.js.map +1 -0
- package/src/mcp-apps/csp.d.ts +111 -0
- package/src/mcp-apps/csp.js +267 -0
- package/src/mcp-apps/csp.js.map +1 -0
- package/src/mcp-apps/index.d.ts +23 -0
- package/src/mcp-apps/index.js +91 -0
- package/src/mcp-apps/index.js.map +1 -0
- package/src/mcp-apps/schemas.d.ts +403 -0
- package/src/mcp-apps/schemas.js +345 -0
- package/src/mcp-apps/schemas.js.map +1 -0
- package/src/mcp-apps/template.d.ts +94 -0
- package/src/mcp-apps/template.js +419 -0
- package/src/mcp-apps/template.js.map +1 -0
- package/src/mcp-apps/types.d.ts +323 -0
- package/src/mcp-apps/types.js +59 -0
- package/src/mcp-apps/types.js.map +1 -0
- package/src/notification/index.d.ts +1 -0
- package/src/notification/index.js +13 -0
- package/src/notification/index.js.map +1 -0
- package/src/notification/notification.service.d.ts +378 -0
- package/src/notification/notification.service.js +727 -0
- package/src/notification/notification.service.js.map +1 -0
- package/src/plugin/plugin.registry.js +12 -9
- package/src/plugin/plugin.registry.js.map +1 -1
- package/src/prompt/flows/get-prompt.flow.d.ts +153 -0
- package/src/prompt/flows/get-prompt.flow.js +214 -0
- package/src/prompt/flows/get-prompt.flow.js.map +1 -0
- package/src/prompt/flows/prompts-list.flow.d.ts +67 -0
- package/src/prompt/flows/prompts-list.flow.js +176 -0
- package/src/prompt/flows/prompts-list.flow.js.map +1 -0
- package/src/prompt/index.d.ts +7 -0
- package/src/prompt/index.js +17 -0
- package/src/prompt/index.js.map +1 -0
- package/src/prompt/prompt.events.d.ts +17 -0
- package/src/prompt/prompt.events.js +25 -0
- package/src/prompt/prompt.events.js.map +1 -0
- package/src/prompt/prompt.instance.d.ts +30 -0
- package/src/prompt/prompt.instance.js +120 -0
- package/src/prompt/prompt.instance.js.map +1 -0
- package/src/prompt/prompt.registry.d.ts +79 -12
- package/src/prompt/prompt.registry.js +360 -15
- package/src/prompt/prompt.registry.js.map +1 -1
- package/src/prompt/prompt.types.d.ts +26 -0
- package/src/prompt/prompt.types.js +11 -0
- package/src/prompt/prompt.types.js.map +1 -0
- package/src/prompt/prompt.utils.d.ts +26 -0
- package/src/prompt/prompt.utils.js +136 -0
- package/src/prompt/prompt.utils.js.map +1 -0
- package/src/provider/provider.registry.d.ts +12 -5
- package/src/provider/provider.registry.js +30 -138
- package/src/provider/provider.registry.js.map +1 -1
- package/src/regsitry/registry.base.d.ts +1 -1
- package/src/regsitry/registry.base.js.map +1 -1
- package/src/resource/flows/read-resource.flow.d.ts +91 -0
- package/src/resource/flows/read-resource.flow.js +270 -0
- package/src/resource/flows/read-resource.flow.js.map +1 -0
- package/src/resource/flows/resource-templates-list.flow.d.ts +64 -0
- package/src/resource/flows/resource-templates-list.flow.js +191 -0
- package/src/resource/flows/resource-templates-list.flow.js.map +1 -0
- package/src/resource/flows/resources-list.flow.d.ts +64 -0
- package/src/resource/flows/resources-list.flow.js +196 -0
- package/src/resource/flows/resources-list.flow.js.map +1 -0
- package/src/resource/flows/subscribe-resource.flow.d.ts +45 -0
- package/src/resource/flows/subscribe-resource.flow.js +123 -0
- package/src/resource/flows/subscribe-resource.flow.js.map +1 -0
- package/src/resource/flows/unsubscribe-resource.flow.d.ts +44 -0
- package/src/resource/flows/unsubscribe-resource.flow.js +107 -0
- package/src/resource/flows/unsubscribe-resource.flow.js.map +1 -0
- package/src/resource/index.d.ts +8 -0
- package/src/resource/index.js +20 -0
- package/src/resource/index.js.map +1 -0
- package/src/resource/resource.events.d.ts +24 -0
- package/src/resource/resource.events.js +17 -0
- package/src/resource/resource.events.js.map +1 -0
- package/src/resource/resource.instance.d.ts +35 -0
- package/src/resource/resource.instance.js +163 -0
- package/src/resource/resource.instance.js.map +1 -0
- package/src/resource/resource.registry.d.ts +106 -12
- package/src/resource/resource.registry.js +449 -13
- package/src/resource/resource.registry.js.map +1 -1
- package/src/resource/resource.types.d.ts +35 -0
- package/src/resource/resource.types.js +11 -0
- package/src/resource/resource.types.js.map +1 -0
- package/src/resource/resource.utils.d.ts +30 -0
- package/src/resource/resource.utils.js +151 -0
- package/src/resource/resource.utils.js.map +1 -0
- package/src/scope/flows/http.request.flow.d.ts +48 -330
- package/src/scope/flows/http.request.flow.js +306 -78
- package/src/scope/flows/http.request.flow.js.map +1 -1
- package/src/scope/scope.instance.d.ts +12 -0
- package/src/scope/scope.instance.js +145 -15
- package/src/scope/scope.instance.js.map +1 -1
- package/src/tool/flows/call-tool.flow.d.ts +64 -1110
- package/src/tool/flows/call-tool.flow.js +303 -15
- package/src/tool/flows/call-tool.flow.js.map +1 -1
- package/src/tool/flows/tools-list.flow.d.ts +32 -473
- package/src/tool/flows/tools-list.flow.js +121 -40
- package/src/tool/flows/tools-list.flow.js.map +1 -1
- package/src/tool/tool.events.d.ts +8 -1
- package/src/tool/tool.events.js.map +1 -1
- package/src/tool/tool.instance.d.ts +3 -1
- package/src/tool/tool.instance.js +17 -3
- package/src/tool/tool.instance.js.map +1 -1
- package/src/tool/tool.registry.d.ts +7 -1
- package/src/tool/tool.registry.js +26 -10
- package/src/tool/tool.registry.js.map +1 -1
- package/src/tool/tool.types.d.ts +4 -4
- package/src/tool/tool.types.js.map +1 -1
- package/src/tool/tool.utils.d.ts +3 -12
- package/src/tool/tool.utils.js +39 -193
- package/src/tool/tool.utils.js.map +1 -1
- package/src/tool/ui/index.d.ts +22 -0
- package/src/tool/ui/index.js +63 -0
- package/src/tool/ui/index.js.map +1 -0
- package/src/tool/ui/platform-adapters.d.ts +10 -0
- package/src/tool/ui/platform-adapters.js +18 -0
- package/src/tool/ui/platform-adapters.js.map +1 -0
- package/src/tool/ui/template-helpers.d.ts +46 -0
- package/src/tool/ui/template-helpers.js +112 -0
- package/src/tool/ui/template-helpers.js.map +1 -0
- package/src/tool/ui/ui-resource-template.d.ts +34 -0
- package/src/tool/ui/ui-resource-template.js +64 -0
- package/src/tool/ui/ui-resource-template.js.map +1 -0
- package/src/tool/ui/ui-resource.handler.d.ts +74 -0
- package/src/tool/ui/ui-resource.handler.js +129 -0
- package/src/tool/ui/ui-resource.handler.js.map +1 -0
- package/src/transport/adapters/transport.local.adapter.d.ts +2 -2
- package/src/transport/adapters/transport.local.adapter.js +28 -7
- package/src/transport/adapters/transport.local.adapter.js.map +1 -1
- package/src/transport/adapters/transport.sse.adapter.d.ts +2 -2
- package/src/transport/adapters/transport.sse.adapter.js +4 -3
- package/src/transport/adapters/transport.sse.adapter.js.map +1 -1
- package/src/transport/adapters/transport.streamable-http.adapter.d.ts +10 -3
- package/src/transport/adapters/transport.streamable-http.adapter.js +54 -8
- package/src/transport/adapters/transport.streamable-http.adapter.js.map +1 -1
- package/src/transport/flows/handle.sse.flow.d.ts +29 -63
- package/src/transport/flows/handle.sse.flow.js +78 -10
- package/src/transport/flows/handle.sse.flow.js.map +1 -1
- package/src/transport/flows/handle.stateless-http.flow.d.ts +29 -0
- package/src/transport/flows/handle.stateless-http.flow.js +102 -0
- package/src/transport/flows/handle.stateless-http.flow.js.map +1 -0
- package/src/transport/flows/handle.streamable-http.flow.d.ts +32 -64
- package/src/transport/flows/handle.streamable-http.flow.js +158 -26
- package/src/transport/flows/handle.streamable-http.flow.js.map +1 -1
- package/src/transport/legacy/legacy.sse.tranporter.d.ts +9 -0
- package/src/transport/legacy/legacy.sse.tranporter.js +17 -2
- package/src/transport/legacy/legacy.sse.tranporter.js.map +1 -1
- package/src/transport/mcp-handlers/call-tool-request.handler.js +27 -1
- package/src/transport/mcp-handlers/call-tool-request.handler.js.map +1 -1
- package/src/transport/mcp-handlers/complete-request.handler.d.ts +69 -0
- package/src/transport/mcp-handlers/complete-request.handler.js +11 -0
- package/src/transport/mcp-handlers/complete-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/get-prompt-request.handler.d.ts +87 -0
- package/src/transport/mcp-handlers/get-prompt-request.handler.js +11 -0
- package/src/transport/mcp-handlers/get-prompt-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/index.d.ts +517 -208
- package/src/transport/mcp-handlers/index.js +39 -2
- package/src/transport/mcp-handlers/index.js.map +1 -1
- package/src/transport/mcp-handlers/initialize-request.handler.d.ts +1 -1
- package/src/transport/mcp-handlers/initialize-request.handler.js +73 -7
- package/src/transport/mcp-handlers/initialize-request.handler.js.map +1 -1
- package/src/transport/mcp-handlers/list-prompts-request.handler.d.ts +54 -0
- package/src/transport/mcp-handlers/list-prompts-request.handler.js +11 -0
- package/src/transport/mcp-handlers/list-prompts-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/list-resource-templates-request.handler.d.ts +51 -0
- package/src/transport/mcp-handlers/list-resource-templates-request.handler.js +12 -0
- package/src/transport/mcp-handlers/list-resource-templates-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/list-resources-request.handler.d.ts +51 -0
- package/src/transport/mcp-handlers/list-resources-request.handler.js +12 -0
- package/src/transport/mcp-handlers/list-resources-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/list-tools-request.handler.d.ts +19 -146
- package/src/transport/mcp-handlers/logging-set-level-request.handler.d.ts +46 -0
- package/src/transport/mcp-handlers/logging-set-level-request.handler.js +34 -0
- package/src/transport/mcp-handlers/logging-set-level-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/mcp-handlers.types.d.ts +3 -7
- package/src/transport/mcp-handlers/mcp-handlers.types.js.map +1 -1
- package/src/transport/mcp-handlers/read-resource-request.handler.d.ts +46 -0
- package/src/transport/mcp-handlers/read-resource-request.handler.js +12 -0
- package/src/transport/mcp-handlers/read-resource-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/roots-list-changed-notification.handler.d.ts +11 -0
- package/src/transport/mcp-handlers/roots-list-changed-notification.handler.js +26 -0
- package/src/transport/mcp-handlers/roots-list-changed-notification.handler.js.map +1 -0
- package/src/transport/mcp-handlers/subscribe-request.handler.d.ts +37 -0
- package/src/transport/mcp-handlers/subscribe-request.handler.js +34 -0
- package/src/transport/mcp-handlers/subscribe-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/unsubscribe-request.handler.d.ts +37 -0
- package/src/transport/mcp-handlers/unsubscribe-request.handler.js +34 -0
- package/src/transport/mcp-handlers/unsubscribe-request.handler.js.map +1 -0
- package/src/transport/transport.local.js +7 -2
- package/src/transport/transport.local.js.map +1 -1
- package/src/transport/transport.registry.d.ts +30 -0
- package/src/transport/transport.registry.js +84 -1
- package/src/transport/transport.registry.js.map +1 -1
- package/src/transport/transport.types.d.ts +3 -3
- package/src/transport/transport.types.js.map +1 -1
- package/src/utils/content.utils.d.ts +48 -0
- package/src/utils/content.utils.js +194 -0
- package/src/utils/content.utils.js.map +1 -0
- package/src/utils/index.d.ts +8 -0
- package/src/utils/index.js +55 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/lineage.utils.d.ts +40 -0
- package/src/utils/lineage.utils.js +82 -0
- package/src/utils/lineage.utils.js.map +1 -0
- package/src/utils/naming.utils.d.ts +46 -0
- package/src/utils/naming.utils.js +136 -0
- package/src/utils/naming.utils.js.map +1 -0
- package/src/utils/types.utils.d.ts +2 -2
- package/src/utils/types.utils.js.map +1 -1
- package/src/utils/uri-template.utils.d.ts +57 -0
- package/src/utils/uri-template.utils.js +113 -0
- package/src/utils/uri-template.utils.js.map +1 -0
- package/src/utils/uri-validation.utils.d.ts +40 -0
- package/src/utils/uri-validation.utils.js +76 -0
- package/src/utils/uri-validation.utils.js.map +1 -0
- package/src/__test-utils__/fixtures/hook.fixtures.d.ts +0 -46
- package/src/__test-utils__/fixtures/hook.fixtures.js +0 -114
- package/src/__test-utils__/fixtures/hook.fixtures.js.map +0 -1
- package/src/__test-utils__/fixtures/index.d.ts +0 -7
- package/src/__test-utils__/fixtures/index.js +0 -11
- package/src/__test-utils__/fixtures/index.js.map +0 -1
- package/src/__test-utils__/fixtures/plugin.fixtures.d.ts +0 -46
- package/src/__test-utils__/fixtures/plugin.fixtures.js +0 -127
- package/src/__test-utils__/fixtures/plugin.fixtures.js.map +0 -1
- package/src/__test-utils__/fixtures/provider.fixtures.d.ts +0 -69
- package/src/__test-utils__/fixtures/provider.fixtures.js +0 -131
- package/src/__test-utils__/fixtures/provider.fixtures.js.map +0 -1
- package/src/__test-utils__/fixtures/scope.fixtures.d.ts +0 -14
- package/src/__test-utils__/fixtures/scope.fixtures.js +0 -59
- package/src/__test-utils__/fixtures/scope.fixtures.js.map +0 -1
- package/src/__test-utils__/fixtures/tool.fixtures.d.ts +0 -36
- package/src/__test-utils__/fixtures/tool.fixtures.js +0 -91
- package/src/__test-utils__/fixtures/tool.fixtures.js.map +0 -1
- package/src/__test-utils__/helpers/assertion.helpers.d.ts +0 -45
- package/src/__test-utils__/helpers/assertion.helpers.js +0 -153
- package/src/__test-utils__/helpers/assertion.helpers.js.map +0 -1
- package/src/__test-utils__/helpers/async.helpers.d.ts +0 -48
- package/src/__test-utils__/helpers/async.helpers.js +0 -112
- package/src/__test-utils__/helpers/async.helpers.js.map +0 -1
- package/src/__test-utils__/helpers/index.d.ts +0 -6
- package/src/__test-utils__/helpers/index.js +0 -10
- package/src/__test-utils__/helpers/index.js.map +0 -1
- package/src/__test-utils__/helpers/setup.helpers.d.ts +0 -54
- package/src/__test-utils__/helpers/setup.helpers.js +0 -106
- package/src/__test-utils__/helpers/setup.helpers.js.map +0 -1
- package/src/__test-utils__/index.d.ts +0 -9
- package/src/__test-utils__/index.js +0 -14
- package/src/__test-utils__/index.js.map +0 -1
- package/src/__test-utils__/mocks/flow-instance.mock.d.ts +0 -50
- package/src/__test-utils__/mocks/flow-instance.mock.js +0 -72
- package/src/__test-utils__/mocks/flow-instance.mock.js.map +0 -1
- package/src/__test-utils__/mocks/hook-registry.mock.d.ts +0 -25
- package/src/__test-utils__/mocks/hook-registry.mock.js +0 -65
- package/src/__test-utils__/mocks/hook-registry.mock.js.map +0 -1
- package/src/__test-utils__/mocks/index.d.ts +0 -8
- package/src/__test-utils__/mocks/index.js +0 -12
- package/src/__test-utils__/mocks/index.js.map +0 -1
- package/src/__test-utils__/mocks/plugin-registry.mock.d.ts +0 -43
- package/src/__test-utils__/mocks/plugin-registry.mock.js +0 -70
- package/src/__test-utils__/mocks/plugin-registry.mock.js.map +0 -1
- package/src/__test-utils__/mocks/provider-registry.mock.d.ts +0 -39
- package/src/__test-utils__/mocks/provider-registry.mock.js +0 -72
- package/src/__test-utils__/mocks/provider-registry.mock.js.map +0 -1
- package/src/__test-utils__/mocks/tool-registry.mock.d.ts +0 -43
- package/src/__test-utils__/mocks/tool-registry.mock.js +0 -79
- package/src/__test-utils__/mocks/tool-registry.mock.js.map +0 -1
- package/src/auth/path.utils.d.ts +0 -20
- package/src/auth/path.utils.js +0 -71
- package/src/auth/path.utils.js.map +0 -1
- package/src/common/decorators-old/async-with.decorator.d.ts +0 -10
- package/src/common/decorators-old/async-with.decorator.js +0 -24
- package/src/common/decorators-old/async-with.decorator.js.map +0 -1
- package/src/common/decorators-old/auth-hook.decorator.d.ts +0 -14
- package/src/common/decorators-old/auth-hook.decorator.js +0 -27
- package/src/common/decorators-old/auth-hook.decorator.js.map +0 -1
- package/src/common/decorators-old/session-hook.decorator.d.ts +0 -14
- package/src/common/decorators-old/session-hook.decorator.js +0 -27
- package/src/common/decorators-old/session-hook.decorator.js.map +0 -1
|
@@ -7,47 +7,94 @@ const zod_1 = require("zod");
|
|
|
7
7
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
8
8
|
const session_id_utils_1 = require("../../auth/session/utils/session-id.utils");
|
|
9
9
|
exports.plan = {
|
|
10
|
-
pre: [
|
|
11
|
-
|
|
12
|
-
'router',
|
|
13
|
-
],
|
|
14
|
-
execute: [
|
|
15
|
-
'onInitialize',
|
|
16
|
-
'onMessage',
|
|
17
|
-
'onElicitResult',
|
|
18
|
-
],
|
|
10
|
+
pre: ['parseInput', 'router'],
|
|
11
|
+
execute: ['onInitialize', 'onMessage', 'onElicitResult', 'onSseListener'],
|
|
19
12
|
post: [],
|
|
20
|
-
finalize: [
|
|
21
|
-
'cleanup',
|
|
22
|
-
],
|
|
13
|
+
finalize: ['cleanup'],
|
|
23
14
|
};
|
|
15
|
+
// Relaxed session schema for state - payload is optional when using mcp-session-id header directly
|
|
16
|
+
const stateSessionSchema = zod_1.z.object({
|
|
17
|
+
id: zod_1.z.string(),
|
|
18
|
+
payload: zod_1.z
|
|
19
|
+
.object({
|
|
20
|
+
nodeId: zod_1.z.string(),
|
|
21
|
+
authSig: zod_1.z.string(),
|
|
22
|
+
uuid: zod_1.z.string().uuid(),
|
|
23
|
+
iat: zod_1.z.number(),
|
|
24
|
+
protocol: zod_1.z.enum(['legacy-sse', 'sse', 'streamable-http', 'stateful-http', 'stateless-http']).optional(),
|
|
25
|
+
isPublic: zod_1.z.boolean().optional(),
|
|
26
|
+
platformType: zod_1.z
|
|
27
|
+
.enum(['openai', 'claude', 'gemini', 'cursor', 'continue', 'cody', 'generic-mcp', 'ext-apps', 'unknown'])
|
|
28
|
+
.optional(),
|
|
29
|
+
})
|
|
30
|
+
.optional(),
|
|
31
|
+
});
|
|
24
32
|
exports.stateSchema = zod_1.z.object({
|
|
25
33
|
token: zod_1.z.string(),
|
|
26
|
-
session:
|
|
27
|
-
requestType: zod_1.z.enum(['initialize', 'message', 'elicitResult']).optional(),
|
|
34
|
+
session: stateSessionSchema,
|
|
35
|
+
requestType: zod_1.z.enum(['initialize', 'message', 'elicitResult', 'sseListener']).optional(),
|
|
28
36
|
});
|
|
29
37
|
const name = 'handle:streamable-http';
|
|
30
38
|
const { Stage } = (0, common_1.FlowHooksOf)(name);
|
|
31
39
|
let HandleStreamableHttpFlow = class HandleStreamableHttpFlow extends common_1.FlowBase {
|
|
32
40
|
name = name;
|
|
33
|
-
async
|
|
41
|
+
async parseInput() {
|
|
34
42
|
const { request } = this.rawInput;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
const authorization = request[common_1.ServerRequestTokens.auth];
|
|
44
|
+
const { token } = authorization;
|
|
45
|
+
// CRITICAL: The mcp-session-id header is the client's reference to their session.
|
|
46
|
+
// We MUST use this exact ID for transport registry lookup.
|
|
47
|
+
//
|
|
48
|
+
// Priority 1: Use mcp-session-id header if present (client's session ID for lookup)
|
|
49
|
+
// This is the ID the client received from initialize and is referencing.
|
|
50
|
+
// Priority 2: Use session from authorization if header matches or is absent
|
|
51
|
+
// Priority 3: Create new session (first request - no header, no authorization.session)
|
|
52
|
+
const mcpSessionHeader = request.headers?.['mcp-session-id'];
|
|
53
|
+
let session;
|
|
54
|
+
if (mcpSessionHeader) {
|
|
55
|
+
// Client sent session ID - ALWAYS use it for transport lookup
|
|
56
|
+
// If authorization.session exists and matches, use its payload for protocol detection
|
|
57
|
+
// If authorization.session differs or is missing, still use header ID (payload may be undefined)
|
|
58
|
+
if (authorization.session?.id === mcpSessionHeader) {
|
|
59
|
+
session = authorization.session;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
session = { id: mcpSessionHeader };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (authorization.session) {
|
|
66
|
+
// No header but authorization has session - use it (shouldn't happen in normal flow)
|
|
67
|
+
session = authorization.session;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// No session - create new one (initialize request)
|
|
71
|
+
session = (0, session_id_utils_1.createSessionId)('streamable-http', token, {
|
|
72
|
+
userAgent: request.headers?.['user-agent'],
|
|
73
|
+
platformDetectionConfig: this.scope.metadata?.session?.platformDetection,
|
|
74
|
+
});
|
|
39
75
|
}
|
|
40
76
|
this.state.set(exports.stateSchema.parse({ token, session }));
|
|
41
77
|
}
|
|
42
78
|
async router() {
|
|
43
79
|
const { request } = this.rawInput;
|
|
44
|
-
|
|
80
|
+
// GET requests are SSE listener streams - no body expected
|
|
81
|
+
// Per MCP spec, clients can open SSE stream with GET + Accept: text/event-stream
|
|
82
|
+
if (request.method.toUpperCase() === 'GET') {
|
|
83
|
+
this.state.set('requestType', 'sseListener');
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// POST requests have MCP JSON-RPC body
|
|
87
|
+
const body = request.body;
|
|
88
|
+
const method = body?.method;
|
|
89
|
+
// Use method-based detection for routing (more permissive than strict schema)
|
|
90
|
+
// The actual schema validation happens in the MCP SDK's transport layer
|
|
91
|
+
if (method === 'initialize') {
|
|
45
92
|
this.state.set('requestType', 'initialize');
|
|
46
93
|
}
|
|
47
94
|
else if (types_js_1.ElicitResultSchema.safeParse(request.body).success) {
|
|
48
95
|
this.state.set('requestType', 'elicitResult');
|
|
49
96
|
}
|
|
50
|
-
else if (types_js_1.RequestSchema.safeParse(request.body).success) {
|
|
97
|
+
else if (method && types_js_1.RequestSchema.safeParse(request.body).success) {
|
|
51
98
|
this.state.set('requestType', 'message');
|
|
52
99
|
}
|
|
53
100
|
else {
|
|
@@ -56,25 +103,102 @@ let HandleStreamableHttpFlow = class HandleStreamableHttpFlow extends common_1.F
|
|
|
56
103
|
}
|
|
57
104
|
async onInitialize() {
|
|
58
105
|
const transportService = this.scope.transportService;
|
|
106
|
+
const logger = this.scope.logger.child('handle:streamable-http:onInitialize');
|
|
59
107
|
const { request, response } = this.rawInput;
|
|
60
108
|
const { token, session } = this.state.required;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
109
|
+
logger.info('onInitialize: creating transport', {
|
|
110
|
+
sessionId: session.id.slice(0, 30),
|
|
111
|
+
hasToken: !!token,
|
|
112
|
+
tokenPrefix: token?.slice(0, 10),
|
|
113
|
+
});
|
|
114
|
+
try {
|
|
115
|
+
const transport = await transportService.createTransporter('streamable-http', token, session.id, response);
|
|
116
|
+
logger.info('onInitialize: transport created, calling initialize');
|
|
117
|
+
await transport.initialize(request, response);
|
|
118
|
+
logger.info('onInitialize: completed successfully');
|
|
119
|
+
this.handled();
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
// FlowControl is expected control flow (from this.handled()), not an error
|
|
123
|
+
if (error instanceof common_1.FlowControl) {
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
logger.error('onInitialize: failed', {
|
|
127
|
+
error: error instanceof Error ? error.message : String(error),
|
|
128
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
129
|
+
});
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
64
132
|
}
|
|
65
133
|
async onElicitResult() {
|
|
66
134
|
this.fail(new Error('Not implemented'));
|
|
67
135
|
}
|
|
68
136
|
async onMessage() {
|
|
137
|
+
const transportService = this.scope.transportService;
|
|
138
|
+
const logger = this.scopeLogger.child('handle:streamable-http:onMessage');
|
|
139
|
+
const { request, response } = this.rawInput;
|
|
140
|
+
const { token, session } = this.state.required;
|
|
141
|
+
const transport = await transportService.getTransporter('streamable-http', token, session.id);
|
|
142
|
+
if (!transport) {
|
|
143
|
+
// Check if session was ever created to differentiate error types per MCP Spec 2025-11-25
|
|
144
|
+
const wasCreated = transportService.wasSessionCreated('streamable-http', token, session.id);
|
|
145
|
+
const body = request.body;
|
|
146
|
+
if (wasCreated) {
|
|
147
|
+
// Session existed but was terminated/evicted → HTTP 404 (client should re-initialize)
|
|
148
|
+
logger.info('Session expired - client should re-initialize', {
|
|
149
|
+
sessionId: session.id?.slice(0, 20),
|
|
150
|
+
tokenHash: token.slice(0, 8),
|
|
151
|
+
method: body?.['method'],
|
|
152
|
+
requestId: body?.['id'],
|
|
153
|
+
mcpSessionId: request.headers?.['mcp-session-id'],
|
|
154
|
+
});
|
|
155
|
+
this.respond(common_1.httpRespond.sessionExpired('session expired'));
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// Session was never created → HTTP 404 (per user requirement: invalid/missing session = 404)
|
|
159
|
+
logger.warn('Session not initialized - client attempted request without initializing', {
|
|
160
|
+
sessionId: session.id?.slice(0, 20),
|
|
161
|
+
tokenHash: token.slice(0, 8),
|
|
162
|
+
method: body?.['method'],
|
|
163
|
+
requestId: body?.['id'],
|
|
164
|
+
mcpSessionId: request.headers?.['mcp-session-id'],
|
|
165
|
+
userAgent: request.headers?.['user-agent']?.slice(0, 50),
|
|
166
|
+
});
|
|
167
|
+
this.respond(common_1.httpRespond.sessionNotFound('session not initialized'));
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
await transport.handleRequest(request, response);
|
|
173
|
+
this.handled();
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
// FlowControl is expected control flow, not an error
|
|
177
|
+
if (!(error instanceof common_1.FlowControl)) {
|
|
178
|
+
const body = request.body;
|
|
179
|
+
logger.error('handleRequest failed', {
|
|
180
|
+
error: error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : error,
|
|
181
|
+
method: body?.['method'],
|
|
182
|
+
id: body?.['id'],
|
|
183
|
+
sessionId: session.id?.slice(0, 20),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async onSseListener() {
|
|
69
190
|
const transportService = this.scope.transportService;
|
|
70
191
|
const { request, response } = this.rawInput;
|
|
71
192
|
const { token, session } = this.state.required;
|
|
193
|
+
// Get existing transport for this session - SSE listener requires existing session
|
|
72
194
|
const transport = await transportService.getTransporter('streamable-http', token, session.id);
|
|
73
195
|
if (!transport) {
|
|
74
|
-
this.respond(common_1.httpRespond.
|
|
196
|
+
this.respond(common_1.httpRespond.notFound('Session not found'));
|
|
75
197
|
return;
|
|
76
198
|
}
|
|
199
|
+
// Forward GET request to transport (opens SSE stream for server→client notifications)
|
|
77
200
|
await transport.handleRequest(request, response);
|
|
201
|
+
this.handled();
|
|
78
202
|
}
|
|
79
203
|
};
|
|
80
204
|
tslib_1.__decorate([
|
|
@@ -82,7 +206,7 @@ tslib_1.__decorate([
|
|
|
82
206
|
tslib_1.__metadata("design:type", Function),
|
|
83
207
|
tslib_1.__metadata("design:paramtypes", []),
|
|
84
208
|
tslib_1.__metadata("design:returntype", Promise)
|
|
85
|
-
], HandleStreamableHttpFlow.prototype, "
|
|
209
|
+
], HandleStreamableHttpFlow.prototype, "parseInput", null);
|
|
86
210
|
tslib_1.__decorate([
|
|
87
211
|
Stage('router'),
|
|
88
212
|
tslib_1.__metadata("design:type", Function),
|
|
@@ -113,6 +237,14 @@ tslib_1.__decorate([
|
|
|
113
237
|
tslib_1.__metadata("design:paramtypes", []),
|
|
114
238
|
tslib_1.__metadata("design:returntype", Promise)
|
|
115
239
|
], HandleStreamableHttpFlow.prototype, "onMessage", null);
|
|
240
|
+
tslib_1.__decorate([
|
|
241
|
+
Stage('onSseListener', {
|
|
242
|
+
filter: ({ state: { requestType } }) => requestType === 'sseListener',
|
|
243
|
+
}),
|
|
244
|
+
tslib_1.__metadata("design:type", Function),
|
|
245
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
246
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
247
|
+
], HandleStreamableHttpFlow.prototype, "onSseListener", null);
|
|
116
248
|
HandleStreamableHttpFlow = tslib_1.__decorate([
|
|
117
249
|
(0, common_1.Flow)({
|
|
118
250
|
name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.streamable-http.flow.js","sourceRoot":"","sources":["../../../../src/transport/flows/handle.streamable-http.flow.ts"],"names":[],"mappings":";;;;AAAA,yCAGsB;AACtB,6BAAsB;AACtB,iEAA8G;AAE9G,gFAA0E;AAE7D,QAAA,IAAI,GAAG;IAClB,GAAG,EAAE;QACH,YAAY;QACZ,QAAQ;KACT;IACD,OAAO,EAAE;QACP,cAAc;QACd,WAAW;QACX,gBAAgB;KACjB;IACD,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE;QACR,SAAS;KACV;CACkC,CAAC;AAGzB,QAAA,WAAW,GA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putSchema, FlowRunOptions, httpOutputSchema, FlowPlan,\n FlowBase, FlowHooksOf, sessionIdSchema, httpRespond, ServerRequestTokens, Authorization,\n} from '../../common';\nimport {z} from 'zod';\nimport {ElicitResultSchema, InitializeRequestSchema, RequestSchema} from '@modelcontextprotocol/sdk/types.js';\nimport {Scope} from '../../scope';\nimport {createSessionId} from '../../auth/session/utils/session-id.utils';\n\nexport const plan = {\n pre: [\n 'parseInput',\n 'router',\n ],\n execute: [\n 'onInitialize',\n 'onMessage',\n 'onElicitResult',\n ],\n post: [],\n finalize: [\n 'cleanup',\n ],\n} as const satisfies FlowPlan<string>;\n\n\nexport const stateSchema = z.object({\n token: z.string(),\n session: sessionIdSchema,\n requestType: z.enum(['initialize', 'message', 'elicitResult']).optional(),\n});\n\nconst name = 'handle:streamable-http' as const;\nconst {Stage} = FlowHooksOf(name);\n\n\ndeclare global {\n interface ExtendFlows {\n 'handle:streamable-http': FlowRunOptions<\n HandleStreamableHttpFlow,\n typeof plan,\n typeof httpInputSchema,\n typeof httpOutputSchema,\n typeof stateSchema\n >;\n }\n}\n\n@Flow({\n name,\n plan,\n access: 'authorized',\n inputSchema: httpInputSchema,\n outputSchema: httpOutputSchema,\n})\nexport default class HandleStreamableHttpFlow extends FlowBase<typeof name> {\n name = name;\n\n @Stage('parseInput')\n async paseInput() {\n const {request} = this.rawInput;\n\n let {token, session} = request[ServerRequestTokens.auth] as Authorization;\n\n if (!session) {\n session = createSessionId('streamable-http', token);\n request[ServerRequestTokens.auth].session = session;\n }\n this.state.set(stateSchema.parse({token, session}));\n }\n\n @Stage('router')\n async router() {\n const {request} = this.rawInput;\n\n if (InitializeRequestSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'initialize');\n } else if (ElicitResultSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'elicitResult');\n } else if (RequestSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'message');\n } else {\n this.respond(httpRespond.rpcError('Invalid Request'));\n }\n }\n\n @Stage('onInitialize', {\n filter: ({state: {requestType}}) => requestType === 'initialize',\n })\n async onInitialize() {\n const transportService = (this.scope as Scope).transportService;\n\n const {request, response} = this.rawInput;\n const {token, session} = this.state.required;\n const transport = await transportService.createTransporter('streamable-http', token, session.id, response);\n await transport.initialize(request, response);\n this.handled();\n }\n\n @Stage('onElicitResult', {\n filter: ({state: {requestType}}) => requestType === 'elicitResult',\n })\n async onElicitResult() {\n this.fail(new Error('Not implemented'));\n }\n\n @Stage('onMessage', {\n filter: ({state: {requestType}}) => requestType === 'message',\n })\n async onMessage() {\n const transportService = (this.scope as Scope).transportService;\n\n const {request, response} = this.rawInput;\n const {token, session} = this.state.required;\n const transport = await transportService.getTransporter('streamable-http', token, session.id);\n if (!transport) {\n this.respond(httpRespond.rpcError('session not initialized'));\n return;\n }\n await transport.handleRequest(request, response);\n }\n\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"handle.streamable-http.flow.js","sourceRoot":"","sources":["../../../../src/transport/flows/handle.streamable-http.flow.ts"],"names":[],"mappings":";;;;AAAA,yCAasB;AACtB,6BAAwB;AACxB,iEAAuF;AAEvF,gFAA4E;AAE/D,QAAA,IAAI,GAAG;IAClB,GAAG,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC;IAC7B,OAAO,EAAE,CAAC,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,CAAC;IACzE,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE,CAAC,SAAS,CAAC;CACc,CAAC;AAEtC,mGAAmG;AACnG,MAAM,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;IACd,OAAO,EAAE,OAAC;SACP,MAAM,CAAC;QACN,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;QAClB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;QACnB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;QACvB,GAAG,EAAE,OAAC,C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AE,CAAC,WAAW,KAAK,aAAa;KACtE,CAAC;;;;6DAiBD;AA/LkB,wBAAwB;IAP5C,IAAA,aAAI,EAAC;QACJ,IAAI;QACJ,IAAI,EAAJ,YAAI;QACJ,MAAM,EAAE,YAAY;QACpB,WAAW,EAAE,wBAAe;QAC5B,YAAY,EAAE,yBAAgB;KAC/B,CAAC;GACmB,wBAAwB,CAgM5C;kBAhMoB,wBAAwB","sourcesContent":["import {\n Flow,\n httpInputSchema,\n FlowRunOptions,\n httpOutputSchema,\n FlowPlan,\n FlowBase,\n FlowHooksOf,\n sessionIdSchema,\n httpRespond,\n ServerRequestTokens,\n Authorization,\n FlowControl,\n} from '../../common';\nimport { z } from 'zod';\nimport { ElicitResultSchema, RequestSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { Scope } from '../../scope';\nimport { createSessionId } from '../../auth/session/utils/session-id.utils';\n\nexport const plan = {\n pre: ['parseInput', 'router'],\n execute: ['onInitialize', 'onMessage', 'onElicitResult', 'onSseListener'],\n post: [],\n finalize: ['cleanup'],\n} as const satisfies FlowPlan<string>;\n\n// Relaxed session schema for state - payload is optional when using mcp-session-id header directly\nconst stateSessionSchema = z.object({\n id: z.string(),\n payload: z\n .object({\n nodeId: z.string(),\n authSig: z.string(),\n uuid: z.string().uuid(),\n iat: z.number(),\n protocol: z.enum(['legacy-sse', 'sse', 'streamable-http', 'stateful-http', 'stateless-http']).optional(),\n isPublic: z.boolean().optional(),\n platformType: z\n .enum(['openai', 'claude', 'gemini', 'cursor', 'continue', 'cody', 'generic-mcp', 'ext-apps', 'unknown'])\n .optional(),\n })\n .optional(),\n});\n\nexport const stateSchema = z.object({\n token: z.string(),\n session: stateSessionSchema,\n requestType: z.enum(['initialize', 'message', 'elicitResult', 'sseListener']).optional(),\n});\n\nconst name = 'handle:streamable-http' as const;\nconst { Stage } = FlowHooksOf(name);\n\ndeclare global {\n interface ExtendFlows {\n 'handle:streamable-http': FlowRunOptions<\n HandleStreamableHttpFlow,\n typeof plan,\n typeof httpInputSchema,\n typeof httpOutputSchema,\n typeof stateSchema\n >;\n }\n}\n\n@Flow({\n name,\n plan,\n access: 'authorized',\n inputSchema: httpInputSchema,\n outputSchema: httpOutputSchema,\n})\nexport default class HandleStreamableHttpFlow extends FlowBase<typeof name> {\n name = name;\n\n @Stage('parseInput')\n async parseInput() {\n const { request } = this.rawInput;\n\n const authorization = request[ServerRequestTokens.auth] as Authorization;\n const { token } = authorization;\n\n // CRITICAL: The mcp-session-id header is the client's reference to their session.\n // We MUST use this exact ID for transport registry lookup.\n //\n // Priority 1: Use mcp-session-id header if present (client's session ID for lookup)\n // This is the ID the client received from initialize and is referencing.\n // Priority 2: Use session from authorization if header matches or is absent\n // Priority 3: Create new session (first request - no header, no authorization.session)\n const mcpSessionHeader = request.headers?.['mcp-session-id'] as string | undefined;\n\n let session: { id: string; payload?: z.infer<typeof stateSchema>['session']['payload'] };\n\n if (mcpSessionHeader) {\n // Client sent session ID - ALWAYS use it for transport lookup\n // If authorization.session exists and matches, use its payload for protocol detection\n // If authorization.session differs or is missing, still use header ID (payload may be undefined)\n if (authorization.session?.id === mcpSessionHeader) {\n session = authorization.session;\n } else {\n session = { id: mcpSessionHeader };\n }\n } else if (authorization.session) {\n // No header but authorization has session - use it (shouldn't happen in normal flow)\n session = authorization.session;\n } else {\n // No session - create new one (initialize request)\n session = createSessionId('streamable-http', token, {\n userAgent: request.headers?.['user-agent'] as string | undefined,\n platformDetectionConfig: (this.scope as Scope).metadata?.session?.platformDetection,\n });\n }\n\n this.state.set(stateSchema.parse({ token, session }));\n }\n\n @Stage('router')\n async router() {\n const { request } = this.rawInput;\n\n // GET requests are SSE listener streams - no body expected\n // Per MCP spec, clients can open SSE stream with GET + Accept: text/event-stream\n if (request.method.toUpperCase() === 'GET') {\n this.state.set('requestType', 'sseListener');\n return;\n }\n\n // POST requests have MCP JSON-RPC body\n const body = request.body as { method?: string } | undefined;\n const method = body?.method;\n\n // Use method-based detection for routing (more permissive than strict schema)\n // The actual schema validation happens in the MCP SDK's transport layer\n if (method === 'initialize') {\n this.state.set('requestType', 'initialize');\n } else if (ElicitResultSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'elicitResult');\n } else if (method && RequestSchema.safeParse(request.body).success) {\n this.state.set('requestType', 'message');\n } else {\n this.respond(httpRespond.rpcError('Invalid Request'));\n }\n }\n\n @Stage('onInitialize', {\n filter: ({ state: { requestType } }) => requestType === 'initialize',\n })\n async onInitialize() {\n const transportService = (this.scope as Scope).transportService;\n const logger = (this.scope as Scope).logger.child('handle:streamable-http:onInitialize');\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n\n logger.info('onInitialize: creating transport', {\n sessionId: session.id.slice(0, 30),\n hasToken: !!token,\n tokenPrefix: token?.slice(0, 10),\n });\n\n try {\n const transport = await transportService.createTransporter('streamable-http', token, session.id, response);\n logger.info('onInitialize: transport created, calling initialize');\n await transport.initialize(request, response);\n logger.info('onInitialize: completed successfully');\n this.handled();\n } catch (error) {\n // FlowControl is expected control flow (from this.handled()), not an error\n if (error instanceof FlowControl) {\n throw error;\n }\n logger.error('onInitialize: failed', {\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n });\n throw error;\n }\n }\n\n @Stage('onElicitResult', {\n filter: ({ state: { requestType } }) => requestType === 'elicitResult',\n })\n async onElicitResult() {\n this.fail(new Error('Not implemented'));\n }\n\n @Stage('onMessage', {\n filter: ({ state: { requestType } }) => requestType === 'message',\n })\n async onMessage() {\n const transportService = (this.scope as Scope).transportService;\n const logger = this.scopeLogger.child('handle:streamable-http:onMessage');\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n const transport = await transportService.getTransporter('streamable-http', token, session.id);\n if (!transport) {\n // Check if session was ever created to differentiate error types per MCP Spec 2025-11-25\n const wasCreated = transportService.wasSessionCreated('streamable-http', token, session.id);\n const body = request.body as Record<string, unknown> | undefined;\n\n if (wasCreated) {\n // Session existed but was terminated/evicted → HTTP 404 (client should re-initialize)\n logger.info('Session expired - client should re-initialize', {\n sessionId: session.id?.slice(0, 20),\n tokenHash: token.slice(0, 8),\n method: body?.['method'],\n requestId: body?.['id'],\n mcpSessionId: request.headers?.['mcp-session-id'],\n });\n this.respond(httpRespond.sessionExpired('session expired'));\n } else {\n // Session was never created → HTTP 404 (per user requirement: invalid/missing session = 404)\n logger.warn('Session not initialized - client attempted request without initializing', {\n sessionId: session.id?.slice(0, 20),\n tokenHash: token.slice(0, 8),\n method: body?.['method'],\n requestId: body?.['id'],\n mcpSessionId: request.headers?.['mcp-session-id'],\n userAgent: (request.headers?.['user-agent'] as string | undefined)?.slice(0, 50),\n });\n this.respond(httpRespond.sessionNotFound('session not initialized'));\n }\n return;\n }\n\n try {\n await transport.handleRequest(request, response);\n this.handled();\n } catch (error) {\n // FlowControl is expected control flow, not an error\n if (!(error instanceof FlowControl)) {\n const body = request.body as Record<string, unknown> | undefined;\n logger.error('handleRequest failed', {\n error: error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : error,\n method: body?.['method'],\n id: body?.['id'],\n sessionId: session.id?.slice(0, 20),\n });\n }\n throw error;\n }\n }\n\n @Stage('onSseListener', {\n filter: ({ state: { requestType } }) => requestType === 'sseListener',\n })\n async onSseListener() {\n const transportService = (this.scope as Scope).transportService;\n\n const { request, response } = this.rawInput;\n const { token, session } = this.state.required;\n\n // Get existing transport for this session - SSE listener requires existing session\n const transport = await transportService.getTransporter('streamable-http', token, session.id);\n if (!transport) {\n this.respond(httpRespond.notFound('Session not found'));\n return;\n }\n\n // Forward GET request to transport (opens SSE stream for server→client notifications)\n await transport.handleRequest(request, response);\n this.handled();\n }\n}\n"]}
|
|
@@ -34,6 +34,8 @@ export declare class SSEServerTransport implements Transport {
|
|
|
34
34
|
private _sseResponse?;
|
|
35
35
|
private _sessionId;
|
|
36
36
|
private _options;
|
|
37
|
+
/** Incrementing event ID counter for SSE events (MCP 2025-11-25 spec compliance) */
|
|
38
|
+
private _eventIdCounter;
|
|
37
39
|
onclose?: () => void;
|
|
38
40
|
onerror?: (error: Error) => void;
|
|
39
41
|
onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
|
|
@@ -72,4 +74,11 @@ export declare class SSEServerTransport implements Transport {
|
|
|
72
74
|
* This can be used to route incoming POST requests.
|
|
73
75
|
*/
|
|
74
76
|
get sessionId(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Returns the current event ID counter value.
|
|
79
|
+
*
|
|
80
|
+
* This is the ID that was used for the last sent event.
|
|
81
|
+
* Useful for testing and debugging reconnection scenarios.
|
|
82
|
+
*/
|
|
83
|
+
get lastEventId(): number;
|
|
75
84
|
}
|
|
@@ -19,6 +19,8 @@ class SSEServerTransport {
|
|
|
19
19
|
_sseResponse;
|
|
20
20
|
_sessionId;
|
|
21
21
|
_options;
|
|
22
|
+
/** Incrementing event ID counter for SSE events (MCP 2025-11-25 spec compliance) */
|
|
23
|
+
_eventIdCounter = 0;
|
|
22
24
|
onclose;
|
|
23
25
|
onerror;
|
|
24
26
|
onmessage;
|
|
@@ -78,7 +80,9 @@ class SSEServerTransport {
|
|
|
78
80
|
endpointUrl.searchParams.set('sessionId', this._sessionId);
|
|
79
81
|
// Reconstruct the relative URL string (pathname + search + hash)
|
|
80
82
|
const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash;
|
|
81
|
-
|
|
83
|
+
// Include event ID per MCP 2025-11-25 spec for client reconnection support
|
|
84
|
+
const eventId = ++this._eventIdCounter;
|
|
85
|
+
this.res.write(`id: ${eventId}\nevent: endpoint\ndata: ${relativeUrlWithSession}\n\n`);
|
|
82
86
|
this._sseResponse = this.res;
|
|
83
87
|
this.res.on('close', () => {
|
|
84
88
|
this._sseResponse = undefined;
|
|
@@ -155,7 +159,9 @@ class SSEServerTransport {
|
|
|
155
159
|
if (!this._sseResponse) {
|
|
156
160
|
throw new Error('Not connected');
|
|
157
161
|
}
|
|
158
|
-
|
|
162
|
+
// Include event ID per MCP 2025-11-25 spec for client reconnection support
|
|
163
|
+
const eventId = ++this._eventIdCounter;
|
|
164
|
+
this._sseResponse.write(`id: ${eventId}\nevent: message\ndata: ${JSON.stringify(message)}\n\n`);
|
|
159
165
|
}
|
|
160
166
|
/**
|
|
161
167
|
* Returns the session ID for this transport.
|
|
@@ -165,6 +171,15 @@ class SSEServerTransport {
|
|
|
165
171
|
get sessionId() {
|
|
166
172
|
return this._sessionId;
|
|
167
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Returns the current event ID counter value.
|
|
176
|
+
*
|
|
177
|
+
* This is the ID that was used for the last sent event.
|
|
178
|
+
* Useful for testing and debugging reconnection scenarios.
|
|
179
|
+
*/
|
|
180
|
+
get lastEventId() {
|
|
181
|
+
return this._eventIdCounter;
|
|
182
|
+
}
|
|
168
183
|
}
|
|
169
184
|
exports.SSEServerTransport = SSEServerTransport;
|
|
170
185
|
//# sourceMappingURL=legacy.sse.tranporter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy.sse.tranporter.js","sourceRoot":"","sources":["../../../../src/transport/legacy/legacy.sse.tranporter.ts"],"names":[],"mappings":";;;;AAAA,6CAAyC;AAEzC,gEAAkC;AAClC,wEAAuC;AACvC,6BAA0B;AAE1B,iEAA4G;AAG5G,MAAM,oBAAoB,GAAG,KAAK,CAAC;AA2BnC;;;;GAIG;AACH,MAAa,kBAAkB;IAWT;IAA2B;IAVvC,YAAY,CAAkB;IAC9B,UAAU,CAAS;IACnB,QAAQ,CAA4B;IAC5C,OAAO,CAAc;IACrB,OAAO,CAA0B;IACjC,SAAS,CAA+D;IAExE;;OAEG;IACH,YAAoB,SAAiB,EAAU,GAAmB,EAAE,OAAmC;QAAnF,cAAS,GAAT,SAAS,CAAQ;QAAU,QAAG,GAAH,GAAG,CAAgB;QAChE,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,SAAS,IAAI,IAAA,wBAAU,GAAE,CAAC;QACrD,IAAI,CAAC,QAAQ,GAAG,OAAO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AoB,IAAI,EAAE,CAAC,CAAC;YACnD,OAAO;QACT,CAAC;QAED,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,OAAgB,EAAE,KAAwB;QAC5D,IAAI,aAA6B,CAAC;QAClC,IAAI,CAAC;YACH,aAAa,GAAG,+BAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,OAAO,EAAE,CAAC,KAAc,CAAC,CAAC;YAC/B,MAAM,KAAK,CAAC;QACd,CAAC;QAED,IAAI,CAAC,SAAS,EAAE,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAC9B,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACnC,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClF,CAAC;IAED;;;;OAIG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AA/KD,gDA+KC","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { IncomingMessage, ServerResponse } from 'node:http';\nimport getRawBody from 'raw-body';\nimport contentType from 'content-type';\nimport { URL } from 'url';\nimport { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { JSONRPCMessage, JSONRPCMessageSchema, MessageExtraInfo } from '@modelcontextprotocol/sdk/types.js';\nimport { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';\n\nconst MAXIMUM_MESSAGE_SIZE = '4mb';\n\n/**\n * Configuration options for SSEServerTransport.\n */\nexport interface SSEServerTransportOptions {\n /**\n * List of allowed host header values for DNS rebinding protection.\n * If not specified, host validation is disabled.\n */\n allowedHosts?: string[];\n\n /**\n * List of allowed origin header values for DNS rebinding protection.\n * If not specified, origin validation is disabled.\n */\n allowedOrigins?: string[];\n\n /**\n * Enable DNS rebinding protection (requires allowedHosts and/or allowedOrigins to be configured).\n * Default is false for backwards compatibility.\n */\n enableDnsRebindingProtection?: boolean;\n\n sessionId?: string;\n}\n\n/**\n * Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests.\n *\n * This transport is only available in Node.js environments.\n */\nexport class SSEServerTransport implements Transport {\n private _sseResponse?: ServerResponse;\n private _sessionId: string;\n private _options: SSEServerTransportOptions;\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;\n\n /**\n * Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by `_endpoint`.\n */\n constructor(private _endpoint: string, private res: ServerResponse, options?: SSEServerTransportOptions) {\n this._sessionId = options?.sessionId ?? randomUUID();\n this._options = options || { enableDnsRebindingProtection: false };\n }\n\n /**\n * Validates request headers for DNS rebinding protection.\n * @returns Error message if validation fails, undefined if validation passes.\n */\n private validateRequestHeaders(req: IncomingMessage): string | undefined {\n // Skip validation if protection is not enabled\n if (!this._options.enableDnsRebindingProtection) {\n return undefined;\n }\n\n // Validate Host header if allowedHosts is configured\n if (this._options.allowedHosts && this._options.allowedHosts.length > 0) {\n const hostHeader = req.headers.host;\n if (!hostHeader || !this._options.allowedHosts.includes(hostHeader)) {\n return `Invalid Host header: ${hostHeader}`;\n }\n }\n\n // Validate Origin header if allowedOrigins is configured\n if (this._options.allowedOrigins && this._options.allowedOrigins.length > 0) {\n const originHeader = req.headers.origin;\n if (!originHeader || !this._options.allowedOrigins.includes(originHeader)) {\n return `Invalid Origin header: ${originHeader}`;\n }\n }\n\n return undefined;\n }\n\n /**\n * Handles the initial SSE connection request.\n *\n * This should be called when a GET request is made to establish the SSE stream.\n */\n async start(): Promise<void> {\n if (this._sseResponse) {\n throw new Error(\n 'SSEServerTransport already started! If using Server class, note that connect() calls start() automatically.',\n );\n }\n\n this.res.writeHead(200, {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache, no-transform',\n Connection: 'keep-alive',\n });\n\n // Send the endpoint event\n // Use a dummy base URL because this._endpoint is relative.\n // This allows using URL/URLSearchParams for robust parameter handling.\n const dummyBase = 'http://localhost'; // Any valid base works\n const endpointUrl = new URL(this._endpoint, dummyBase);\n endpointUrl.searchParams.set('sessionId', this._sessionId);\n\n // Reconstruct the relative URL string (pathname + search + hash)\n const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash;\n\n this.res.write(`event: endpoint\\ndata: ${relativeUrlWithSession}\\n\\n`);\n\n this._sseResponse = this.res;\n this.res.on('close', () => {\n this._sseResponse = undefined;\n this.onclose?.();\n });\n }\n\n /**\n * Handles incoming POST messages.\n *\n * This should be called when a POST request is made to send a message to the server.\n */\n async handlePostMessage(\n req: IncomingMessage & { auth?: AuthInfo },\n res: ServerResponse,\n parsedBody?: unknown,\n ): Promise<void> {\n if (!this._sseResponse) {\n const message = 'SSE connection not established';\n res.writeHead(500).end(message);\n throw new Error(message);\n }\n\n // Validate request headers for DNS rebinding protection\n const validationError = this.validateRequestHeaders(req);\n if (validationError) {\n res.writeHead(403).end(validationError);\n this.onerror?.(new Error(validationError));\n return;\n }\n\n const authInfo: AuthInfo | undefined = req.auth;\n const requestInfo: RequestInfo = { headers: req.headers } as any;\n\n let body: string | unknown;\n try {\n const ct = contentType.parse(req.headers['content-type'] ?? '');\n if (ct.type !== 'application/json') {\n throw new Error(`Unsupported content-type: ${ct.type}`);\n }\n\n body =\n parsedBody ??\n (await getRawBody(req, {\n limit: MAXIMUM_MESSAGE_SIZE,\n encoding: ct.parameters.charset ?? 'utf-8',\n }));\n } catch (error) {\n res.writeHead(400).end(String(error));\n this.onerror?.(error as Error);\n return;\n }\n\n try {\n await this.handleMessage(typeof body === 'string' ? JSON.parse(body) : body, { requestInfo, authInfo } as any);\n } catch {\n res.writeHead(400).end(`Invalid message: ${body}`);\n return;\n }\n\n res.writeHead(202).end('Accepted');\n }\n\n /**\n * Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.\n */\n async handleMessage(message: unknown, extra?: MessageExtraInfo): Promise<void> {\n let parsedMessage: JSONRPCMessage;\n try {\n parsedMessage = JSONRPCMessageSchema.parse(message);\n } catch (error) {\n this.onerror?.(error as Error);\n throw error;\n }\n\n this.onmessage?.(parsedMessage, extra);\n }\n\n async close(): Promise<void> {\n this._sseResponse?.end();\n this._sseResponse = undefined;\n this.onclose?.();\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._sseResponse) {\n throw new Error('Not connected');\n }\n\n this._sseResponse.write(`event: message\\ndata: ${JSON.stringify(message)}\\n\\n`);\n }\n\n /**\n * Returns the session ID for this transport.\n *\n * This can be used to route incoming POST requests.\n */\n get sessionId(): string {\n return this._sessionId;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"legacy.sse.tranporter.js","sourceRoot":"","sources":["../../../../src/transport/legacy/legacy.sse.tranporter.ts"],"names":[],"mappings":";;;;AAAA,6CAAyC;AAEzC,gEAAkC;AAClC,wEAAuC;AACvC,6BAA0B;AAE1B,iEAA4G;AAG5G,MAAM,oBAAoB,GAAG,KAAK,CAAC;AA2BnC;;;;GAIG;AACH,MAAa,kBAAkB;IAaT;IAA2B;IAZvC,YAAY,CAAkB;IAC9B,UAAU,CAAS;IACnB,QAAQ,CAA4B;IAC5C,oFAAoF;IAC5E,eAAe,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAc;I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AI,CAAC,eAAe,CAAC;QACvC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,OAAO,2BAA2B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClG,CAAC;IAED;;;;OAIG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF;AA/LD,gDA+LC","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { IncomingMessage, ServerResponse } from 'node:http';\nimport getRawBody from 'raw-body';\nimport contentType from 'content-type';\nimport { URL } from 'url';\nimport { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { JSONRPCMessage, JSONRPCMessageSchema, MessageExtraInfo } from '@modelcontextprotocol/sdk/types.js';\nimport { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';\n\nconst MAXIMUM_MESSAGE_SIZE = '4mb';\n\n/**\n * Configuration options for SSEServerTransport.\n */\nexport interface SSEServerTransportOptions {\n /**\n * List of allowed host header values for DNS rebinding protection.\n * If not specified, host validation is disabled.\n */\n allowedHosts?: string[];\n\n /**\n * List of allowed origin header values for DNS rebinding protection.\n * If not specified, origin validation is disabled.\n */\n allowedOrigins?: string[];\n\n /**\n * Enable DNS rebinding protection (requires allowedHosts and/or allowedOrigins to be configured).\n * Default is false for backwards compatibility.\n */\n enableDnsRebindingProtection?: boolean;\n\n sessionId?: string;\n}\n\n/**\n * Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests.\n *\n * This transport is only available in Node.js environments.\n */\nexport class SSEServerTransport implements Transport {\n private _sseResponse?: ServerResponse;\n private _sessionId: string;\n private _options: SSEServerTransportOptions;\n /** Incrementing event ID counter for SSE events (MCP 2025-11-25 spec compliance) */\n private _eventIdCounter = 0;\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;\n\n /**\n * Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by `_endpoint`.\n */\n constructor(private _endpoint: string, private res: ServerResponse, options?: SSEServerTransportOptions) {\n this._sessionId = options?.sessionId ?? randomUUID();\n this._options = options || { enableDnsRebindingProtection: false };\n }\n\n /**\n * Validates request headers for DNS rebinding protection.\n * @returns Error message if validation fails, undefined if validation passes.\n */\n private validateRequestHeaders(req: IncomingMessage): string | undefined {\n // Skip validation if protection is not enabled\n if (!this._options.enableDnsRebindingProtection) {\n return undefined;\n }\n\n // Validate Host header if allowedHosts is configured\n if (this._options.allowedHosts && this._options.allowedHosts.length > 0) {\n const hostHeader = req.headers.host;\n if (!hostHeader || !this._options.allowedHosts.includes(hostHeader)) {\n return `Invalid Host header: ${hostHeader}`;\n }\n }\n\n // Validate Origin header if allowedOrigins is configured\n if (this._options.allowedOrigins && this._options.allowedOrigins.length > 0) {\n const originHeader = req.headers.origin;\n if (!originHeader || !this._options.allowedOrigins.includes(originHeader)) {\n return `Invalid Origin header: ${originHeader}`;\n }\n }\n\n return undefined;\n }\n\n /**\n * Handles the initial SSE connection request.\n *\n * This should be called when a GET request is made to establish the SSE stream.\n */\n async start(): Promise<void> {\n if (this._sseResponse) {\n throw new Error(\n 'SSEServerTransport already started! If using Server class, note that connect() calls start() automatically.',\n );\n }\n\n this.res.writeHead(200, {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache, no-transform',\n Connection: 'keep-alive',\n });\n\n // Send the endpoint event\n // Use a dummy base URL because this._endpoint is relative.\n // This allows using URL/URLSearchParams for robust parameter handling.\n const dummyBase = 'http://localhost'; // Any valid base works\n const endpointUrl = new URL(this._endpoint, dummyBase);\n endpointUrl.searchParams.set('sessionId', this._sessionId);\n\n // Reconstruct the relative URL string (pathname + search + hash)\n const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash;\n\n // Include event ID per MCP 2025-11-25 spec for client reconnection support\n const eventId = ++this._eventIdCounter;\n this.res.write(`id: ${eventId}\\nevent: endpoint\\ndata: ${relativeUrlWithSession}\\n\\n`);\n\n this._sseResponse = this.res;\n this.res.on('close', () => {\n this._sseResponse = undefined;\n this.onclose?.();\n });\n }\n\n /**\n * Handles incoming POST messages.\n *\n * This should be called when a POST request is made to send a message to the server.\n */\n async handlePostMessage(\n req: IncomingMessage & { auth?: AuthInfo },\n res: ServerResponse,\n parsedBody?: unknown,\n ): Promise<void> {\n if (!this._sseResponse) {\n const message = 'SSE connection not established';\n res.writeHead(500).end(message);\n throw new Error(message);\n }\n\n // Validate request headers for DNS rebinding protection\n const validationError = this.validateRequestHeaders(req);\n if (validationError) {\n res.writeHead(403).end(validationError);\n this.onerror?.(new Error(validationError));\n return;\n }\n\n const authInfo: AuthInfo | undefined = req.auth;\n const requestInfo: RequestInfo = { headers: req.headers } as any;\n\n let body: string | unknown;\n try {\n const ct = contentType.parse(req.headers['content-type'] ?? '');\n if (ct.type !== 'application/json') {\n throw new Error(`Unsupported content-type: ${ct.type}`);\n }\n\n body =\n parsedBody ??\n (await getRawBody(req, {\n limit: MAXIMUM_MESSAGE_SIZE,\n encoding: ct.parameters.charset ?? 'utf-8',\n }));\n } catch (error) {\n res.writeHead(400).end(String(error));\n this.onerror?.(error as Error);\n return;\n }\n\n try {\n await this.handleMessage(typeof body === 'string' ? JSON.parse(body) : body, { requestInfo, authInfo } as any);\n } catch {\n res.writeHead(400).end(`Invalid message: ${body}`);\n return;\n }\n\n res.writeHead(202).end('Accepted');\n }\n\n /**\n * Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.\n */\n async handleMessage(message: unknown, extra?: MessageExtraInfo): Promise<void> {\n let parsedMessage: JSONRPCMessage;\n try {\n parsedMessage = JSONRPCMessageSchema.parse(message);\n } catch (error) {\n this.onerror?.(error as Error);\n throw error;\n }\n\n this.onmessage?.(parsedMessage, extra);\n }\n\n async close(): Promise<void> {\n this._sseResponse?.end();\n this._sseResponse = undefined;\n this.onclose?.();\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._sseResponse) {\n throw new Error('Not connected');\n }\n\n // Include event ID per MCP 2025-11-25 spec for client reconnection support\n const eventId = ++this._eventIdCounter;\n this._sseResponse.write(`id: ${eventId}\\nevent: message\\ndata: ${JSON.stringify(message)}\\n\\n`);\n }\n\n /**\n * Returns the session ID for this transport.\n *\n * This can be used to route incoming POST requests.\n */\n get sessionId(): string {\n return this._sessionId;\n }\n\n /**\n * Returns the current event ID counter value.\n *\n * This is the ID that was used for the last sent event.\n * Useful for testing and debugging reconnection scenarios.\n */\n get lastEventId(): number {\n return this._eventIdCounter;\n }\n}\n"]}
|
|
@@ -3,15 +3,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = callToolRequestHandler;
|
|
4
4
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
5
5
|
const errors_1 = require("../../errors");
|
|
6
|
+
const common_1 = require("../../common");
|
|
6
7
|
function callToolRequestHandler({ scope, }) {
|
|
8
|
+
const logger = scope.logger.child('call-tool-request-handler');
|
|
7
9
|
return {
|
|
8
10
|
requestSchema: types_js_1.CallToolRequestSchema,
|
|
9
11
|
handler: async (request, ctx) => {
|
|
12
|
+
const toolName = request.params?.name || 'unknown';
|
|
13
|
+
logger.verbose(`tools/call: ${toolName}`);
|
|
10
14
|
try {
|
|
11
15
|
return await scope.runFlowForOutput('tools:call-tool', { request, ctx });
|
|
12
16
|
}
|
|
13
17
|
catch (e) {
|
|
14
|
-
|
|
18
|
+
// FlowControl is a control flow mechanism, not an error - handle silently
|
|
19
|
+
if (e instanceof common_1.FlowControl) {
|
|
20
|
+
if (e.type === 'respond') {
|
|
21
|
+
// Validate output using MCP schema
|
|
22
|
+
const parseResult = types_js_1.CallToolResultSchema.safeParse(e.output);
|
|
23
|
+
if (parseResult.success) {
|
|
24
|
+
return parseResult.data;
|
|
25
|
+
}
|
|
26
|
+
logger.error('FlowControl.respond has invalid output', {
|
|
27
|
+
tool: toolName,
|
|
28
|
+
validationErrors: parseResult.error.issues,
|
|
29
|
+
});
|
|
30
|
+
return (0, errors_1.formatMcpErrorResponse)(new errors_1.InternalMcpError('FlowControl output is not a valid CallToolResult'));
|
|
31
|
+
}
|
|
32
|
+
// For handled, next, abort, fail - return appropriate response
|
|
33
|
+
logger.warn(`FlowControl ended with type: ${e.type}`, { tool: toolName, type: e.type, output: e.output });
|
|
34
|
+
return (0, errors_1.formatMcpErrorResponse)(new errors_1.InternalMcpError(`Flow ended with: ${e.type}`));
|
|
35
|
+
}
|
|
36
|
+
// Log detailed error info
|
|
37
|
+
logger.error('CallTool Failed', {
|
|
38
|
+
tool: toolName,
|
|
39
|
+
error: e instanceof Error ? { name: e.name, message: e.message, stack: e.stack } : e,
|
|
40
|
+
});
|
|
15
41
|
return (0, errors_1.formatMcpErrorResponse)(e);
|
|
16
42
|
}
|
|
17
43
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-tool-request.handler.js","sourceRoot":"","sources":["../../../../src/transport/mcp-handlers/call-tool-request.handler.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"call-tool-request.handler.js","sourceRoot":"","sources":["../../../../src/transport/mcp-handlers/call-tool-request.handler.ts"],"names":[],"mappings":";;AAUA,yCA0CC;AApDD,iEAK4C;AAE5C,yCAAwE;AACxE,yCAA2C;AAE3C,SAAwB,sBAAsB,CAAC,EAC7C,KAAK,GACa;IAClB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAE/D,OAAO;QACL,aAAa,EAAE,gCAAqB;QACpC,OAAO,EAAE,KAAK,EAAE,OAAwB,EAAE,GAAG,EAAE,EAAE;YAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,IAAI,SAAS,CAAC;YACnD,MAAM,CAAC,OAAO,CAAC,eAAe,Q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,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;iBACrF,CAAC,CAAC;gBACH,OAAO,IAAA,+BAAsB,EAAC,CAAC,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;KACoD,CAAC;AAC1D,CAAC","sourcesContent":["import {\n CallToolRequest,\n CallToolRequestSchema,\n CallToolResult,\n CallToolResultSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { McpHandler, McpHandlerOptions } from './mcp-handlers.types';\nimport { formatMcpErrorResponse, InternalMcpError } from '../../errors';\nimport { FlowControl } from '../../common';\n\nexport default function callToolRequestHandler({\n scope,\n}: McpHandlerOptions): McpHandler<CallToolRequest, CallToolResult> {\n const logger = scope.logger.child('call-tool-request-handler');\n\n return {\n requestSchema: CallToolRequestSchema,\n handler: async (request: CallToolRequest, ctx) => {\n const toolName = request.params?.name || 'unknown';\n logger.verbose(`tools/call: ${toolName}`);\n\n try {\n return await scope.runFlowForOutput('tools:call-tool', { request, ctx });\n } catch (e) {\n // FlowControl is a control flow mechanism, not an error - handle silently\n if (e instanceof FlowControl) {\n if (e.type === 'respond') {\n // Validate output using MCP schema\n const parseResult = CallToolResultSchema.safeParse(e.output);\n if (parseResult.success) {\n return parseResult.data;\n }\n logger.error('FlowControl.respond has invalid output', {\n tool: toolName,\n validationErrors: parseResult.error.issues,\n });\n return formatMcpErrorResponse(new InternalMcpError('FlowControl output is not a valid CallToolResult'));\n }\n // For handled, next, abort, fail - return appropriate response\n logger.warn(`FlowControl ended with type: ${e.type}`, { tool: toolName, type: e.type, output: e.output });\n return formatMcpErrorResponse(new InternalMcpError(`Flow ended with: ${e.type}`));\n }\n\n // Log detailed error info\n logger.error('CallTool Failed', {\n tool: toolName,\n error: e instanceof Error ? { name: e.name, message: e.message, stack: e.stack } : e,\n });\n return formatMcpErrorResponse(e);\n }\n },\n } satisfies McpHandler<CallToolRequest, CallToolResult>;\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CompleteRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { McpHandlerOptions } from './mcp-handlers.types';
|
|
3
|
+
export default function CompleteRequestHandler({ scope }: McpHandlerOptions): {
|
|
4
|
+
requestSchema: import("zod").ZodObject<{
|
|
5
|
+
method: import("zod").ZodLiteral<"completion/complete">;
|
|
6
|
+
params: import("zod").ZodObject<{
|
|
7
|
+
_meta: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
8
|
+
progressToken: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>>;
|
|
9
|
+
}, import("zod/v4/core").$loose>>;
|
|
10
|
+
ref: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
|
|
11
|
+
type: import("zod").ZodLiteral<"ref/prompt">;
|
|
12
|
+
name: import("zod").ZodString;
|
|
13
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
14
|
+
type: import("zod").ZodLiteral<"ref/resource">;
|
|
15
|
+
uri: import("zod").ZodString;
|
|
16
|
+
}, import("zod/v4/core").$strip>]>;
|
|
17
|
+
argument: import("zod").ZodObject<{
|
|
18
|
+
name: import("zod").ZodString;
|
|
19
|
+
value: import("zod").ZodString;
|
|
20
|
+
}, import("zod/v4/core").$strip>;
|
|
21
|
+
context: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
22
|
+
arguments: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
|
|
23
|
+
}, import("zod/v4/core").$strip>>;
|
|
24
|
+
}, import("zod/v4/core").$loose>;
|
|
25
|
+
}, import("zod/v4/core").$strip>;
|
|
26
|
+
handler: (request: CompleteRequest, ctx: import("./mcp-handlers.types").McpRequestHandler<{
|
|
27
|
+
method: "completion/complete";
|
|
28
|
+
params: {
|
|
29
|
+
[x: string]: unknown;
|
|
30
|
+
ref: {
|
|
31
|
+
type: "ref/prompt";
|
|
32
|
+
name: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: "ref/resource";
|
|
35
|
+
uri: string;
|
|
36
|
+
};
|
|
37
|
+
argument: {
|
|
38
|
+
name: string;
|
|
39
|
+
value: string;
|
|
40
|
+
};
|
|
41
|
+
_meta?: {
|
|
42
|
+
[x: string]: unknown;
|
|
43
|
+
progressToken?: string | number | undefined;
|
|
44
|
+
} | undefined;
|
|
45
|
+
context?: {
|
|
46
|
+
arguments?: {
|
|
47
|
+
[x: string]: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
} | undefined;
|
|
50
|
+
};
|
|
51
|
+
}, {
|
|
52
|
+
method: string;
|
|
53
|
+
params?: {
|
|
54
|
+
[x: string]: unknown;
|
|
55
|
+
_meta?: {
|
|
56
|
+
[x: string]: unknown;
|
|
57
|
+
} | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
}>) => Promise<{
|
|
60
|
+
[x: string]: unknown;
|
|
61
|
+
completion: {
|
|
62
|
+
[x: string]: unknown;
|
|
63
|
+
values: string[];
|
|
64
|
+
total?: number | undefined;
|
|
65
|
+
hasMore?: boolean | undefined;
|
|
66
|
+
};
|
|
67
|
+
_meta?: Record<string, unknown> | undefined;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = CompleteRequestHandler;
|
|
4
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
5
|
+
function CompleteRequestHandler({ scope }) {
|
|
6
|
+
return {
|
|
7
|
+
requestSchema: types_js_1.CompleteRequestSchema,
|
|
8
|
+
handler: (request, ctx) => scope.runFlowForOutput('completion:complete', { request, ctx }),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=complete-request.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete-request.handler.js","sourceRoot":"","sources":["../../../../src/transport/mcp-handlers/complete-request.handler.ts"],"names":[],"mappings":";;AAGA,yCAKC;AARD,iEAA4G;AAG5G,SAAwB,sBAAsB,CAAC,EAAE,KAAK,EAAqB;IACzE,OAAO;QACL,aAAa,EAAE,gCAAqB;QACpC,OAAO,EAAE,CAAC,OAAwB,EAAE,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;KACtD,CAAC;AAC1D,CAAC","sourcesContent":["import { CompleteRequestSchema, CompleteRequest, CompleteResult } from '@modelcontextprotocol/sdk/types.js';\nimport { McpHandler, McpHandlerOptions } from './mcp-handlers.types';\n\nexport default function CompleteRequestHandler({ scope }: McpHandlerOptions) {\n return {\n requestSchema: CompleteRequestSchema,\n handler: (request: CompleteRequest, ctx) => scope.runFlowForOutput('completion:complete', { request, ctx }),\n } satisfies McpHandler<CompleteRequest, CompleteResult>;\n}\n"]}
|