@structured-world/gitlab-mcp 10.1.0 → 12.0.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 +8 -8
- package/README.md.in +2 -2
- package/dist/src/accounts/chat-accounts.d.ts +17 -0
- package/dist/src/accounts/chat-accounts.js +245 -0
- package/dist/src/accounts/chat-accounts.js.map +1 -0
- package/dist/src/accounts/instance-tokens.d.ts +2 -0
- package/dist/src/accounts/instance-tokens.js +43 -0
- package/dist/src/accounts/instance-tokens.js.map +1 -0
- package/dist/src/accounts/link.d.ts +16 -0
- package/dist/src/accounts/link.js +469 -0
- package/dist/src/accounts/link.js.map +1 -0
- package/dist/src/accounts/token-account.d.ts +6 -0
- package/dist/src/accounts/token-account.js +13 -0
- package/dist/src/accounts/token-account.js.map +1 -0
- package/dist/src/channel-gateway/format.js +7 -1
- package/dist/src/channel-gateway/format.js.map +1 -1
- package/dist/src/channel-gateway/forwarding.d.ts +3 -0
- package/dist/src/channel-gateway/forwarding.js +8 -1
- package/dist/src/channel-gateway/forwarding.js.map +1 -1
- package/dist/src/channel-gateway/gateway.d.ts +7 -0
- package/dist/src/channel-gateway/gateway.js +80 -16
- package/dist/src/channel-gateway/gateway.js.map +1 -1
- package/dist/src/cli/docker/container-runtime.d.ts +1 -0
- package/dist/src/cli/docker/container-runtime.js +37 -5
- package/dist/src/cli/docker/container-runtime.js.map +1 -1
- package/dist/src/cli/docker/docker-command.js +11 -2
- package/dist/src/cli/docker/docker-command.js.map +1 -1
- package/dist/src/cli/docker/docker-utils.d.ts +1 -0
- package/dist/src/cli/docker/docker-utils.js +137 -27
- package/dist/src/cli/docker/docker-utils.js.map +1 -1
- package/dist/src/cli/docker/oauth-issuer-prompt.d.ts +2 -0
- package/dist/src/cli/docker/oauth-issuer-prompt.js +47 -0
- package/dist/src/cli/docker/oauth-issuer-prompt.js.map +1 -0
- package/dist/src/cli/docker/types.d.ts +18 -4
- package/dist/src/cli/docker/types.js.map +1 -1
- package/dist/src/cli/init/config-generator.d.ts +3 -2
- package/dist/src/cli/init/config-generator.js +15 -0
- package/dist/src/cli/init/config-generator.js.map +1 -1
- package/dist/src/cli/init/types.d.ts +7 -2
- package/dist/src/cli/init/types.js +9 -0
- package/dist/src/cli/init/types.js.map +1 -1
- package/dist/src/cli/init/wizard.js +31 -1
- package/dist/src/cli/init/wizard.js.map +1 -1
- package/dist/src/cli/install/codex.d.ts +25 -0
- package/dist/src/cli/install/codex.js +261 -0
- package/dist/src/cli/install/codex.js.map +1 -0
- package/dist/src/cli/install/detector.js +22 -0
- package/dist/src/cli/install/detector.js.map +1 -1
- package/dist/src/cli/install/index.d.ts +2 -1
- package/dist/src/cli/install/index.js +3 -1
- package/dist/src/cli/install/index.js.map +1 -1
- package/dist/src/cli/install/install-command.d.ts +5 -2
- package/dist/src/cli/install/install-command.js +52 -8
- package/dist/src/cli/install/install-command.js.map +1 -1
- package/dist/src/cli/install/installers.d.ts +8 -8
- package/dist/src/cli/install/installers.js +18 -3
- package/dist/src/cli/install/installers.js.map +1 -1
- package/dist/src/cli/install/notes.d.ts +2 -0
- package/dist/src/cli/install/notes.js +8 -0
- package/dist/src/cli/install/notes.js.map +1 -0
- package/dist/src/cli/install/types.d.ts +1 -0
- package/dist/src/cli/install/types.js +12 -0
- package/dist/src/cli/install/types.js.map +1 -1
- package/dist/src/cli/list-tools.js +14 -35
- package/dist/src/cli/list-tools.js.map +1 -1
- package/dist/src/cli/plugin/build.d.ts +23 -0
- package/dist/src/cli/plugin/build.js +165 -0
- package/dist/src/cli/plugin/build.js.map +1 -0
- package/dist/src/cli/plugin/command.d.ts +4 -0
- package/dist/src/cli/plugin/command.js +89 -0
- package/dist/src/cli/plugin/command.js.map +1 -0
- package/dist/src/cli/plugin/index.d.ts +5 -0
- package/dist/src/cli/plugin/index.js +15 -0
- package/dist/src/cli/plugin/index.js.map +1 -0
- package/dist/src/cli/plugin/listing.d.ts +21 -0
- package/dist/src/cli/plugin/listing.js +44 -0
- package/dist/src/cli/plugin/listing.js.map +1 -0
- package/dist/src/cli/plugin/validate.d.ts +21 -0
- package/dist/src/cli/plugin/validate.js +496 -0
- package/dist/src/cli/plugin/validate.js.map +1 -0
- package/dist/src/cli/plugin/zip.d.ts +6 -0
- package/dist/src/cli/plugin/zip.js +83 -0
- package/dist/src/cli/plugin/zip.js.map +1 -0
- package/dist/src/cli/setup/flows/configure-existing.js +5 -0
- package/dist/src/cli/setup/flows/configure-existing.js.map +1 -1
- package/dist/src/cli/setup/flows/local-setup.js +3 -0
- package/dist/src/cli/setup/flows/local-setup.js.map +1 -1
- package/dist/src/cli/setup/flows/server-setup.js +15 -0
- package/dist/src/cli/setup/flows/server-setup.js.map +1 -1
- package/dist/src/cli-utils.d.ts +2 -0
- package/dist/src/cli-utils.js +6 -0
- package/dist/src/cli-utils.js.map +1 -1
- package/dist/src/config/instances-loader.js +17 -3
- package/dist/src/config/instances-loader.js.map +1 -1
- package/dist/src/config/instances-schema.d.ts +8 -3
- package/dist/src/config/instances-schema.js +12 -6
- package/dist/src/config/instances-schema.js.map +1 -1
- package/dist/src/config.js.map +1 -1
- package/dist/src/configuration/caller.d.ts +10 -0
- package/dist/src/configuration/caller.js +39 -0
- package/dist/src/configuration/caller.js.map +1 -0
- package/dist/src/configuration/composed-feeds.d.ts +31 -0
- package/dist/src/configuration/composed-feeds.js +698 -0
- package/dist/src/configuration/composed-feeds.js.map +1 -0
- package/dist/src/configuration/composed-listings.d.ts +14 -0
- package/dist/src/configuration/composed-listings.js +157 -0
- package/dist/src/configuration/composed-listings.js.map +1 -0
- package/dist/src/configuration/groups.d.ts +8 -0
- package/dist/src/configuration/groups.js +39 -0
- package/dist/src/configuration/groups.js.map +1 -0
- package/dist/src/configuration/index.d.ts +6 -0
- package/dist/src/configuration/index.js +87 -0
- package/dist/src/configuration/index.js.map +1 -0
- package/dist/src/configuration/policy.d.ts +34 -0
- package/dist/src/configuration/policy.js +122 -0
- package/dist/src/configuration/policy.js.map +1 -0
- package/dist/src/configuration/scope-ids.d.ts +7 -0
- package/dist/src/configuration/scope-ids.js +78 -0
- package/dist/src/configuration/scope-ids.js.map +1 -0
- package/dist/src/configuration/scope-projects.d.ts +5 -0
- package/dist/src/configuration/scope-projects.js +76 -0
- package/dist/src/configuration/scope-projects.js.map +1 -0
- package/dist/src/configuration/scope-targets.d.ts +26 -0
- package/dist/src/configuration/scope-targets.js +307 -0
- package/dist/src/configuration/scope-targets.js.map +1 -0
- package/dist/src/configuration/scoped-execution.d.ts +6 -0
- package/dist/src/configuration/scoped-execution.js +577 -0
- package/dist/src/configuration/scoped-execution.js.map +1 -0
- package/dist/src/configuration/scoped-feeds.d.ts +22 -0
- package/dist/src/configuration/scoped-feeds.js +136 -0
- package/dist/src/configuration/scoped-feeds.js.map +1 -0
- package/dist/src/configuration/service.d.ts +52 -0
- package/dist/src/configuration/service.js +169 -0
- package/dist/src/configuration/service.js.map +1 -0
- package/dist/src/configuration/settings-store.d.ts +20 -0
- package/dist/src/configuration/settings-store.js +228 -0
- package/dist/src/configuration/settings-store.js.map +1 -0
- package/dist/src/configuration/types.d.ts +30 -0
- package/dist/src/configuration/types.js +20 -0
- package/dist/src/configuration/types.js.map +1 -0
- package/dist/src/contracts/storage.d.ts +3 -2
- package/dist/src/dashboard/html-template.js +8 -15
- package/dist/src/dashboard/html-template.js.map +1 -1
- package/dist/src/dashboard/metrics.d.ts +1 -1
- package/dist/src/entities/context/accounts.d.ts +19 -0
- package/dist/src/entities/context/accounts.js +115 -0
- package/dist/src/entities/context/accounts.js.map +1 -0
- package/dist/src/entities/context/connection-check.d.ts +64 -0
- package/dist/src/entities/context/connection-check.js +117 -0
- package/dist/src/entities/context/connection-check.js.map +1 -0
- package/dist/src/entities/context/context-manager.d.ts +10 -23
- package/dist/src/entities/context/context-manager.js +101 -282
- package/dist/src/entities/context/context-manager.js.map +1 -1
- package/dist/src/entities/context/handlers.d.ts +5 -5
- package/dist/src/entities/context/handlers.js +11 -14
- package/dist/src/entities/context/handlers.js.map +1 -1
- package/dist/src/entities/context/output-schema.d.ts +320 -0
- package/dist/src/entities/context/output-schema.js +210 -0
- package/dist/src/entities/context/output-schema.js.map +1 -0
- package/dist/src/entities/context/profile.d.ts +29 -0
- package/dist/src/entities/context/profile.js +72 -0
- package/dist/src/entities/context/profile.js.map +1 -0
- package/dist/src/entities/context/registry.js +140 -3
- package/dist/src/entities/context/registry.js.map +1 -1
- package/dist/src/entities/context/schema.d.ts +32 -14
- package/dist/src/entities/context/schema.js +36 -13
- package/dist/src/entities/context/schema.js.map +1 -1
- package/dist/src/entities/context/scope-search.d.ts +49 -0
- package/dist/src/entities/context/scope-search.js +71 -0
- package/dist/src/entities/context/scope-search.js.map +1 -0
- package/dist/src/entities/context/settings-panel.d.ts +13 -0
- package/dist/src/entities/context/settings-panel.js +508 -0
- package/dist/src/entities/context/settings-panel.js.map +1 -0
- package/dist/src/entities/context/settings.d.ts +78 -0
- package/dist/src/entities/context/settings.js +239 -0
- package/dist/src/entities/context/settings.js.map +1 -0
- package/dist/src/entities/context/types.d.ts +3 -4
- package/dist/src/entities/context/whoami.js +39 -31
- package/dist/src/entities/context/whoami.js.map +1 -1
- package/dist/src/entities/core/registry.js +34 -33
- package/dist/src/entities/core/registry.js.map +1 -1
- package/dist/src/entities/core/schema-readonly.d.ts +4 -4
- package/dist/src/entities/environments/schema-readonly.d.ts +4 -4
- package/dist/src/entities/files/registry.js +3 -2
- package/dist/src/entities/files/registry.js.map +1 -1
- package/dist/src/entities/iterations/registry.js +3 -2
- package/dist/src/entities/iterations/registry.js.map +1 -1
- package/dist/src/entities/mrs/registry.js +6 -4
- package/dist/src/entities/mrs/registry.js.map +1 -1
- package/dist/src/entities/mrs/schema-readonly.d.ts +2 -2
- package/dist/src/entities/mrs/schema-readonly.js +19 -2
- package/dist/src/entities/mrs/schema-readonly.js.map +1 -1
- package/dist/src/entities/mrs/schema.d.ts +1 -1
- package/dist/src/entities/pipelines/registry.js +23 -31
- package/dist/src/entities/pipelines/registry.js.map +1 -1
- package/dist/src/entities/pipelines/schema-readonly.d.ts +11 -11
- package/dist/src/entities/pipelines/schema-readonly.js +5 -2
- package/dist/src/entities/pipelines/schema-readonly.js.map +1 -1
- package/dist/src/entities/pipelines/trace.d.ts +20 -0
- package/dist/src/entities/pipelines/trace.js +156 -0
- package/dist/src/entities/pipelines/trace.js.map +1 -0
- package/dist/src/entities/runners/project-access.d.ts +14 -0
- package/dist/src/entities/runners/project-access.js +64 -0
- package/dist/src/entities/runners/project-access.js.map +1 -0
- package/dist/src/entities/runners/registry.js +54 -26
- package/dist/src/entities/runners/registry.js.map +1 -1
- package/dist/src/entities/search/schema-readonly.d.ts +28 -28
- package/dist/src/graphql/runners.d.ts +26 -1
- package/dist/src/graphql/runners.js +43 -6
- package/dist/src/graphql/runners.js.map +1 -1
- package/dist/src/graphql/vulnerabilities.d.ts +3 -0
- package/dist/src/graphql/vulnerabilities.js +1 -0
- package/dist/src/graphql/vulnerabilities.js.map +1 -1
- package/dist/src/handlers.js +351 -190
- package/dist/src/handlers.js.map +1 -1
- package/dist/src/main.js +23 -5
- package/dist/src/main.js.map +1 -1
- package/dist/src/mcp-apps.d.ts +6 -0
- package/dist/src/mcp-apps.js +8 -0
- package/dist/src/mcp-apps.js.map +1 -0
- package/dist/src/mcp-server-context.d.ts +3 -0
- package/dist/src/mcp-server-context.js +13 -0
- package/dist/src/mcp-server-context.js.map +1 -0
- package/dist/src/middleware/mcp-auth-routes.d.ts +3 -0
- package/dist/src/middleware/mcp-auth-routes.js +9 -0
- package/dist/src/middleware/mcp-auth-routes.js.map +1 -0
- package/dist/src/middleware/oauth-auth.js +87 -24
- package/dist/src/middleware/oauth-auth.js.map +1 -1
- package/dist/src/middleware/rate-limiter.js +11 -10
- package/dist/src/middleware/rate-limiter.js.map +1 -1
- package/dist/src/oauth/authorization-response.d.ts +1 -0
- package/dist/src/oauth/authorization-response.js +14 -0
- package/dist/src/oauth/authorization-response.js.map +1 -0
- package/dist/src/oauth/client-auth.d.ts +16 -0
- package/dist/src/oauth/client-auth.js +73 -0
- package/dist/src/oauth/client-auth.js.map +1 -0
- package/dist/src/oauth/code-exchange.d.ts +7 -0
- package/dist/src/oauth/code-exchange.js +38 -0
- package/dist/src/oauth/code-exchange.js.map +1 -0
- package/dist/src/oauth/config.d.ts +2 -0
- package/dist/src/oauth/config.js +37 -0
- package/dist/src/oauth/config.js.map +1 -1
- package/dist/src/oauth/endpoints/authorize.d.ts +1 -0
- package/dist/src/oauth/endpoints/authorize.js +361 -102
- package/dist/src/oauth/endpoints/authorize.js.map +1 -1
- package/dist/src/oauth/endpoints/callback.js +76 -41
- package/dist/src/oauth/endpoints/callback.js.map +1 -1
- package/dist/src/oauth/endpoints/index.d.ts +1 -0
- package/dist/src/oauth/endpoints/index.js +3 -1
- package/dist/src/oauth/endpoints/index.js.map +1 -1
- package/dist/src/oauth/endpoints/metadata.d.ts +1 -1
- package/dist/src/oauth/endpoints/metadata.js +23 -8
- package/dist/src/oauth/endpoints/metadata.js.map +1 -1
- package/dist/src/oauth/endpoints/register.d.ts +3 -2
- package/dist/src/oauth/endpoints/register.js +70 -19
- package/dist/src/oauth/endpoints/register.js.map +1 -1
- package/dist/src/oauth/endpoints/revoke.d.ts +2 -0
- package/dist/src/oauth/endpoints/revoke.js +78 -0
- package/dist/src/oauth/endpoints/revoke.js.map +1 -0
- package/dist/src/oauth/endpoints/token.js +136 -62
- package/dist/src/oauth/endpoints/token.js.map +1 -1
- package/dist/src/oauth/gitlab-device-flow.d.ts +27 -8
- package/dist/src/oauth/gitlab-device-flow.js +119 -57
- package/dist/src/oauth/gitlab-device-flow.js.map +1 -1
- package/dist/src/oauth/gitlab-request-bound.d.ts +1 -0
- package/dist/src/oauth/gitlab-request-bound.js +6 -0
- package/dist/src/oauth/gitlab-request-bound.js.map +1 -0
- package/dist/src/oauth/gitlab-token-refresh.d.ts +7 -0
- package/dist/src/oauth/gitlab-token-refresh.js +147 -0
- package/dist/src/oauth/gitlab-token-refresh.js.map +1 -0
- package/dist/src/oauth/grant-revocation.d.ts +10 -0
- package/dist/src/oauth/grant-revocation.js +179 -0
- package/dist/src/oauth/grant-revocation.js.map +1 -0
- package/dist/src/oauth/granted-scopes.d.ts +1 -0
- package/dist/src/oauth/granted-scopes.js +7 -0
- package/dist/src/oauth/granted-scopes.js.map +1 -0
- package/dist/src/oauth/index.d.ts +2 -2
- package/dist/src/oauth/index.js +4 -2
- package/dist/src/oauth/index.js.map +1 -1
- package/dist/src/oauth/instance-app.d.ts +4 -0
- package/dist/src/oauth/instance-app.js +45 -0
- package/dist/src/oauth/instance-app.js.map +1 -0
- package/dist/src/oauth/issued-tokens.d.ts +1 -0
- package/dist/src/oauth/issued-tokens.js +24 -0
- package/dist/src/oauth/issued-tokens.js.map +1 -0
- package/dist/src/oauth/oauth-app.d.ts +9 -0
- package/dist/src/oauth/oauth-app.js +14 -0
- package/dist/src/oauth/oauth-app.js.map +1 -0
- package/dist/src/oauth/request-params.d.ts +1 -0
- package/dist/src/oauth/request-params.js +17 -0
- package/dist/src/oauth/request-params.js.map +1 -0
- package/dist/src/oauth/resource.d.ts +12 -0
- package/dist/src/oauth/resource.js +66 -0
- package/dist/src/oauth/resource.js.map +1 -0
- package/dist/src/oauth/routes.d.ts +2 -0
- package/dist/src/oauth/routes.js +31 -0
- package/dist/src/oauth/routes.js.map +1 -0
- package/dist/src/oauth/session-store.d.ts +51 -36
- package/dist/src/oauth/session-store.js +156 -251
- package/dist/src/oauth/session-store.js.map +1 -1
- package/dist/src/oauth/storage/factory.js +1 -1
- package/dist/src/oauth/storage/factory.js.map +1 -1
- package/dist/src/oauth/storage/file.d.ts +29 -2
- package/dist/src/oauth/storage/file.js +194 -42
- package/dist/src/oauth/storage/file.js.map +1 -1
- package/dist/src/oauth/storage/memory.d.ts +35 -2
- package/dist/src/oauth/storage/memory.js +327 -32
- package/dist/src/oauth/storage/memory.js.map +1 -1
- package/dist/src/oauth/storage/types.d.ts +37 -1
- package/dist/src/oauth/storage/types.js +6 -1
- package/dist/src/oauth/storage/types.js.map +1 -1
- package/dist/src/oauth/tool-auth.d.ts +12 -0
- package/dist/src/oauth/tool-auth.js +108 -0
- package/dist/src/oauth/tool-auth.js.map +1 -0
- package/dist/src/oauth/types.d.ts +41 -0
- package/dist/src/profiles/scope-enforcer.d.ts +8 -0
- package/dist/src/profiles/scope-enforcer.js +86 -24
- package/dist/src/profiles/scope-enforcer.js.map +1 -1
- package/dist/src/profiles/types.js +4 -1
- package/dist/src/profiles/types.js.map +1 -1
- package/dist/src/registry-manager.d.ts +16 -4
- package/dist/src/registry-manager.js +122 -33
- package/dist/src/registry-manager.js.map +1 -1
- package/dist/src/server.js +82 -50
- package/dist/src/server.js.map +1 -1
- package/dist/src/services/AdminDetector.d.ts +1 -1
- package/dist/src/services/AdminDetector.js +4 -4
- package/dist/src/services/AdminDetector.js.map +1 -1
- package/dist/src/services/ConnectionManager.d.ts +2 -2
- package/dist/src/services/ConnectionManager.js +43 -70
- package/dist/src/services/ConnectionManager.js.map +1 -1
- package/dist/src/services/HealthMonitor.js +4 -2
- package/dist/src/services/HealthMonitor.js.map +1 -1
- package/dist/src/services/NamespaceTierDetector.js +26 -27
- package/dist/src/services/NamespaceTierDetector.js.map +1 -1
- package/dist/src/services/TokenScopeDetector.d.ts +6 -2
- package/dist/src/services/TokenScopeDetector.js +22 -3
- package/dist/src/services/TokenScopeDetector.js.map +1 -1
- package/dist/src/session-manager.d.ts +3 -1
- package/dist/src/session-manager.js +43 -10
- package/dist/src/session-manager.js.map +1 -1
- package/dist/src/types.d.ts +3 -2
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/bounded-map.d.ts +1 -0
- package/dist/src/utils/bounded-map.js +23 -0
- package/dist/src/utils/bounded-map.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +1 -2
- package/dist/src/utils/fetch.js +12 -17
- package/dist/src/utils/fetch.js.map +1 -1
- package/dist/src/utils/gitlab-api.js +2 -1
- package/dist/src/utils/gitlab-api.js.map +1 -1
- package/dist/src/utils/gitlab-base-url.d.ts +2 -0
- package/dist/src/utils/gitlab-base-url.js +34 -0
- package/dist/src/utils/gitlab-base-url.js.map +1 -0
- package/dist/src/utils/html.d.ts +1 -0
- package/dist/src/utils/html.js +12 -0
- package/dist/src/utils/html.js.map +1 -0
- package/dist/src/utils/namespace.d.ts +1 -0
- package/dist/src/utils/namespace.js +72 -24
- package/dist/src/utils/namespace.js.map +1 -1
- package/dist/src/utils/schema-utils.d.ts +5 -3
- package/dist/src/utils/schema-utils.js +50 -22
- package/dist/src/utils/schema-utils.js.map +1 -1
- package/dist/src/utils/smart-user-search.js +2 -1
- package/dist/src/utils/smart-user-search.js.map +1 -1
- package/dist/src/utils/sync-directory.d.ts +1 -0
- package/dist/src/utils/sync-directory.js +49 -0
- package/dist/src/utils/sync-directory.js.map +1 -0
- package/dist/src/utils/tool-result.d.ts +4 -0
- package/dist/src/utils/tool-result.js +41 -0
- package/dist/src/utils/tool-result.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +74 -21
- package/plugin/assets/composer-icon-dark.png +0 -0
- package/plugin/assets/composer-icon-dark.svg +17 -0
- package/plugin/assets/composer-icon.png +0 -0
- package/plugin/assets/composer-icon.svg +17 -0
- package/plugin/assets/logo.png +0 -0
- package/plugin/assets/screenshot-1.png +0 -0
- package/plugin/assets/screenshot-2.png +0 -0
- package/plugin/schemas/mcp.schema.json +120 -0
- package/plugin/schemas/plugin.schema.json +65 -0
- package/skills/gitlab-ci/SKILL.md +16 -0
- package/skills/gitlab-discovery/SKILL.md +15 -0
- package/skills/gitlab-review/SKILL.md +16 -0
- package/skills/gitlab-setup/SKILL.md +16 -0
- package/skills/gitlab-work-items/SKILL.md +16 -0
package/dist/src/handlers.js
CHANGED
|
@@ -36,6 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.resetHandlersState = resetHandlersState;
|
|
37
37
|
exports.setupHandlers = setupHandlers;
|
|
38
38
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
39
|
+
const settings_panel_1 = require("./entities/context/settings-panel");
|
|
40
|
+
const mcp_apps_1 = require("./mcp-apps");
|
|
39
41
|
const ConnectionManager_1 = require("./services/ConnectionManager");
|
|
40
42
|
const HealthMonitor_1 = require("./services/HealthMonitor");
|
|
41
43
|
const url_1 = require("./utils/url");
|
|
@@ -44,6 +46,16 @@ const error_handler_1 = require("./utils/error-handler");
|
|
|
44
46
|
const fetch_1 = require("./utils/fetch");
|
|
45
47
|
const index_1 = require("./logging/index");
|
|
46
48
|
const config_1 = require("./config");
|
|
49
|
+
const schema_utils_1 = require("./utils/schema-utils");
|
|
50
|
+
const tool_result_1 = require("./utils/tool-result");
|
|
51
|
+
const tool_auth_1 = require("./oauth/tool-auth");
|
|
52
|
+
const chat_accounts_1 = require("./accounts/chat-accounts");
|
|
53
|
+
const mcp_server_context_1 = require("./mcp-server-context");
|
|
54
|
+
const token_account_1 = require("./accounts/token-account");
|
|
55
|
+
const configuration_1 = require("./configuration");
|
|
56
|
+
const policy_1 = require("./configuration/policy");
|
|
57
|
+
const scoped_execution_1 = require("./configuration/scoped-execution");
|
|
58
|
+
const scope_ids_1 = require("./configuration/scope-ids");
|
|
47
59
|
function hasAction(value) {
|
|
48
60
|
return (typeof value === 'object' &&
|
|
49
61
|
value !== null &&
|
|
@@ -74,14 +86,15 @@ function recordEarlyReturnError(toolName, action, errorMessage) {
|
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
88
|
}
|
|
77
|
-
function isIdempotentOperation(toolName) {
|
|
89
|
+
function isIdempotentOperation(toolName, declared) {
|
|
90
|
+
if (declared !== undefined)
|
|
91
|
+
return declared;
|
|
78
92
|
return (toolName.startsWith('browse_') ||
|
|
79
93
|
toolName.startsWith('list_') ||
|
|
80
94
|
toolName.startsWith('get_') ||
|
|
81
|
-
toolName.startsWith('download_')
|
|
82
|
-
toolName === 'manage_context');
|
|
95
|
+
toolName.startsWith('download_'));
|
|
83
96
|
}
|
|
84
|
-
function toStructuredError(error, toolName, toolArgs) {
|
|
97
|
+
function toStructuredError(error, toolName, toolArgs, declaredIdempotent) {
|
|
85
98
|
if ((0, error_handler_1.isStructuredToolError)(error)) {
|
|
86
99
|
return error.structuredError;
|
|
87
100
|
}
|
|
@@ -101,13 +114,13 @@ function toStructuredError(error, toolName, toolArgs) {
|
|
|
101
114
|
error.name === 'GitLabTimeoutError' &&
|
|
102
115
|
'timeoutMs' in error &&
|
|
103
116
|
typeof error.timeoutMs === 'number')) {
|
|
104
|
-
const retryable = isIdempotentOperation(toolName);
|
|
117
|
+
const retryable = isIdempotentOperation(toolName, declaredIdempotent);
|
|
105
118
|
return (0, error_handler_1.createTimeoutError)(toolName, action, error.timeoutMs, retryable);
|
|
106
119
|
}
|
|
107
120
|
if (error instanceof Error) {
|
|
108
121
|
const timeoutMs = (0, error_handler_1.parseTimeoutError)(error.message);
|
|
109
122
|
if (timeoutMs !== null) {
|
|
110
|
-
const retryable = isIdempotentOperation(toolName);
|
|
123
|
+
const retryable = isIdempotentOperation(toolName, declaredIdempotent);
|
|
111
124
|
return (0, error_handler_1.createTimeoutError)(toolName, action, timeoutMs, retryable);
|
|
112
125
|
}
|
|
113
126
|
}
|
|
@@ -117,7 +130,8 @@ function toStructuredError(error, toolName, toolArgs) {
|
|
|
117
130
|
return (0, error_handler_1.handleGitLabError)({ status: parsed.status, message: parsed.message }, toolName, action, toolArgs);
|
|
118
131
|
}
|
|
119
132
|
function checkUnreachableInstance(toolName, toolArguments, effectiveInstanceUrl, healthMonitor) {
|
|
120
|
-
if (healthMonitor.isInstanceReachable(effectiveInstanceUrl) ||
|
|
133
|
+
if (healthMonitor.isInstanceReachable(effectiveInstanceUrl) ||
|
|
134
|
+
policy_1.CONFIGURATION_TOOLS.has(toolName)) {
|
|
121
135
|
return null;
|
|
122
136
|
}
|
|
123
137
|
const action = toolArguments && typeof toolArguments.action === 'string' ? toolArguments.action : 'unknown';
|
|
@@ -134,37 +148,26 @@ function checkUnreachableInstance(toolName, toolArguments, effectiveInstanceUrl,
|
|
|
134
148
|
}
|
|
135
149
|
const connError = (0, error_handler_1.createConnectionFailedError)(toolName, action, effectiveInstanceUrl, connectionState);
|
|
136
150
|
recordEarlyReturnError(toolName, action, connError.message);
|
|
137
|
-
return
|
|
151
|
+
return (0, tool_result_1.errorToolResult)(connError);
|
|
138
152
|
}
|
|
139
|
-
async function
|
|
140
|
-
if (toolName
|
|
141
|
-
|
|
142
|
-
const action = toolArguments && typeof toolArguments.action === 'string' ? toolArguments.action : undefined;
|
|
143
|
-
if (action !== 'switch_profile')
|
|
144
|
-
return;
|
|
145
|
-
try {
|
|
146
|
-
const { getContextManager } = await Promise.resolve().then(() => __importStar(require('./entities/context/context-manager')));
|
|
147
|
-
const newProfileUrl = await getContextManager().getCurrentProfileUrl();
|
|
148
|
-
if (!newProfileUrl)
|
|
149
|
-
return;
|
|
150
|
-
const normalized = (0, url_1.normalizeInstanceUrl)(newProfileUrl);
|
|
151
|
-
const { getSessionManager } = await Promise.resolve().then(() => __importStar(require('./session-manager')));
|
|
152
|
-
const sessionManager = getSessionManager();
|
|
153
|
-
const pinnedUrl = sessionManager.getSessionInstanceUrl(sessionId);
|
|
154
|
-
if (pinnedUrl && (0, url_1.normalizeInstanceUrl)(pinnedUrl) === normalized)
|
|
155
|
-
return;
|
|
156
|
-
sessionManager.setSessionInstanceUrl(sessionId, normalized);
|
|
157
|
-
}
|
|
158
|
-
catch (err) {
|
|
159
|
-
(0, logger_1.logWarn)('Failed to re-pin session after switch_profile', {
|
|
160
|
-
error: err instanceof Error ? err.message : String(err),
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
async function tryManageContextFastPath(toolName, toolArguments, effectiveInstanceUrl, healthMonitor, sessionId) {
|
|
165
|
-
if (toolName !== 'manage_context' || healthMonitor.isInstanceReachable(effectiveInstanceUrl)) {
|
|
153
|
+
async function tryManageContextFastPath(toolName, toolArguments, effectiveInstanceUrl, healthMonitor, sessionId, requestScopes) {
|
|
154
|
+
if (!policy_1.CONFIGURATION_TOOLS.has(toolName) ||
|
|
155
|
+
healthMonitor.isInstanceReachable(effectiveInstanceUrl)) {
|
|
166
156
|
return null;
|
|
167
157
|
}
|
|
158
|
+
const result = await executeWithoutBootstrap(toolName, toolArguments, effectiveInstanceUrl, requestScopes);
|
|
159
|
+
if (result)
|
|
160
|
+
healthMonitor.forceReconnect(effectiveInstanceUrl);
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
async function tryWithoutBootstrap(request, toolArguments, effectiveInstanceUrl, healthMonitor, sessionId, requestScopes) {
|
|
164
|
+
const toolName = request.params.name;
|
|
165
|
+
const fastPath = await tryManageContextFastPath(toolName, toolArguments, effectiveInstanceUrl, healthMonitor, sessionId, requestScopes);
|
|
166
|
+
if (fastPath || !managesAccounts(request))
|
|
167
|
+
return fastPath;
|
|
168
|
+
return executeWithoutBootstrap(toolName, toolArguments, effectiveInstanceUrl, requestScopes);
|
|
169
|
+
}
|
|
170
|
+
async function executeWithoutBootstrap(toolName, toolArguments, effectiveInstanceUrl, requestScopes) {
|
|
168
171
|
if (config_1.LOG_FORMAT === 'condensed') {
|
|
169
172
|
const action = toolArguments && typeof toolArguments.action === 'string' ? toolArguments.action : undefined;
|
|
170
173
|
const requestTracker = (0, index_1.getRequestTracker)();
|
|
@@ -172,21 +175,21 @@ async function tryManageContextFastPath(toolName, toolArguments, effectiveInstan
|
|
|
172
175
|
}
|
|
173
176
|
const { RegistryManager } = await Promise.resolve().then(() => __importStar(require('./registry-manager')));
|
|
174
177
|
const registryManager = RegistryManager.getInstance();
|
|
175
|
-
if (registryManager.hasToolHandler(toolName, effectiveInstanceUrl)) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
178
|
+
if (!registryManager.hasToolHandler(toolName, effectiveInstanceUrl)) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const result = await registryManager.executeTool(toolName, toolArguments, effectiveInstanceUrl, requestScopes);
|
|
182
|
+
if (result === undefined) {
|
|
183
|
+
return null;
|
|
182
184
|
}
|
|
183
|
-
return
|
|
185
|
+
return (0, tool_result_1.formatToolResult)(result, registryManager.getTool(toolName, effectiveInstanceUrl, requestScopes));
|
|
184
186
|
}
|
|
185
187
|
async function ensureBootstrapped(ctx) {
|
|
186
|
-
const {
|
|
188
|
+
const { effectiveInstanceUrl, oauthMode, requestScopes, connectionManager, bootstrapState } = ctx;
|
|
187
189
|
bootstrapState.started = true;
|
|
188
190
|
try {
|
|
189
|
-
|
|
191
|
+
const firstInitialization = !connectionManager.isConnected(effectiveInstanceUrl);
|
|
192
|
+
if (firstInitialization) {
|
|
190
193
|
if (config_1.LOG_FORMAT === 'verbose') {
|
|
191
194
|
(0, logger_1.logInfo)('Connection not initialized, attempting to initialize...');
|
|
192
195
|
}
|
|
@@ -194,7 +197,7 @@ async function ensureBootstrapped(ctx) {
|
|
|
194
197
|
}
|
|
195
198
|
connectionManager.getClient(effectiveInstanceUrl);
|
|
196
199
|
if (oauthMode) {
|
|
197
|
-
await connectionManager.ensureIntrospected(effectiveInstanceUrl);
|
|
200
|
+
await connectionManager.ensureIntrospected(effectiveInstanceUrl, requestScopes);
|
|
198
201
|
}
|
|
199
202
|
bootstrapState.complete = true;
|
|
200
203
|
try {
|
|
@@ -207,6 +210,8 @@ async function ensureBootstrapped(ctx) {
|
|
|
207
210
|
err: cacheError,
|
|
208
211
|
});
|
|
209
212
|
}
|
|
213
|
+
if (firstInitialization)
|
|
214
|
+
announceToolListChange(effectiveInstanceUrl);
|
|
210
215
|
if (config_1.LOG_FORMAT === 'verbose') {
|
|
211
216
|
try {
|
|
212
217
|
const instanceInfo = connectionManager.getInstanceInfo(effectiveInstanceUrl);
|
|
@@ -221,37 +226,177 @@ async function ensureBootstrapped(ctx) {
|
|
|
221
226
|
return undefined;
|
|
222
227
|
}
|
|
223
228
|
catch (initError) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
229
|
+
return formatBootstrapFailure(ctx, initError);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function announceToolListChange(instanceUrl) {
|
|
233
|
+
void Promise.resolve().then(() => __importStar(require('./session-manager'))).then(({ getSessionManager }) => getSessionManager().broadcastToolsListChanged(instanceUrl))
|
|
234
|
+
.catch((error) => (0, logger_1.logDebug)('Could not announce the tool list', { err: error }));
|
|
235
|
+
void (0, mcp_server_context_1.currentMcpServer)()
|
|
236
|
+
?.sendToolListChanged()
|
|
237
|
+
.catch((error) => (0, logger_1.logDebug)('Could not announce the tool list', { err: error }));
|
|
238
|
+
}
|
|
239
|
+
function bootstrapFailureState(monitorState, category) {
|
|
240
|
+
if (monitorState === 'connecting' || monitorState === 'failed')
|
|
241
|
+
return monitorState;
|
|
242
|
+
return category === 'auth' || category === 'permanent' ? 'failed' : 'disconnected';
|
|
243
|
+
}
|
|
244
|
+
function formatBootstrapFailure(ctx, initError) {
|
|
245
|
+
const { toolName, toolArguments, effectiveInstanceUrl, healthMonitor, isTimedOut } = ctx;
|
|
246
|
+
const errorCategory = initError instanceof Error ? (0, error_handler_1.classifyError)(initError) : 'permanent';
|
|
247
|
+
if (initError instanceof Error) {
|
|
248
|
+
if (!isTimedOut() || errorCategory === 'auth' || errorCategory === 'permanent') {
|
|
249
|
+
healthMonitor.reportError(effectiveInstanceUrl, initError);
|
|
242
250
|
}
|
|
243
|
-
|
|
244
|
-
|
|
251
|
+
}
|
|
252
|
+
(0, logger_1.logError)(`Connection initialization failed: ${initError instanceof Error ? initError.message : String(initError)}`, {
|
|
253
|
+
instanceUrl: effectiveInstanceUrl,
|
|
254
|
+
err: initError instanceof Error ? initError : new Error(String(initError)),
|
|
255
|
+
});
|
|
256
|
+
const action = toolArguments && typeof toolArguments.action === 'string' ? toolArguments.action : 'unknown';
|
|
257
|
+
const monitorState = healthMonitor.getState(effectiveInstanceUrl);
|
|
258
|
+
const derivedState = bootstrapFailureState(monitorState, errorCategory);
|
|
259
|
+
const connError = (0, error_handler_1.createConnectionFailedError)(toolName, action, effectiveInstanceUrl, derivedState);
|
|
260
|
+
if (!isTimedOut()) {
|
|
261
|
+
recordEarlyReturnError(toolName, action, connError.message);
|
|
262
|
+
}
|
|
263
|
+
return (0, tool_auth_1.withReauthChallenge)((0, tool_result_1.errorToolResult)(connError), initError);
|
|
264
|
+
}
|
|
265
|
+
const ACCOUNT_ACTIONS = new Set([
|
|
266
|
+
'list_accounts',
|
|
267
|
+
'switch_account',
|
|
268
|
+
'link_account',
|
|
269
|
+
'unlink_account',
|
|
270
|
+
]);
|
|
271
|
+
function managesAccounts(request) {
|
|
272
|
+
const action = request.params.arguments?.action;
|
|
273
|
+
return (request.params.name === 'manage_context' &&
|
|
274
|
+
typeof action === 'string' &&
|
|
275
|
+
ACCOUNT_ACTIONS.has(action));
|
|
276
|
+
}
|
|
277
|
+
function activeInstanceUrl(oauthEnabled, oauthContextUrl) {
|
|
278
|
+
const raw = oauthEnabled
|
|
279
|
+
? (oauthContextUrl ?? config_1.GITLAB_BASE_URL)
|
|
280
|
+
: ((0, token_account_1.currentTokenAccount)()?.instanceUrl ?? config_1.GITLAB_BASE_URL);
|
|
281
|
+
return (0, url_1.normalizeInstanceUrl)(raw);
|
|
282
|
+
}
|
|
283
|
+
async function pinSessionInstance(sessionId, oauthEnabled, oauthContextUrl, instanceUrl) {
|
|
284
|
+
if (oauthEnabled && oauthContextUrl === undefined)
|
|
285
|
+
return;
|
|
286
|
+
const { getSessionManager } = await Promise.resolve().then(() => __importStar(require('./session-manager')));
|
|
287
|
+
getSessionManager().setSessionInstanceUrl(sessionId, instanceUrl);
|
|
288
|
+
}
|
|
289
|
+
const HANDLER_TIMEOUT = Symbol('handler_timeout');
|
|
290
|
+
function startCallDeadline() {
|
|
291
|
+
let expired = false;
|
|
292
|
+
let timer;
|
|
293
|
+
const promise = new Promise((resolve) => {
|
|
294
|
+
timer = setTimeout(() => {
|
|
295
|
+
expired = true;
|
|
296
|
+
resolve(HANDLER_TIMEOUT);
|
|
297
|
+
}, config_1.HANDLER_TIMEOUT_MS);
|
|
298
|
+
});
|
|
299
|
+
return { expired: promise, isExpired: () => expired, clear: () => clearTimeout(timer) };
|
|
300
|
+
}
|
|
301
|
+
function handlerTimeoutResult(request, declaredIdempotent, bootstrapState, requestInstanceUrl) {
|
|
302
|
+
const toolName = request.params.name;
|
|
303
|
+
const requested = request.params.arguments?.action;
|
|
304
|
+
const action = typeof requested === 'string' ? requested : 'unknown';
|
|
305
|
+
const retryable = isIdempotentOperation(toolName, declaredIdempotent);
|
|
306
|
+
const timeoutError = (0, error_handler_1.createTimeoutError)(toolName, action, config_1.HANDLER_TIMEOUT_MS, retryable);
|
|
307
|
+
(0, logger_1.logError)(`Handler timeout: tool '${toolName}' timed out after ${config_1.HANDLER_TIMEOUT_MS}ms`);
|
|
308
|
+
if (bootstrapState.started && !bootstrapState.complete) {
|
|
309
|
+
HealthMonitor_1.HealthMonitor.getInstance().reportError(requestInstanceUrl, new Error(`Handler timed out after ${config_1.HANDLER_TIMEOUT_MS}ms — bootstrap did not complete`));
|
|
310
|
+
ConnectionManager_1.ConnectionManager.getInstance().clearInflight(requestInstanceUrl);
|
|
311
|
+
}
|
|
312
|
+
recordEarlyReturnError(toolName, action, timeoutError.message);
|
|
313
|
+
return (0, tool_result_1.errorToolResult)(timeoutError);
|
|
314
|
+
}
|
|
315
|
+
function recordToolError(errMsg) {
|
|
316
|
+
const reqTracker = (0, index_1.getRequestTracker)();
|
|
317
|
+
reqTracker.setErrorForCurrentRequest(errMsg);
|
|
318
|
+
const curRequestId = (0, index_1.getCurrentRequestId)();
|
|
319
|
+
const sessionId = curRequestId ? reqTracker.getStack(curRequestId)?.sessionId : undefined;
|
|
320
|
+
if (sessionId) {
|
|
321
|
+
(0, index_1.getConnectionTracker)().recordError(sessionId, errMsg);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async function withoutRestrictedTools(tools, caller, registryManager) {
|
|
325
|
+
let policy;
|
|
326
|
+
try {
|
|
327
|
+
policy = (await (0, configuration_1.getConfigurationService)().resolve(caller)).policy;
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
(0, logger_1.logWarn)('Could not read the caller settings for the tool list', { err: error });
|
|
331
|
+
return tools;
|
|
332
|
+
}
|
|
333
|
+
const listed = [];
|
|
334
|
+
for (const tool of tools) {
|
|
335
|
+
const inputSchema = (0, policy_1.listedToolSchema)(policy, registryManager.getToolFacts(tool.name), tool.inputSchema);
|
|
336
|
+
if (inputSchema)
|
|
337
|
+
listed.push(inputSchema === tool.inputSchema ? tool : { ...tool, inputSchema });
|
|
338
|
+
}
|
|
339
|
+
return listed;
|
|
340
|
+
}
|
|
341
|
+
async function prepareScopedCall(toolName, args, configured, registryManager) {
|
|
342
|
+
const unscoped = settingsRejection(toolName, args, (0, policy_1.withoutScope)(configured), registryManager);
|
|
343
|
+
if (unscoped || !configured.scopeEnforcer || (0, policy_1.isExemptFromSettings)(toolName))
|
|
344
|
+
return { rejection: unscoped, args, policy: configured };
|
|
345
|
+
const policy = await (0, scope_ids_1.withScopePaths)(configured);
|
|
346
|
+
const selected = (0, scoped_execution_1.parseScopedArguments)(toolName, args);
|
|
347
|
+
const action = typeof args.action === 'string' ? args.action : undefined;
|
|
348
|
+
const declared = selected === args ? registryManager.getDeclaredArguments(toolName, action) : undefined;
|
|
349
|
+
const own = declared
|
|
350
|
+
? Object.fromEntries(Object.entries(selected).filter(([name]) => declared.has(name)))
|
|
351
|
+
: selected;
|
|
352
|
+
return {
|
|
353
|
+
rejection: settingsRejection(toolName, await (0, scope_ids_1.withTargetPaths)(own, undefined, policy.scopeEnforcer), policy, registryManager),
|
|
354
|
+
args: selected,
|
|
355
|
+
policy,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function settingsRejection(toolName, args, policy, registryManager) {
|
|
359
|
+
const reason = (0, policy_1.callRestriction)(policy, registryManager.getToolFacts(toolName), args);
|
|
360
|
+
if (reason === null)
|
|
361
|
+
return null;
|
|
362
|
+
const action = typeof args.action === 'string' ? args.action : undefined;
|
|
363
|
+
const call = action ? `${toolName} ${action}` : toolName;
|
|
364
|
+
const message = `'${call}' is not allowed by the current settings: ` +
|
|
365
|
+
`${reason}. The account settings are changed with update_settings, this session's ` +
|
|
366
|
+
'with manage_context.';
|
|
367
|
+
recordEarlyReturnError(toolName, action, message);
|
|
368
|
+
return (0, tool_result_1.errorToolResult)({ error: message });
|
|
369
|
+
}
|
|
370
|
+
async function executeInScope(registryManager, toolName, requested, policy, instanceUrl, requestScopes) {
|
|
371
|
+
const run = (tool, toolArgs) => requestScopes === undefined
|
|
372
|
+
? registryManager.executeTool(tool, toolArgs, instanceUrl)
|
|
373
|
+
: registryManager.executeTool(tool, toolArgs, instanceUrl, requestScopes);
|
|
374
|
+
return (0, scoped_execution_1.executeScoped)(run, toolName, requested, policy, true);
|
|
375
|
+
}
|
|
376
|
+
function recordCallContext(scopePath, readOnly) {
|
|
377
|
+
const requestTracker = (0, index_1.getRequestTracker)();
|
|
378
|
+
if (scopePath) {
|
|
379
|
+
requestTracker.setContextForCurrentRequest(scopePath);
|
|
380
|
+
}
|
|
381
|
+
requestTracker.setReadOnlyForCurrentRequest(readOnly);
|
|
382
|
+
const currentRequestId = (0, index_1.getCurrentRequestId)();
|
|
383
|
+
if (currentRequestId) {
|
|
384
|
+
const stack = requestTracker.getStack(currentRequestId);
|
|
385
|
+
if (stack?.sessionId) {
|
|
386
|
+
const connectionTracker = (0, index_1.getConnectionTracker)();
|
|
387
|
+
connectionTracker.incrementTools(stack.sessionId);
|
|
245
388
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
function throwDispatchError(error, toolName, instanceUrl, healthMonitor, timedOut) {
|
|
392
|
+
if (!timedOut && error instanceof Error) {
|
|
393
|
+
const category = (0, error_handler_1.classifyError)(error);
|
|
394
|
+
if (category === 'transient' || category === 'auth') {
|
|
395
|
+
healthMonitor.reportError(instanceUrl, error);
|
|
249
396
|
}
|
|
250
|
-
return {
|
|
251
|
-
content: [{ type: 'text', text: JSON.stringify(connError, null, 2) }],
|
|
252
|
-
isError: true,
|
|
253
|
-
};
|
|
254
397
|
}
|
|
398
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
399
|
+
throw new Error(`Failed to execute tool '${toolName}': ${errorMessage}`, { cause: error });
|
|
255
400
|
}
|
|
256
401
|
let healthMonitorStartup = null;
|
|
257
402
|
let stateChangeRegistered = false;
|
|
@@ -312,7 +457,40 @@ async function setupHandlers(server) {
|
|
|
312
457
|
else {
|
|
313
458
|
(0, logger_1.logInfo)('Skipping connection initialization - no authentication configured');
|
|
314
459
|
}
|
|
315
|
-
server.setRequestHandler(types_js_1.
|
|
460
|
+
server.setRequestHandler(types_js_1.ListResourcesRequestSchema, () => {
|
|
461
|
+
const rejection = (0, tool_auth_1.resourceScopeRejection)();
|
|
462
|
+
if (rejection)
|
|
463
|
+
throw rejection;
|
|
464
|
+
return {
|
|
465
|
+
resources: [
|
|
466
|
+
{
|
|
467
|
+
uri: settings_panel_1.SETTINGS_PANEL_URI,
|
|
468
|
+
name: 'GitLab connection panel',
|
|
469
|
+
mimeType: mcp_apps_1.MCP_APP_MIME_TYPE,
|
|
470
|
+
_meta: settings_panel_1.SETTINGS_PANEL_RESOURCE_META,
|
|
471
|
+
},
|
|
472
|
+
],
|
|
473
|
+
};
|
|
474
|
+
});
|
|
475
|
+
server.setRequestHandler(types_js_1.ReadResourceRequestSchema, (request) => {
|
|
476
|
+
const rejection = (0, tool_auth_1.resourceScopeRejection)();
|
|
477
|
+
if (rejection)
|
|
478
|
+
throw rejection;
|
|
479
|
+
if (request.params.uri !== settings_panel_1.SETTINGS_PANEL_URI) {
|
|
480
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Unknown resource: ${request.params.uri}`);
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
contents: [
|
|
484
|
+
{
|
|
485
|
+
uri: settings_panel_1.SETTINGS_PANEL_URI,
|
|
486
|
+
mimeType: mcp_apps_1.MCP_APP_MIME_TYPE,
|
|
487
|
+
text: (0, settings_panel_1.settingsPanelHtml)(),
|
|
488
|
+
_meta: settings_panel_1.SETTINGS_PANEL_RESOURCE_META,
|
|
489
|
+
},
|
|
490
|
+
],
|
|
491
|
+
};
|
|
492
|
+
});
|
|
493
|
+
const listTools = async (extra) => {
|
|
316
494
|
(0, logger_1.logInfo)('ListToolsRequest received');
|
|
317
495
|
const { getSessionManager: getSessionMgr } = await Promise.resolve().then(() => __importStar(require('./session-manager')));
|
|
318
496
|
const sessionMgr = getSessionMgr();
|
|
@@ -322,7 +500,16 @@ async function setupHandlers(server) {
|
|
|
322
500
|
: undefined;
|
|
323
501
|
const { RegistryManager } = await Promise.resolve().then(() => __importStar(require('./registry-manager')));
|
|
324
502
|
const registryManager = RegistryManager.getInstance();
|
|
325
|
-
const
|
|
503
|
+
const mode = (0, schema_utils_1.getSchemaMode)(server.getClientVersion()?.name);
|
|
504
|
+
const { getTokenContext: getCatalogContext, isOAuthEnabled: isCatalogOAuth, getGitLabApiUrlFromContext: getCatalogUrl, } = await Promise.resolve().then(() => __importStar(require('./oauth/index')));
|
|
505
|
+
const scopes = getCatalogContext()?.gitlabScopes;
|
|
506
|
+
const securitySchemes = isCatalogOAuth() ? tool_auth_1.OAUTH_SECURITY_SCHEMES : undefined;
|
|
507
|
+
const catalog = scopes === undefined
|
|
508
|
+
? registryManager.getAllToolDefinitions(sessionInstanceUrl, mode)
|
|
509
|
+
: registryManager.getAllToolDefinitions(sessionInstanceUrl, mode, scopes);
|
|
510
|
+
const callerInstanceUrl = sessionInstanceUrl ??
|
|
511
|
+
activeInstanceUrl(isCatalogOAuth(), isCatalogOAuth() ? getCatalogUrl() : undefined);
|
|
512
|
+
const tools = await withoutRestrictedTools(catalog, (0, configuration_1.resolveCaller)(listToolsSessionId, callerInstanceUrl), registryManager);
|
|
326
513
|
(0, logger_1.logInfo)('Returning tools list', { toolCount: tools.length });
|
|
327
514
|
function resolveRefs(schema, rootSchema) {
|
|
328
515
|
if (!schema || typeof schema !== 'object')
|
|
@@ -378,39 +565,51 @@ async function setupHandlers(server) {
|
|
|
378
565
|
delete cleanedSchema.$schema;
|
|
379
566
|
inputSchema = cleanedSchema;
|
|
380
567
|
}
|
|
381
|
-
|
|
568
|
+
if (!securitySchemes || tool._meta?.securitySchemes !== undefined) {
|
|
569
|
+
return { ...tool, inputSchema };
|
|
570
|
+
}
|
|
571
|
+
const schemes = tool._meta?.ui ? tool_auth_1.APP_PANEL_SECURITY_SCHEMES : securitySchemes;
|
|
572
|
+
return {
|
|
573
|
+
...tool,
|
|
574
|
+
inputSchema,
|
|
575
|
+
securitySchemes: schemes,
|
|
576
|
+
_meta: { ...tool._meta, securitySchemes: schemes },
|
|
577
|
+
};
|
|
382
578
|
});
|
|
383
579
|
return {
|
|
384
580
|
tools: modifiedTools,
|
|
385
581
|
};
|
|
582
|
+
};
|
|
583
|
+
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async (_request, extra) => {
|
|
584
|
+
try {
|
|
585
|
+
return await (0, chat_accounts_1.withChatAccount)(extra?.sessionId, () => listTools(extra));
|
|
586
|
+
}
|
|
587
|
+
catch (error) {
|
|
588
|
+
if (!(error instanceof chat_accounts_1.AccountUnavailableError))
|
|
589
|
+
throw error;
|
|
590
|
+
return listTools(extra);
|
|
591
|
+
}
|
|
386
592
|
});
|
|
387
|
-
|
|
388
|
-
const { getGitLabApiUrlFromContext: getUrlFromCtx, isOAuthEnabled } = await Promise.resolve().then(() => __importStar(require('./oauth/index')));
|
|
593
|
+
const callTool = async (request, extra, deadline) => {
|
|
594
|
+
const { getGitLabApiUrlFromContext: getUrlFromCtx, isOAuthEnabled, getTokenContext: getCallContext, } = await Promise.resolve().then(() => __importStar(require('./oauth/index')));
|
|
389
595
|
const oauthEnabled = isOAuthEnabled();
|
|
596
|
+
if (oauthEnabled) {
|
|
597
|
+
const rejection = (0, tool_auth_1.toolScopeRejection)();
|
|
598
|
+
if (rejection)
|
|
599
|
+
return rejection;
|
|
600
|
+
}
|
|
601
|
+
const requestScopes = oauthEnabled ? getCallContext()?.gitlabScopes : undefined;
|
|
602
|
+
let declaredIdempotent;
|
|
390
603
|
const oauthContextUrl = oauthEnabled ? getUrlFromCtx() : undefined;
|
|
391
|
-
const
|
|
392
|
-
? (oauthContextUrl ?? config_1.GITLAB_BASE_URL)
|
|
393
|
-
: (ConnectionManager_1.ConnectionManager.getInstance().getCurrentInstanceUrl() ?? config_1.GITLAB_BASE_URL);
|
|
394
|
-
const requestInstanceUrl = (0, url_1.normalizeInstanceUrl)(rawInstanceUrl);
|
|
604
|
+
const requestInstanceUrl = activeInstanceUrl(oauthEnabled, oauthContextUrl);
|
|
395
605
|
const callSessionId = extra?.sessionId;
|
|
396
|
-
if (callSessionId && (
|
|
397
|
-
|
|
398
|
-
getSessionMgrForCall().setSessionInstanceUrl(callSessionId, requestInstanceUrl);
|
|
606
|
+
if (callSessionId && !managesAccounts(request)) {
|
|
607
|
+
await pinSessionInstance(callSessionId, oauthEnabled, oauthContextUrl, requestInstanceUrl);
|
|
399
608
|
}
|
|
400
|
-
|
|
609
|
+
const caller = (0, configuration_1.resolveCaller)(callSessionId, requestInstanceUrl);
|
|
401
610
|
const bootstrapState = { started: false, complete: false };
|
|
402
|
-
const
|
|
403
|
-
let handlerTimeoutId;
|
|
404
|
-
const timeoutPromise = new Promise((resolve) => {
|
|
405
|
-
handlerTimeoutId = setTimeout(() => {
|
|
406
|
-
timedOut = true;
|
|
407
|
-
resolve(HANDLER_TIMEOUT_SYMBOL);
|
|
408
|
-
}, config_1.HANDLER_TIMEOUT_MS);
|
|
409
|
-
});
|
|
611
|
+
const timedOut = deadline.isExpired;
|
|
410
612
|
const handlerWork = async () => {
|
|
411
|
-
if (!request.params.arguments) {
|
|
412
|
-
throw new Error('Arguments are required');
|
|
413
|
-
}
|
|
414
613
|
if (config_1.LOG_FORMAT === 'verbose') {
|
|
415
614
|
(0, logger_1.logInfo)(`Tool called: ${request.params.name}`);
|
|
416
615
|
}
|
|
@@ -425,22 +624,29 @@ async function setupHandlers(server) {
|
|
|
425
624
|
const connectionManager = ConnectionManager_1.ConnectionManager.getInstance();
|
|
426
625
|
const healthMonitor = HealthMonitor_1.HealthMonitor.getInstance();
|
|
427
626
|
const toolName = request.params.name;
|
|
428
|
-
|
|
627
|
+
let toolArguments = request.params.arguments;
|
|
628
|
+
const { RegistryManager: CallRegistry } = await Promise.resolve().then(() => __importStar(require('./registry-manager')));
|
|
629
|
+
const configuration = await (0, configuration_1.getConfigurationService)().resolve(caller);
|
|
630
|
+
const prepared = await prepareScopedCall(toolName, toolArguments ?? {}, configuration.policy, CallRegistry.getInstance());
|
|
631
|
+
if (prepared.rejection)
|
|
632
|
+
return prepared.rejection;
|
|
633
|
+
toolArguments = prepared.args;
|
|
429
634
|
const unreachableResult = checkUnreachableInstance(toolName, toolArguments, effectiveInstanceUrl, healthMonitor);
|
|
430
635
|
if (unreachableResult)
|
|
431
636
|
return unreachableResult;
|
|
432
|
-
const
|
|
433
|
-
if (
|
|
434
|
-
return
|
|
637
|
+
const withoutBootstrap = await tryWithoutBootstrap(request, toolArguments, effectiveInstanceUrl, healthMonitor, callSessionId, requestScopes);
|
|
638
|
+
if (withoutBootstrap)
|
|
639
|
+
return withoutBootstrap;
|
|
435
640
|
const oauthMode = isOAuthEnabled();
|
|
436
641
|
const bootstrapFailure = await ensureBootstrapped({
|
|
437
642
|
toolName,
|
|
438
643
|
toolArguments,
|
|
439
644
|
effectiveInstanceUrl,
|
|
440
645
|
oauthMode,
|
|
646
|
+
requestScopes,
|
|
441
647
|
connectionManager,
|
|
442
648
|
healthMonitor,
|
|
443
|
-
isTimedOut:
|
|
649
|
+
isTimedOut: timedOut,
|
|
444
650
|
bootstrapState,
|
|
445
651
|
});
|
|
446
652
|
if (bootstrapFailure)
|
|
@@ -450,25 +656,13 @@ async function setupHandlers(server) {
|
|
|
450
656
|
if (config_1.LOG_FORMAT === 'condensed') {
|
|
451
657
|
const requestTracker = (0, index_1.getRequestTracker)();
|
|
452
658
|
requestTracker.setToolForCurrentRequest(toolName, action);
|
|
453
|
-
|
|
454
|
-
const contextManager = getContextManager();
|
|
455
|
-
const sessionContext = contextManager.getContext();
|
|
456
|
-
if (sessionContext.scope?.path) {
|
|
457
|
-
requestTracker.setContextForCurrentRequest(sessionContext.scope.path);
|
|
458
|
-
}
|
|
459
|
-
requestTracker.setReadOnlyForCurrentRequest(sessionContext.readOnly);
|
|
460
|
-
const currentRequestId = (0, index_1.getCurrentRequestId)();
|
|
461
|
-
if (currentRequestId) {
|
|
462
|
-
const stack = requestTracker.getStack(currentRequestId);
|
|
463
|
-
if (stack?.sessionId) {
|
|
464
|
-
const connectionTracker = (0, index_1.getConnectionTracker)();
|
|
465
|
-
connectionTracker.incrementTools(stack.sessionId);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
659
|
+
recordCallContext((0, policy_1.scopeLabel)(configuration.policy.scope), config_1.GITLAB_READ_ONLY_MODE || configuration.policy.readOnly);
|
|
468
660
|
}
|
|
469
661
|
try {
|
|
470
662
|
const { RegistryManager } = await Promise.resolve().then(() => __importStar(require('./registry-manager')));
|
|
471
663
|
const registryManager = RegistryManager.getInstance();
|
|
664
|
+
const definition = registryManager.getTool(toolName, effectiveInstanceUrl, requestScopes);
|
|
665
|
+
declaredIdempotent = definition?.idempotent ?? definition?.annotations?.idempotentHint;
|
|
472
666
|
if (!registryManager.hasToolHandler(toolName, effectiveInstanceUrl)) {
|
|
473
667
|
throw new Error(`Tool '${toolName}' is not available or has been filtered out`);
|
|
474
668
|
}
|
|
@@ -484,103 +678,70 @@ async function setupHandlers(server) {
|
|
|
484
678
|
tool: toolName,
|
|
485
679
|
});
|
|
486
680
|
}
|
|
487
|
-
const result = await registryManager
|
|
681
|
+
const result = await executeInScope(registryManager, toolName, toolArguments, prepared.policy, effectiveInstanceUrl, requestScopes);
|
|
488
682
|
if (result === undefined) {
|
|
489
683
|
throw new Error(`Tool '${toolName}' is not available or has been filtered out`);
|
|
490
684
|
}
|
|
491
|
-
|
|
492
|
-
if (!timedOut) {
|
|
685
|
+
if (!timedOut()) {
|
|
493
686
|
healthMonitor.reportSuccess(effectiveInstanceUrl);
|
|
494
687
|
}
|
|
495
|
-
return
|
|
496
|
-
content: [
|
|
497
|
-
{
|
|
498
|
-
type: 'text',
|
|
499
|
-
text: JSON.stringify(result, null, 2),
|
|
500
|
-
},
|
|
501
|
-
],
|
|
502
|
-
};
|
|
688
|
+
return (0, tool_result_1.formatToolResult)(result, definition);
|
|
503
689
|
}
|
|
504
690
|
catch (error) {
|
|
505
|
-
|
|
506
|
-
const category = (0, error_handler_1.classifyError)(error);
|
|
507
|
-
if (category === 'transient' || category === 'auth') {
|
|
508
|
-
healthMonitor.reportError(effectiveInstanceUrl, error);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
512
|
-
throw new Error(`Failed to execute tool '${toolName}': ${errorMessage}`, { cause: error });
|
|
691
|
+
throwDispatchError(error, toolName, effectiveInstanceUrl, healthMonitor, timedOut());
|
|
513
692
|
}
|
|
514
693
|
};
|
|
515
694
|
try {
|
|
516
|
-
const result = await Promise.race([
|
|
517
|
-
if (result ===
|
|
518
|
-
|
|
519
|
-
const action = request.params.arguments && typeof request.params.arguments.action === 'string'
|
|
520
|
-
? request.params.arguments.action
|
|
521
|
-
: 'unknown';
|
|
522
|
-
const retryable = isIdempotentOperation(toolName);
|
|
523
|
-
const timeoutError = (0, error_handler_1.createTimeoutError)(toolName, action, config_1.HANDLER_TIMEOUT_MS, retryable);
|
|
524
|
-
(0, logger_1.logError)(`Handler timeout: tool '${toolName}' timed out after ${config_1.HANDLER_TIMEOUT_MS}ms`);
|
|
525
|
-
if (bootstrapState.started && !bootstrapState.complete) {
|
|
526
|
-
HealthMonitor_1.HealthMonitor.getInstance().reportError(requestInstanceUrl, new Error(`Handler timed out after ${config_1.HANDLER_TIMEOUT_MS}ms — bootstrap did not complete`));
|
|
527
|
-
ConnectionManager_1.ConnectionManager.getInstance().clearInflight(requestInstanceUrl);
|
|
528
|
-
}
|
|
529
|
-
recordEarlyReturnError(toolName, action, timeoutError.message);
|
|
530
|
-
return {
|
|
531
|
-
content: [
|
|
532
|
-
{
|
|
533
|
-
type: 'text',
|
|
534
|
-
text: JSON.stringify(timeoutError, null, 2),
|
|
535
|
-
},
|
|
536
|
-
],
|
|
537
|
-
isError: true,
|
|
538
|
-
};
|
|
695
|
+
const result = await Promise.race([(0, configuration_1.runWithCaller)(caller, handlerWork), deadline.expired]);
|
|
696
|
+
if (result === HANDLER_TIMEOUT) {
|
|
697
|
+
return handlerTimeoutResult(request, declaredIdempotent, bootstrapState, requestInstanceUrl);
|
|
539
698
|
}
|
|
540
699
|
return result;
|
|
541
700
|
}
|
|
542
701
|
catch (error) {
|
|
543
702
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
544
703
|
(0, logger_1.logError)(`Error in tool handler: ${errMsg}`);
|
|
545
|
-
|
|
546
|
-
reqTracker.setErrorForCurrentRequest(errMsg);
|
|
547
|
-
const curRequestId = (0, index_1.getCurrentRequestId)();
|
|
548
|
-
if (curRequestId) {
|
|
549
|
-
const stack = reqTracker.getStack(curRequestId);
|
|
550
|
-
if (stack?.sessionId) {
|
|
551
|
-
const connTracker = (0, index_1.getConnectionTracker)();
|
|
552
|
-
connTracker.recordError(stack.sessionId, errMsg);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
704
|
+
recordToolError(errMsg);
|
|
555
705
|
const toolName = request.params.name;
|
|
556
706
|
const toolArgs = request.params.arguments;
|
|
557
|
-
const structuredError = toStructuredError(error, toolName, toolArgs);
|
|
707
|
+
const structuredError = toStructuredError(error, toolName, toolArgs, declaredIdempotent);
|
|
558
708
|
if (structuredError) {
|
|
559
709
|
(0, logger_1.logDebug)('Returning structured error response', { structuredError });
|
|
560
|
-
return
|
|
561
|
-
content: [
|
|
562
|
-
{
|
|
563
|
-
type: 'text',
|
|
564
|
-
text: JSON.stringify(structuredError, null, 2),
|
|
565
|
-
},
|
|
566
|
-
],
|
|
567
|
-
isError: true,
|
|
568
|
-
};
|
|
710
|
+
return (0, tool_auth_1.withReauthChallenge)((0, tool_result_1.errorToolResult)(structuredError), error);
|
|
569
711
|
}
|
|
570
712
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
571
|
-
return {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
713
|
+
return (0, tool_auth_1.withReauthChallenge)((0, tool_result_1.errorToolResult)({ error: errorMessage }), error);
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
server.setRequestHandler(types_js_1.CallToolRequestSchema, (request, extra) => (0, mcp_server_context_1.runWithMcpServer)(server, async () => {
|
|
717
|
+
const deadline = startCallDeadline();
|
|
718
|
+
try {
|
|
719
|
+
if (managesAccounts(request))
|
|
720
|
+
return await callTool(request, extra, deadline);
|
|
721
|
+
let running = false;
|
|
722
|
+
const call = (0, chat_accounts_1.withChatAccount)(extra?.sessionId, async () => {
|
|
723
|
+
if (deadline.isExpired())
|
|
724
|
+
return undefined;
|
|
725
|
+
running = true;
|
|
726
|
+
return callTool(request, extra, deadline);
|
|
727
|
+
});
|
|
728
|
+
const first = await Promise.race([call, deadline.expired]);
|
|
729
|
+
if (first !== HANDLER_TIMEOUT && first !== undefined)
|
|
730
|
+
return first;
|
|
731
|
+
const answered = running ? await call : undefined;
|
|
732
|
+
if (answered)
|
|
733
|
+
return answered;
|
|
734
|
+
call.catch((error) => (0, logger_1.logDebug)('Account resolution failed after the call timed out', { err: error }));
|
|
735
|
+
return handlerTimeoutResult(request, undefined, { started: false, complete: false }, config_1.GITLAB_BASE_URL);
|
|
736
|
+
}
|
|
737
|
+
catch (error) {
|
|
738
|
+
if (!(error instanceof chat_accounts_1.AccountUnavailableError))
|
|
739
|
+
throw error;
|
|
740
|
+
return (0, tool_result_1.errorToolResult)({ error: error.message });
|
|
580
741
|
}
|
|
581
742
|
finally {
|
|
582
|
-
|
|
743
|
+
deadline.clear();
|
|
583
744
|
}
|
|
584
|
-
});
|
|
745
|
+
}));
|
|
585
746
|
}
|
|
586
747
|
//# sourceMappingURL=handlers.js.map
|