@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
|
@@ -5,12 +5,15 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const common_1 = require("../../common");
|
|
6
6
|
require("reflect-metadata");
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
|
+
const v4_1 = require("zod/v4");
|
|
8
9
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
9
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
10
10
|
const errors_1 = require("../../errors");
|
|
11
|
+
const ui_1 = require("../ui");
|
|
12
|
+
const build_1 = require("@frontmcp/ui/build");
|
|
13
|
+
const types_1 = require("@frontmcp/ui/types");
|
|
11
14
|
const inputSchema = zod_1.z.object({
|
|
12
15
|
request: types_js_1.ListToolsRequestSchema,
|
|
13
|
-
ctx: zod_1.z.
|
|
16
|
+
ctx: zod_1.z.unknown(),
|
|
14
17
|
});
|
|
15
18
|
const outputSchema = types_js_1.ListToolsResultSchema;
|
|
16
19
|
const stateSchema = zod_1.z.object({
|
|
@@ -49,7 +52,7 @@ let ToolsListFlow = class ToolsListFlow extends common_1.FlowBase {
|
|
|
49
52
|
params = inputData.request.params;
|
|
50
53
|
}
|
|
51
54
|
catch (e) {
|
|
52
|
-
throw new errors_1.InvalidInputError('Invalid request format', e instanceof zod_1.z.ZodError ? e.
|
|
55
|
+
throw new errors_1.InvalidInputError('Invalid request format', e instanceof zod_1.z.ZodError ? e.issues : undefined);
|
|
53
56
|
}
|
|
54
57
|
if (method !== 'tools/list') {
|
|
55
58
|
this.logger.warn(`parseInput: invalid method "${method}"`);
|
|
@@ -117,46 +120,124 @@ let ToolsListFlow = class ToolsListFlow extends common_1.FlowBase {
|
|
|
117
120
|
}
|
|
118
121
|
async parseTools() {
|
|
119
122
|
this.logger.verbose('parseTools:start');
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
123
|
+
try {
|
|
124
|
+
const resolved = this.state.required.resolvedTools;
|
|
125
|
+
const tools = resolved.map(({ finalName, tool }) => {
|
|
126
|
+
// Get the input schema - prefer rawInputSchema (JSON Schema), then convert from tool.inputSchema
|
|
127
|
+
let inputSchema;
|
|
128
|
+
if (tool.rawInputSchema) {
|
|
129
|
+
// Already converted to JSON Schema
|
|
130
|
+
inputSchema = tool.rawInputSchema;
|
|
131
|
+
}
|
|
132
|
+
else if (tool.inputSchema && Object.keys(tool.inputSchema).length > 0) {
|
|
133
|
+
// tool.inputSchema is a ZodRawShape (extracted .shape from ZodObject in ToolInstance constructor)
|
|
134
|
+
// Convert to JSON Schema
|
|
135
|
+
try {
|
|
136
|
+
// as any used here to prevent hard ts-check on tool input that is redundant
|
|
137
|
+
// and just slow down the build process. types here are unnecessary.
|
|
138
|
+
inputSchema = (0, v4_1.toJSONSchema)(zod_1.z.object(tool.inputSchema));
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
this.logger.warn(`Failed to convert inputSchema for tool ${finalName}:`, e);
|
|
142
|
+
inputSchema = { type: 'object', properties: {} };
|
|
143
|
+
}
|
|
136
144
|
}
|
|
137
|
-
|
|
138
|
-
|
|
145
|
+
else {
|
|
146
|
+
// No schema defined - use empty object schema
|
|
139
147
|
inputSchema = { type: 'object', properties: {} };
|
|
140
148
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
149
|
+
const item = {
|
|
150
|
+
name: finalName,
|
|
151
|
+
title: tool.metadata.name,
|
|
152
|
+
description: tool.metadata.description,
|
|
153
|
+
annotations: tool.metadata.annotations,
|
|
154
|
+
inputSchema,
|
|
155
|
+
};
|
|
156
|
+
// Add OpenAI _meta for tools with UI configuration
|
|
157
|
+
// This is CRITICAL for ChatGPT to discover widget-producing tools at listing time
|
|
158
|
+
// NOTE: Use static URI (like pizzaz example: ui://widget/tool-name.html), NOT template with {requestId}
|
|
159
|
+
// OpenAI tries to fetch the outputTemplate URI directly at discovery time
|
|
160
|
+
if ((0, ui_1.hasUIConfig)(tool.metadata)) {
|
|
161
|
+
const uiConfig = tool.metadata.ui;
|
|
162
|
+
if (!uiConfig) {
|
|
163
|
+
// This should never happen if hasUIConfig returned true
|
|
164
|
+
return item;
|
|
165
|
+
}
|
|
166
|
+
// Get manifest info from registry (if available)
|
|
167
|
+
// Type guard: verify scope has toolUI with required methods before accessing
|
|
168
|
+
const isValidScope = (obj) => {
|
|
169
|
+
return (obj !== null &&
|
|
170
|
+
typeof obj === 'object' &&
|
|
171
|
+
'toolUI' in obj &&
|
|
172
|
+
typeof obj.toolUI === 'object' &&
|
|
173
|
+
obj.toolUI !== null &&
|
|
174
|
+
typeof obj.toolUI.getManifest === 'function' &&
|
|
175
|
+
typeof obj.toolUI.detectUIType === 'function');
|
|
176
|
+
};
|
|
177
|
+
if (!isValidScope(this.scope)) {
|
|
178
|
+
this.logger.warn(`parseTools: toolUI not available in scope for ${finalName}`);
|
|
179
|
+
return item;
|
|
180
|
+
}
|
|
181
|
+
const scope = this.scope;
|
|
182
|
+
// Get manifest and detect UI type with error handling
|
|
183
|
+
let manifest;
|
|
184
|
+
let detectedType;
|
|
185
|
+
try {
|
|
186
|
+
manifest = scope.toolUI.getManifest(finalName);
|
|
187
|
+
detectedType = scope.toolUI.detectUIType(uiConfig.template);
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
this.logger.warn(`parseTools: failed to access toolUI for ${finalName}`, error);
|
|
191
|
+
return item;
|
|
192
|
+
}
|
|
193
|
+
// Use centralized type guard from @frontmcp/ui/types
|
|
194
|
+
const uiType = manifest?.uiType ?? ((0, types_1.isUIType)(detectedType) ? detectedType : 'auto');
|
|
195
|
+
// Always include outputTemplate for all UI tools
|
|
196
|
+
// - static mode: Full widget with React runtime and bridge
|
|
197
|
+
// - inline mode: Lean shell (just HTML + theme), actual widget comes in tool response
|
|
198
|
+
const meta = {
|
|
199
|
+
'openai/outputTemplate': `ui://widget/${encodeURIComponent(finalName)}.html`,
|
|
200
|
+
'openai/resultCanProduceWidget': true,
|
|
201
|
+
'openai/widgetAccessible': uiConfig.widgetAccessible ?? false,
|
|
202
|
+
// CDN info for client-side resource loading
|
|
203
|
+
'ui/cdn': (0, build_1.buildCDNInfoForUIType)(uiType),
|
|
204
|
+
};
|
|
205
|
+
// Add manifest information for client-side renderer selection
|
|
206
|
+
if (manifest) {
|
|
207
|
+
meta['ui/type'] = manifest.uiType;
|
|
208
|
+
meta['ui/manifestUri'] = `ui://widget/${encodeURIComponent(finalName)}/manifest.json`;
|
|
209
|
+
meta['ui/displayMode'] = manifest.displayMode;
|
|
210
|
+
meta['ui/bundlingMode'] = manifest.bundlingMode;
|
|
211
|
+
}
|
|
212
|
+
else if (uiConfig.template) {
|
|
213
|
+
// Fallback to detecting UI type from template
|
|
214
|
+
meta['ui/type'] = uiType;
|
|
215
|
+
// Note: ui/manifestUri is only set when a manifest exists in the registry
|
|
216
|
+
}
|
|
217
|
+
// Add invocation status if configured
|
|
218
|
+
if (uiConfig.invocationStatus?.invoking) {
|
|
219
|
+
meta['openai/toolInvocation/invoking'] = uiConfig.invocationStatus.invoking;
|
|
220
|
+
}
|
|
221
|
+
if (uiConfig.invocationStatus?.invoked) {
|
|
222
|
+
meta['openai/toolInvocation/invoked'] = uiConfig.invocationStatus.invoked;
|
|
223
|
+
}
|
|
224
|
+
item._meta = meta;
|
|
225
|
+
}
|
|
226
|
+
return item;
|
|
227
|
+
});
|
|
228
|
+
const preview = this.sample(tools.map((t) => t.name)).join(', ');
|
|
229
|
+
const extra = tools.length > 5 ? `, +${tools.length - 5} more` : '';
|
|
230
|
+
this.logger.info(`parseTools: prepared ${tools.length} tool descriptor(s): ${preview}${extra}`);
|
|
231
|
+
this.respond({ tools });
|
|
232
|
+
this.logger.info('parseTools: response sent');
|
|
233
|
+
this.logger.verbose('parseTools:done');
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
if (error instanceof common_1.FlowControl)
|
|
237
|
+
throw error;
|
|
238
|
+
this.logger.error('parseTools: failed to parse tools', error);
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
160
241
|
}
|
|
161
242
|
};
|
|
162
243
|
tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools-list.flow.js","sourceRoot":"","sources":["../../../../src/tool/flows/tools-list.flow.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,yCAAgG;AAChG,4BAA0B;AAC1B,6BAAwB;AACxB,iEAAmG;AACnG,2DAAqD;AACrD,yCAAqE;AAErE,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,OAAO,EAAE,iCAAsB;IAC/B,GAAG,EAAE,OAAC,CAAC,GAAG,EAAE;CACb,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,gCAAqB,CAAC;AAE3C,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,KAAK,EAAE,OAAC,CAAC,KAAK,CACZ,OAAC,CAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;QACnB,IAAI,EAAE,OAAC,CAAC,UAAU,CAAC,kBAAS,CAAC;KAC9B,CAAC,CACH;IACD,aAAa,EAAE,OAAC,CAAC,KAAK,CACpB,OAAC,CAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;QACnB,IAAI,EAAE,OAAC,CAAC,UAAU,CAAC,kBAAS,CAAC;QAC7B,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;KACtB,CAAC,CACH;CACF,CAAC,CAAC;AAIH,mCAAmC;AACnC,4CAA4C;AAC5C,MAAM,IAAI,GAAG;IACX,GAAG,EAAE,CAAC,YAAY,CAAC;IACnB,OAAO,EAAE,CAAC,WAAW,EAAE,kBAAkB,CAAC;IAC1C,IAAI,EAAE,CAAC,YAAY,CAAC;CACe,CAAC;AActC,MAAM,IAAI,GAAG,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G,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,KAAK,CAAC,MAAM,wBAAwB,OAAO,GAAG,KAAK,EAAE,CAAC,CAAC;QAEhG,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACzC,CAAC;CACF,CAAA;AAzIO;IADL,KAAK,CAAC,YAAY,CAAC;;;;+CAuBnB;AAGK;IADL,KAAK,CAAC,WAAW,CAAC;;;;8CA4BlB;AAGK;IADL,KAAK,CAAC,kBAAkB,CAAC;;;;qDAmCzB;AAGK;IADL,KAAK,CAAC,YAAY,CAAC;;;;+CA6CnB;AAhJkB,aAAa;IAPjC,IAAA,aAAI,EAAC;QACJ,IAAI;QACJ,IAAI;QACJ,WAAW;QACX,YAAY;QACZ,MAAM,EAAE,YAAY;KACrB,CAAC;GACmB,aAAa,CAiJjC;kBAjJoB,aAAa","sourcesContent":["// tools/flows/list-tools.flow.ts\nimport { Flow, FlowBase, FlowHooksOf, FlowPlan, FlowRunOptions, ToolEntry } from '../../common';\nimport 'reflect-metadata';\nimport { z } from 'zod';\nimport { ListToolsRequestSchema, ListToolsResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport { InvalidMethodError, InvalidInputError } from '../../errors';\n\nconst inputSchema = z.object({\n request: ListToolsRequestSchema,\n ctx: z.any(),\n});\n\nconst outputSchema = ListToolsResultSchema;\n\nconst stateSchema = z.object({\n cursor: z.string().optional(),\n tools: z.array(\n z.object({\n appName: z.string(),\n tool: z.instanceof(ToolEntry),\n }),\n ),\n resolvedTools: z.array(\n z.object({\n appName: z.string(),\n tool: z.instanceof(ToolEntry),\n finalName: z.string(),\n }),\n ),\n});\n\ntype ResponseToolItem = z.infer<typeof outputSchema>['tools'][number];\n\n// TODO: add support for pagination\n// TODO: add support for session based tools\nconst plan = {\n pre: ['parseInput'],\n execute: ['findTools', 'resolveConflicts'],\n post: ['parseTools'],\n} as const satisfies FlowPlan<string>;\n\ndeclare global {\n interface ExtendFlows {\n 'tools:list-tools': FlowRunOptions<\n ToolsListFlow,\n typeof plan,\n typeof inputSchema,\n typeof outputSchema,\n typeof stateSchema\n >;\n }\n}\n\nconst name = 'tools:list-tools' as const;\nconst { Stage } = FlowHooksOf('tools:list-tools');\n\n@Flow({\n name,\n plan,\n inputSchema,\n outputSchema,\n access: 'authorized',\n})\nexport default class ToolsListFlow extends FlowBase<typeof name> {\n logger = this.scopeLogger.child('ToolsListFlow');\n\n private sample<T>(arr: T[], n = 5): T[] {\n return arr.slice(0, n);\n }\n\n @Stage('parseInput')\n async parseInput() {\n this.logger.verbose('parseInput:start');\n\n let method!: string;\n let params: any;\n try {\n const inputData = inputSchema.parse(this.rawInput);\n method = inputData.request.method;\n params = inputData.request.params;\n } catch (e) {\n throw new InvalidInputError('Invalid request format', e instanceof z.ZodError ? e.errors : undefined);\n }\n\n if (method !== 'tools/list') {\n this.logger.warn(`parseInput: invalid method \"${method}\"`);\n throw new InvalidMethodError(method, 'tools/list');\n }\n\n const cursor = params?.cursor;\n if (cursor) this.logger.verbose(`parseInput: cursor=${cursor}`);\n this.state.set('cursor', cursor);\n this.logger.verbose('parseInput:done');\n }\n\n @Stage('findTools')\n async findTools() {\n this.logger.info('findTools:start');\n\n try {\n const apps = this.scope.apps.getApps();\n this.logger.info(`findTools: discovered ${apps.length} app(s)`);\n\n const tools: Array<{ appName: string; tool: ToolEntry }> = [];\n\n const scopeTools = this.scope.tools.getTools();\n this.logger.verbose(`findTools: scope tools=${scopeTools.length}`);\n\n for (const tool of scopeTools) {\n tools.push({ appName: tool.owner.id, tool });\n }\n\n this.logger.info(`findTools: total tools collected=${tools.length}`);\n if (tools.length === 0) {\n this.logger.warn('findTools: no tools found across apps');\n }\n\n this.state.set('tools', tools);\n this.logger.verbose('findTools:done');\n } catch (error) {\n this.logger.error('findTools: failed to collect tools', error);\n throw error;\n }\n }\n\n @Stage('resolveConflicts')\n async resolveConflicts() {\n this.logger.verbose('resolveConflicts:start');\n\n try {\n const found = this.state.required.tools;\n\n const counts = new Map<string, number>();\n for (const { tool } of found) {\n const baseName = tool.metadata.id ?? tool.metadata.name;\n counts.set(baseName, (counts.get(baseName) ?? 0) + 1);\n }\n\n const conflicts = new Set<string>([...counts.entries()].filter(([, n]) => n > 1).map(([k]) => k));\n\n if (conflicts.size > 0) {\n const preview = this.sample(Array.from(conflicts)).join(', ');\n const extra = conflicts.size > 5 ? `, +${conflicts.size - 5} more` : '';\n this.logger.warn(`resolveConflicts: ${conflicts.size} name conflict(s) detected: ${preview}${extra}`);\n } else {\n this.logger.info('resolveConflicts: no name conflicts detected');\n }\n\n const resolved = found.map(({ appName, tool }) => {\n const baseName = tool.metadata.id ?? tool.metadata.name;\n const finalName = conflicts.has(baseName) ? `${appName}:${baseName}` : baseName;\n return { appName, tool, finalName };\n });\n\n this.state.set('resolvedTools', resolved);\n this.logger.verbose('resolveConflicts:done');\n } catch (error) {\n this.logger.error('resolveConflicts: failed to resolve conflicts', error);\n throw error;\n }\n }\n\n @Stage('parseTools')\n async parseTools() {\n this.logger.verbose('parseTools:start');\n\n const resolved = this.state.required.resolvedTools;\n\n const tools: ResponseToolItem[] = resolved.map(({ finalName, tool }) => {\n // Get the input schema - prefer rawInputSchema (JSON Schema), then convert from tool.inputSchema\n let inputSchema: any;\n if (tool.rawInputSchema) {\n // Already converted to JSON Schema\n inputSchema = tool.rawInputSchema;\n } else if (tool.inputSchema && Object.keys(tool.inputSchema).length > 0) {\n // tool.inputSchema is a ZodRawShape (extracted .shape from ZodObject in ToolInstance constructor)\n // Convert to JSON Schema\n try {\n // as any used here to prevent hard ts-check on tool input that is redundant\n // and just slow down the build process. types here are unnecessary.\n // eslint-disable-next-line\n inputSchema = zodToJsonSchema(z.object(tool.inputSchema) as any) as any;\n } catch (e) {\n this.logger.warn(`Failed to convert inputSchema for tool ${finalName}:`, e);\n inputSchema = { type: 'object', properties: {} };\n }\n } else {\n // No schema defined - use empty object schema\n inputSchema = { type: 'object', properties: {} };\n }\n\n return {\n name: finalName,\n title: tool.metadata.name,\n description: tool.metadata.description,\n annotations: tool.metadata.annotations,\n inputSchema,\n };\n });\n\n const preview = this.sample(tools.map((t) => t.name)).join(', ');\n const extra = tools.length > 5 ? `, +${tools.length - 5} more` : '';\n this.logger.info(`parseTools: prepared ${tools.length} tool descriptor(s): ${preview}${extra}`);\n\n this.respond({ tools });\n this.logger.info('parseTools: response sent');\n this.logger.verbose('parseTools:done');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tools-list.flow.js","sourceRoot":"","sources":["../../../../src/tool/flows/tools-list.flow.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,yCAA6G;AAC7G,4BAA0B;AAC1B,6BAAwB;AACxB,+BAAsC;AACtC,iEAAmG;AACnG,yCAAqE;AACrE,8BAAoC;AACpC,8CAAwE;AACxE,8CAA8C;AAG9C,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,OAAO,EAAE,iCAAsB;IAC/B,GAAG,EAAE,OAAC,CAAC,OAAO,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,gCAAqB,CAAC;AAE3C,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,KAAK,EAAE,OAAC,CAAC,KAAK,CACZ,OAAC,CAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;QACnB,IAAI,EAAE,OAAC,CAAC,UAAU,CAAC,kBAAS,CAAC;KA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I,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;YAC9D,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAA;AA/NO;IADL,KAAK,CAAC,YAAY,CAAC;;;;+CAuBnB;AAGK;IADL,KAAK,CAAC,WAAW,CAAC;;;;8CA4BlB;AAGK;IADL,KAAK,CAAC,kBAAkB,CAAC;;;;qDAmCzB;AAGK;IADL,KAAK,CAAC,YAAY,CAAC;;;;+CAmInB;AAtOkB,aAAa;IAPjC,IAAA,aAAI,EAAC;QACJ,IAAI;QACJ,IAAI;QACJ,WAAW;QACX,YAAY;QACZ,MAAM,EAAE,YAAY;KACrB,CAAC;GACmB,aAAa,CAuOjC;kBAvOoB,aAAa","sourcesContent":["// tools/flows/list-tools.flow.ts\nimport { Flow, FlowBase, FlowControl, FlowHooksOf, FlowPlan, FlowRunOptions, ToolEntry } from '../../common';\nimport 'reflect-metadata';\nimport { z } from 'zod';\nimport { toJSONSchema } from 'zod/v4';\nimport { ListToolsRequestSchema, ListToolsResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { InvalidMethodError, InvalidInputError } from '../../errors';\nimport { hasUIConfig } from '../ui';\nimport { buildCDNInfoForUIType, type UIType } from '@frontmcp/ui/build';\nimport { isUIType } from '@frontmcp/ui/types';\nimport type { Scope } from '../../scope/scope.instance';\n\nconst inputSchema = z.object({\n request: ListToolsRequestSchema,\n ctx: z.unknown(),\n});\n\nconst outputSchema = ListToolsResultSchema;\n\nconst stateSchema = z.object({\n cursor: z.string().optional(),\n tools: z.array(\n z.object({\n appName: z.string(),\n tool: z.instanceof(ToolEntry),\n }),\n ),\n resolvedTools: z.array(\n z.object({\n appName: z.string(),\n tool: z.instanceof(ToolEntry),\n finalName: z.string(),\n }),\n ),\n});\n\ntype ResponseToolItem = z.infer<typeof outputSchema>['tools'][number];\n\n// TODO: add support for pagination\n// TODO: add support for session based tools\nconst plan = {\n pre: ['parseInput'],\n execute: ['findTools', 'resolveConflicts'],\n post: ['parseTools'],\n} as const satisfies FlowPlan<string>;\n\ndeclare global {\n interface ExtendFlows {\n 'tools:list-tools': FlowRunOptions<\n ToolsListFlow,\n typeof plan,\n typeof inputSchema,\n typeof outputSchema,\n typeof stateSchema\n >;\n }\n}\n\nconst name = 'tools:list-tools' as const;\nconst { Stage } = FlowHooksOf('tools:list-tools');\n\n@Flow({\n name,\n plan,\n inputSchema,\n outputSchema,\n access: 'authorized',\n})\nexport default class ToolsListFlow extends FlowBase<typeof name> {\n logger = this.scopeLogger.child('ToolsListFlow');\n\n private sample<T>(arr: T[], n = 5): T[] {\n return arr.slice(0, n);\n }\n\n @Stage('parseInput')\n async parseInput() {\n this.logger.verbose('parseInput:start');\n\n let method!: string;\n let params: any;\n try {\n const inputData = inputSchema.parse(this.rawInput);\n method = inputData.request.method;\n params = inputData.request.params;\n } catch (e) {\n throw new InvalidInputError('Invalid request format', e instanceof z.ZodError ? e.issues : undefined);\n }\n\n if (method !== 'tools/list') {\n this.logger.warn(`parseInput: invalid method \"${method}\"`);\n throw new InvalidMethodError(method, 'tools/list');\n }\n\n const cursor = params?.cursor;\n if (cursor) this.logger.verbose(`parseInput: cursor=${cursor}`);\n this.state.set('cursor', cursor);\n this.logger.verbose('parseInput:done');\n }\n\n @Stage('findTools')\n async findTools() {\n this.logger.info('findTools:start');\n\n try {\n const apps = this.scope.apps.getApps();\n this.logger.info(`findTools: discovered ${apps.length} app(s)`);\n\n const tools: Array<{ appName: string; tool: ToolEntry }> = [];\n\n const scopeTools = this.scope.tools.getTools();\n this.logger.verbose(`findTools: scope tools=${scopeTools.length}`);\n\n for (const tool of scopeTools) {\n tools.push({ appName: tool.owner.id, tool });\n }\n\n this.logger.info(`findTools: total tools collected=${tools.length}`);\n if (tools.length === 0) {\n this.logger.warn('findTools: no tools found across apps');\n }\n\n this.state.set('tools', tools);\n this.logger.verbose('findTools:done');\n } catch (error) {\n this.logger.error('findTools: failed to collect tools', error);\n throw error;\n }\n }\n\n @Stage('resolveConflicts')\n async resolveConflicts() {\n this.logger.verbose('resolveConflicts:start');\n\n try {\n const found = this.state.required.tools;\n\n const counts = new Map<string, number>();\n for (const { tool } of found) {\n const baseName = tool.metadata.id ?? tool.metadata.name;\n counts.set(baseName, (counts.get(baseName) ?? 0) + 1);\n }\n\n const conflicts = new Set<string>([...counts.entries()].filter(([, n]) => n > 1).map(([k]) => k));\n\n if (conflicts.size > 0) {\n const preview = this.sample(Array.from(conflicts)).join(', ');\n const extra = conflicts.size > 5 ? `, +${conflicts.size - 5} more` : '';\n this.logger.warn(`resolveConflicts: ${conflicts.size} name conflict(s) detected: ${preview}${extra}`);\n } else {\n this.logger.info('resolveConflicts: no name conflicts detected');\n }\n\n const resolved = found.map(({ appName, tool }) => {\n const baseName = tool.metadata.id ?? tool.metadata.name;\n const finalName = conflicts.has(baseName) ? `${appName}:${baseName}` : baseName;\n return { appName, tool, finalName };\n });\n\n this.state.set('resolvedTools', resolved);\n this.logger.verbose('resolveConflicts:done');\n } catch (error) {\n this.logger.error('resolveConflicts: failed to resolve conflicts', error);\n throw error;\n }\n }\n\n @Stage('parseTools')\n async parseTools() {\n this.logger.verbose('parseTools:start');\n\n try {\n const resolved = this.state.required.resolvedTools;\n\n const tools: ResponseToolItem[] = resolved.map(({ finalName, tool }) => {\n // Get the input schema - prefer rawInputSchema (JSON Schema), then convert from tool.inputSchema\n let inputSchema: any;\n if (tool.rawInputSchema) {\n // Already converted to JSON Schema\n inputSchema = tool.rawInputSchema;\n } else if (tool.inputSchema && Object.keys(tool.inputSchema).length > 0) {\n // tool.inputSchema is a ZodRawShape (extracted .shape from ZodObject in ToolInstance constructor)\n // Convert to JSON Schema\n try {\n // as any used here to prevent hard ts-check on tool input that is redundant\n // and just slow down the build process. types here are unnecessary.\n inputSchema = toJSONSchema(z.object(tool.inputSchema));\n } catch (e) {\n this.logger.warn(`Failed to convert inputSchema for tool ${finalName}:`, e);\n inputSchema = { type: 'object', properties: {} };\n }\n } else {\n // No schema defined - use empty object schema\n inputSchema = { type: 'object', properties: {} };\n }\n\n const item: ResponseToolItem = {\n name: finalName,\n title: tool.metadata.name,\n description: tool.metadata.description,\n annotations: tool.metadata.annotations,\n inputSchema,\n };\n\n // Add OpenAI _meta for tools with UI configuration\n // This is CRITICAL for ChatGPT to discover widget-producing tools at listing time\n // NOTE: Use static URI (like pizzaz example: ui://widget/tool-name.html), NOT template with {requestId}\n // OpenAI tries to fetch the outputTemplate URI directly at discovery time\n if (hasUIConfig(tool.metadata)) {\n const uiConfig = tool.metadata.ui;\n if (!uiConfig) {\n // This should never happen if hasUIConfig returned true\n return item;\n }\n\n // Get manifest info from registry (if available)\n // Type guard: verify scope has toolUI with required methods before accessing\n const isValidScope = (obj: unknown): obj is Scope => {\n return (\n obj !== null &&\n typeof obj === 'object' &&\n 'toolUI' in obj &&\n typeof (obj as { toolUI?: unknown }).toolUI === 'object' &&\n (obj as { toolUI?: unknown }).toolUI !== null &&\n typeof (obj as { toolUI: { getManifest?: unknown } }).toolUI.getManifest === 'function' &&\n typeof (obj as { toolUI: { detectUIType?: unknown } }).toolUI.detectUIType === 'function'\n );\n };\n\n if (!isValidScope(this.scope)) {\n this.logger.warn(`parseTools: toolUI not available in scope for ${finalName}`);\n return item;\n }\n const scope = this.scope;\n\n // Get manifest and detect UI type with error handling\n let manifest;\n let detectedType: string;\n try {\n manifest = scope.toolUI.getManifest(finalName);\n detectedType = scope.toolUI.detectUIType(uiConfig.template);\n } catch (error) {\n this.logger.warn(`parseTools: failed to access toolUI for ${finalName}`, error);\n return item;\n }\n\n // Use centralized type guard from @frontmcp/ui/types\n const uiType: UIType = manifest?.uiType ?? (isUIType(detectedType) ? detectedType : 'auto');\n\n // Always include outputTemplate for all UI tools\n // - static mode: Full widget with React runtime and bridge\n // - inline mode: Lean shell (just HTML + theme), actual widget comes in tool response\n const meta: Record<string, unknown> = {\n 'openai/outputTemplate': `ui://widget/${encodeURIComponent(finalName)}.html`,\n 'openai/resultCanProduceWidget': true,\n 'openai/widgetAccessible': uiConfig.widgetAccessible ?? false,\n // CDN info for client-side resource loading\n 'ui/cdn': buildCDNInfoForUIType(uiType),\n };\n\n // Add manifest information for client-side renderer selection\n if (manifest) {\n meta['ui/type'] = manifest.uiType;\n meta['ui/manifestUri'] = `ui://widget/${encodeURIComponent(finalName)}/manifest.json`;\n meta['ui/displayMode'] = manifest.displayMode;\n meta['ui/bundlingMode'] = manifest.bundlingMode;\n } else if (uiConfig.template) {\n // Fallback to detecting UI type from template\n meta['ui/type'] = uiType;\n // Note: ui/manifestUri is only set when a manifest exists in the registry\n }\n\n // Add invocation status if configured\n if (uiConfig.invocationStatus?.invoking) {\n meta['openai/toolInvocation/invoking'] = uiConfig.invocationStatus.invoking;\n }\n if (uiConfig.invocationStatus?.invoked) {\n meta['openai/toolInvocation/invoked'] = uiConfig.invocationStatus.invoked;\n }\n\n item._meta = meta;\n }\n\n return item;\n });\n\n const preview = this.sample(tools.map((t) => t.name)).join(', ');\n const extra = tools.length > 5 ? `, +${tools.length - 5} more` : '';\n this.logger.info(`parseTools: prepared ${tools.length} tool descriptor(s): ${preview}${extra}`);\n\n this.respond({ tools });\n this.logger.info('parseTools: response sent');\n this.logger.verbose('parseTools:done');\n } catch (error) {\n if (error instanceof FlowControl) throw error;\n this.logger.error('parseTools: failed to parse tools', error);\n throw error;\n }\n }\n}\n"]}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { ToolInstance } from './tool.instance';
|
|
2
2
|
export type ToolChangeKind = 'added' | 'updated' | 'removed' | 'reset';
|
|
3
|
+
/**
|
|
4
|
+
* The scope of a change event.
|
|
5
|
+
* - `global`: Change affects all sessions
|
|
6
|
+
* - `session`: Change affects only a specific session
|
|
7
|
+
*/
|
|
8
|
+
export type ToolChangeScope = 'global' | 'session';
|
|
3
9
|
export type ToolChangeEvent = {
|
|
4
10
|
kind: ToolChangeKind;
|
|
5
|
-
|
|
11
|
+
/** Whether the change affects all sessions or a specific session */
|
|
12
|
+
changeScope: ToolChangeScope;
|
|
6
13
|
sessionId?: string;
|
|
7
14
|
relatedRequestId?: string;
|
|
8
15
|
version: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.events.js","sourceRoot":"","sources":["../../../src/tool/tool.events.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"tool.events.js","sourceRoot":"","sources":["../../../src/tool/tool.events.ts"],"names":[],"mappings":";;;AAuBA,MAAa,WAAW;IACd,SAAS,GAAG,IAAI,GAAG,EAAY,CAAC;IAExC,EAAE,CAAC,CAAW;QACZ,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACtB,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,CAAC,CAAkB;QACrB,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;YAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;CACF;AAXD,kCAWC","sourcesContent":["import { ToolInstance } from './tool.instance';\n\nexport type ToolChangeKind = 'added' | 'updated' | 'removed' | 'reset';\n\n/**\n * The scope of a change event.\n * - `global`: Change affects all sessions\n * - `session`: Change affects only a specific session\n */\nexport type ToolChangeScope = 'global' | 'session';\n\nexport type ToolChangeEvent = {\n kind: ToolChangeKind;\n /** Whether the change affects all sessions or a specific session */\n changeScope: ToolChangeScope;\n sessionId?: string;\n relatedRequestId?: string;\n version: number;\n snapshot: readonly ToolInstance[];\n};\n\ntype Listener = (e: ToolChangeEvent) => void;\n\nexport class ToolEmitter {\n private listeners = new Set<Listener>();\n\n on(l: Listener): () => void {\n this.listeners.add(l);\n return () => this.listeners.delete(l);\n }\n\n emit(e: ToolChangeEvent) {\n for (const l of [...this.listeners]) l(e);\n }\n}\n"]}
|
|
@@ -14,7 +14,9 @@ export declare class ToolInstance<InSchema extends ToolInputType = ToolInputType
|
|
|
14
14
|
readonly hooks: HookRegistry;
|
|
15
15
|
constructor(record: ToolRecord, providers: ProviderRegistry, owner: EntryOwnerRef);
|
|
16
16
|
protected initialize(): Promise<void>;
|
|
17
|
-
getMetadata(): import("../common").ToolMetadata<
|
|
17
|
+
getMetadata(): import("../common").ToolMetadata<Readonly<{
|
|
18
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
19
|
+
}>, ToolOutputType>;
|
|
18
20
|
getOutputSchema(): OutSchema | undefined;
|
|
19
21
|
create(input: ToolCallArgs, ctx: ToolCallExtra): ToolContext<InSchema, OutSchema, In, Out>;
|
|
20
22
|
parseInput(input: CallToolRequest['params']): CallToolRequest['params']['arguments'];
|
|
@@ -6,6 +6,7 @@ const common_1 = require("../common");
|
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
7
|
const hooks_utils_1 = require("../hooks/hooks.utils");
|
|
8
8
|
const tool_utils_1 = require("./tool.utils");
|
|
9
|
+
const mcp_error_1 = require("../errors/mcp.error");
|
|
9
10
|
class ToolInstance extends common_1.ToolEntry {
|
|
10
11
|
providers;
|
|
11
12
|
scope;
|
|
@@ -28,9 +29,22 @@ class ToolInstance extends common_1.ToolEntry {
|
|
|
28
29
|
this.ready = this.initialize();
|
|
29
30
|
}
|
|
30
31
|
async initialize() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// Valid flows for tool hooks
|
|
33
|
+
const validFlows = ['tools:call-tool', 'tools:list-tools'];
|
|
34
|
+
const allHooks = (0, hooks_utils_1.normalizeHooksFromCls)(this.record.provide);
|
|
35
|
+
// Separate valid and invalid hooks
|
|
36
|
+
const validHooks = allHooks.filter((hook) => validFlows.includes(hook.metadata.flow));
|
|
37
|
+
const invalidHooks = allHooks.filter((hook) => !validFlows.includes(hook.metadata.flow));
|
|
38
|
+
// Throw error for invalid hooks (fail fast)
|
|
39
|
+
if (invalidHooks.length > 0) {
|
|
40
|
+
const className = this.record.provide?.name ?? 'Unknown';
|
|
41
|
+
const invalidFlowNames = invalidHooks.map((h) => h.metadata.flow).join(', ');
|
|
42
|
+
throw new mcp_error_1.InvalidHookFlowError(`Tool "${className}" has hooks for unsupported flows: ${invalidFlowNames}. ` +
|
|
43
|
+
`Only tool flows (${validFlows.join(', ')}) are supported on tool classes.`);
|
|
44
|
+
}
|
|
45
|
+
// Register valid hooks
|
|
46
|
+
if (validHooks.length > 0) {
|
|
47
|
+
await this.hooks.registerHooks(true, ...validHooks);
|
|
34
48
|
}
|
|
35
49
|
return Promise.resolve();
|
|
36
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.instance.js","sourceRoot":"","sources":["../../../src/tool/tool.instance.ts"],"names":[],"mappings":";AAAA,2CAA2C;;;AAE3C,sCAgBmB;AAEnB,6BAAwB;AAGxB,sDAA6D;AAE7D,6CAAqD;
|
|
1
|
+
{"version":3,"file":"tool.instance.js","sourceRoot":"","sources":["../../../src/tool/tool.instance.ts"],"names":[],"mappings":";AAAA,2CAA2C;;;AAE3C,sCAgBmB;AAEnB,6BAAwB;AAGxB,sDAA6D;AAE7D,6CAAqD;AACrD,mDAA2D;AAE3D,MAAa,YAKX,SAAQ,kBAAuC;IAC9B,SAAS,CAAmB;IACpC,KAAK,CAAQ;IACb,KAAK,CAAe;IAE7B,YAAY,MAAkB,EAAE,SAA2B,EAAE,KAAoB;QAC/E,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;QAChD,IAAI,CA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\n ToolCallArgs,\n ToolCallExtra,\n ToolContext,\n ToolCtorArgs,\n ToolEntry,\n ToolFunctionTokenRecord,\n ToolInputType,\n ToolKind,\n ToolOutputType,\n ToolRecord,\n ParsedToolResult,\n ToolInputOf,\n ToolOutputOf,\n SafeTransformResult,\n} from '../common';\nimport ProviderRegistry from '../provider/provider.registry';\nimport { z } from 'zod';\nimport HookRegistry from '../hooks/hook.registry';\nimport { Scope } from '../scope';\nimport { normalizeHooksFromCls } from '../hooks/hooks.utils';\nimport type { CallToolRequest } from '@modelcontextprotocol/sdk/types.js';\nimport { buildParsedToolResult } from './tool.utils';\nimport { InvalidHookFlowError } from '../errors/mcp.error';\n\nexport class ToolInstance<\n InSchema extends ToolInputType = ToolInputType,\n OutSchema extends ToolOutputType = ToolOutputType,\n In = ToolInputOf<{ inputSchema: InSchema }>,\n Out = ToolOutputOf<{ outputSchema: OutSchema }>,\n> extends ToolEntry<InSchema, OutSchema, In, Out> {\n private readonly providers: ProviderRegistry;\n readonly scope: Scope;\n readonly hooks: HookRegistry;\n\n constructor(record: ToolRecord, providers: ProviderRegistry, owner: EntryOwnerRef) {\n super(record);\n this.owner = owner;\n this.providers = providers;\n this.name = record.metadata.id || record.metadata.name;\n this.fullName = this.owner.id + ':' + this.name;\n this.scope = this.providers.getActiveScope();\n this.hooks = this.scope.providers.getHooksRegistry();\n\n const schema: any = record.metadata.inputSchema;\n // Support both Zod objects and raw ZodRawShape\n this.inputSchema = schema instanceof z.ZodObject ? schema.shape : schema ?? {};\n\n // Whatever JSON schema representation you’re storing for inputs\n this.rawInputSchema = record.metadata.rawInputSchema;\n\n // IMPORTANT: keep the *raw* outputSchema (string literal, zod, raw shape, or array)\n this.outputSchema = record.metadata.outputSchema as OutSchema;\n\n this.ready = this.initialize();\n }\n\n protected async initialize() {\n // Valid flows for tool hooks\n const validFlows = ['tools:call-tool', 'tools:list-tools'];\n\n const allHooks = normalizeHooksFromCls(this.record.provide);\n\n // Separate valid and invalid hooks\n const validHooks = allHooks.filter((hook) => validFlows.includes(hook.metadata.flow));\n const invalidHooks = allHooks.filter((hook) => !validFlows.includes(hook.metadata.flow));\n\n // Throw error for invalid hooks (fail fast)\n if (invalidHooks.length > 0) {\n const className = (this.record.provide as any)?.name ?? 'Unknown';\n const invalidFlowNames = invalidHooks.map((h) => h.metadata.flow).join(', ');\n throw new InvalidHookFlowError(\n `Tool \"${className}\" has hooks for unsupported flows: ${invalidFlowNames}. ` +\n `Only tool flows (${validFlows.join(', ')}) are supported on tool classes.`,\n );\n }\n\n // Register valid hooks\n if (validHooks.length > 0) {\n await this.hooks.registerHooks(true, ...validHooks);\n }\n return Promise.resolve();\n }\n\n getMetadata() {\n return this.record.metadata;\n }\n\n override getOutputSchema() {\n return this.outputSchema;\n }\n\n override create(input: ToolCallArgs, ctx: ToolCallExtra): ToolContext<InSchema, OutSchema, In, Out> {\n const metadata = this.metadata;\n const providers = this.providers;\n const scope = this.providers.getActiveScope();\n const logger = scope.logger;\n const authInfo = ctx.authInfo;\n\n const toolCtorArgs: ToolCtorArgs<In> = {\n metadata,\n input: input as In,\n providers,\n logger,\n authInfo,\n };\n switch (this.record.kind) {\n case ToolKind.CLASS_TOKEN:\n return new this.record.provide(toolCtorArgs) as ToolContext<InSchema, OutSchema, In, Out>;\n case ToolKind.FUNCTION:\n return new FunctionToolContext<InSchema, OutSchema, In, Out>(this.record, toolCtorArgs);\n }\n }\n\n override parseInput(input: CallToolRequest['params']): CallToolRequest['params']['arguments'] {\n const inputSchema = z.object(this.inputSchema);\n return inputSchema.parse(input.arguments);\n }\n /**\n * Turn the raw tool function result into an MCP-compliant CallToolResult:\n * - `content`: list of ContentBlocks (text / image / audio / resource / resource_link)\n * - `structuredContent`: sanitized JSON when outputSchema is \"json-like\"\n *\n * Rules:\n * - If outputSchema is a JS array → multiple content items, each with its own type.\n * - Primitive → stringifies into a TextContent block.\n * - image/audio/resource/resource_link → passed through as-is.\n * - JSON / structured → JSON.stringify for text, and full sanitized JSON in structuredContent.\n */\n override parseOutput(raw: Out | Partial<Out> | any): ParsedToolResult {\n const descriptor = this.outputSchema as any;\n\n return buildParsedToolResult(descriptor, raw);\n }\n\n override safeParseOutput(raw: Out | Partial<Out> | any): SafeTransformResult<ParsedToolResult> {\n const descriptor = this.outputSchema as any;\n try {\n return { success: true, data: buildParsedToolResult(descriptor, raw) };\n } catch (error: any) {\n return { success: false, error };\n }\n }\n}\n\nclass FunctionToolContext<\n InSchema extends ToolInputType,\n OutSchema extends ToolOutputType,\n In = ToolInputOf<{ inputSchema: InSchema }>,\n Out = ToolOutputOf<{ outputSchema: OutSchema }>,\n> extends ToolContext<InSchema, OutSchema, In, Out> {\n constructor(private readonly record: ToolFunctionTokenRecord, args: ToolCtorArgs<In>) {\n super(args);\n }\n\n execute(input: In): Promise<Out> {\n return this.record.provide(input, this);\n }\n}\n"]}
|
|
@@ -3,7 +3,8 @@ import { ToolChangeEvent } from './tool.events';
|
|
|
3
3
|
import ProviderRegistry from '../provider/provider.registry';
|
|
4
4
|
import { RegistryAbstract, RegistryBuildMapResult } from '../regsitry';
|
|
5
5
|
import { ToolInstance } from './tool.instance';
|
|
6
|
-
import { ExportNameOptions } from
|
|
6
|
+
import { ExportNameOptions } from './tool.types';
|
|
7
|
+
import { ServerCapabilities } from '@modelcontextprotocol/sdk/types.js';
|
|
7
8
|
export default class ToolRegistry extends RegistryAbstract<ToolInstance, // IMPORTANT: instances map holds ToolInstance (not the interface)
|
|
8
9
|
ToolRecord, ToolType[]> implements ToolRegistryInterface {
|
|
9
10
|
/** Who owns this registry (used for provenance). Optional. */
|
|
@@ -69,4 +70,9 @@ ToolRecord, ToolType[]> implements ToolRegistryInterface {
|
|
|
69
70
|
private providerIdOf;
|
|
70
71
|
/** True if this registry (or adopted children) has any tools. */
|
|
71
72
|
hasAny(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Get the MCP capabilities for tools.
|
|
75
|
+
* These are reported to clients during initialization.
|
|
76
|
+
*/
|
|
77
|
+
getCapabilities(): Partial<ServerCapabilities>;
|
|
72
78
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
5
|
const tool_events_1 = require("./tool.events");
|
|
6
6
|
const tool_utils_1 = require("./tool.utils");
|
|
7
|
-
const token_utils_1 = require("../utils/token.utils");
|
|
8
7
|
const regsitry_1 = require("../regsitry");
|
|
9
8
|
const tool_instance_1 = require("./tool.instance");
|
|
10
9
|
const tool_types_1 = require("./tool.types");
|
|
@@ -124,11 +123,14 @@ class ToolRegistry extends regsitry_1.RegistryAbstract {
|
|
|
124
123
|
this.reindex();
|
|
125
124
|
this.bump('reset');
|
|
126
125
|
}
|
|
126
|
+
// NOTE: `any` is intentional here - heterogeneous tool collections can't use `unknown`
|
|
127
|
+
// because ToolEntry has constrained generics (InSchema extends ToolInputType, etc.)
|
|
127
128
|
getTools(includeHidden = false) {
|
|
128
|
-
const local = [...this.localRows].flat().map(t => t.instance);
|
|
129
|
-
const adopted = [...this.adopted.values()].flat().map(t => t.instance);
|
|
130
|
-
return [...local, ...adopted].filter(t => t.metadata.hideFromDiscovery !== true || includeHidden);
|
|
129
|
+
const local = [...this.localRows].flat().map((t) => t.instance);
|
|
130
|
+
const adopted = [...this.adopted.values()].flat().map((t) => t.instance);
|
|
131
|
+
return [...local, ...adopted].filter((t) => t.metadata.hideFromDiscovery !== true || includeHidden);
|
|
131
132
|
}
|
|
133
|
+
// NOTE: `any` is intentional - see getTools comment above
|
|
132
134
|
getInlineTools() {
|
|
133
135
|
return [...this.instances.values()];
|
|
134
136
|
}
|
|
@@ -257,7 +259,7 @@ class ToolRegistry extends regsitry_1.RegistryAbstract {
|
|
|
257
259
|
if (opts.immediate) {
|
|
258
260
|
cb({
|
|
259
261
|
kind: 'reset',
|
|
260
|
-
|
|
262
|
+
changeScope: 'global',
|
|
261
263
|
version: this.version,
|
|
262
264
|
snapshot: this.listAllInstances().filter(filter),
|
|
263
265
|
});
|
|
@@ -266,7 +268,7 @@ class ToolRegistry extends regsitry_1.RegistryAbstract {
|
|
|
266
268
|
}
|
|
267
269
|
bump(kind) {
|
|
268
270
|
const version = ++this.version;
|
|
269
|
-
this.emitter.emit({ kind,
|
|
271
|
+
this.emitter.emit({ kind, changeScope: 'global', version, snapshot: this.listAllInstances() });
|
|
270
272
|
}
|
|
271
273
|
/* -------------------- Helpers -------------------- */
|
|
272
274
|
/** Build an IndexedTool row */
|
|
@@ -274,7 +276,7 @@ class ToolRegistry extends regsitry_1.RegistryAbstract {
|
|
|
274
276
|
const ownerKey = (0, tool_utils_1.ownerKeyOf)(lineage);
|
|
275
277
|
const baseName = instance.name;
|
|
276
278
|
const qualifiedName = (0, tool_utils_1.qualifiedNameOf)(lineage, baseName);
|
|
277
|
-
const qualifiedId = `${ownerKey}:${(0,
|
|
279
|
+
const qualifiedId = `${ownerKey}:${(0, utils_1.tokenName)(token)}`;
|
|
278
280
|
return { token, instance, baseName, lineage, ownerKey, qualifiedName, qualifiedId, source };
|
|
279
281
|
}
|
|
280
282
|
/** Clone a child row and prepend lineage (with adjacent de-dup to avoid double prefixes). */
|
|
@@ -283,7 +285,7 @@ class ToolRegistry extends regsitry_1.RegistryAbstract {
|
|
|
283
285
|
const lineage = dedupLineage(merged);
|
|
284
286
|
const ownerKey = (0, tool_utils_1.ownerKeyOf)(lineage);
|
|
285
287
|
const qualifiedName = (0, tool_utils_1.qualifiedNameOf)(lineage, row.baseName);
|
|
286
|
-
const qualifiedId = `${ownerKey}:${(0,
|
|
288
|
+
const qualifiedId = `${ownerKey}:${(0, utils_1.tokenName)(row.token)}`;
|
|
287
289
|
return {
|
|
288
290
|
token: row.token,
|
|
289
291
|
instance: row.instance, // REFERENCE the same instance
|
|
@@ -305,7 +307,7 @@ class ToolRegistry extends regsitry_1.RegistryAbstract {
|
|
|
305
307
|
return maybe;
|
|
306
308
|
const cls = meta && meta.cls ? meta.cls : undefined;
|
|
307
309
|
if (cls) {
|
|
308
|
-
const id = (0,
|
|
310
|
+
const id = (0, utils_1.getMetadata)('id', cls);
|
|
309
311
|
if (typeof id === 'string' && id.length)
|
|
310
312
|
return id;
|
|
311
313
|
if (cls.name)
|
|
@@ -321,6 +323,20 @@ class ToolRegistry extends regsitry_1.RegistryAbstract {
|
|
|
321
323
|
hasAny() {
|
|
322
324
|
return this.listAllIndexed().length > 0 || this.tokens.size > 0;
|
|
323
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Get the MCP capabilities for tools.
|
|
328
|
+
* These are reported to clients during initialization.
|
|
329
|
+
*/
|
|
330
|
+
getCapabilities() {
|
|
331
|
+
return this.hasAny()
|
|
332
|
+
? {
|
|
333
|
+
tools: {
|
|
334
|
+
// List change notifications are supported if we have any tools registered
|
|
335
|
+
listChanged: true,
|
|
336
|
+
},
|
|
337
|
+
}
|
|
338
|
+
: {};
|
|
339
|
+
}
|
|
324
340
|
}
|
|
325
341
|
exports.default = ToolRegistry;
|
|
326
342
|
/* -------------------- lineage utility -------------------- */
|