@anthropic-field/core 0.1.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/dist/.last_build +0 -0
- package/dist/docs/architecture.md +80 -0
- package/dist/docs/assets/connected_devtools.png +0 -0
- package/dist/docs/assets/gemini-screenshot.png +0 -0
- package/dist/docs/assets/monitoring-dashboard-logs.png +0 -0
- package/dist/docs/assets/monitoring-dashboard-metrics.png +0 -0
- package/dist/docs/assets/monitoring-dashboard-overview.png +0 -0
- package/dist/docs/assets/release_patch.png +0 -0
- package/dist/docs/assets/theme-ansi-light.png +0 -0
- package/dist/docs/assets/theme-ansi.png +0 -0
- package/dist/docs/assets/theme-atom-one.png +0 -0
- package/dist/docs/assets/theme-ayu-light.png +0 -0
- package/dist/docs/assets/theme-ayu.png +0 -0
- package/dist/docs/assets/theme-custom.png +0 -0
- package/dist/docs/assets/theme-default-light.png +0 -0
- package/dist/docs/assets/theme-default.png +0 -0
- package/dist/docs/assets/theme-dracula.png +0 -0
- package/dist/docs/assets/theme-github-light.png +0 -0
- package/dist/docs/assets/theme-github.png +0 -0
- package/dist/docs/assets/theme-google-light.png +0 -0
- package/dist/docs/assets/theme-xcode-light.png +0 -0
- package/dist/docs/changelogs/index.md +743 -0
- package/dist/docs/changelogs/latest.md +338 -0
- package/dist/docs/changelogs/preview.md +437 -0
- package/dist/docs/cli/authentication.md +3 -0
- package/dist/docs/cli/checkpointing.md +94 -0
- package/dist/docs/cli/cli-reference.md +101 -0
- package/dist/docs/cli/commands.md +430 -0
- package/dist/docs/cli/creating-skills.md +80 -0
- package/dist/docs/cli/custom-commands.md +315 -0
- package/dist/docs/cli/enterprise.md +565 -0
- package/dist/docs/cli/gemini-ignore.md +71 -0
- package/dist/docs/cli/gemini-md.md +108 -0
- package/dist/docs/cli/generation-settings.md +210 -0
- package/dist/docs/cli/headless.md +388 -0
- package/dist/docs/cli/index.md +65 -0
- package/dist/docs/cli/keyboard-shortcuts.md +140 -0
- package/dist/docs/cli/model-routing.md +42 -0
- package/dist/docs/cli/model.md +62 -0
- package/dist/docs/cli/rewind.md +51 -0
- package/dist/docs/cli/sandbox.md +171 -0
- package/dist/docs/cli/session-management.md +158 -0
- package/dist/docs/cli/settings.md +139 -0
- package/dist/docs/cli/skills.md +112 -0
- package/dist/docs/cli/system-prompt.md +125 -0
- package/dist/docs/cli/telemetry.md +826 -0
- package/dist/docs/cli/themes.md +235 -0
- package/dist/docs/cli/token-caching.md +20 -0
- package/dist/docs/cli/trusted-folders.md +95 -0
- package/dist/docs/cli/tutorials/skills-getting-started.md +97 -0
- package/dist/docs/cli/tutorials.md +87 -0
- package/dist/docs/cli/uninstall.md +65 -0
- package/dist/docs/core/index.md +107 -0
- package/dist/docs/core/memport.md +246 -0
- package/dist/docs/core/policy-engine.md +305 -0
- package/dist/docs/core/remote-agents.md +84 -0
- package/dist/docs/core/subagents.md +191 -0
- package/dist/docs/core/tools-api.md +131 -0
- package/dist/docs/examples/proxy-script.md +83 -0
- package/dist/docs/extensions/best-practices.md +139 -0
- package/dist/docs/extensions/index.md +45 -0
- package/dist/docs/extensions/reference.md +336 -0
- package/dist/docs/extensions/releasing.md +183 -0
- package/dist/docs/extensions/writing-extensions.md +281 -0
- package/dist/docs/faq.md +154 -0
- package/dist/docs/get-started/authentication.md +321 -0
- package/dist/docs/get-started/configuration-v1.md +888 -0
- package/dist/docs/get-started/configuration.md +1585 -0
- package/dist/docs/get-started/examples.md +219 -0
- package/dist/docs/get-started/gemini-3.md +101 -0
- package/dist/docs/get-started/index.md +71 -0
- package/dist/docs/get-started/installation.md +141 -0
- package/dist/docs/hooks/best-practices.md +677 -0
- package/dist/docs/hooks/index.md +164 -0
- package/dist/docs/hooks/reference.md +322 -0
- package/dist/docs/hooks/writing-hooks.md +450 -0
- package/dist/docs/ide-integration/ide-companion-spec.md +267 -0
- package/dist/docs/ide-integration/index.md +202 -0
- package/dist/docs/index.md +149 -0
- package/dist/docs/integration-tests.md +211 -0
- package/dist/docs/issue-and-pr-automation.md +134 -0
- package/dist/docs/local-development.md +128 -0
- package/dist/docs/mermaid/context.mmd +103 -0
- package/dist/docs/mermaid/render-path.mmd +64 -0
- package/dist/docs/npm.md +62 -0
- package/dist/docs/quota-and-pricing.md +158 -0
- package/dist/docs/release-confidence.md +164 -0
- package/dist/docs/releases.md +540 -0
- package/dist/docs/sidebar.json +152 -0
- package/dist/docs/tools/file-system.md +217 -0
- package/dist/docs/tools/index.md +98 -0
- package/dist/docs/tools/mcp-server.md +1079 -0
- package/dist/docs/tools/memory.md +54 -0
- package/dist/docs/tools/shell.md +260 -0
- package/dist/docs/tools/todos.md +57 -0
- package/dist/docs/tools/web-fetch.md +59 -0
- package/dist/docs/tools/web-search.md +42 -0
- package/dist/docs/tos-privacy.md +96 -0
- package/dist/docs/troubleshooting.md +173 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/src/__mocks__/fs/promises.d.ts +11 -0
- package/dist/src/__mocks__/fs/promises.js +17 -0
- package/dist/src/__mocks__/fs/promises.js.map +1 -0
- package/dist/src/agents/a2a-client-manager.d.ts +77 -0
- package/dist/src/agents/a2a-client-manager.js +173 -0
- package/dist/src/agents/a2a-client-manager.js.map +1 -0
- package/dist/src/agents/a2aUtils.d.ts +29 -0
- package/dist/src/agents/a2aUtils.js +113 -0
- package/dist/src/agents/a2aUtils.js.map +1 -0
- package/dist/src/agents/acknowledgedAgents.d.ts +18 -0
- package/dist/src/agents/acknowledgedAgents.js +58 -0
- package/dist/src/agents/acknowledgedAgents.js.map +1 -0
- package/dist/src/agents/agent-scheduler.d.ts +33 -0
- package/dist/src/agents/agent-scheduler.js +29 -0
- package/dist/src/agents/agent-scheduler.js.map +1 -0
- package/dist/src/agents/agentLoader.d.ts +73 -0
- package/dist/src/agents/agentLoader.js +268 -0
- package/dist/src/agents/agentLoader.js.map +1 -0
- package/dist/src/agents/cli-help-agent.d.ts +24 -0
- package/dist/src/agents/cli-help-agent.js +80 -0
- package/dist/src/agents/cli-help-agent.js.map +1 -0
- package/dist/src/agents/codebase-investigator.d.ts +47 -0
- package/dist/src/agents/codebase-investigator.js +159 -0
- package/dist/src/agents/codebase-investigator.js.map +1 -0
- package/dist/src/agents/generalist-agent.d.ts +21 -0
- package/dist/src/agents/generalist-agent.js +60 -0
- package/dist/src/agents/generalist-agent.js.map +1 -0
- package/dist/src/agents/local-executor.d.ts +110 -0
- package/dist/src/agents/local-executor.js +879 -0
- package/dist/src/agents/local-executor.js.map +1 -0
- package/dist/src/agents/local-invocation.d.ts +45 -0
- package/dist/src/agents/local-invocation.js +101 -0
- package/dist/src/agents/local-invocation.js.map +1 -0
- package/dist/src/agents/registry.d.ts +85 -0
- package/dist/src/agents/registry.js +374 -0
- package/dist/src/agents/registry.js.map +1 -0
- package/dist/src/agents/remote-invocation.d.ts +35 -0
- package/dist/src/agents/remote-invocation.js +127 -0
- package/dist/src/agents/remote-invocation.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.d.ts +38 -0
- package/dist/src/agents/subagent-tool-wrapper.js +51 -0
- package/dist/src/agents/subagent-tool-wrapper.js.map +1 -0
- package/dist/src/agents/subagent-tool.d.ts +15 -0
- package/dist/src/agents/subagent-tool.js +61 -0
- package/dist/src/agents/subagent-tool.js.map +1 -0
- package/dist/src/agents/types.d.ts +154 -0
- package/dist/src/agents/types.js +23 -0
- package/dist/src/agents/types.js.map +1 -0
- package/dist/src/agents/utils.d.ts +15 -0
- package/dist/src/agents/utils.js +29 -0
- package/dist/src/agents/utils.js.map +1 -0
- package/dist/src/availability/errorClassification.d.ts +7 -0
- package/dist/src/availability/errorClassification.js +20 -0
- package/dist/src/availability/errorClassification.js.map +1 -0
- package/dist/src/availability/modelAvailabilityService.d.ts +36 -0
- package/dist/src/availability/modelAvailabilityService.js +87 -0
- package/dist/src/availability/modelAvailabilityService.js.map +1 -0
- package/dist/src/availability/modelPolicy.d.ts +49 -0
- package/dist/src/availability/modelPolicy.js +7 -0
- package/dist/src/availability/modelPolicy.js.map +1 -0
- package/dist/src/availability/policyCatalog.d.ts +24 -0
- package/dist/src/availability/policyCatalog.js +106 -0
- package/dist/src/availability/policyCatalog.js.map +1 -0
- package/dist/src/availability/policyHelpers.d.ts +52 -0
- package/dist/src/availability/policyHelpers.js +143 -0
- package/dist/src/availability/policyHelpers.js.map +1 -0
- package/dist/src/availability/testUtils.d.ts +10 -0
- package/dist/src/availability/testUtils.js +22 -0
- package/dist/src/availability/testUtils.js.map +1 -0
- package/dist/src/code_assist/admin/admin_controls.d.ts +32 -0
- package/dist/src/code_assist/admin/admin_controls.js +120 -0
- package/dist/src/code_assist/admin/admin_controls.js.map +1 -0
- package/dist/src/code_assist/codeAssist.d.ts +12 -0
- package/dist/src/code_assist/codeAssist.js +31 -0
- package/dist/src/code_assist/codeAssist.js.map +1 -0
- package/dist/src/code_assist/converter.d.ts +75 -0
- package/dist/src/code_assist/converter.js +161 -0
- package/dist/src/code_assist/converter.js.map +1 -0
- package/dist/src/code_assist/experiments/client_metadata.d.ts +12 -0
- package/dist/src/code_assist/experiments/client_metadata.js +51 -0
- package/dist/src/code_assist/experiments/client_metadata.js.map +1 -0
- package/dist/src/code_assist/experiments/experiments.d.ts +17 -0
- package/dist/src/code_assist/experiments/experiments.js +57 -0
- package/dist/src/code_assist/experiments/experiments.js.map +1 -0
- package/dist/src/code_assist/experiments/flagNames.d.ts +16 -0
- package/dist/src/code_assist/experiments/flagNames.js +16 -0
- package/dist/src/code_assist/experiments/flagNames.js.map +1 -0
- package/dist/src/code_assist/experiments/types.d.ts +35 -0
- package/dist/src/code_assist/experiments/types.js +7 -0
- package/dist/src/code_assist/experiments/types.js.map +1 -0
- package/dist/src/code_assist/oauth-credential-storage.d.ts +25 -0
- package/dist/src/code_assist/oauth-credential-storage.js +109 -0
- package/dist/src/code_assist/oauth-credential-storage.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +25 -0
- package/dist/src/code_assist/oauth2.js +579 -0
- package/dist/src/code_assist/oauth2.js.map +1 -0
- package/dist/src/code_assist/server.d.ts +50 -0
- package/dist/src/code_assist/server.js +228 -0
- package/dist/src/code_assist/server.js.map +1 -0
- package/dist/src/code_assist/setup.d.ts +46 -0
- package/dist/src/code_assist/setup.js +179 -0
- package/dist/src/code_assist/setup.js.map +1 -0
- package/dist/src/code_assist/telemetry.d.ts +14 -0
- package/dist/src/code_assist/telemetry.js +157 -0
- package/dist/src/code_assist/telemetry.js.map +1 -0
- package/dist/src/code_assist/types.d.ts +306 -0
- package/dist/src/code_assist/types.js +94 -0
- package/dist/src/code_assist/types.js.map +1 -0
- package/dist/src/cognitive/gemini-adapter.d.ts +29 -0
- package/dist/src/cognitive/gemini-adapter.js +109 -0
- package/dist/src/cognitive/gemini-adapter.js.map +1 -0
- package/dist/src/cognitive/index.d.ts +22 -0
- package/dist/src/cognitive/index.js +50 -0
- package/dist/src/cognitive/index.js.map +1 -0
- package/dist/src/cognitive/integration.d.ts +57 -0
- package/dist/src/cognitive/integration.js +103 -0
- package/dist/src/cognitive/integration.js.map +1 -0
- package/dist/src/cognitive/loader/index.d.ts +8 -0
- package/dist/src/cognitive/loader/index.js +9 -0
- package/dist/src/cognitive/loader/index.js.map +1 -0
- package/dist/src/cognitive/loader/module-loader.d.ts +67 -0
- package/dist/src/cognitive/loader/module-loader.js +369 -0
- package/dist/src/cognitive/loader/module-loader.js.map +1 -0
- package/dist/src/cognitive/runtime/envelope.d.ts +31 -0
- package/dist/src/cognitive/runtime/envelope.js +167 -0
- package/dist/src/cognitive/runtime/envelope.js.map +1 -0
- package/dist/src/cognitive/runtime/executor.d.ts +65 -0
- package/dist/src/cognitive/runtime/executor.js +245 -0
- package/dist/src/cognitive/runtime/executor.js.map +1 -0
- package/dist/src/cognitive/runtime/index.d.ts +12 -0
- package/dist/src/cognitive/runtime/index.js +18 -0
- package/dist/src/cognitive/runtime/index.js.map +1 -0
- package/dist/src/cognitive/runtime/prompt-builder.d.ts +34 -0
- package/dist/src/cognitive/runtime/prompt-builder.js +216 -0
- package/dist/src/cognitive/runtime/prompt-builder.js.map +1 -0
- package/dist/src/cognitive/runtime/repair-pass.d.ts +43 -0
- package/dist/src/cognitive/runtime/repair-pass.js +170 -0
- package/dist/src/cognitive/runtime/repair-pass.js.map +1 -0
- package/dist/src/cognitive/runtime/risk-aggregator.d.ts +39 -0
- package/dist/src/cognitive/runtime/risk-aggregator.js +90 -0
- package/dist/src/cognitive/runtime/risk-aggregator.js.map +1 -0
- package/dist/src/cognitive/tool/cognitive-registry.d.ts +99 -0
- package/dist/src/cognitive/tool/cognitive-registry.js +192 -0
- package/dist/src/cognitive/tool/cognitive-registry.js.map +1 -0
- package/dist/src/cognitive/tool/cognitive-tool.d.ts +56 -0
- package/dist/src/cognitive/tool/cognitive-tool.js +217 -0
- package/dist/src/cognitive/tool/cognitive-tool.js.map +1 -0
- package/dist/src/cognitive/tool/index.d.ts +9 -0
- package/dist/src/cognitive/tool/index.js +10 -0
- package/dist/src/cognitive/tool/index.js.map +1 -0
- package/dist/src/cognitive/types.d.ts +234 -0
- package/dist/src/cognitive/types.js +10 -0
- package/dist/src/cognitive/types.js.map +1 -0
- package/dist/src/cognitive/validator/envelope-validator.d.ts +45 -0
- package/dist/src/cognitive/validator/envelope-validator.js +214 -0
- package/dist/src/cognitive/validator/envelope-validator.js.map +1 -0
- package/dist/src/cognitive/validator/index.d.ts +9 -0
- package/dist/src/cognitive/validator/index.js +10 -0
- package/dist/src/cognitive/validator/index.js.map +1 -0
- package/dist/src/cognitive/validator/schema-validator.d.ts +46 -0
- package/dist/src/cognitive/validator/schema-validator.js +202 -0
- package/dist/src/cognitive/validator/schema-validator.js.map +1 -0
- package/dist/src/commands/cognitive.d.ts +39 -0
- package/dist/src/commands/cognitive.js +335 -0
- package/dist/src/commands/cognitive.js.map +1 -0
- package/dist/src/commands/extensions.d.ts +7 -0
- package/dist/src/commands/extensions.js +9 -0
- package/dist/src/commands/extensions.js.map +1 -0
- package/dist/src/commands/init.d.ts +7 -0
- package/dist/src/commands/init.js +53 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/memory.d.ts +11 -0
- package/dist/src/commands/memory.js +80 -0
- package/dist/src/commands/memory.js.map +1 -0
- package/dist/src/commands/restore.d.ts +9 -0
- package/dist/src/commands/restore.js +46 -0
- package/dist/src/commands/restore.js.map +1 -0
- package/dist/src/commands/types.d.ts +41 -0
- package/dist/src/commands/types.js +7 -0
- package/dist/src/commands/types.js.map +1 -0
- package/dist/src/config/config.d.ts +766 -0
- package/dist/src/config/config.js +1625 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/constants.d.ts +15 -0
- package/dist/src/config/constants.js +24 -0
- package/dist/src/config/constants.js.map +1 -0
- package/dist/src/config/defaultModelConfigs.d.ts +7 -0
- package/dist/src/config/defaultModelConfigs.js +231 -0
- package/dist/src/config/defaultModelConfigs.js.map +1 -0
- package/dist/src/config/models.d.ts +67 -0
- package/dist/src/config/models.js +144 -0
- package/dist/src/config/models.js.map +1 -0
- package/dist/src/config/storage.d.ts +44 -0
- package/dist/src/config/storage.js +139 -0
- package/dist/src/config/storage.js.map +1 -0
- package/dist/src/confirmation-bus/index.d.ts +7 -0
- package/dist/src/confirmation-bus/index.js +8 -0
- package/dist/src/confirmation-bus/index.js.map +1 -0
- package/dist/src/confirmation-bus/message-bus.d.ts +24 -0
- package/dist/src/confirmation-bus/message-bus.js +120 -0
- package/dist/src/confirmation-bus/message-bus.js.map +1 -0
- package/dist/src/confirmation-bus/types.d.ts +147 -0
- package/dist/src/confirmation-bus/types.js +25 -0
- package/dist/src/confirmation-bus/types.js.map +1 -0
- package/dist/src/core/apiKeyCredentialStorage.d.ts +17 -0
- package/dist/src/core/apiKeyCredentialStorage.js +64 -0
- package/dist/src/core/apiKeyCredentialStorage.js.map +1 -0
- package/dist/src/core/baseLlmClient.d.ts +74 -0
- package/dist/src/core/baseLlmClient.js +167 -0
- package/dist/src/core/baseLlmClient.js.map +1 -0
- package/dist/src/core/client.d.ts +59 -0
- package/dist/src/core/client.js +716 -0
- package/dist/src/core/client.js.map +1 -0
- package/dist/src/core/contentGenerator.d.ts +34 -0
- package/dist/src/core/contentGenerator.js +107 -0
- package/dist/src/core/contentGenerator.js.map +1 -0
- package/dist/src/core/coreToolHookTriggers.d.ts +23 -0
- package/dist/src/core/coreToolHookTriggers.js +195 -0
- package/dist/src/core/coreToolHookTriggers.js.map +1 -0
- package/dist/src/core/coreToolScheduler.d.ts +50 -0
- package/dist/src/core/coreToolScheduler.js +703 -0
- package/dist/src/core/coreToolScheduler.js.map +1 -0
- package/dist/src/core/fakeContentGenerator.d.ts +34 -0
- package/dist/src/core/fakeContentGenerator.js +59 -0
- package/dist/src/core/fakeContentGenerator.js.map +1 -0
- package/dist/src/core/geminiChat.d.ts +160 -0
- package/dist/src/core/geminiChat.js +744 -0
- package/dist/src/core/geminiChat.js.map +1 -0
- package/dist/src/core/geminiRequest.d.ts +13 -0
- package/dist/src/core/geminiRequest.js +11 -0
- package/dist/src/core/geminiRequest.js.map +1 -0
- package/dist/src/core/logger.d.ts +65 -0
- package/dist/src/core/logger.js +368 -0
- package/dist/src/core/logger.js.map +1 -0
- package/dist/src/core/loggingContentGenerator.d.ts +29 -0
- package/dist/src/core/loggingContentGenerator.js +202 -0
- package/dist/src/core/loggingContentGenerator.js.map +1 -0
- package/dist/src/core/prompts.d.ts +19 -0
- package/dist/src/core/prompts.js +27 -0
- package/dist/src/core/prompts.js.map +1 -0
- package/dist/src/core/recordingContentGenerator.d.ts +19 -0
- package/dist/src/core/recordingContentGenerator.js +82 -0
- package/dist/src/core/recordingContentGenerator.js.map +1 -0
- package/dist/src/core/tokenLimits.d.ts +10 -0
- package/dist/src/core/tokenLimits.js +22 -0
- package/dist/src/core/tokenLimits.js.map +1 -0
- package/dist/src/core/turn.d.ts +167 -0
- package/dist/src/core/turn.js +209 -0
- package/dist/src/core/turn.js.map +1 -0
- package/dist/src/fallback/handler.d.ts +7 -0
- package/dist/src/fallback/handler.js +110 -0
- package/dist/src/fallback/handler.js.map +1 -0
- package/dist/src/fallback/types.d.ts +31 -0
- package/dist/src/fallback/types.js +7 -0
- package/dist/src/fallback/types.js.map +1 -0
- package/dist/src/generated/git-commit.d.ts +7 -0
- package/dist/src/generated/git-commit.js +10 -0
- package/dist/src/generated/git-commit.js.map +1 -0
- package/dist/src/hooks/hookAggregator.d.ts +68 -0
- package/dist/src/hooks/hookAggregator.js +279 -0
- package/dist/src/hooks/hookAggregator.js.map +1 -0
- package/dist/src/hooks/hookEventHandler.d.ts +107 -0
- package/dist/src/hooks/hookEventHandler.js +325 -0
- package/dist/src/hooks/hookEventHandler.js.map +1 -0
- package/dist/src/hooks/hookPlanner.d.ts +42 -0
- package/dist/src/hooks/hookPlanner.js +103 -0
- package/dist/src/hooks/hookPlanner.js.map +1 -0
- package/dist/src/hooks/hookRegistry.d.ts +75 -0
- package/dist/src/hooks/hookRegistry.js +215 -0
- package/dist/src/hooks/hookRegistry.js.map +1 -0
- package/dist/src/hooks/hookRunner.d.ts +44 -0
- package/dist/src/hooks/hookRunner.js +329 -0
- package/dist/src/hooks/hookRunner.js.map +1 -0
- package/dist/src/hooks/hookSystem.d.ts +99 -0
- package/dist/src/hooks/hookSystem.js +262 -0
- package/dist/src/hooks/hookSystem.js.map +1 -0
- package/dist/src/hooks/hookTranslator.d.ts +113 -0
- package/dist/src/hooks/hookTranslator.js +233 -0
- package/dist/src/hooks/hookTranslator.js.map +1 -0
- package/dist/src/hooks/index.d.ts +16 -0
- package/dist/src/hooks/index.js +16 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/trustedHooks.d.ts +28 -0
- package/dist/src/hooks/trustedHooks.js +90 -0
- package/dist/src/hooks/trustedHooks.js.map +1 -0
- package/dist/src/hooks/types.d.ts +442 -0
- package/dist/src/hooks/types.js +303 -0
- package/dist/src/hooks/types.js.map +1 -0
- package/dist/src/ide/constants.d.ts +9 -0
- package/dist/src/ide/constants.js +10 -0
- package/dist/src/ide/constants.js.map +1 -0
- package/dist/src/ide/detect-ide.d.ts +109 -0
- package/dist/src/ide/detect-ide.js +125 -0
- package/dist/src/ide/detect-ide.js.map +1 -0
- package/dist/src/ide/ide-client.d.ts +113 -0
- package/dist/src/ide/ide-client.js +669 -0
- package/dist/src/ide/ide-client.js.map +1 -0
- package/dist/src/ide/ide-installer.d.ts +14 -0
- package/dist/src/ide/ide-installer.js +227 -0
- package/dist/src/ide/ide-installer.js.map +1 -0
- package/dist/src/ide/ideContext.d.ts +44 -0
- package/dist/src/ide/ideContext.js +101 -0
- package/dist/src/ide/ideContext.js.map +1 -0
- package/dist/src/ide/process-utils.d.ts +21 -0
- package/dist/src/ide/process-utils.js +181 -0
- package/dist/src/ide/process-utils.js.map +1 -0
- package/dist/src/ide/types.d.ts +486 -0
- package/dist/src/ide/types.js +138 -0
- package/dist/src/ide/types.js.map +1 -0
- package/dist/src/index.d.ts +145 -0
- package/dist/src/index.js +161 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/auth-provider.d.ts +16 -0
- package/dist/src/mcp/auth-provider.js +7 -0
- package/dist/src/mcp/auth-provider.js.map +1 -0
- package/dist/src/mcp/google-auth-provider.d.ts +33 -0
- package/dist/src/mcp/google-auth-provider.js +118 -0
- package/dist/src/mcp/google-auth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-provider.d.ts +160 -0
- package/dist/src/mcp/oauth-provider.js +729 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.d.ts +65 -0
- package/dist/src/mcp/oauth-token-storage.js +181 -0
- package/dist/src/mcp/oauth-token-storage.js.map +1 -0
- package/dist/src/mcp/oauth-utils.d.ts +142 -0
- package/dist/src/mcp/oauth-utils.js +289 -0
- package/dist/src/mcp/oauth-utils.js.map +1 -0
- package/dist/src/mcp/sa-impersonation-provider.d.ts +27 -0
- package/dist/src/mcp/sa-impersonation-provider.js +113 -0
- package/dist/src/mcp/sa-impersonation-provider.js.map +1 -0
- package/dist/src/mcp/token-storage/base-token-storage.d.ts +19 -0
- package/dist/src/mcp/token-storage/base-token-storage.js +36 -0
- package/dist/src/mcp/token-storage/base-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/file-token-storage.d.ts +24 -0
- package/dist/src/mcp/token-storage/file-token-storage.js +145 -0
- package/dist/src/mcp/token-storage/file-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.d.ts +23 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.js +78 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/index.d.ts +11 -0
- package/dist/src/mcp/token-storage/index.js +12 -0
- package/dist/src/mcp/token-storage/index.js.map +1 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.d.ts +35 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.js +246 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/types.d.ts +44 -0
- package/dist/src/mcp/token-storage/types.js +11 -0
- package/dist/src/mcp/token-storage/types.js.map +1 -0
- package/dist/src/mocks/msw.d.ts +6 -0
- package/dist/src/mocks/msw.js +8 -0
- package/dist/src/mocks/msw.js.map +1 -0
- package/dist/src/output/json-formatter.d.ts +11 -0
- package/dist/src/output/json-formatter.js +33 -0
- package/dist/src/output/json-formatter.js.map +1 -0
- package/dist/src/output/stream-json-formatter.d.ts +32 -0
- package/dist/src/output/stream-json-formatter.js +58 -0
- package/dist/src/output/stream-json-formatter.js.map +1 -0
- package/dist/src/output/types.d.ts +85 -0
- package/dist/src/output/types.js +22 -0
- package/dist/src/output/types.js.map +1 -0
- package/dist/src/policy/config.d.ts +31 -0
- package/dist/src/policy/config.js +355 -0
- package/dist/src/policy/config.js.map +1 -0
- package/dist/src/policy/index.d.ts +9 -0
- package/dist/src/policy/index.js +10 -0
- package/dist/src/policy/index.js.map +1 -0
- package/dist/src/policy/policies/discovered.toml +8 -0
- package/dist/src/policy/policies/plan.toml +79 -0
- package/dist/src/policy/policies/read-only.toml +51 -0
- package/dist/src/policy/policies/write.toml +78 -0
- package/dist/src/policy/policies/yolo.toml +32 -0
- package/dist/src/policy/policy-engine.d.ts +65 -0
- package/dist/src/policy/policy-engine.js +357 -0
- package/dist/src/policy/policy-engine.js.map +1 -0
- package/dist/src/policy/stable-stringify.d.ts +58 -0
- package/dist/src/policy/stable-stringify.js +122 -0
- package/dist/src/policy/stable-stringify.js.map +1 -0
- package/dist/src/policy/toml-loader.d.ts +45 -0
- package/dist/src/policy/toml-loader.js +366 -0
- package/dist/src/policy/toml-loader.js.map +1 -0
- package/dist/src/policy/types.d.ts +220 -0
- package/dist/src/policy/types.js +44 -0
- package/dist/src/policy/types.js.map +1 -0
- package/dist/src/policy/utils.d.ts +21 -0
- package/dist/src/policy/utils.js +45 -0
- package/dist/src/policy/utils.js.map +1 -0
- package/dist/src/prompts/mcp-prompts.d.ts +8 -0
- package/dist/src/prompts/mcp-prompts.js +13 -0
- package/dist/src/prompts/mcp-prompts.js.map +1 -0
- package/dist/src/prompts/prompt-registry.d.ts +34 -0
- package/dist/src/prompts/prompt-registry.js +64 -0
- package/dist/src/prompts/prompt-registry.js.map +1 -0
- package/dist/src/prompts/promptProvider.d.ts +18 -0
- package/dist/src/prompts/promptProvider.js +129 -0
- package/dist/src/prompts/promptProvider.js.map +1 -0
- package/dist/src/prompts/snippets.d.ts +76 -0
- package/dist/src/prompts/snippets.js +455 -0
- package/dist/src/prompts/snippets.js.map +1 -0
- package/dist/src/prompts/utils.d.ts +23 -0
- package/dist/src/prompts/utils.js +72 -0
- package/dist/src/prompts/utils.js.map +1 -0
- package/dist/src/resources/resource-registry.d.ts +30 -0
- package/dist/src/resources/resource-registry.js +57 -0
- package/dist/src/resources/resource-registry.js.map +1 -0
- package/dist/src/routing/modelRouterService.d.ts +23 -0
- package/dist/src/routing/modelRouterService.js +80 -0
- package/dist/src/routing/modelRouterService.js.map +1 -0
- package/dist/src/routing/routingStrategy.d.ts +64 -0
- package/dist/src/routing/routingStrategy.js +7 -0
- package/dist/src/routing/routingStrategy.js.map +1 -0
- package/dist/src/routing/strategies/classifierStrategy.d.ts +12 -0
- package/dist/src/routing/strategies/classifierStrategy.js +152 -0
- package/dist/src/routing/strategies/classifierStrategy.js.map +1 -0
- package/dist/src/routing/strategies/compositeStrategy.d.ts +26 -0
- package/dist/src/routing/strategies/compositeStrategy.js +70 -0
- package/dist/src/routing/strategies/compositeStrategy.js.map +1 -0
- package/dist/src/routing/strategies/defaultStrategy.d.ts +12 -0
- package/dist/src/routing/strategies/defaultStrategy.js +21 -0
- package/dist/src/routing/strategies/defaultStrategy.js.map +1 -0
- package/dist/src/routing/strategies/fallbackStrategy.d.ts +12 -0
- package/dist/src/routing/strategies/fallbackStrategy.js +33 -0
- package/dist/src/routing/strategies/fallbackStrategy.js.map +1 -0
- package/dist/src/routing/strategies/numericalClassifierStrategy.d.ts +13 -0
- package/dist/src/routing/strategies/numericalClassifierStrategy.js +178 -0
- package/dist/src/routing/strategies/numericalClassifierStrategy.js.map +1 -0
- package/dist/src/routing/strategies/overrideStrategy.d.ts +15 -0
- package/dist/src/routing/strategies/overrideStrategy.js +29 -0
- package/dist/src/routing/strategies/overrideStrategy.js.map +1 -0
- package/dist/src/safety/built-in.d.ts +21 -0
- package/dist/src/safety/built-in.js +106 -0
- package/dist/src/safety/built-in.js.map +1 -0
- package/dist/src/safety/checker-runner.d.ts +48 -0
- package/dist/src/safety/checker-runner.js +219 -0
- package/dist/src/safety/checker-runner.js.map +1 -0
- package/dist/src/safety/context-builder.d.ts +23 -0
- package/dist/src/safety/context-builder.js +47 -0
- package/dist/src/safety/context-builder.js.map +1 -0
- package/dist/src/safety/protocol.d.ts +88 -0
- package/dist/src/safety/protocol.js +15 -0
- package/dist/src/safety/protocol.js.map +1 -0
- package/dist/src/safety/registry.d.ts +26 -0
- package/dist/src/safety/registry.js +65 -0
- package/dist/src/safety/registry.js.map +1 -0
- package/dist/src/scheduler/confirmation.d.ts +49 -0
- package/dist/src/scheduler/confirmation.js +183 -0
- package/dist/src/scheduler/confirmation.js.map +1 -0
- package/dist/src/scheduler/policy.d.ts +25 -0
- package/dist/src/scheduler/policy.js +108 -0
- package/dist/src/scheduler/policy.js.map +1 -0
- package/dist/src/scheduler/scheduler.d.ts +61 -0
- package/dist/src/scheduler/scheduler.js +356 -0
- package/dist/src/scheduler/scheduler.js.map +1 -0
- package/dist/src/scheduler/state-manager.d.ts +73 -0
- package/dist/src/scheduler/state-manager.js +356 -0
- package/dist/src/scheduler/state-manager.js.map +1 -0
- package/dist/src/scheduler/tool-executor.d.ts +22 -0
- package/dist/src/scheduler/tool-executor.js +201 -0
- package/dist/src/scheduler/tool-executor.js.map +1 -0
- package/dist/src/scheduler/tool-modifier.d.ts +23 -0
- package/dist/src/scheduler/tool-modifier.js +50 -0
- package/dist/src/scheduler/tool-modifier.js.map +1 -0
- package/dist/src/scheduler/types.d.ts +118 -0
- package/dist/src/scheduler/types.js +7 -0
- package/dist/src/scheduler/types.js.map +1 -0
- package/dist/src/services/chatCompressionService.d.ts +41 -0
- package/dist/src/services/chatCompressionService.js +339 -0
- package/dist/src/services/chatCompressionService.js.map +1 -0
- package/dist/src/services/chatRecordingService.d.ts +174 -0
- package/dist/src/services/chatRecordingService.js +427 -0
- package/dist/src/services/chatRecordingService.js.map +1 -0
- package/dist/src/services/contextManager.d.ts +29 -0
- package/dist/src/services/contextManager.js +71 -0
- package/dist/src/services/contextManager.js.map +1 -0
- package/dist/src/services/environmentSanitization.d.ts +15 -0
- package/dist/src/services/environmentSanitization.js +145 -0
- package/dist/src/services/environmentSanitization.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.d.ts +45 -0
- package/dist/src/services/fileDiscoveryService.js +141 -0
- package/dist/src/services/fileDiscoveryService.js.map +1 -0
- package/dist/src/services/fileSystemService.d.ts +31 -0
- package/dist/src/services/fileSystemService.js +18 -0
- package/dist/src/services/fileSystemService.js.map +1 -0
- package/dist/src/services/gitService.d.ts +24 -0
- package/dist/src/services/gitService.js +132 -0
- package/dist/src/services/gitService.js.map +1 -0
- package/dist/src/services/loopDetectionService.d.ts +106 -0
- package/dist/src/services/loopDetectionService.js +433 -0
- package/dist/src/services/loopDetectionService.js.map +1 -0
- package/dist/src/services/modelConfigService.d.ts +86 -0
- package/dist/src/services/modelConfigService.js +215 -0
- package/dist/src/services/modelConfigService.js.map +1 -0
- package/dist/src/services/modelConfigServiceTestUtils.d.ts +10 -0
- package/dist/src/services/modelConfigServiceTestUtils.js +17 -0
- package/dist/src/services/modelConfigServiceTestUtils.js.map +1 -0
- package/dist/src/services/sessionSummaryService.d.ts +28 -0
- package/dist/src/services/sessionSummaryService.js +131 -0
- package/dist/src/services/sessionSummaryService.js.map +1 -0
- package/dist/src/services/sessionSummaryUtils.d.ts +16 -0
- package/dist/src/services/sessionSummaryUtils.js +129 -0
- package/dist/src/services/sessionSummaryUtils.js.map +1 -0
- package/dist/src/services/shellExecutionService.d.ts +145 -0
- package/dist/src/services/shellExecutionService.js +871 -0
- package/dist/src/services/shellExecutionService.js.map +1 -0
- package/dist/src/services/test-data/resolved-aliases-retry.golden.json +238 -0
- package/dist/src/services/test-data/resolved-aliases.golden.json +238 -0
- package/dist/src/skills/builtin/skill-creator/SKILL.md +382 -0
- package/dist/src/skills/builtin/skill-creator/scripts/init_skill.cjs +235 -0
- package/dist/src/skills/builtin/skill-creator/scripts/package_skill.cjs +102 -0
- package/dist/src/skills/builtin/skill-creator/scripts/validate_skill.cjs +127 -0
- package/dist/src/skills/skillLoader.d.ts +31 -0
- package/dist/src/skills/skillLoader.js +133 -0
- package/dist/src/skills/skillLoader.js.map +1 -0
- package/dist/src/skills/skillManager.d.ts +69 -0
- package/dist/src/skills/skillManager.js +138 -0
- package/dist/src/skills/skillManager.js.map +1 -0
- package/dist/src/telemetry/activity-detector.d.ts +41 -0
- package/dist/src/telemetry/activity-detector.js +61 -0
- package/dist/src/telemetry/activity-detector.js.map +1 -0
- package/dist/src/telemetry/activity-monitor.d.ts +116 -0
- package/dist/src/telemetry/activity-monitor.js +209 -0
- package/dist/src/telemetry/activity-monitor.js.map +1 -0
- package/dist/src/telemetry/activity-types.d.ts +19 -0
- package/dist/src/telemetry/activity-types.js +21 -0
- package/dist/src/telemetry/activity-types.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +172 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +1316 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +150 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +377 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -0
- package/dist/src/telemetry/config.d.ts +31 -0
- package/dist/src/telemetry/config.js +78 -0
- package/dist/src/telemetry/config.js.map +1 -0
- package/dist/src/telemetry/constants.d.ts +6 -0
- package/dist/src/telemetry/constants.js +7 -0
- package/dist/src/telemetry/constants.js.map +1 -0
- package/dist/src/telemetry/file-exporters.d.ts +29 -0
- package/dist/src/telemetry/file-exporters.js +62 -0
- package/dist/src/telemetry/file-exporters.js.map +1 -0
- package/dist/src/telemetry/gcp-exporters.d.ts +35 -0
- package/dist/src/telemetry/gcp-exporters.js +120 -0
- package/dist/src/telemetry/gcp-exporters.js.map +1 -0
- package/dist/src/telemetry/high-water-mark-tracker.d.ts +43 -0
- package/dist/src/telemetry/high-water-mark-tracker.js +88 -0
- package/dist/src/telemetry/high-water-mark-tracker.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +33 -0
- package/dist/src/telemetry/index.js +44 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/integration.test.circular.d.ts +6 -0
- package/dist/src/telemetry/integration.test.circular.js +54 -0
- package/dist/src/telemetry/integration.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.d.ts +46 -0
- package/dist/src/telemetry/loggers.js +517 -0
- package/dist/src/telemetry/loggers.js.map +1 -0
- package/dist/src/telemetry/loggers.test.circular.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.circular.js +107 -0
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -0
- package/dist/src/telemetry/memory-monitor.d.ts +149 -0
- package/dist/src/telemetry/memory-monitor.js +335 -0
- package/dist/src/telemetry/memory-monitor.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +533 -0
- package/dist/src/telemetry/metrics.js +852 -0
- package/dist/src/telemetry/metrics.js.map +1 -0
- package/dist/src/telemetry/rate-limiter.d.ts +48 -0
- package/dist/src/telemetry/rate-limiter.js +100 -0
- package/dist/src/telemetry/rate-limiter.js.map +1 -0
- package/dist/src/telemetry/sanitize.d.ts +25 -0
- package/dist/src/telemetry/sanitize.js +48 -0
- package/dist/src/telemetry/sanitize.js.map +1 -0
- package/dist/src/telemetry/sdk.d.ts +16 -0
- package/dist/src/telemetry/sdk.js +307 -0
- package/dist/src/telemetry/sdk.js.map +1 -0
- package/dist/src/telemetry/semantic.d.ts +82 -0
- package/dist/src/telemetry/semantic.js +357 -0
- package/dist/src/telemetry/semantic.js.map +1 -0
- package/dist/src/telemetry/startupProfiler.d.ts +51 -0
- package/dist/src/telemetry/startupProfiler.js +170 -0
- package/dist/src/telemetry/startupProfiler.js.map +1 -0
- package/dist/src/telemetry/telemetry-utils.d.ts +6 -0
- package/dist/src/telemetry/telemetry-utils.js +14 -0
- package/dist/src/telemetry/telemetry-utils.js.map +1 -0
- package/dist/src/telemetry/telemetryAttributes.d.ts +8 -0
- package/dist/src/telemetry/telemetryAttributes.js +19 -0
- package/dist/src/telemetry/telemetryAttributes.js.map +1 -0
- package/dist/src/telemetry/tool-call-decision.d.ts +13 -0
- package/dist/src/telemetry/tool-call-decision.js +29 -0
- package/dist/src/telemetry/tool-call-decision.js.map +1 -0
- package/dist/src/telemetry/trace.d.ts +46 -0
- package/dist/src/telemetry/trace.js +121 -0
- package/dist/src/telemetry/trace.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +566 -0
- package/dist/src/telemetry/types.js +1495 -0
- package/dist/src/telemetry/types.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.d.ts +76 -0
- package/dist/src/telemetry/uiTelemetry.js +154 -0
- package/dist/src/telemetry/uiTelemetry.js.map +1 -0
- package/dist/src/test-utils/config.d.ts +17 -0
- package/dist/src/test-utils/config.js +32 -0
- package/dist/src/test-utils/config.js.map +1 -0
- package/dist/src/test-utils/index.d.ts +6 -0
- package/dist/src/test-utils/index.js +7 -0
- package/dist/src/test-utils/index.js.map +1 -0
- package/dist/src/test-utils/mock-message-bus.d.ts +43 -0
- package/dist/src/test-utils/mock-message-bus.js +96 -0
- package/dist/src/test-utils/mock-message-bus.js.map +1 -0
- package/dist/src/test-utils/mock-tool.d.ts +69 -0
- package/dist/src/test-utils/mock-tool.js +123 -0
- package/dist/src/test-utils/mock-tool.js.map +1 -0
- package/dist/src/test-utils/mockWorkspaceContext.d.ts +13 -0
- package/dist/src/test-utils/mockWorkspaceContext.js +24 -0
- package/dist/src/test-utils/mockWorkspaceContext.js.map +1 -0
- package/dist/src/tools/activate-skill.d.ts +27 -0
- package/dist/src/tools/activate-skill.js +133 -0
- package/dist/src/tools/activate-skill.js.map +1 -0
- package/dist/src/tools/ask-user.d.ts +23 -0
- package/dist/src/tools/ask-user.js +155 -0
- package/dist/src/tools/ask-user.js.map +1 -0
- package/dist/src/tools/constants.d.ts +7 -0
- package/dist/src/tools/constants.js +8 -0
- package/dist/src/tools/constants.js.map +1 -0
- package/dist/src/tools/diffOptions.d.ts +9 -0
- package/dist/src/tools/diffOptions.js +50 -0
- package/dist/src/tools/diffOptions.js.map +1 -0
- package/dist/src/tools/edit.d.ts +79 -0
- package/dist/src/tools/edit.js +750 -0
- package/dist/src/tools/edit.js.map +1 -0
- package/dist/src/tools/get-internal-docs.d.ts +27 -0
- package/dist/src/tools/get-internal-docs.js +122 -0
- package/dist/src/tools/get-internal-docs.js.map +1 -0
- package/dist/src/tools/glob.d.ts +57 -0
- package/dist/src/tools/glob.js +240 -0
- package/dist/src/tools/glob.js.map +1 -0
- package/dist/src/tools/grep.d.ts +41 -0
- package/dist/src/tools/grep.js +505 -0
- package/dist/src/tools/grep.js.map +1 -0
- package/dist/src/tools/ls.d.ts +69 -0
- package/dist/src/tools/ls.js +214 -0
- package/dist/src/tools/ls.js.map +1 -0
- package/dist/src/tools/mcp-client-manager.d.ts +93 -0
- package/dist/src/tools/mcp-client-manager.js +338 -0
- package/dist/src/tools/mcp-client-manager.js.map +1 -0
- package/dist/src/tools/mcp-client.d.ts +243 -0
- package/dist/src/tools/mcp-client.js +1351 -0
- package/dist/src/tools/mcp-client.js.map +1 -0
- package/dist/src/tools/mcp-tool.d.ts +49 -0
- package/dist/src/tools/mcp-tool.js +300 -0
- package/dist/src/tools/mcp-tool.js.map +1 -0
- package/dist/src/tools/memoryTool.d.ts +42 -0
- package/dist/src/tools/memoryTool.js +269 -0
- package/dist/src/tools/memoryTool.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +36 -0
- package/dist/src/tools/modifiable-tool.js +110 -0
- package/dist/src/tools/modifiable-tool.js.map +1 -0
- package/dist/src/tools/read-file.d.ts +37 -0
- package/dist/src/tools/read-file.js +141 -0
- package/dist/src/tools/read-file.js.map +1 -0
- package/dist/src/tools/read-many-files.d.ts +54 -0
- package/dist/src/tools/read-many-files.js +364 -0
- package/dist/src/tools/read-many-files.js.map +1 -0
- package/dist/src/tools/ripGrep.d.ts +74 -0
- package/dist/src/tools/ripGrep.js +422 -0
- package/dist/src/tools/ripGrep.js.map +1 -0
- package/dist/src/tools/shell.d.ts +33 -0
- package/dist/src/tools/shell.js +436 -0
- package/dist/src/tools/shell.js.map +1 -0
- package/dist/src/tools/tool-error.d.ts +70 -0
- package/dist/src/tools/tool-error.js +92 -0
- package/dist/src/tools/tool-error.js.map +1 -0
- package/dist/src/tools/tool-names.d.ts +41 -0
- package/dist/src/tools/tool-names.js +94 -0
- package/dist/src/tools/tool-names.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +103 -0
- package/dist/src/tools/tool-registry.js +429 -0
- package/dist/src/tools/tool-registry.js.map +1 -0
- package/dist/src/tools/tools.d.ts +347 -0
- package/dist/src/tools/tools.js +405 -0
- package/dist/src/tools/tools.js.map +1 -0
- package/dist/src/tools/web-fetch.d.ts +35 -0
- package/dist/src/tools/web-fetch.js +299 -0
- package/dist/src/tools/web-fetch.js.map +1 -0
- package/dist/src/tools/web-search.d.ts +50 -0
- package/dist/src/tools/web-search.js +141 -0
- package/dist/src/tools/web-search.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +53 -0
- package/dist/src/tools/write-file.js +341 -0
- package/dist/src/tools/write-file.js.map +1 -0
- package/dist/src/tools/write-todos.d.ts +50 -0
- package/dist/src/tools/write-todos.js +194 -0
- package/dist/src/tools/write-todos.js.map +1 -0
- package/dist/src/utils/apiConversionUtils.d.ts +12 -0
- package/dist/src/utils/apiConversionUtils.js +46 -0
- package/dist/src/utils/apiConversionUtils.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.d.ts +32 -0
- package/dist/src/utils/bfsFileSearch.js +136 -0
- package/dist/src/utils/bfsFileSearch.js.map +1 -0
- package/dist/src/utils/browser.d.ts +13 -0
- package/dist/src/utils/browser.js +50 -0
- package/dist/src/utils/browser.js.map +1 -0
- package/dist/src/utils/channel.d.ts +19 -0
- package/dist/src/utils/channel.js +49 -0
- package/dist/src/utils/channel.js.map +1 -0
- package/dist/src/utils/checkpointUtils.d.ts +82 -0
- package/dist/src/utils/checkpointUtils.js +117 -0
- package/dist/src/utils/checkpointUtils.js.map +1 -0
- package/dist/src/utils/constants.d.ts +7 -0
- package/dist/src/utils/constants.js +8 -0
- package/dist/src/utils/constants.js.map +1 -0
- package/dist/src/utils/customHeaderUtils.d.ts +9 -0
- package/dist/src/utils/customHeaderUtils.js +34 -0
- package/dist/src/utils/customHeaderUtils.js.map +1 -0
- package/dist/src/utils/debugLogger.d.ts +28 -0
- package/dist/src/utils/debugLogger.js +61 -0
- package/dist/src/utils/debugLogger.js.map +1 -0
- package/dist/src/utils/delay.d.ts +16 -0
- package/dist/src/utils/delay.js +43 -0
- package/dist/src/utils/delay.js.map +1 -0
- package/dist/src/utils/editCorrector.d.ts +54 -0
- package/dist/src/utils/editCorrector.js +596 -0
- package/dist/src/utils/editCorrector.js.map +1 -0
- package/dist/src/utils/editor.d.ts +39 -0
- package/dist/src/utils/editor.js +219 -0
- package/dist/src/utils/editor.js.map +1 -0
- package/dist/src/utils/environmentContext.d.ts +23 -0
- package/dist/src/utils/environmentContext.js +81 -0
- package/dist/src/utils/environmentContext.js.map +1 -0
- package/dist/src/utils/errorParsing.d.ts +8 -0
- package/dist/src/utils/errorParsing.js +65 -0
- package/dist/src/utils/errorParsing.js.map +1 -0
- package/dist/src/utils/errorReporting.d.ts +14 -0
- package/dist/src/utils/errorReporting.js +89 -0
- package/dist/src/utils/errorReporting.js.map +1 -0
- package/dist/src/utils/errors.d.ts +53 -0
- package/dist/src/utils/errors.js +145 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/events.d.ts +211 -0
- package/dist/src/utils/events.js +134 -0
- package/dist/src/utils/events.js.map +1 -0
- package/dist/src/utils/exitCodes.d.ts +12 -0
- package/dist/src/utils/exitCodes.js +13 -0
- package/dist/src/utils/exitCodes.js.map +1 -0
- package/dist/src/utils/extensionLoader.d.ts +86 -0
- package/dist/src/utils/extensionLoader.js +208 -0
- package/dist/src/utils/extensionLoader.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +12 -0
- package/dist/src/utils/fetch.js +55 -0
- package/dist/src/utils/fetch.js.map +1 -0
- package/dist/src/utils/fileDiffUtils.d.ts +18 -0
- package/dist/src/utils/fileDiffUtils.js +37 -0
- package/dist/src/utils/fileDiffUtils.js.map +1 -0
- package/dist/src/utils/fileUtils.d.ts +86 -0
- package/dist/src/utils/fileUtils.js +495 -0
- package/dist/src/utils/fileUtils.js.map +1 -0
- package/dist/src/utils/filesearch/crawlCache.d.ts +25 -0
- package/dist/src/utils/filesearch/crawlCache.js +57 -0
- package/dist/src/utils/filesearch/crawlCache.js.map +1 -0
- package/dist/src/utils/filesearch/crawler.d.ts +16 -0
- package/dist/src/utils/filesearch/crawler.js +67 -0
- package/dist/src/utils/filesearch/crawler.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.d.ts +39 -0
- package/dist/src/utils/filesearch/fileSearch.js +192 -0
- package/dist/src/utils/filesearch/fileSearch.js.map +1 -0
- package/dist/src/utils/filesearch/ignore.d.ts +37 -0
- package/dist/src/utils/filesearch/ignore.js +99 -0
- package/dist/src/utils/filesearch/ignore.js.map +1 -0
- package/dist/src/utils/filesearch/result-cache.d.ts +33 -0
- package/dist/src/utils/filesearch/result-cache.js +59 -0
- package/dist/src/utils/filesearch/result-cache.js.map +1 -0
- package/dist/src/utils/formatters.d.ts +7 -0
- package/dist/src/utils/formatters.js +17 -0
- package/dist/src/utils/formatters.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.d.ts +15 -0
- package/dist/src/utils/generateContentResponseUtilities.js +186 -0
- package/dist/src/utils/generateContentResponseUtilities.js.map +1 -0
- package/dist/src/utils/getFolderStructure.d.ts +31 -0
- package/dist/src/utils/getFolderStructure.js +243 -0
- package/dist/src/utils/getFolderStructure.js.map +1 -0
- package/dist/src/utils/getPty.d.ts +19 -0
- package/dist/src/utils/getPty.js +23 -0
- package/dist/src/utils/getPty.js.map +1 -0
- package/dist/src/utils/gitIgnoreParser.d.ts +19 -0
- package/dist/src/utils/gitIgnoreParser.js +169 -0
- package/dist/src/utils/gitIgnoreParser.js.map +1 -0
- package/dist/src/utils/gitUtils.d.ts +17 -0
- package/dist/src/utils/gitUtils.js +61 -0
- package/dist/src/utils/gitUtils.js.map +1 -0
- package/dist/src/utils/googleErrors.d.ts +104 -0
- package/dist/src/utils/googleErrors.js +165 -0
- package/dist/src/utils/googleErrors.js.map +1 -0
- package/dist/src/utils/googleQuotaErrors.d.ts +51 -0
- package/dist/src/utils/googleQuotaErrors.js +250 -0
- package/dist/src/utils/googleQuotaErrors.js.map +1 -0
- package/dist/src/utils/httpErrors.d.ts +18 -0
- package/dist/src/utils/httpErrors.js +36 -0
- package/dist/src/utils/httpErrors.js.map +1 -0
- package/dist/src/utils/ignoreFileParser.d.ts +30 -0
- package/dist/src/utils/ignoreFileParser.js +100 -0
- package/dist/src/utils/ignoreFileParser.js.map +1 -0
- package/dist/src/utils/ignorePatterns.d.ts +103 -0
- package/dist/src/utils/ignorePatterns.js +220 -0
- package/dist/src/utils/ignorePatterns.js.map +1 -0
- package/dist/src/utils/installationManager.d.ts +16 -0
- package/dist/src/utils/installationManager.js +51 -0
- package/dist/src/utils/installationManager.js.map +1 -0
- package/dist/src/utils/language-detection.d.ts +6 -0
- package/dist/src/utils/language-detection.js +101 -0
- package/dist/src/utils/language-detection.js.map +1 -0
- package/dist/src/utils/llm-edit-fixer.d.ts +26 -0
- package/dist/src/utils/llm-edit-fixer.js +152 -0
- package/dist/src/utils/llm-edit-fixer.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.d.ts +40 -0
- package/dist/src/utils/memoryDiscovery.js +421 -0
- package/dist/src/utils/memoryDiscovery.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.d.ts +42 -0
- package/dist/src/utils/memoryImportProcessor.js +273 -0
- package/dist/src/utils/memoryImportProcessor.js.map +1 -0
- package/dist/src/utils/messageInspectors.d.ts +8 -0
- package/dist/src/utils/messageInspectors.js +16 -0
- package/dist/src/utils/messageInspectors.js.map +1 -0
- package/dist/src/utils/nextSpeakerChecker.d.ts +12 -0
- package/dist/src/utils/nextSpeakerChecker.js +97 -0
- package/dist/src/utils/nextSpeakerChecker.js.map +1 -0
- package/dist/src/utils/package.d.ts +26 -0
- package/dist/src/utils/package.js +35 -0
- package/dist/src/utils/package.js.map +1 -0
- package/dist/src/utils/partUtils.d.ts +35 -0
- package/dist/src/utils/partUtils.js +133 -0
- package/dist/src/utils/partUtils.js.map +1 -0
- package/dist/src/utils/pathCorrector.d.ts +25 -0
- package/dist/src/utils/pathCorrector.js +43 -0
- package/dist/src/utils/pathCorrector.js.map +1 -0
- package/dist/src/utils/pathReader.d.ts +17 -0
- package/dist/src/utils/pathReader.js +92 -0
- package/dist/src/utils/pathReader.js.map +1 -0
- package/dist/src/utils/paths.d.ts +78 -0
- package/dist/src/utils/paths.js +311 -0
- package/dist/src/utils/paths.js.map +1 -0
- package/dist/src/utils/process-utils.d.ts +32 -0
- package/dist/src/utils/process-utils.js +88 -0
- package/dist/src/utils/process-utils.js.map +1 -0
- package/dist/src/utils/promptIdContext.d.ts +13 -0
- package/dist/src/utils/promptIdContext.js +23 -0
- package/dist/src/utils/promptIdContext.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.d.ts +16 -0
- package/dist/src/utils/quotaErrorDetection.js +19 -0
- package/dist/src/utils/quotaErrorDetection.js.map +1 -0
- package/dist/src/utils/retry.d.ts +39 -0
- package/dist/src/utils/retry.js +267 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.d.ts +13 -0
- package/dist/src/utils/safeJsonStringify.js +49 -0
- package/dist/src/utils/safeJsonStringify.js.map +1 -0
- package/dist/src/utils/schemaValidator.d.ts +21 -0
- package/dist/src/utils/schemaValidator.js +59 -0
- package/dist/src/utils/schemaValidator.js.map +1 -0
- package/dist/src/utils/secure-browser-launcher.d.ts +23 -0
- package/dist/src/utils/secure-browser-launcher.js +165 -0
- package/dist/src/utils/secure-browser-launcher.js.map +1 -0
- package/dist/src/utils/security.d.ts +16 -0
- package/dist/src/utils/security.js +88 -0
- package/dist/src/utils/security.js.map +1 -0
- package/dist/src/utils/session.d.ts +6 -0
- package/dist/src/utils/session.js +8 -0
- package/dist/src/utils/session.js.map +1 -0
- package/dist/src/utils/shell-utils.d.ts +118 -0
- package/dist/src/utils/shell-utils.js +708 -0
- package/dist/src/utils/shell-utils.js.map +1 -0
- package/dist/src/utils/stdio.d.ts +32 -0
- package/dist/src/utils/stdio.js +85 -0
- package/dist/src/utils/stdio.js.map +1 -0
- package/dist/src/utils/summarizer.d.ts +27 -0
- package/dist/src/utils/summarizer.js +50 -0
- package/dist/src/utils/summarizer.js.map +1 -0
- package/dist/src/utils/systemEncoding.d.ts +40 -0
- package/dist/src/utils/systemEncoding.js +150 -0
- package/dist/src/utils/systemEncoding.js.map +1 -0
- package/dist/src/utils/terminal.d.ts +22 -0
- package/dist/src/utils/terminal.js +62 -0
- package/dist/src/utils/terminal.js.map +1 -0
- package/dist/src/utils/terminalSerializer.d.ts +25 -0
- package/dist/src/utils/terminalSerializer.js +444 -0
- package/dist/src/utils/terminalSerializer.js.map +1 -0
- package/dist/src/utils/testUtils.d.ts +29 -0
- package/dist/src/utils/testUtils.js +70 -0
- package/dist/src/utils/testUtils.js.map +1 -0
- package/dist/src/utils/textUtils.d.ts +32 -0
- package/dist/src/utils/textUtils.js +65 -0
- package/dist/src/utils/textUtils.js.map +1 -0
- package/dist/src/utils/thoughtUtils.d.ts +21 -0
- package/dist/src/utils/thoughtUtils.js +39 -0
- package/dist/src/utils/thoughtUtils.js.map +1 -0
- package/dist/src/utils/tokenCalculation.d.ts +19 -0
- package/dist/src/utils/tokenCalculation.js +150 -0
- package/dist/src/utils/tokenCalculation.js.map +1 -0
- package/dist/src/utils/tool-utils.d.ts +28 -0
- package/dist/src/utils/tool-utils.js +96 -0
- package/dist/src/utils/tool-utils.js.map +1 -0
- package/dist/src/utils/toolCallContext.d.ts +35 -0
- package/dist/src/utils/toolCallContext.js +29 -0
- package/dist/src/utils/toolCallContext.js.map +1 -0
- package/dist/src/utils/userAccountManager.d.ts +20 -0
- package/dist/src/utils/userAccountManager.js +115 -0
- package/dist/src/utils/userAccountManager.js.map +1 -0
- package/dist/src/utils/version.d.ts +6 -0
- package/dist/src/utils/version.js +15 -0
- package/dist/src/utils/version.js.map +1 -0
- package/dist/src/utils/workspaceContext.d.ts +82 -0
- package/dist/src/utils/workspaceContext.js +192 -0
- package/dist/src/utils/workspaceContext.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +97 -0
|
@@ -0,0 +1,1351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
7
|
+
import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
|
|
8
|
+
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
9
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
10
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
11
|
+
import { ListResourcesResultSchema, ListRootsRequestSchema, ReadResourceResultSchema, ResourceListChangedNotificationSchema, ToolListChangedNotificationSchema, PromptListChangedNotificationSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
12
|
+
import { parse } from 'shell-quote';
|
|
13
|
+
import { AuthProviderType } from '../config/config.js';
|
|
14
|
+
import { GoogleCredentialProvider } from '../mcp/google-auth-provider.js';
|
|
15
|
+
import { ServiceAccountImpersonationProvider } from '../mcp/sa-impersonation-provider.js';
|
|
16
|
+
import { DiscoveredMCPTool } from './mcp-tool.js';
|
|
17
|
+
import { basename } from 'node:path';
|
|
18
|
+
import { pathToFileURL } from 'node:url';
|
|
19
|
+
import { MCPOAuthProvider } from '../mcp/oauth-provider.js';
|
|
20
|
+
import { MCPOAuthTokenStorage } from '../mcp/oauth-token-storage.js';
|
|
21
|
+
import { OAuthUtils } from '../mcp/oauth-utils.js';
|
|
22
|
+
import { getErrorMessage, isAuthenticationError, UnauthorizedError, } from '../utils/errors.js';
|
|
23
|
+
import { debugLogger } from '../utils/debugLogger.js';
|
|
24
|
+
import {} from '../confirmation-bus/message-bus.js';
|
|
25
|
+
import { coreEvents } from '../utils/events.js';
|
|
26
|
+
import { sanitizeEnvironment, } from '../services/environmentSanitization.js';
|
|
27
|
+
export const MCP_DEFAULT_TIMEOUT_MSEC = 10 * 60 * 1000; // default to 10 minutes
|
|
28
|
+
/**
|
|
29
|
+
* Enum representing the connection status of an MCP server
|
|
30
|
+
*/
|
|
31
|
+
export var MCPServerStatus;
|
|
32
|
+
(function (MCPServerStatus) {
|
|
33
|
+
/** Server is disconnected or experiencing errors */
|
|
34
|
+
MCPServerStatus["DISCONNECTED"] = "disconnected";
|
|
35
|
+
/** Server is actively disconnecting */
|
|
36
|
+
MCPServerStatus["DISCONNECTING"] = "disconnecting";
|
|
37
|
+
/** Server is in the process of connecting */
|
|
38
|
+
MCPServerStatus["CONNECTING"] = "connecting";
|
|
39
|
+
/** Server is connected and ready to use */
|
|
40
|
+
MCPServerStatus["CONNECTED"] = "connected";
|
|
41
|
+
})(MCPServerStatus || (MCPServerStatus = {}));
|
|
42
|
+
/**
|
|
43
|
+
* Enum representing the overall MCP discovery state
|
|
44
|
+
*/
|
|
45
|
+
export var MCPDiscoveryState;
|
|
46
|
+
(function (MCPDiscoveryState) {
|
|
47
|
+
/** Discovery has not started yet */
|
|
48
|
+
MCPDiscoveryState["NOT_STARTED"] = "not_started";
|
|
49
|
+
/** Discovery is currently in progress */
|
|
50
|
+
MCPDiscoveryState["IN_PROGRESS"] = "in_progress";
|
|
51
|
+
/** Discovery has completed (with or without errors) */
|
|
52
|
+
MCPDiscoveryState["COMPLETED"] = "completed";
|
|
53
|
+
})(MCPDiscoveryState || (MCPDiscoveryState = {}));
|
|
54
|
+
/**
|
|
55
|
+
* A client for a single MCP server.
|
|
56
|
+
*
|
|
57
|
+
* This class is responsible for connecting to, discovering tools from, and
|
|
58
|
+
* managing the state of a single MCP server.
|
|
59
|
+
*/
|
|
60
|
+
export class McpClient {
|
|
61
|
+
serverName;
|
|
62
|
+
serverConfig;
|
|
63
|
+
toolRegistry;
|
|
64
|
+
promptRegistry;
|
|
65
|
+
resourceRegistry;
|
|
66
|
+
workspaceContext;
|
|
67
|
+
cliConfig;
|
|
68
|
+
debugMode;
|
|
69
|
+
clientVersion;
|
|
70
|
+
onToolsUpdated;
|
|
71
|
+
client;
|
|
72
|
+
transport;
|
|
73
|
+
status = MCPServerStatus.DISCONNECTED;
|
|
74
|
+
isRefreshingTools = false;
|
|
75
|
+
pendingToolRefresh = false;
|
|
76
|
+
isRefreshingResources = false;
|
|
77
|
+
pendingResourceRefresh = false;
|
|
78
|
+
isRefreshingPrompts = false;
|
|
79
|
+
pendingPromptRefresh = false;
|
|
80
|
+
constructor(serverName, serverConfig, toolRegistry, promptRegistry, resourceRegistry, workspaceContext, cliConfig, debugMode, clientVersion, onToolsUpdated) {
|
|
81
|
+
this.serverName = serverName;
|
|
82
|
+
this.serverConfig = serverConfig;
|
|
83
|
+
this.toolRegistry = toolRegistry;
|
|
84
|
+
this.promptRegistry = promptRegistry;
|
|
85
|
+
this.resourceRegistry = resourceRegistry;
|
|
86
|
+
this.workspaceContext = workspaceContext;
|
|
87
|
+
this.cliConfig = cliConfig;
|
|
88
|
+
this.debugMode = debugMode;
|
|
89
|
+
this.clientVersion = clientVersion;
|
|
90
|
+
this.onToolsUpdated = onToolsUpdated;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Connects to the MCP server.
|
|
94
|
+
*/
|
|
95
|
+
async connect() {
|
|
96
|
+
if (this.status !== MCPServerStatus.DISCONNECTED) {
|
|
97
|
+
throw new Error(`Can only connect when the client is disconnected, current state is ${this.status}`);
|
|
98
|
+
}
|
|
99
|
+
this.updateStatus(MCPServerStatus.CONNECTING);
|
|
100
|
+
try {
|
|
101
|
+
this.client = await connectToMcpServer(this.clientVersion, this.serverName, this.serverConfig, this.debugMode, this.workspaceContext, this.cliConfig.sanitizationConfig);
|
|
102
|
+
this.registerNotificationHandlers();
|
|
103
|
+
const originalOnError = this.client.onerror;
|
|
104
|
+
this.client.onerror = (error) => {
|
|
105
|
+
if (this.status !== MCPServerStatus.CONNECTED) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (originalOnError)
|
|
109
|
+
originalOnError(error);
|
|
110
|
+
coreEvents.emitFeedback('error', `MCP ERROR (${this.serverName})`, error);
|
|
111
|
+
this.updateStatus(MCPServerStatus.DISCONNECTED);
|
|
112
|
+
};
|
|
113
|
+
this.updateStatus(MCPServerStatus.CONNECTED);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
this.updateStatus(MCPServerStatus.DISCONNECTED);
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Discovers tools and prompts from the MCP server.
|
|
122
|
+
*/
|
|
123
|
+
async discover(cliConfig) {
|
|
124
|
+
this.assertConnected();
|
|
125
|
+
const prompts = await this.fetchPrompts();
|
|
126
|
+
const tools = await this.discoverTools(cliConfig);
|
|
127
|
+
const resources = await this.discoverResources();
|
|
128
|
+
this.updateResourceRegistry(resources);
|
|
129
|
+
if (prompts.length === 0 && tools.length === 0 && resources.length === 0) {
|
|
130
|
+
throw new Error('No prompts, tools, or resources found on the server.');
|
|
131
|
+
}
|
|
132
|
+
for (const prompt of prompts) {
|
|
133
|
+
this.promptRegistry.registerPrompt(prompt);
|
|
134
|
+
}
|
|
135
|
+
for (const tool of tools) {
|
|
136
|
+
this.toolRegistry.registerTool(tool);
|
|
137
|
+
}
|
|
138
|
+
this.toolRegistry.sortTools();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Disconnects from the MCP server.
|
|
142
|
+
*/
|
|
143
|
+
async disconnect() {
|
|
144
|
+
if (this.status !== MCPServerStatus.CONNECTED) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
this.toolRegistry.removeMcpToolsByServer(this.serverName);
|
|
148
|
+
this.promptRegistry.removePromptsByServer(this.serverName);
|
|
149
|
+
this.resourceRegistry.removeResourcesByServer(this.serverName);
|
|
150
|
+
this.updateStatus(MCPServerStatus.DISCONNECTING);
|
|
151
|
+
const client = this.client;
|
|
152
|
+
this.client = undefined;
|
|
153
|
+
if (this.transport) {
|
|
154
|
+
await this.transport.close();
|
|
155
|
+
}
|
|
156
|
+
if (client) {
|
|
157
|
+
await client.close();
|
|
158
|
+
}
|
|
159
|
+
this.updateStatus(MCPServerStatus.DISCONNECTED);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns the current status of the client.
|
|
163
|
+
*/
|
|
164
|
+
getStatus() {
|
|
165
|
+
return this.status;
|
|
166
|
+
}
|
|
167
|
+
updateStatus(status) {
|
|
168
|
+
this.status = status;
|
|
169
|
+
updateMCPServerStatus(this.serverName, status);
|
|
170
|
+
}
|
|
171
|
+
assertConnected() {
|
|
172
|
+
if (this.status !== MCPServerStatus.CONNECTED) {
|
|
173
|
+
throw new Error(`Client is not connected, must connect before interacting with the server. Current state is ${this.status}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async discoverTools(cliConfig, options) {
|
|
177
|
+
this.assertConnected();
|
|
178
|
+
return discoverTools(this.serverName, this.serverConfig, this.client, cliConfig, this.toolRegistry.getMessageBus(), options ?? {
|
|
179
|
+
timeout: this.serverConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
async fetchPrompts(options) {
|
|
183
|
+
this.assertConnected();
|
|
184
|
+
return discoverPrompts(this.serverName, this.client, options);
|
|
185
|
+
}
|
|
186
|
+
async discoverResources() {
|
|
187
|
+
this.assertConnected();
|
|
188
|
+
return discoverResources(this.serverName, this.client);
|
|
189
|
+
}
|
|
190
|
+
updateResourceRegistry(resources) {
|
|
191
|
+
this.resourceRegistry.setResourcesForServer(this.serverName, resources);
|
|
192
|
+
}
|
|
193
|
+
async readResource(uri) {
|
|
194
|
+
this.assertConnected();
|
|
195
|
+
return this.client.request({
|
|
196
|
+
method: 'resources/read',
|
|
197
|
+
params: { uri },
|
|
198
|
+
}, ReadResourceResultSchema);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Registers notification handlers for dynamic updates from the MCP server.
|
|
202
|
+
* This includes handlers for tool list changes and resource list changes.
|
|
203
|
+
*/
|
|
204
|
+
registerNotificationHandlers() {
|
|
205
|
+
if (!this.client) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const capabilities = this.client.getServerCapabilities();
|
|
209
|
+
if (capabilities?.tools?.listChanged) {
|
|
210
|
+
debugLogger.log(`Server '${this.serverName}' supports tool updates. Listening for changes...`);
|
|
211
|
+
this.client.setNotificationHandler(ToolListChangedNotificationSchema, async () => {
|
|
212
|
+
debugLogger.log(`🔔 Received tool update notification from '${this.serverName}'`);
|
|
213
|
+
await this.refreshTools();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (capabilities?.resources?.listChanged) {
|
|
217
|
+
debugLogger.log(`Server '${this.serverName}' supports resource updates. Listening for changes...`);
|
|
218
|
+
this.client.setNotificationHandler(ResourceListChangedNotificationSchema, async () => {
|
|
219
|
+
debugLogger.log(`🔔 Received resource update notification from '${this.serverName}'`);
|
|
220
|
+
await this.refreshResources();
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
if (capabilities?.prompts?.listChanged) {
|
|
224
|
+
debugLogger.log(`Server '${this.serverName}' supports prompt updates. Listening for changes...`);
|
|
225
|
+
this.client.setNotificationHandler(PromptListChangedNotificationSchema, async () => {
|
|
226
|
+
debugLogger.log(`🔔 Received prompt update notification from '${this.serverName}'`);
|
|
227
|
+
await this.refreshPrompts();
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Refreshes the resources for this server by re-querying the MCP `resources/list` endpoint.
|
|
233
|
+
*
|
|
234
|
+
* This method implements a **Coalescing Pattern** to handle rapid bursts of notifications
|
|
235
|
+
* (e.g., during server startup or bulk updates) without overwhelming the server or
|
|
236
|
+
* creating race conditions in the ResourceRegistry.
|
|
237
|
+
*/
|
|
238
|
+
async refreshResources() {
|
|
239
|
+
if (this.isRefreshingResources) {
|
|
240
|
+
debugLogger.log(`Resource refresh for '${this.serverName}' is already in progress. Pending update.`);
|
|
241
|
+
this.pendingResourceRefresh = true;
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
this.isRefreshingResources = true;
|
|
245
|
+
try {
|
|
246
|
+
do {
|
|
247
|
+
this.pendingResourceRefresh = false;
|
|
248
|
+
if (this.status !== MCPServerStatus.CONNECTED || !this.client)
|
|
249
|
+
break;
|
|
250
|
+
const timeoutMs = this.serverConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC;
|
|
251
|
+
const abortController = new AbortController();
|
|
252
|
+
const timeoutId = setTimeout(() => abortController.abort(), timeoutMs);
|
|
253
|
+
let newResources;
|
|
254
|
+
try {
|
|
255
|
+
newResources = await this.discoverResources();
|
|
256
|
+
}
|
|
257
|
+
catch (err) {
|
|
258
|
+
debugLogger.error(`Resource discovery failed during refresh: ${getErrorMessage(err)}`);
|
|
259
|
+
clearTimeout(timeoutId);
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
this.updateResourceRegistry(newResources);
|
|
263
|
+
clearTimeout(timeoutId);
|
|
264
|
+
coreEvents.emitFeedback('info', `Resources updated for server: ${this.serverName}`);
|
|
265
|
+
} while (this.pendingResourceRefresh);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
debugLogger.error(`Critical error in resource refresh loop for ${this.serverName}: ${getErrorMessage(error)}`);
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
this.isRefreshingResources = false;
|
|
272
|
+
this.pendingResourceRefresh = false;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Refreshes prompts for this server by re-querying the MCP `prompts/list` endpoint.
|
|
277
|
+
*/
|
|
278
|
+
async refreshPrompts() {
|
|
279
|
+
if (this.isRefreshingPrompts) {
|
|
280
|
+
debugLogger.log(`Prompt refresh for '${this.serverName}' is already in progress. Pending update.`);
|
|
281
|
+
this.pendingPromptRefresh = true;
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.isRefreshingPrompts = true;
|
|
285
|
+
try {
|
|
286
|
+
do {
|
|
287
|
+
this.pendingPromptRefresh = false;
|
|
288
|
+
if (this.status !== MCPServerStatus.CONNECTED || !this.client)
|
|
289
|
+
break;
|
|
290
|
+
const timeoutMs = this.serverConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC;
|
|
291
|
+
const abortController = new AbortController();
|
|
292
|
+
const timeoutId = setTimeout(() => abortController.abort(), timeoutMs);
|
|
293
|
+
try {
|
|
294
|
+
const newPrompts = await this.fetchPrompts({
|
|
295
|
+
signal: abortController.signal,
|
|
296
|
+
});
|
|
297
|
+
this.promptRegistry.removePromptsByServer(this.serverName);
|
|
298
|
+
for (const prompt of newPrompts) {
|
|
299
|
+
this.promptRegistry.registerPrompt(prompt);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
debugLogger.error(`Prompt discovery failed during refresh: ${getErrorMessage(err)}`);
|
|
304
|
+
clearTimeout(timeoutId);
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
clearTimeout(timeoutId);
|
|
308
|
+
coreEvents.emitFeedback('info', `Prompts updated for server: ${this.serverName}`);
|
|
309
|
+
} while (this.pendingPromptRefresh);
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
debugLogger.error(`Critical error in prompt refresh loop for ${this.serverName}: ${getErrorMessage(error)}`);
|
|
313
|
+
}
|
|
314
|
+
finally {
|
|
315
|
+
this.isRefreshingPrompts = false;
|
|
316
|
+
this.pendingPromptRefresh = false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
getServerConfig() {
|
|
320
|
+
return this.serverConfig;
|
|
321
|
+
}
|
|
322
|
+
getInstructions() {
|
|
323
|
+
return this.client?.getInstructions();
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Refreshes the tools for this server by re-querying the MCP `tools/list` endpoint.
|
|
327
|
+
*
|
|
328
|
+
* This method implements a **Coalescing Pattern** to handle rapid bursts of notifications
|
|
329
|
+
* (e.g., during server startup or bulk updates) without overwhelming the server or
|
|
330
|
+
* creating race conditions in the global ToolRegistry.
|
|
331
|
+
*/
|
|
332
|
+
async refreshTools() {
|
|
333
|
+
if (this.isRefreshingTools) {
|
|
334
|
+
debugLogger.log(`Tool refresh for '${this.serverName}' is already in progress. Pending update.`);
|
|
335
|
+
this.pendingToolRefresh = true;
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
this.isRefreshingTools = true;
|
|
339
|
+
try {
|
|
340
|
+
do {
|
|
341
|
+
this.pendingToolRefresh = false;
|
|
342
|
+
if (this.status !== MCPServerStatus.CONNECTED || !this.client)
|
|
343
|
+
break;
|
|
344
|
+
const timeoutMs = this.serverConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC;
|
|
345
|
+
const abortController = new AbortController();
|
|
346
|
+
const timeoutId = setTimeout(() => abortController.abort(), timeoutMs);
|
|
347
|
+
let newTools;
|
|
348
|
+
try {
|
|
349
|
+
newTools = await this.discoverTools(this.cliConfig, {
|
|
350
|
+
signal: abortController.signal,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
debugLogger.error(`Discovery failed during refresh: ${getErrorMessage(err)}`);
|
|
355
|
+
clearTimeout(timeoutId);
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
this.toolRegistry.removeMcpToolsByServer(this.serverName);
|
|
359
|
+
for (const tool of newTools) {
|
|
360
|
+
this.toolRegistry.registerTool(tool);
|
|
361
|
+
}
|
|
362
|
+
this.toolRegistry.sortTools();
|
|
363
|
+
if (this.onToolsUpdated) {
|
|
364
|
+
await this.onToolsUpdated(abortController.signal);
|
|
365
|
+
}
|
|
366
|
+
clearTimeout(timeoutId);
|
|
367
|
+
coreEvents.emitFeedback('info', `Tools updated for server: ${this.serverName}`);
|
|
368
|
+
} while (this.pendingToolRefresh);
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
debugLogger.error(`Critical error in refresh loop for ${this.serverName}: ${getErrorMessage(error)}`);
|
|
372
|
+
}
|
|
373
|
+
finally {
|
|
374
|
+
this.isRefreshingTools = false;
|
|
375
|
+
this.pendingToolRefresh = false;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Map to track the status of each MCP server within the core package
|
|
381
|
+
*/
|
|
382
|
+
const serverStatuses = new Map();
|
|
383
|
+
/**
|
|
384
|
+
* Track the overall MCP discovery state
|
|
385
|
+
*/
|
|
386
|
+
let mcpDiscoveryState = MCPDiscoveryState.NOT_STARTED;
|
|
387
|
+
/**
|
|
388
|
+
* Map to track which MCP servers have been discovered to require OAuth
|
|
389
|
+
*/
|
|
390
|
+
export const mcpServerRequiresOAuth = new Map();
|
|
391
|
+
const statusChangeListeners = [];
|
|
392
|
+
/**
|
|
393
|
+
* Add a listener for MCP server status changes
|
|
394
|
+
*/
|
|
395
|
+
export function addMCPStatusChangeListener(listener) {
|
|
396
|
+
statusChangeListeners.push(listener);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Remove a listener for MCP server status changes
|
|
400
|
+
*/
|
|
401
|
+
export function removeMCPStatusChangeListener(listener) {
|
|
402
|
+
const index = statusChangeListeners.indexOf(listener);
|
|
403
|
+
if (index !== -1) {
|
|
404
|
+
statusChangeListeners.splice(index, 1);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Update the status of an MCP server
|
|
409
|
+
*/
|
|
410
|
+
export function updateMCPServerStatus(serverName, status) {
|
|
411
|
+
serverStatuses.set(serverName, status);
|
|
412
|
+
// Notify all listeners
|
|
413
|
+
for (const listener of statusChangeListeners) {
|
|
414
|
+
listener(serverName, status);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Get the current status of an MCP server
|
|
419
|
+
*/
|
|
420
|
+
export function getMCPServerStatus(serverName) {
|
|
421
|
+
return serverStatuses.get(serverName) || MCPServerStatus.DISCONNECTED;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Get all MCP server statuses
|
|
425
|
+
*/
|
|
426
|
+
export function getAllMCPServerStatuses() {
|
|
427
|
+
return new Map(serverStatuses);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Get the current MCP discovery state
|
|
431
|
+
*/
|
|
432
|
+
export function getMCPDiscoveryState() {
|
|
433
|
+
return mcpDiscoveryState;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Extract WWW-Authenticate header from error message string.
|
|
437
|
+
* This is a more robust approach than regex matching.
|
|
438
|
+
*
|
|
439
|
+
* @param errorString The error message string
|
|
440
|
+
* @returns The www-authenticate header value if found, null otherwise
|
|
441
|
+
*/
|
|
442
|
+
function extractWWWAuthenticateHeader(errorString) {
|
|
443
|
+
// Try multiple patterns to extract the header
|
|
444
|
+
const patterns = [
|
|
445
|
+
/www-authenticate:\s*([^\n\r]+)/i,
|
|
446
|
+
/WWW-Authenticate:\s*([^\n\r]+)/i,
|
|
447
|
+
/"www-authenticate":\s*"([^"]+)"/i,
|
|
448
|
+
/'www-authenticate':\s*'([^']+)'/i,
|
|
449
|
+
];
|
|
450
|
+
for (const pattern of patterns) {
|
|
451
|
+
const match = errorString.match(pattern);
|
|
452
|
+
if (match) {
|
|
453
|
+
return match[1].trim();
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Handle automatic OAuth discovery and authentication for a server.
|
|
460
|
+
*
|
|
461
|
+
* @param mcpServerName The name of the MCP server
|
|
462
|
+
* @param mcpServerConfig The MCP server configuration
|
|
463
|
+
* @param wwwAuthenticate The www-authenticate header value
|
|
464
|
+
* @returns True if OAuth was successfully configured and authenticated, false otherwise
|
|
465
|
+
*/
|
|
466
|
+
async function handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthenticate) {
|
|
467
|
+
try {
|
|
468
|
+
debugLogger.log(`🔐 '${mcpServerName}' requires OAuth authentication`);
|
|
469
|
+
// Always try to parse the resource metadata URI from the www-authenticate header
|
|
470
|
+
let oauthConfig;
|
|
471
|
+
const resourceMetadataUri = OAuthUtils.parseWWWAuthenticateHeader(wwwAuthenticate);
|
|
472
|
+
if (resourceMetadataUri) {
|
|
473
|
+
oauthConfig = await OAuthUtils.discoverOAuthConfig(resourceMetadataUri);
|
|
474
|
+
}
|
|
475
|
+
else if (hasNetworkTransport(mcpServerConfig)) {
|
|
476
|
+
// Fallback: try to discover OAuth config from the base URL
|
|
477
|
+
const serverUrl = new URL(mcpServerConfig.httpUrl || mcpServerConfig.url);
|
|
478
|
+
const baseUrl = `${serverUrl.protocol}//${serverUrl.host}`;
|
|
479
|
+
oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl);
|
|
480
|
+
}
|
|
481
|
+
if (!oauthConfig) {
|
|
482
|
+
coreEvents.emitFeedback('error', `Could not configure OAuth for '${mcpServerName}' - please authenticate manually with /mcp auth ${mcpServerName}`);
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
// OAuth configuration discovered - proceed with authentication
|
|
486
|
+
// Create OAuth configuration for authentication
|
|
487
|
+
const oauthAuthConfig = {
|
|
488
|
+
enabled: true,
|
|
489
|
+
authorizationUrl: oauthConfig.authorizationUrl,
|
|
490
|
+
tokenUrl: oauthConfig.tokenUrl,
|
|
491
|
+
scopes: oauthConfig.scopes || [],
|
|
492
|
+
};
|
|
493
|
+
// Perform OAuth authentication
|
|
494
|
+
// Pass the server URL for proper discovery
|
|
495
|
+
const serverUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
|
|
496
|
+
debugLogger.log(`Starting OAuth authentication for server '${mcpServerName}'...`);
|
|
497
|
+
const authProvider = new MCPOAuthProvider(new MCPOAuthTokenStorage());
|
|
498
|
+
await authProvider.authenticate(mcpServerName, oauthAuthConfig, serverUrl);
|
|
499
|
+
debugLogger.log(`OAuth authentication successful for server '${mcpServerName}'`);
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
coreEvents.emitFeedback('error', `Failed to handle automatic OAuth for server '${mcpServerName}': ${getErrorMessage(error)}`, error);
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Create RequestInit for TransportOptions.
|
|
509
|
+
*
|
|
510
|
+
* @param mcpServerConfig The MCP server configuration
|
|
511
|
+
* @param headers Additional headers
|
|
512
|
+
*/
|
|
513
|
+
function createTransportRequestInit(mcpServerConfig, headers) {
|
|
514
|
+
return {
|
|
515
|
+
headers: {
|
|
516
|
+
...mcpServerConfig.headers,
|
|
517
|
+
...headers,
|
|
518
|
+
},
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Create an AuthProvider for the MCP Transport.
|
|
523
|
+
*
|
|
524
|
+
* @param mcpServerConfig The MCP server configuration
|
|
525
|
+
*/
|
|
526
|
+
function createAuthProvider(mcpServerConfig) {
|
|
527
|
+
if (mcpServerConfig.authProviderType ===
|
|
528
|
+
AuthProviderType.SERVICE_ACCOUNT_IMPERSONATION) {
|
|
529
|
+
return new ServiceAccountImpersonationProvider(mcpServerConfig);
|
|
530
|
+
}
|
|
531
|
+
if (mcpServerConfig.authProviderType === AuthProviderType.GOOGLE_CREDENTIALS) {
|
|
532
|
+
return new GoogleCredentialProvider(mcpServerConfig);
|
|
533
|
+
}
|
|
534
|
+
return undefined;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Create a transport with OAuth token for the given server configuration.
|
|
538
|
+
*
|
|
539
|
+
* @param mcpServerName The name of the MCP server
|
|
540
|
+
* @param mcpServerConfig The MCP server configuration
|
|
541
|
+
* @param accessToken The OAuth access token
|
|
542
|
+
* @returns The transport with OAuth token, or null if creation fails
|
|
543
|
+
*/
|
|
544
|
+
async function createTransportWithOAuth(mcpServerName, mcpServerConfig, accessToken) {
|
|
545
|
+
try {
|
|
546
|
+
const headers = {
|
|
547
|
+
Authorization: `Bearer ${accessToken}`,
|
|
548
|
+
};
|
|
549
|
+
const transportOptions = {
|
|
550
|
+
requestInit: createTransportRequestInit(mcpServerConfig, headers),
|
|
551
|
+
};
|
|
552
|
+
return createUrlTransport(mcpServerName, mcpServerConfig, transportOptions);
|
|
553
|
+
}
|
|
554
|
+
catch (error) {
|
|
555
|
+
coreEvents.emitFeedback('error', `Failed to create OAuth transport for server '${mcpServerName}': ${getErrorMessage(error)}`, error);
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Discovers tools from all configured MCP servers and registers them with the tool registry.
|
|
561
|
+
* It orchestrates the connection and discovery process for each server defined in the
|
|
562
|
+
* configuration, as well as any server specified via a command-line argument.
|
|
563
|
+
*
|
|
564
|
+
* @param mcpServers A record of named MCP server configurations.
|
|
565
|
+
* @param mcpServerCommand An optional command string for a dynamically specified MCP server.
|
|
566
|
+
* @param toolRegistry The central registry where discovered tools will be registered.
|
|
567
|
+
* @returns A promise that resolves when the discovery process has been attempted for all servers.
|
|
568
|
+
*/
|
|
569
|
+
export async function discoverMcpTools(clientVersion, mcpServers, mcpServerCommand, toolRegistry, promptRegistry, debugMode, workspaceContext, cliConfig) {
|
|
570
|
+
mcpDiscoveryState = MCPDiscoveryState.IN_PROGRESS;
|
|
571
|
+
try {
|
|
572
|
+
mcpServers = populateMcpServerCommand(mcpServers, mcpServerCommand);
|
|
573
|
+
const discoveryPromises = Object.entries(mcpServers).map(([mcpServerName, mcpServerConfig]) => connectAndDiscover(clientVersion, mcpServerName, mcpServerConfig, toolRegistry, promptRegistry, debugMode, workspaceContext, cliConfig));
|
|
574
|
+
await Promise.all(discoveryPromises);
|
|
575
|
+
}
|
|
576
|
+
finally {
|
|
577
|
+
mcpDiscoveryState = MCPDiscoveryState.COMPLETED;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* A tolerant JSON Schema validator for MCP tool output schemas.
|
|
582
|
+
*
|
|
583
|
+
* Some MCP servers (e.g. third‑party extensions) return complex schemas that
|
|
584
|
+
* include `$defs` / `$ref` chains which can occasionally trip AJV's resolver,
|
|
585
|
+
* causing discovery to fail. This wrapper keeps the default AJV validator for
|
|
586
|
+
* normal operation but falls back to a no‑op validator any time schema
|
|
587
|
+
* compilation throws, so we can still list and use the tool while emitting a
|
|
588
|
+
* debug log.
|
|
589
|
+
*/
|
|
590
|
+
class LenientJsonSchemaValidator {
|
|
591
|
+
ajvValidator = new AjvJsonSchemaValidator();
|
|
592
|
+
getValidator(schema) {
|
|
593
|
+
try {
|
|
594
|
+
return this.ajvValidator.getValidator(schema);
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
debugLogger.warn(`Failed to compile MCP tool output schema (${schema?.['$id'] ?? '<no $id>'}): ${error instanceof Error ? error.message : String(error)}. ` +
|
|
598
|
+
'Skipping output validation for this tool.');
|
|
599
|
+
return (input) => ({
|
|
600
|
+
valid: true,
|
|
601
|
+
data: input,
|
|
602
|
+
errorMessage: undefined,
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
/** Visible for Testing */
|
|
608
|
+
export function populateMcpServerCommand(mcpServers, mcpServerCommand) {
|
|
609
|
+
if (mcpServerCommand) {
|
|
610
|
+
const cmd = mcpServerCommand;
|
|
611
|
+
const args = parse(cmd, process.env);
|
|
612
|
+
if (args.some((arg) => typeof arg !== 'string')) {
|
|
613
|
+
throw new Error('failed to parse mcpServerCommand: ' + cmd);
|
|
614
|
+
}
|
|
615
|
+
// use generic server name 'mcp'
|
|
616
|
+
mcpServers['mcp'] = {
|
|
617
|
+
command: args[0],
|
|
618
|
+
args: args.slice(1),
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
return mcpServers;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Connects to an MCP server and discovers available tools, registering them with the tool registry.
|
|
625
|
+
* This function handles the complete lifecycle of connecting to a server, discovering tools,
|
|
626
|
+
* and cleaning up resources if no tools are found.
|
|
627
|
+
*
|
|
628
|
+
* @param mcpServerName The name identifier for this MCP server
|
|
629
|
+
* @param mcpServerConfig Configuration object containing connection details
|
|
630
|
+
* @param toolRegistry The registry to register discovered tools with
|
|
631
|
+
* @returns Promise that resolves when discovery is complete
|
|
632
|
+
*/
|
|
633
|
+
export async function connectAndDiscover(clientVersion, mcpServerName, mcpServerConfig, toolRegistry, promptRegistry, debugMode, workspaceContext, cliConfig) {
|
|
634
|
+
updateMCPServerStatus(mcpServerName, MCPServerStatus.CONNECTING);
|
|
635
|
+
let mcpClient;
|
|
636
|
+
try {
|
|
637
|
+
mcpClient = await connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig, debugMode, workspaceContext, cliConfig.sanitizationConfig);
|
|
638
|
+
mcpClient.onerror = (error) => {
|
|
639
|
+
coreEvents.emitFeedback('error', `MCP ERROR (${mcpServerName}):`, error);
|
|
640
|
+
updateMCPServerStatus(mcpServerName, MCPServerStatus.DISCONNECTED);
|
|
641
|
+
};
|
|
642
|
+
// Attempt to discover both prompts and tools
|
|
643
|
+
const prompts = await discoverPrompts(mcpServerName, mcpClient);
|
|
644
|
+
const tools = await discoverTools(mcpServerName, mcpServerConfig, mcpClient, cliConfig, toolRegistry.getMessageBus(), { timeout: mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC });
|
|
645
|
+
// If we have neither prompts nor tools, it's a failed discovery
|
|
646
|
+
if (prompts.length === 0 && tools.length === 0) {
|
|
647
|
+
throw new Error('No prompts or tools found on the server.');
|
|
648
|
+
}
|
|
649
|
+
// If we found anything, the server is connected
|
|
650
|
+
updateMCPServerStatus(mcpServerName, MCPServerStatus.CONNECTED);
|
|
651
|
+
// Register any discovered prompts and tools
|
|
652
|
+
for (const prompt of prompts) {
|
|
653
|
+
promptRegistry.registerPrompt(prompt);
|
|
654
|
+
}
|
|
655
|
+
for (const tool of tools) {
|
|
656
|
+
toolRegistry.registerTool(tool);
|
|
657
|
+
}
|
|
658
|
+
toolRegistry.sortTools();
|
|
659
|
+
}
|
|
660
|
+
catch (error) {
|
|
661
|
+
if (mcpClient) {
|
|
662
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
663
|
+
mcpClient.close();
|
|
664
|
+
}
|
|
665
|
+
coreEvents.emitFeedback('error', `Error connecting to MCP server '${mcpServerName}': ${getErrorMessage(error)}`, error);
|
|
666
|
+
updateMCPServerStatus(mcpServerName, MCPServerStatus.DISCONNECTED);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Discovers and sanitizes tools from a connected MCP client.
|
|
671
|
+
* It retrieves function declarations from the client, filters out disabled tools,
|
|
672
|
+
* generates valid names for them, and wraps them in `DiscoveredMCPTool` instances.
|
|
673
|
+
*
|
|
674
|
+
* @param mcpServerName The name of the MCP server.
|
|
675
|
+
* @param mcpServerConfig The configuration for the MCP server.
|
|
676
|
+
* @param mcpClient The active MCP client instance.
|
|
677
|
+
* @param cliConfig The CLI configuration object.
|
|
678
|
+
* @param messageBus Optional message bus for policy engine integration.
|
|
679
|
+
* @returns A promise that resolves to an array of discovered and enabled tools.
|
|
680
|
+
* @throws An error if no enabled tools are found or if the server provides invalid function declarations.
|
|
681
|
+
*/
|
|
682
|
+
export async function discoverTools(mcpServerName, mcpServerConfig, mcpClient, cliConfig, messageBus, options) {
|
|
683
|
+
try {
|
|
684
|
+
// Only request tools if the server supports them.
|
|
685
|
+
if (mcpClient.getServerCapabilities()?.tools == null)
|
|
686
|
+
return [];
|
|
687
|
+
const response = await mcpClient.listTools({}, options);
|
|
688
|
+
const discoveredTools = [];
|
|
689
|
+
for (const toolDef of response.tools) {
|
|
690
|
+
try {
|
|
691
|
+
if (!isEnabled(toolDef, mcpServerName, mcpServerConfig)) {
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
const mcpCallableTool = new McpCallableTool(mcpClient, toolDef, mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC);
|
|
695
|
+
const tool = new DiscoveredMCPTool(mcpCallableTool, mcpServerName, toolDef.name, toolDef.description ?? '', toolDef.inputSchema ?? { type: 'object', properties: {} }, messageBus, mcpServerConfig.trust, undefined, cliConfig, mcpServerConfig.extension?.name, mcpServerConfig.extension?.id);
|
|
696
|
+
discoveredTools.push(tool);
|
|
697
|
+
}
|
|
698
|
+
catch (error) {
|
|
699
|
+
coreEvents.emitFeedback('error', `Error discovering tool: '${toolDef.name}' from MCP server '${mcpServerName}': ${error.message}`, error);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return discoveredTools;
|
|
703
|
+
}
|
|
704
|
+
catch (error) {
|
|
705
|
+
if (error instanceof Error &&
|
|
706
|
+
!error.message?.includes('Method not found')) {
|
|
707
|
+
coreEvents.emitFeedback('error', `Error discovering tools from ${mcpServerName}: ${getErrorMessage(error)}`, error);
|
|
708
|
+
}
|
|
709
|
+
return [];
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
class McpCallableTool {
|
|
713
|
+
client;
|
|
714
|
+
toolDef;
|
|
715
|
+
timeout;
|
|
716
|
+
constructor(client, toolDef, timeout) {
|
|
717
|
+
this.client = client;
|
|
718
|
+
this.toolDef = toolDef;
|
|
719
|
+
this.timeout = timeout;
|
|
720
|
+
}
|
|
721
|
+
async tool() {
|
|
722
|
+
return {
|
|
723
|
+
functionDeclarations: [
|
|
724
|
+
{
|
|
725
|
+
name: this.toolDef.name,
|
|
726
|
+
description: this.toolDef.description,
|
|
727
|
+
parametersJsonSchema: this.toolDef.inputSchema,
|
|
728
|
+
},
|
|
729
|
+
],
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
async callTool(functionCalls) {
|
|
733
|
+
// We only expect one function call at a time for MCP tools in this context
|
|
734
|
+
if (functionCalls.length !== 1) {
|
|
735
|
+
throw new Error('McpCallableTool only supports single function call');
|
|
736
|
+
}
|
|
737
|
+
const call = functionCalls[0];
|
|
738
|
+
try {
|
|
739
|
+
const result = await this.client.callTool({
|
|
740
|
+
name: call.name,
|
|
741
|
+
arguments: call.args,
|
|
742
|
+
}, undefined, { timeout: this.timeout });
|
|
743
|
+
return [
|
|
744
|
+
{
|
|
745
|
+
functionResponse: {
|
|
746
|
+
name: call.name,
|
|
747
|
+
response: result,
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
];
|
|
751
|
+
}
|
|
752
|
+
catch (error) {
|
|
753
|
+
// Return error in the format expected by DiscoveredMCPTool
|
|
754
|
+
return [
|
|
755
|
+
{
|
|
756
|
+
functionResponse: {
|
|
757
|
+
name: call.name,
|
|
758
|
+
response: {
|
|
759
|
+
error: {
|
|
760
|
+
message: error instanceof Error ? error.message : String(error),
|
|
761
|
+
isError: true,
|
|
762
|
+
},
|
|
763
|
+
},
|
|
764
|
+
},
|
|
765
|
+
},
|
|
766
|
+
];
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Discovers and logs prompts from a connected MCP client.
|
|
772
|
+
* It retrieves prompt declarations from the client and logs their names.
|
|
773
|
+
*
|
|
774
|
+
* @param mcpServerName The name of the MCP server.
|
|
775
|
+
* @param mcpClient The active MCP client instance.
|
|
776
|
+
*/
|
|
777
|
+
export async function discoverPrompts(mcpServerName, mcpClient, options) {
|
|
778
|
+
// Only request prompts if the server supports them.
|
|
779
|
+
if (mcpClient.getServerCapabilities()?.prompts == null)
|
|
780
|
+
return [];
|
|
781
|
+
try {
|
|
782
|
+
const response = await mcpClient.listPrompts({}, options);
|
|
783
|
+
return response.prompts.map((prompt) => ({
|
|
784
|
+
...prompt,
|
|
785
|
+
serverName: mcpServerName,
|
|
786
|
+
invoke: (params) => invokeMcpPrompt(mcpServerName, mcpClient, prompt.name, params),
|
|
787
|
+
}));
|
|
788
|
+
}
|
|
789
|
+
catch (error) {
|
|
790
|
+
// It's okay if the method is not found, which is a common case.
|
|
791
|
+
if (error instanceof Error && error.message?.includes('Method not found')) {
|
|
792
|
+
return [];
|
|
793
|
+
}
|
|
794
|
+
coreEvents.emitFeedback('error', `Error discovering prompts from ${mcpServerName}: ${getErrorMessage(error)}`, error);
|
|
795
|
+
throw error;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
export async function discoverResources(mcpServerName, mcpClient) {
|
|
799
|
+
if (mcpClient.getServerCapabilities()?.resources == null) {
|
|
800
|
+
return [];
|
|
801
|
+
}
|
|
802
|
+
const resources = await listResources(mcpServerName, mcpClient);
|
|
803
|
+
return resources;
|
|
804
|
+
}
|
|
805
|
+
async function listResources(mcpServerName, mcpClient) {
|
|
806
|
+
const resources = [];
|
|
807
|
+
let cursor;
|
|
808
|
+
try {
|
|
809
|
+
do {
|
|
810
|
+
const response = await mcpClient.request({
|
|
811
|
+
method: 'resources/list',
|
|
812
|
+
params: cursor ? { cursor } : {},
|
|
813
|
+
}, ListResourcesResultSchema);
|
|
814
|
+
resources.push(...(response.resources ?? []));
|
|
815
|
+
cursor = response.nextCursor ?? undefined;
|
|
816
|
+
} while (cursor);
|
|
817
|
+
}
|
|
818
|
+
catch (error) {
|
|
819
|
+
if (error instanceof Error && error.message?.includes('Method not found')) {
|
|
820
|
+
return [];
|
|
821
|
+
}
|
|
822
|
+
coreEvents.emitFeedback('error', `Error discovering resources from ${mcpServerName}: ${getErrorMessage(error)}`, error);
|
|
823
|
+
throw error;
|
|
824
|
+
}
|
|
825
|
+
return resources;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Invokes a prompt on a connected MCP client.
|
|
829
|
+
*
|
|
830
|
+
* @param mcpServerName The name of the MCP server.
|
|
831
|
+
* @param mcpClient The active MCP client instance.
|
|
832
|
+
* @param promptName The name of the prompt to invoke.
|
|
833
|
+
* @param promptParams The parameters to pass to the prompt.
|
|
834
|
+
* @returns A promise that resolves to the result of the prompt invocation.
|
|
835
|
+
*/
|
|
836
|
+
export async function invokeMcpPrompt(mcpServerName, mcpClient, promptName, promptParams) {
|
|
837
|
+
try {
|
|
838
|
+
const sanitizedParams = {};
|
|
839
|
+
for (const [key, value] of Object.entries(promptParams)) {
|
|
840
|
+
if (value !== undefined && value !== null) {
|
|
841
|
+
sanitizedParams[key] = String(value);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const response = await mcpClient.getPrompt({
|
|
845
|
+
name: promptName,
|
|
846
|
+
arguments: sanitizedParams,
|
|
847
|
+
});
|
|
848
|
+
return response;
|
|
849
|
+
}
|
|
850
|
+
catch (error) {
|
|
851
|
+
if (error instanceof Error &&
|
|
852
|
+
!error.message?.includes('Method not found')) {
|
|
853
|
+
coreEvents.emitFeedback('error', `Error invoking prompt '${promptName}' from ${mcpServerName} ${promptParams}: ${getErrorMessage(error)}`, error);
|
|
854
|
+
}
|
|
855
|
+
throw error;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* @visiblefortesting
|
|
860
|
+
* Checks if the MCP server configuration has a network transport URL (SSE or HTTP).
|
|
861
|
+
* @param config The MCP server configuration.
|
|
862
|
+
* @returns True if a `url` or `httpUrl` is present, false otherwise.
|
|
863
|
+
*/
|
|
864
|
+
export function hasNetworkTransport(config) {
|
|
865
|
+
return !!(config.url || config.httpUrl);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Helper function to retrieve a stored OAuth token for an MCP server.
|
|
869
|
+
* Handles token validation and refresh automatically.
|
|
870
|
+
*
|
|
871
|
+
* @param serverName The name of the MCP server
|
|
872
|
+
* @returns The valid access token, or null if no token is stored
|
|
873
|
+
*/
|
|
874
|
+
async function getStoredOAuthToken(serverName) {
|
|
875
|
+
const tokenStorage = new MCPOAuthTokenStorage();
|
|
876
|
+
const credentials = await tokenStorage.getCredentials(serverName);
|
|
877
|
+
if (!credentials)
|
|
878
|
+
return null;
|
|
879
|
+
const authProvider = new MCPOAuthProvider(tokenStorage);
|
|
880
|
+
return authProvider.getValidToken(serverName, {
|
|
881
|
+
// Pass client ID if available
|
|
882
|
+
clientId: credentials.clientId,
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Helper function to create an SSE transport with optional OAuth authentication.
|
|
887
|
+
*
|
|
888
|
+
* @param config The MCP server configuration
|
|
889
|
+
* @param accessToken Optional OAuth access token for authentication
|
|
890
|
+
* @returns A configured SSE transport ready for connection
|
|
891
|
+
*/
|
|
892
|
+
function createSSETransportWithAuth(config, accessToken) {
|
|
893
|
+
const headers = {
|
|
894
|
+
...config.headers,
|
|
895
|
+
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
|
896
|
+
};
|
|
897
|
+
const options = {};
|
|
898
|
+
if (Object.keys(headers).length > 0) {
|
|
899
|
+
options.requestInit = { headers };
|
|
900
|
+
}
|
|
901
|
+
return new SSEClientTransport(new URL(config.url), options);
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Helper function to connect a client using SSE transport with optional OAuth.
|
|
905
|
+
*
|
|
906
|
+
* @param client The MCP client to connect
|
|
907
|
+
* @param config The MCP server configuration
|
|
908
|
+
* @param accessToken Optional OAuth access token for authentication
|
|
909
|
+
*/
|
|
910
|
+
async function connectWithSSETransport(client, config, accessToken) {
|
|
911
|
+
const transport = createSSETransportWithAuth(config, accessToken);
|
|
912
|
+
await client.connect(transport, {
|
|
913
|
+
timeout: config.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Helper function to show authentication required message and throw error.
|
|
918
|
+
* Checks if there's a stored token that was rejected (requires re-auth).
|
|
919
|
+
*
|
|
920
|
+
* @param serverName The name of the MCP server
|
|
921
|
+
* @throws Always throws an error with authentication instructions
|
|
922
|
+
*/
|
|
923
|
+
async function showAuthRequiredMessage(serverName) {
|
|
924
|
+
const hasRejectedToken = !!(await getStoredOAuthToken(serverName));
|
|
925
|
+
const message = hasRejectedToken
|
|
926
|
+
? `MCP server '${serverName}' rejected stored OAuth token. Please re-authenticate using: /mcp auth ${serverName}`
|
|
927
|
+
: `MCP server '${serverName}' requires authentication using: /mcp auth ${serverName}`;
|
|
928
|
+
coreEvents.emitFeedback('info', message);
|
|
929
|
+
throw new UnauthorizedError(message);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Helper function to retry connection with OAuth token after authentication.
|
|
933
|
+
* Handles both HTTP and SSE transports based on what previously failed.
|
|
934
|
+
*
|
|
935
|
+
* @param client The MCP client to connect
|
|
936
|
+
* @param serverName The name of the MCP server
|
|
937
|
+
* @param config The MCP server configuration
|
|
938
|
+
* @param accessToken The OAuth access token to use
|
|
939
|
+
* @param httpReturned404 Whether the HTTP transport returned 404 (indicating SSE-only server)
|
|
940
|
+
*/
|
|
941
|
+
async function retryWithOAuth(client, serverName, config, accessToken, httpReturned404) {
|
|
942
|
+
if (httpReturned404) {
|
|
943
|
+
// HTTP returned 404, only try SSE
|
|
944
|
+
debugLogger.log(`Retrying SSE connection to '${serverName}' with OAuth token...`);
|
|
945
|
+
await connectWithSSETransport(client, config, accessToken);
|
|
946
|
+
debugLogger.log(`Successfully connected to '${serverName}' using SSE with OAuth.`);
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
// HTTP returned 401, try HTTP with OAuth first
|
|
950
|
+
debugLogger.log(`Retrying connection to '${serverName}' with OAuth token...`);
|
|
951
|
+
const httpTransport = await createTransportWithOAuth(serverName, config, accessToken);
|
|
952
|
+
if (!httpTransport) {
|
|
953
|
+
throw new Error(`Failed to create OAuth transport for server '${serverName}'`);
|
|
954
|
+
}
|
|
955
|
+
try {
|
|
956
|
+
await client.connect(httpTransport, {
|
|
957
|
+
timeout: config.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
|
958
|
+
});
|
|
959
|
+
debugLogger.log(`Successfully connected to '${serverName}' using HTTP with OAuth.`);
|
|
960
|
+
}
|
|
961
|
+
catch (httpError) {
|
|
962
|
+
await httpTransport.close();
|
|
963
|
+
// If HTTP+OAuth returns 404 and auto-detection enabled, try SSE+OAuth
|
|
964
|
+
if (String(httpError).includes('404') &&
|
|
965
|
+
config.url &&
|
|
966
|
+
!config.type &&
|
|
967
|
+
!config.httpUrl) {
|
|
968
|
+
debugLogger.log(`HTTP with OAuth returned 404, trying SSE with OAuth...`);
|
|
969
|
+
await connectWithSSETransport(client, config, accessToken);
|
|
970
|
+
debugLogger.log(`Successfully connected to '${serverName}' using SSE with OAuth.`);
|
|
971
|
+
}
|
|
972
|
+
else {
|
|
973
|
+
throw httpError;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Creates and connects an MCP client to a server based on the provided configuration.
|
|
979
|
+
* It determines the appropriate transport (Stdio, SSE, or Streamable HTTP) and
|
|
980
|
+
* establishes a connection. It also applies a patch to handle request timeouts.
|
|
981
|
+
*
|
|
982
|
+
* @param mcpServerName The name of the MCP server, used for logging and identification.
|
|
983
|
+
* @param mcpServerConfig The configuration specifying how to connect to the server.
|
|
984
|
+
* @returns A promise that resolves to a connected MCP `Client` instance.
|
|
985
|
+
* @throws An error if the connection fails or the configuration is invalid.
|
|
986
|
+
*/
|
|
987
|
+
export async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig, debugMode, workspaceContext, sanitizationConfig) {
|
|
988
|
+
const mcpClient = new Client({
|
|
989
|
+
name: 'gemini-cli-mcp-client',
|
|
990
|
+
version: clientVersion,
|
|
991
|
+
}, {
|
|
992
|
+
// Use a tolerant validator so bad output schemas don't block discovery.
|
|
993
|
+
jsonSchemaValidator: new LenientJsonSchemaValidator(),
|
|
994
|
+
});
|
|
995
|
+
mcpClient.registerCapabilities({
|
|
996
|
+
roots: {
|
|
997
|
+
listChanged: true,
|
|
998
|
+
},
|
|
999
|
+
});
|
|
1000
|
+
mcpClient.setRequestHandler(ListRootsRequestSchema, async () => {
|
|
1001
|
+
const roots = [];
|
|
1002
|
+
for (const dir of workspaceContext.getDirectories()) {
|
|
1003
|
+
roots.push({
|
|
1004
|
+
uri: pathToFileURL(dir).toString(),
|
|
1005
|
+
name: basename(dir),
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
return {
|
|
1009
|
+
roots,
|
|
1010
|
+
};
|
|
1011
|
+
});
|
|
1012
|
+
let unlistenDirectories = workspaceContext.onDirectoriesChanged(async () => {
|
|
1013
|
+
try {
|
|
1014
|
+
await mcpClient.notification({
|
|
1015
|
+
method: 'notifications/roots/list_changed',
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
catch (_) {
|
|
1019
|
+
// If this fails, its almost certainly because the connection was closed
|
|
1020
|
+
// and we should just stop listening for future directory changes.
|
|
1021
|
+
unlistenDirectories?.();
|
|
1022
|
+
unlistenDirectories = undefined;
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
// Attempt to pro-actively unsubscribe if the mcp client closes. This API is
|
|
1026
|
+
// very brittle though so we don't have any guarantees, hence the try/catch
|
|
1027
|
+
// above as well.
|
|
1028
|
+
//
|
|
1029
|
+
// Be a good steward and don't just bash over onclose.
|
|
1030
|
+
const oldOnClose = mcpClient.onclose;
|
|
1031
|
+
mcpClient.onclose = () => {
|
|
1032
|
+
oldOnClose?.();
|
|
1033
|
+
unlistenDirectories?.();
|
|
1034
|
+
unlistenDirectories = undefined;
|
|
1035
|
+
};
|
|
1036
|
+
let firstAttemptError = null;
|
|
1037
|
+
let httpReturned404 = false; // Track if HTTP returned 404 to skip it in OAuth retry
|
|
1038
|
+
let sseError = null; // Track SSE fallback error
|
|
1039
|
+
try {
|
|
1040
|
+
const transport = await createTransport(mcpServerName, mcpServerConfig, debugMode, sanitizationConfig);
|
|
1041
|
+
try {
|
|
1042
|
+
await mcpClient.connect(transport, {
|
|
1043
|
+
timeout: mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
|
1044
|
+
});
|
|
1045
|
+
return mcpClient;
|
|
1046
|
+
}
|
|
1047
|
+
catch (error) {
|
|
1048
|
+
await transport.close();
|
|
1049
|
+
firstAttemptError = error;
|
|
1050
|
+
throw error;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
catch (initialError) {
|
|
1054
|
+
let error = initialError;
|
|
1055
|
+
// Check if this is a 401 error FIRST (before attempting SSE fallback)
|
|
1056
|
+
// This ensures OAuth flow happens before we try SSE
|
|
1057
|
+
if (isAuthenticationError(error) && hasNetworkTransport(mcpServerConfig)) {
|
|
1058
|
+
// Continue to OAuth handling below (after SSE fallback section)
|
|
1059
|
+
}
|
|
1060
|
+
else if (
|
|
1061
|
+
// If not 401, and HTTP failed with url without explicit type, try SSE fallback
|
|
1062
|
+
firstAttemptError &&
|
|
1063
|
+
mcpServerConfig.url &&
|
|
1064
|
+
!mcpServerConfig.type &&
|
|
1065
|
+
!mcpServerConfig.httpUrl) {
|
|
1066
|
+
// Check if HTTP returned 404 - if so, we know it's not an HTTP server
|
|
1067
|
+
httpReturned404 = String(firstAttemptError).includes('404');
|
|
1068
|
+
const logMessage = httpReturned404
|
|
1069
|
+
? `HTTP returned 404, trying SSE transport...`
|
|
1070
|
+
: `HTTP connection failed, attempting SSE fallback...`;
|
|
1071
|
+
debugLogger.log(`MCP server '${mcpServerName}': ${logMessage}`);
|
|
1072
|
+
try {
|
|
1073
|
+
// Try SSE with stored OAuth token if available
|
|
1074
|
+
// This ensures that SSE fallback works for authenticated servers
|
|
1075
|
+
await connectWithSSETransport(mcpClient, mcpServerConfig, await getStoredOAuthToken(mcpServerName));
|
|
1076
|
+
debugLogger.log(`MCP server '${mcpServerName}': Successfully connected using SSE transport.`);
|
|
1077
|
+
return mcpClient;
|
|
1078
|
+
}
|
|
1079
|
+
catch (sseFallbackError) {
|
|
1080
|
+
sseError = sseFallbackError;
|
|
1081
|
+
// If SSE also returned 401, handle OAuth below
|
|
1082
|
+
if (isAuthenticationError(sseError)) {
|
|
1083
|
+
debugLogger.log(`MCP server '${mcpServerName}': SSE returned 401, OAuth authentication required.`);
|
|
1084
|
+
// Update error to be the SSE error for OAuth handling
|
|
1085
|
+
error = sseError;
|
|
1086
|
+
// Continue to OAuth handling below
|
|
1087
|
+
}
|
|
1088
|
+
else {
|
|
1089
|
+
debugLogger.log(`MCP server '${mcpServerName}': SSE fallback also failed.`);
|
|
1090
|
+
// Both failed without 401, throw the original error
|
|
1091
|
+
throw firstAttemptError;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
// Check if this is a 401 error that might indicate OAuth is required
|
|
1096
|
+
if (isAuthenticationError(error) && hasNetworkTransport(mcpServerConfig)) {
|
|
1097
|
+
mcpServerRequiresOAuth.set(mcpServerName, true);
|
|
1098
|
+
// Only trigger automatic OAuth if explicitly enabled in config
|
|
1099
|
+
// Otherwise, show error and tell user to run /mcp auth command
|
|
1100
|
+
const shouldTriggerOAuth = mcpServerConfig.oauth?.enabled;
|
|
1101
|
+
if (!shouldTriggerOAuth) {
|
|
1102
|
+
await showAuthRequiredMessage(mcpServerName);
|
|
1103
|
+
}
|
|
1104
|
+
// Try to extract www-authenticate header from the error
|
|
1105
|
+
const errorString = String(error);
|
|
1106
|
+
let wwwAuthenticate = extractWWWAuthenticateHeader(errorString);
|
|
1107
|
+
// If we didn't get the header from the error string, try to get it from the server
|
|
1108
|
+
if (!wwwAuthenticate && hasNetworkTransport(mcpServerConfig)) {
|
|
1109
|
+
debugLogger.log(`No www-authenticate header in error, trying to fetch it from server...`);
|
|
1110
|
+
try {
|
|
1111
|
+
const urlToFetch = mcpServerConfig.httpUrl || mcpServerConfig.url;
|
|
1112
|
+
// Determine correct Accept header based on what transport failed
|
|
1113
|
+
let acceptHeader;
|
|
1114
|
+
if (mcpServerConfig.httpUrl) {
|
|
1115
|
+
acceptHeader = 'application/json';
|
|
1116
|
+
}
|
|
1117
|
+
else if (mcpServerConfig.type === 'http') {
|
|
1118
|
+
acceptHeader = 'application/json';
|
|
1119
|
+
}
|
|
1120
|
+
else if (mcpServerConfig.type === 'sse') {
|
|
1121
|
+
acceptHeader = 'text/event-stream';
|
|
1122
|
+
}
|
|
1123
|
+
else if (httpReturned404) {
|
|
1124
|
+
// HTTP failed with 404, SSE returned 401 - use SSE header
|
|
1125
|
+
acceptHeader = 'text/event-stream';
|
|
1126
|
+
}
|
|
1127
|
+
else {
|
|
1128
|
+
// HTTP returned 401 - use HTTP header
|
|
1129
|
+
acceptHeader = 'application/json';
|
|
1130
|
+
}
|
|
1131
|
+
const response = await fetch(urlToFetch, {
|
|
1132
|
+
method: 'HEAD',
|
|
1133
|
+
headers: {
|
|
1134
|
+
Accept: acceptHeader,
|
|
1135
|
+
},
|
|
1136
|
+
signal: AbortSignal.timeout(5000),
|
|
1137
|
+
});
|
|
1138
|
+
if (response.status === 401) {
|
|
1139
|
+
wwwAuthenticate = response.headers.get('www-authenticate');
|
|
1140
|
+
if (wwwAuthenticate) {
|
|
1141
|
+
debugLogger.log(`Found www-authenticate header from server: ${wwwAuthenticate}`);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
catch (fetchError) {
|
|
1146
|
+
debugLogger.debug(`Failed to fetch www-authenticate header: ${getErrorMessage(fetchError)}`);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
if (wwwAuthenticate) {
|
|
1150
|
+
debugLogger.log(`Received 401 with www-authenticate header: ${wwwAuthenticate}`);
|
|
1151
|
+
// Try automatic OAuth discovery and authentication
|
|
1152
|
+
const oauthSuccess = await handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthenticate);
|
|
1153
|
+
if (oauthSuccess) {
|
|
1154
|
+
// Retry connection with OAuth token
|
|
1155
|
+
const accessToken = await getStoredOAuthToken(mcpServerName);
|
|
1156
|
+
if (!accessToken) {
|
|
1157
|
+
throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
|
|
1158
|
+
}
|
|
1159
|
+
await retryWithOAuth(mcpClient, mcpServerName, mcpServerConfig, accessToken, httpReturned404);
|
|
1160
|
+
return mcpClient;
|
|
1161
|
+
}
|
|
1162
|
+
else {
|
|
1163
|
+
throw new Error(`Failed to handle automatic OAuth for server '${mcpServerName}'`);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
else {
|
|
1167
|
+
// No www-authenticate header found, but we got a 401
|
|
1168
|
+
// Only try OAuth discovery when OAuth is explicitly enabled in config
|
|
1169
|
+
const shouldTryDiscovery = mcpServerConfig.oauth?.enabled;
|
|
1170
|
+
if (!shouldTryDiscovery) {
|
|
1171
|
+
await showAuthRequiredMessage(mcpServerName);
|
|
1172
|
+
}
|
|
1173
|
+
// For SSE/HTTP servers, try to discover OAuth configuration from the base URL
|
|
1174
|
+
debugLogger.log(`🔍 Attempting OAuth discovery for '${mcpServerName}'...`);
|
|
1175
|
+
if (hasNetworkTransport(mcpServerConfig)) {
|
|
1176
|
+
const serverUrl = new URL(mcpServerConfig.httpUrl || mcpServerConfig.url);
|
|
1177
|
+
const baseUrl = `${serverUrl.protocol}//${serverUrl.host}`;
|
|
1178
|
+
// Try to discover OAuth configuration from the base URL
|
|
1179
|
+
const oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl);
|
|
1180
|
+
if (oauthConfig) {
|
|
1181
|
+
debugLogger.log(`Discovered OAuth configuration from base URL for server '${mcpServerName}'`);
|
|
1182
|
+
// Create OAuth configuration for authentication
|
|
1183
|
+
const oauthAuthConfig = {
|
|
1184
|
+
enabled: true,
|
|
1185
|
+
authorizationUrl: oauthConfig.authorizationUrl,
|
|
1186
|
+
tokenUrl: oauthConfig.tokenUrl,
|
|
1187
|
+
scopes: oauthConfig.scopes || [],
|
|
1188
|
+
};
|
|
1189
|
+
// Perform OAuth authentication
|
|
1190
|
+
// Pass the server URL for proper discovery
|
|
1191
|
+
const authServerUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
|
|
1192
|
+
debugLogger.log(`Starting OAuth authentication for server '${mcpServerName}'...`);
|
|
1193
|
+
const authProvider = new MCPOAuthProvider(new MCPOAuthTokenStorage());
|
|
1194
|
+
await authProvider.authenticate(mcpServerName, oauthAuthConfig, authServerUrl);
|
|
1195
|
+
// Retry connection with OAuth token
|
|
1196
|
+
const accessToken = await getStoredOAuthToken(mcpServerName);
|
|
1197
|
+
if (!accessToken) {
|
|
1198
|
+
throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
|
|
1199
|
+
}
|
|
1200
|
+
// Create transport with OAuth token
|
|
1201
|
+
const oauthTransport = await createTransportWithOAuth(mcpServerName, mcpServerConfig, accessToken);
|
|
1202
|
+
if (!oauthTransport) {
|
|
1203
|
+
throw new Error(`Failed to create OAuth transport for server '${mcpServerName}'`);
|
|
1204
|
+
}
|
|
1205
|
+
await mcpClient.connect(oauthTransport, {
|
|
1206
|
+
timeout: mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
|
1207
|
+
});
|
|
1208
|
+
// Connection successful with OAuth
|
|
1209
|
+
return mcpClient;
|
|
1210
|
+
}
|
|
1211
|
+
else {
|
|
1212
|
+
throw new Error(`OAuth configuration failed for '${mcpServerName}'. Please authenticate manually with /mcp auth ${mcpServerName}`);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
else {
|
|
1216
|
+
throw new Error(`MCP server '${mcpServerName}' requires authentication. Please configure OAuth or check server settings.`);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
else {
|
|
1221
|
+
// Handle other connection errors
|
|
1222
|
+
// Re-throw the original error to preserve its structure
|
|
1223
|
+
throw error;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Helper function to create the appropriate transport based on config
|
|
1229
|
+
* This handles the logic for httpUrl/url/type consistently
|
|
1230
|
+
*/
|
|
1231
|
+
function createUrlTransport(mcpServerName, mcpServerConfig, transportOptions) {
|
|
1232
|
+
// Priority 1: httpUrl (deprecated)
|
|
1233
|
+
if (mcpServerConfig.httpUrl) {
|
|
1234
|
+
if (mcpServerConfig.url) {
|
|
1235
|
+
debugLogger.warn(`MCP server '${mcpServerName}': Both 'httpUrl' and 'url' are configured. ` +
|
|
1236
|
+
`Using deprecated 'httpUrl'. Please migrate to 'url' with 'type: "http"'.`);
|
|
1237
|
+
}
|
|
1238
|
+
return new StreamableHTTPClientTransport(new URL(mcpServerConfig.httpUrl), transportOptions);
|
|
1239
|
+
}
|
|
1240
|
+
// Priority 2 & 3: url with explicit type
|
|
1241
|
+
if (mcpServerConfig.url && mcpServerConfig.type) {
|
|
1242
|
+
if (mcpServerConfig.type === 'http') {
|
|
1243
|
+
return new StreamableHTTPClientTransport(new URL(mcpServerConfig.url), transportOptions);
|
|
1244
|
+
}
|
|
1245
|
+
else if (mcpServerConfig.type === 'sse') {
|
|
1246
|
+
return new SSEClientTransport(new URL(mcpServerConfig.url), transportOptions);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
// Priority 4: url without type (default to HTTP)
|
|
1250
|
+
if (mcpServerConfig.url) {
|
|
1251
|
+
return new StreamableHTTPClientTransport(new URL(mcpServerConfig.url), transportOptions);
|
|
1252
|
+
}
|
|
1253
|
+
throw new Error(`No URL configured for MCP server '${mcpServerName}'`);
|
|
1254
|
+
}
|
|
1255
|
+
/** Visible for Testing */
|
|
1256
|
+
export async function createTransport(mcpServerName, mcpServerConfig, debugMode, sanitizationConfig) {
|
|
1257
|
+
const noUrl = !mcpServerConfig.url && !mcpServerConfig.httpUrl;
|
|
1258
|
+
if (noUrl) {
|
|
1259
|
+
if (mcpServerConfig.authProviderType === AuthProviderType.GOOGLE_CREDENTIALS) {
|
|
1260
|
+
throw new Error(`URL must be provided in the config for Google Credentials provider`);
|
|
1261
|
+
}
|
|
1262
|
+
if (mcpServerConfig.authProviderType ===
|
|
1263
|
+
AuthProviderType.SERVICE_ACCOUNT_IMPERSONATION) {
|
|
1264
|
+
throw new Error(`No URL configured for ServiceAccountImpersonation MCP Server`);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
if (mcpServerConfig.httpUrl || mcpServerConfig.url) {
|
|
1268
|
+
const authProvider = createAuthProvider(mcpServerConfig);
|
|
1269
|
+
const headers = (await authProvider?.getRequestHeaders?.()) ?? {};
|
|
1270
|
+
if (authProvider === undefined) {
|
|
1271
|
+
// Check if we have OAuth configuration or stored tokens
|
|
1272
|
+
let accessToken = null;
|
|
1273
|
+
if (mcpServerConfig.oauth?.enabled && mcpServerConfig.oauth) {
|
|
1274
|
+
const tokenStorage = new MCPOAuthTokenStorage();
|
|
1275
|
+
const mcpAuthProvider = new MCPOAuthProvider(tokenStorage);
|
|
1276
|
+
accessToken = await mcpAuthProvider.getValidToken(mcpServerName, mcpServerConfig.oauth);
|
|
1277
|
+
if (!accessToken) {
|
|
1278
|
+
// Emit info message (not error) since this is expected behavior
|
|
1279
|
+
coreEvents.emitFeedback('info', `MCP server '${mcpServerName}' requires authentication using: /mcp auth ${mcpServerName}`);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
else {
|
|
1283
|
+
// Check if we have stored OAuth tokens for this server (from previous authentication)
|
|
1284
|
+
accessToken = await getStoredOAuthToken(mcpServerName);
|
|
1285
|
+
if (accessToken) {
|
|
1286
|
+
debugLogger.log(`Found stored OAuth token for server '${mcpServerName}'`);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
if (accessToken) {
|
|
1290
|
+
headers['Authorization'] = `Bearer ${accessToken}`;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
const transportOptions = {
|
|
1294
|
+
requestInit: createTransportRequestInit(mcpServerConfig, headers),
|
|
1295
|
+
authProvider,
|
|
1296
|
+
};
|
|
1297
|
+
return createUrlTransport(mcpServerName, mcpServerConfig, transportOptions);
|
|
1298
|
+
}
|
|
1299
|
+
if (mcpServerConfig.command) {
|
|
1300
|
+
const transport = new StdioClientTransport({
|
|
1301
|
+
command: mcpServerConfig.command,
|
|
1302
|
+
args: mcpServerConfig.args || [],
|
|
1303
|
+
env: sanitizeEnvironment({
|
|
1304
|
+
...process.env,
|
|
1305
|
+
...getExtensionEnvironment(mcpServerConfig.extension),
|
|
1306
|
+
...(mcpServerConfig.env || {}),
|
|
1307
|
+
}, {
|
|
1308
|
+
...sanitizationConfig,
|
|
1309
|
+
allowedEnvironmentVariables: [
|
|
1310
|
+
...(sanitizationConfig.allowedEnvironmentVariables ?? []),
|
|
1311
|
+
...(mcpServerConfig.extension?.resolvedSettings?.map((s) => s.envVar) ?? []),
|
|
1312
|
+
],
|
|
1313
|
+
enableEnvironmentVariableRedaction: true,
|
|
1314
|
+
}),
|
|
1315
|
+
cwd: mcpServerConfig.cwd,
|
|
1316
|
+
stderr: 'pipe',
|
|
1317
|
+
});
|
|
1318
|
+
if (debugMode) {
|
|
1319
|
+
transport.stderr.on('data', (data) => {
|
|
1320
|
+
const stderrStr = data.toString().trim();
|
|
1321
|
+
debugLogger.debug(`[DEBUG] [MCP STDERR (${mcpServerName})]: `, stderrStr);
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
return transport;
|
|
1325
|
+
}
|
|
1326
|
+
throw new Error(`Invalid configuration: missing httpUrl (for Streamable HTTP), url (for SSE), and command (for stdio).`);
|
|
1327
|
+
}
|
|
1328
|
+
/** Visible for testing */
|
|
1329
|
+
export function isEnabled(funcDecl, mcpServerName, mcpServerConfig) {
|
|
1330
|
+
if (!funcDecl.name) {
|
|
1331
|
+
debugLogger.warn(`Discovered a function declaration without a name from MCP server '${mcpServerName}'. Skipping.`);
|
|
1332
|
+
return false;
|
|
1333
|
+
}
|
|
1334
|
+
const { includeTools, excludeTools } = mcpServerConfig;
|
|
1335
|
+
// excludeTools takes precedence over includeTools
|
|
1336
|
+
if (excludeTools && excludeTools.includes(funcDecl.name)) {
|
|
1337
|
+
return false;
|
|
1338
|
+
}
|
|
1339
|
+
return (!includeTools ||
|
|
1340
|
+
includeTools.some((tool) => tool === funcDecl.name || tool.startsWith(`${funcDecl.name}(`)));
|
|
1341
|
+
}
|
|
1342
|
+
function getExtensionEnvironment(extension) {
|
|
1343
|
+
const env = {};
|
|
1344
|
+
if (extension?.resolvedSettings) {
|
|
1345
|
+
for (const setting of extension.resolvedSettings) {
|
|
1346
|
+
env[setting.envVar] = setting.value;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
return env;
|
|
1350
|
+
}
|
|
1351
|
+
//# sourceMappingURL=mcp-client.js.map
|