@humain/terminal 0.0.2 → 0.0.3-beta.1
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/CHANGELOG.md +251 -24
- package/README.md +143 -119
- package/dist/cli/args.d.ts +4 -2
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +37 -39
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/auth-check.d.ts +19 -0
- package/dist/cli/auth-check.d.ts.map +1 -0
- package/dist/cli/auth-check.js +50 -0
- package/dist/cli/auth-check.js.map +1 -0
- package/dist/cli/auth-command.d.ts +24 -0
- package/dist/cli/auth-command.d.ts.map +1 -0
- package/dist/cli/auth-command.js +103 -0
- package/dist/cli/auth-command.js.map +1 -0
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +2 -2
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/credential-print.d.ts +5 -15
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +42 -83
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/cli/experimental/auth.d.ts +16 -0
- package/dist/cli/experimental/auth.d.ts.map +1 -0
- package/dist/cli/experimental/auth.js +13 -0
- package/dist/cli/experimental/auth.js.map +1 -0
- package/dist/cli/experimental/cli.d.ts +6 -0
- package/dist/cli/experimental/cli.d.ts.map +1 -0
- package/dist/cli/experimental/cli.js +5 -0
- package/dist/cli/experimental/cli.js.map +1 -0
- package/dist/cli/experimental/command-options.d.ts +17 -0
- package/dist/cli/experimental/command-options.d.ts.map +1 -0
- package/dist/cli/experimental/command-options.js +35 -0
- package/dist/cli/experimental/command-options.js.map +1 -0
- package/dist/cli/experimental/command.d.ts +63 -0
- package/dist/cli/experimental/command.d.ts.map +1 -0
- package/dist/cli/experimental/command.js +130 -0
- package/dist/cli/experimental/command.js.map +1 -0
- package/dist/cli/experimental/commands/client.d.ts +13 -0
- package/dist/cli/experimental/commands/client.d.ts.map +1 -0
- package/dist/cli/experimental/commands/client.js +25 -0
- package/dist/cli/experimental/commands/client.js.map +1 -0
- package/dist/cli/experimental/commands/pi.d.ts +15 -0
- package/dist/cli/experimental/commands/pi.d.ts.map +1 -0
- package/dist/cli/experimental/commands/pi.js +28 -0
- package/dist/cli/experimental/commands/pi.js.map +1 -0
- package/dist/cli/experimental/commands/server.d.ts +13 -0
- package/dist/cli/experimental/commands/server.d.ts.map +1 -0
- package/dist/cli/experimental/commands/server.js +25 -0
- package/dist/cli/experimental/commands/server.js.map +1 -0
- package/dist/cli/experimental/transport-address.d.ts +10 -0
- package/dist/cli/experimental/transport-address.d.ts.map +1 -0
- package/dist/cli/experimental/transport-address.js +38 -0
- package/dist/cli/experimental/transport-address.js.map +1 -0
- package/dist/cli/list-models.d.ts +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +2 -2
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/startup-ui.d.ts +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +2 -2
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/remote-session.d.ts +53 -0
- package/dist/client/remote-session.d.ts.map +1 -0
- package/dist/client/remote-session.js +340 -0
- package/dist/client/remote-session.js.map +1 -0
- package/dist/client/transcript.d.ts +12 -0
- package/dist/client/transcript.d.ts.map +1 -0
- package/dist/client/transcript.js +98 -0
- package/dist/client/transcript.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -3
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -10
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +72 -70
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +25 -9
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +237 -39
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +60 -41
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +27 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +5 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/keybindings.d.ts +45 -5
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +29 -5
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +4 -0
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -3
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +13 -10
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +4 -3
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +42 -10
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +30 -13
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +233 -73
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts +12 -7
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +83 -14
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/package-manager.d.ts +6 -3
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +80 -61
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts +8 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +28 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/provider-composer.d.ts +4 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +36 -15
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +73 -67
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +2 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +5 -5
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +11 -8
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +3 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +12 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +40 -16
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +8 -0
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +5 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -15
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +4 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +11 -7
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +7 -0
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +16 -19
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +4 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +5 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts +4 -0
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +5 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +4 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +7 -3
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +4 -0
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +6 -2
- package/dist/core/tools/write.js.map +1 -1
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +11 -2
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +21 -7
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/humain/agent-execution-protocol.d.ts +218 -0
- package/dist/humain/agent-execution-protocol.d.ts.map +1 -0
- package/dist/humain/agent-execution-protocol.js +204 -0
- package/dist/humain/agent-execution-protocol.js.map +1 -0
- package/dist/humain/agent-execution-runtime.d.ts +35 -0
- package/dist/humain/agent-execution-runtime.d.ts.map +1 -0
- package/dist/humain/agent-execution-runtime.js +170 -0
- package/dist/humain/agent-execution-runtime.js.map +1 -0
- package/dist/humain/index.d.ts.map +1 -1
- package/dist/humain/index.js +8 -7
- package/dist/humain/index.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +673 -0
- package/dist/humain/mcp-adapter/vendor/LICENSE +21 -0
- package/dist/humain/mcp-adapter/vendor/README.md +736 -0
- package/dist/humain/mcp-adapter/vendor/abort.ts +34 -0
- package/dist/humain/mcp-adapter/vendor/agent-dir.ts +68 -0
- package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +377 -0
- package/dist/humain/mcp-adapter/vendor/app-bridge.bundle.js +67 -0
- package/dist/humain/mcp-adapter/vendor/banner.png +0 -0
- package/dist/humain/mcp-adapter/vendor/cli.js +230 -0
- package/dist/humain/mcp-adapter/vendor/commands.ts +627 -0
- package/dist/humain/mcp-adapter/vendor/config.ts +1226 -0
- package/dist/humain/mcp-adapter/vendor/consent-manager.ts +64 -0
- package/dist/humain/mcp-adapter/vendor/direct-tools.ts +607 -0
- package/dist/humain/mcp-adapter/vendor/elicitation-handler.ts +348 -0
- package/dist/humain/mcp-adapter/vendor/error-signal.ts +21 -0
- package/dist/humain/mcp-adapter/vendor/errors.ts +223 -0
- package/dist/humain/mcp-adapter/vendor/glimpse-ui.ts +80 -0
- package/dist/humain/mcp-adapter/vendor/host-html-template.ts +461 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.d.mts +4 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +16279 -0
- package/dist/humain/mcp-adapter/vendor/index.ts +898 -0
- package/dist/humain/mcp-adapter/vendor/init.ts +649 -0
- package/dist/humain/mcp-adapter/vendor/json-schema-validator.ts +69 -0
- package/dist/humain/mcp-adapter/vendor/lifecycle.ts +147 -0
- package/dist/humain/mcp-adapter/vendor/logger.ts +169 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +993 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +1000 -0
- package/dist/humain/mcp-adapter/vendor/mcp-callback-server.ts +510 -0
- package/dist/humain/mcp-adapter/vendor/mcp-code.ts +354 -0
- package/dist/humain/mcp-adapter/vendor/mcp-keyring-helper.cjs +89 -0
- package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +616 -0
- package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +408 -0
- package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +1015 -0
- package/dist/humain/mcp-adapter/vendor/mcp-probe.ts +187 -0
- package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +130 -0
- package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +667 -0
- package/dist/humain/mcp-adapter/vendor/mcp-status.ts +109 -0
- package/dist/humain/mcp-adapter/vendor/mcp-trace.ts +306 -0
- package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +363 -0
- package/dist/humain/mcp-adapter/vendor/npx-resolver.ts +543 -0
- package/dist/humain/mcp-adapter/vendor/oauth-handler.ts +30 -0
- package/dist/humain/mcp-adapter/vendor/oauth.ts +48 -0
- package/dist/humain/mcp-adapter/vendor/onboarding-state.ts +76 -0
- package/dist/humain/mcp-adapter/vendor/package.json +179 -0
- package/dist/humain/mcp-adapter/vendor/panel-keys.ts +53 -0
- package/dist/humain/mcp-adapter/vendor/prompts.ts +353 -0
- package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +1331 -0
- package/dist/humain/mcp-adapter/vendor/request-headers-command.ts +336 -0
- package/dist/humain/mcp-adapter/vendor/resource-tools.ts +17 -0
- package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +91 -0
- package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +284 -0
- package/dist/humain/mcp-adapter/vendor/search-ranking.ts +206 -0
- package/dist/humain/mcp-adapter/vendor/server-manager.ts +1129 -0
- package/dist/humain/mcp-adapter/vendor/session-recovery.ts +151 -0
- package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +38 -0
- package/dist/humain/mcp-adapter/vendor/state.ts +62 -0
- package/dist/humain/mcp-adapter/vendor/tool-approval.ts +182 -0
- package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +296 -0
- package/dist/humain/mcp-adapter/vendor/tool-registrar.ts +253 -0
- package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +423 -0
- package/dist/humain/mcp-adapter/vendor/ts-shape.ts +149 -0
- package/dist/humain/mcp-adapter/vendor/types.ts +942 -0
- package/dist/humain/mcp-adapter/vendor/ui-app-bridge-helpers.ts +40 -0
- package/dist/humain/mcp-adapter/vendor/ui-resource-handler.ts +250 -0
- package/dist/humain/mcp-adapter/vendor/ui-server.ts +866 -0
- package/dist/humain/mcp-adapter/vendor/ui-session.ts +570 -0
- package/dist/humain/mcp-adapter/vendor/ui-stream-types.ts +89 -0
- package/dist/humain/mcp-adapter/vendor/ui-tool-visibility.ts +25 -0
- package/dist/humain/mcp-adapter/vendor/unix-socket-transport.ts +85 -0
- package/dist/humain/mcp-adapter/vendor/utils.ts +310 -0
- package/dist/humain/mcp-adapter.d.ts +3 -0
- package/dist/humain/mcp-adapter.d.ts.map +1 -0
- package/dist/humain/mcp-adapter.js +5 -0
- package/dist/humain/mcp-adapter.js.map +1 -0
- package/dist/humain/pi-agent-execution-host.d.ts +34 -0
- package/dist/humain/pi-agent-execution-host.d.ts.map +1 -0
- package/dist/humain/pi-agent-execution-host.js +77 -0
- package/dist/humain/pi-agent-execution-host.js.map +1 -0
- package/dist/humain/web-access/host.d.ts +4 -0
- package/dist/humain/web-access/host.d.ts.map +1 -0
- package/dist/humain/web-access/host.js +3 -0
- package/dist/humain/web-access/host.js.map +1 -0
- package/dist/humain/web-access/index.d.ts +3 -0
- package/dist/humain/web-access/index.d.ts.map +1 -0
- package/dist/humain/web-access/index.js +5 -0
- package/dist/humain/web-access/index.js.map +1 -0
- package/dist/humain/web-access/vendor/activity.d.ts +34 -0
- package/dist/humain/web-access/vendor/activity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/activity.js +68 -0
- package/dist/humain/web-access/vendor/activity.js.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts +8 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.js +167 -0
- package/dist/humain/web-access/vendor/anysearch.js.map +1 -0
- package/dist/humain/web-access/vendor/auth-fetch.d.ts +13 -0
- package/dist/humain/web-access/vendor/auth-fetch.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/auth-fetch.js +134 -0
- package/dist/humain/web-access/vendor/auth-fetch.js.map +1 -0
- package/dist/humain/web-access/vendor/bocha.d.ts +4 -0
- package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/bocha.js +219 -0
- package/dist/humain/web-access/vendor/bocha.js.map +1 -0
- package/dist/humain/web-access/vendor/brave.d.ts +4 -0
- package/dist/humain/web-access/vendor/brave.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brave.js +194 -0
- package/dist/humain/web-access/vendor/brave.js.map +1 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts +12 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.js +230 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -0
- package/dist/humain/web-access/vendor/brightdata.d.ts +8 -0
- package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brightdata.js +519 -0
- package/dist/humain/web-access/vendor/brightdata.js.map +1 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts +23 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/chrome-cookies.js +522 -0
- package/dist/humain/web-access/vendor/chrome-cookies.js.map +1 -0
- package/dist/humain/web-access/vendor/content-find.d.ts +11 -0
- package/dist/humain/web-access/vendor/content-find.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/content-find.js +117 -0
- package/dist/humain/web-access/vendor/content-find.js.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts +28 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.js +151 -0
- package/dist/humain/web-access/vendor/credential-source.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts +30 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.js +3556 -0
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts +94 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.js +690 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts +60 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.js +416 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/declared-web-links.d.ts +16 -0
- package/dist/humain/web-access/vendor/declared-web-links.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/declared-web-links.js +168 -0
- package/dist/humain/web-access/vendor/declared-web-links.js.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts +4 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo.js +123 -0
- package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -0
- package/dist/humain/web-access/vendor/exa.d.ts +10 -0
- package/dist/humain/web-access/vendor/exa.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/exa.js +426 -0
- package/dist/humain/web-access/vendor/exa.js.map +1 -0
- package/dist/humain/web-access/vendor/extract.d.ts +48 -0
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/extract.js +1126 -0
- package/dist/humain/web-access/vendor/extract.js.map +1 -0
- package/dist/humain/web-access/vendor/feature-config.d.ts +3 -0
- package/dist/humain/web-access/vendor/feature-config.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/feature-config.js +27 -0
- package/dist/humain/web-access/vendor/feature-config.js.map +1 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts +27 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/fetch-params.js +71 -0
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts +19 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.js +370 -0
- package/dist/humain/web-access/vendor/firecrawl.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts +27 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-api.js +230 -0
- package/dist/humain/web-access/vendor/gemini-api.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts +9 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.js +85 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-search.d.ts +40 -0
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-search.js +832 -0
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-url-context.d.ts +4 -0
- package/dist/humain/web-access/vendor/gemini-url-context.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-url-context.js +101 -0
- package/dist/humain/web-access/vendor/gemini-url-context.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts +4 -0
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web-config.js +42 -0
- package/dist/humain/web-access/vendor/gemini-web-config.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web.d.ts +18 -0
- package/dist/humain/web-access/vendor/gemini-web.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web.js +385 -0
- package/dist/humain/web-access/vendor/gemini-web.js.map +1 -0
- package/dist/humain/web-access/vendor/github-api.d.ts +7 -0
- package/dist/humain/web-access/vendor/github-api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/github-api.js +160 -0
- package/dist/humain/web-access/vendor/github-api.js.map +1 -0
- package/dist/humain/web-access/vendor/github-extract.d.ts +13 -0
- package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/github-extract.js +635 -0
- package/dist/humain/web-access/vendor/github-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/index.d.ts +4 -0
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/index.js +3076 -0
- package/dist/humain/web-access/vendor/index.js.map +1 -0
- package/dist/humain/web-access/vendor/jina-search.d.ts +8 -0
- package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/jina-search.js +255 -0
- package/dist/humain/web-access/vendor/jina-search.js.map +1 -0
- package/dist/humain/web-access/vendor/kagi.d.ts +15 -0
- package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/kagi.js +262 -0
- package/dist/humain/web-access/vendor/kagi.js.map +1 -0
- package/dist/humain/web-access/vendor/ollama.d.ts +15 -0
- package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ollama.js +216 -0
- package/dist/humain/web-access/vendor/ollama.js.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts +15 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.js +459 -0
- package/dist/humain/web-access/vendor/openai-search.js.map +1 -0
- package/dist/humain/web-access/vendor/page-query.d.ts +16 -0
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/page-query.js +79 -0
- package/dist/humain/web-access/vendor/page-query.js.map +1 -0
- package/dist/humain/web-access/vendor/parallel.d.ts +12 -0
- package/dist/humain/web-access/vendor/parallel.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/parallel.js +343 -0
- package/dist/humain/web-access/vendor/parallel.js.map +1 -0
- package/dist/humain/web-access/vendor/pdf-extract.d.ts +44 -0
- package/dist/humain/web-access/vendor/pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/pdf-extract.js +298 -0
- package/dist/humain/web-access/vendor/pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/perplexity.d.ts +20 -0
- package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/perplexity.js +159 -0
- package/dist/humain/web-access/vendor/perplexity.js.map +1 -0
- package/dist/humain/web-access/vendor/querit.d.ts +10 -0
- package/dist/humain/web-access/vendor/querit.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/querit.js +335 -0
- package/dist/humain/web-access/vendor/querit.js.map +1 -0
- package/dist/humain/web-access/vendor/render-search-error.d.ts +57 -0
- package/dist/humain/web-access/vendor/render-search-error.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/render-search-error.js +130 -0
- package/dist/humain/web-access/vendor/render-search-error.js.map +1 -0
- package/dist/humain/web-access/vendor/rsc-extract.d.ts +12 -0
- package/dist/humain/web-access/vendor/rsc-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/rsc-extract.js +329 -0
- package/dist/humain/web-access/vendor/rsc-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/search1api.d.ts +10 -0
- package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/search1api.js +251 -0
- package/dist/humain/web-access/vendor/search1api.js.map +1 -0
- package/dist/humain/web-access/vendor/searchinfinity.d.ts +8 -0
- package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/searchinfinity.js +229 -0
- package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -0
- package/dist/humain/web-access/vendor/searxng.d.ts +4 -0
- package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/searxng.js +238 -0
- package/dist/humain/web-access/vendor/searxng.js.map +1 -0
- package/dist/humain/web-access/vendor/serpbase.d.ts +4 -0
- package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpbase.js +211 -0
- package/dist/humain/web-access/vendor/serpbase.js.map +1 -0
- package/dist/humain/web-access/vendor/serpdive.d.ts +8 -0
- package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpdive.js +267 -0
- package/dist/humain/web-access/vendor/serpdive.js.map +1 -0
- package/dist/humain/web-access/vendor/source-check.d.ts +99 -0
- package/dist/humain/web-access/vendor/source-check.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/source-check.js +205 -0
- package/dist/humain/web-access/vendor/source-check.js.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts +50 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js +466 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -0
- package/dist/humain/web-access/vendor/storage.d.ts +55 -0
- package/dist/humain/web-access/vendor/storage.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/storage.js +485 -0
- package/dist/humain/web-access/vendor/storage.js.map +1 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts +25 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/summary-model-scope.js +98 -0
- package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -0
- package/dist/humain/web-access/vendor/summary-review.d.ts +26 -0
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/summary-review.js +344 -0
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -0
- package/dist/humain/web-access/vendor/tavily.d.ts +8 -0
- package/dist/humain/web-access/vendor/tavily.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/tavily.js +194 -0
- package/dist/humain/web-access/vendor/tavily.js.map +1 -0
- package/dist/humain/web-access/vendor/tinyfish.d.ts +11 -0
- package/dist/humain/web-access/vendor/tinyfish.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/tinyfish.js +331 -0
- package/dist/humain/web-access/vendor/tinyfish.js.map +1 -0
- package/dist/humain/web-access/vendor/utils.d.ts +20 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/utils.js +91 -0
- package/dist/humain/web-access/vendor/utils.js.map +1 -0
- package/dist/humain/web-access/vendor/video-extract.d.ts +16 -0
- package/dist/humain/web-access/vendor/video-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/video-extract.js +335 -0
- package/dist/humain/web-access/vendor/video-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/xai-search.d.ts +13 -0
- package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/xai-search.js +331 -0
- package/dist/humain/web-access/vendor/xai-search.js.map +1 -0
- package/dist/humain/web-access/vendor/youtube-extract.d.ts +27 -0
- package/dist/humain/web-access/vendor/youtube-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/youtube-extract.js +282 -0
- package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +169 -102
- package/dist/main.js.map +1 -1
- package/dist/modes/agent-exec-mode.d.ts +14 -0
- package/dist/modes/agent-exec-mode.d.ts.map +1 -0
- package/dist/modes/agent-exec-mode.js +92 -0
- package/dist/modes/agent-exec-mode.js.map +1 -0
- package/dist/modes/index.d.ts +4 -2
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +2 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +5 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +13 -4
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +7 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.js +19 -0
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
- package/dist/modes/interactive/components/mermaid.d.ts +11 -0
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
- package/dist/modes/interactive/components/mermaid.js +75 -0
- package/dist/modes/interactive/components/mermaid.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +16 -4
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +4 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +26 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +8 -2
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +30 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +3 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +9 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +45 -9
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +581 -211
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -0
- package/dist/modes/interactive/theme/light.json +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts +3 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +10 -1
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.json +5 -1
- package/dist/modes/interactive/theme/theme.d.ts +2 -2
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +24 -6
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts +28 -0
- package/dist/modes/json-event.d.ts.map +1 -0
- package/dist/modes/json-event.js +12 -0
- package/dist/modes/json-event.js.map +1 -0
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +12 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +12 -5
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +55 -1
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +13 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +11 -9
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/rpc-entry.d.ts.map +1 -1
- package/dist/rpc-entry.js +3 -2
- package/dist/rpc-entry.js.map +1 -1
- package/dist/server/create-harness.d.ts +26 -0
- package/dist/server/create-harness.d.ts.map +1 -0
- package/dist/server/create-harness.js +104 -0
- package/dist/server/create-harness.js.map +1 -0
- package/dist/utils/abort.d.ts +5 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +48 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/clipboard.d.ts +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +22 -2
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/management-http.d.ts +23 -0
- package/dist/utils/management-http.d.ts.map +1 -0
- package/dist/utils/management-http.js +50 -0
- package/dist/utils/management-http.js.map +1 -0
- package/dist/utils/paths.d.ts +3 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +23 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/tool-result-images.d.ts +19 -0
- package/dist/utils/tool-result-images.d.ts.map +1 -0
- package/dist/utils/tool-result-images.js +45 -0
- package/dist/utils/tool-result-images.js.map +1 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +13 -25
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +4 -0
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +23 -5
- package/dist/utils/version-check.js.map +1 -1
- package/docs/compaction.md +2 -2
- package/docs/custom-provider.md +7 -5
- package/docs/extensions.md +30 -5
- package/docs/humain-terminal.md +21 -1
- package/docs/json.md +24 -19
- package/docs/keybindings.md +46 -14
- package/docs/models.md +32 -11
- package/docs/providers.md +9 -1
- package/docs/quickstart.md +39 -37
- package/docs/rpc.md +31 -11
- package/docs/sdk.md +21 -2
- package/docs/security.md +21 -21
- package/docs/session-format.md +14 -14
- package/docs/settings.md +4 -1
- package/docs/themes.md +5 -3
- package/docs/usage.md +7 -0
- package/examples/extensions/custom-compaction.ts +3 -18
- package/examples/extensions/custom-provider-anthropic/index.ts +5 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +5 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/handoff.ts +4 -13
- package/examples/extensions/qna.ts +5 -9
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +9 -20
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/rpc-extension-ui.ts +11 -2
- package/examples/sdk/02-custom-model.ts +2 -3
- package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +2771 -535
- package/package.json +40 -11
- package/src/humain/mcp-adapter/UPSTREAM.md +15 -0
- package/src/humain/mcp-adapter/upstream.json +7 -0
- package/src/humain/mcp-adapter/vendor/CHANGELOG.md +673 -0
- package/src/humain/mcp-adapter/vendor/LICENSE +21 -0
- package/src/humain/web-access/UPSTREAM.md +17 -0
- package/src/humain/web-access/upstream.json +23 -0
- package/src/humain/web-access/vendor/LICENSE +21 -0
|
@@ -0,0 +1,1331 @@
|
|
|
1
|
+
import type { AgentToolResult, ToolInfo } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { UrlElicitationRequiredError, type Client } from "@modelcontextprotocol/client";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import type { McpExtensionState } from "./state.ts";
|
|
5
|
+
import type { ToolMetadata, McpContent } from "./types.ts";
|
|
6
|
+
import { getServerPrefix, isServerDisabled, parseUiPromptHandoff } from "./types.ts";
|
|
7
|
+
import { lazyConnect, markKeepAliveAfterConnect, notifyToolMetadataUpdated, updateServerMetadata, updateMetadataCache, getFailureAgeSeconds, updateStatusBar, clearFailure, recordFailure } from "./init.ts";
|
|
8
|
+
import { abortable, throwIfAborted } from "./abort.ts";
|
|
9
|
+
import { combineAbortSignals, isAbortError } from "./runtime-owner.ts";
|
|
10
|
+
import { buildToolMetadata, getToolNames, findToolByName, formatSchema } from "./tool-metadata.ts";
|
|
11
|
+
import { renderTsShape } from "./ts-shape.ts";
|
|
12
|
+
import { reconstructPromptMetadata } from "./metadata-cache.ts";
|
|
13
|
+
import { resolveMcpResultContent, transformMcpContent, transformMcpResourceContents } from "./tool-registrar.ts";
|
|
14
|
+
import { guardMcpOutput, guardedMcpDetails, resolveMcpOutputGuardOptions } from "./mcp-output-guard.ts";
|
|
15
|
+
import { maybeStartUiSession, summarizeUiSessionResult, type UiSessionRuntime } from "./ui-session.ts";
|
|
16
|
+
import { formatAuthRequiredMessage, formatMcpStatus, resolveServerUrl, truncateAtWord } from "./utils.ts";
|
|
17
|
+
import { authenticate, completeAuthFromInput, startAuth, supportsOAuth } from "./mcp-auth-flow.ts";
|
|
18
|
+
import { SessionRecoveryAuthRequiredError, withSessionRecovery } from "./session-recovery.ts";
|
|
19
|
+
import { paginate, rankSuggestions, rankToolMatches, resolveSearchKeywords } from "./search-ranking.ts";
|
|
20
|
+
import { ensureToolCallApproved, isToolCallApprovalRequired } from "./tool-approval.ts";
|
|
21
|
+
|
|
22
|
+
type ProxyToolResult = AgentToolResult<Record<string, unknown>>;
|
|
23
|
+
type ClientCallToolResult = Awaited<ReturnType<Client["callTool"]>>;
|
|
24
|
+
type ClientReadResourceResult = Awaited<ReturnType<Client["readResource"]>>;
|
|
25
|
+
|
|
26
|
+
const require = createRequire(import.meta.url);
|
|
27
|
+
const MAX_REGEX_SEARCH_QUERY_LENGTH = 256;
|
|
28
|
+
const INSTRUCTIONS_PREVIEW_LENGTH = 300;
|
|
29
|
+
const REGEX_SAFETY_CHECK_PARAMS = {
|
|
30
|
+
attackTimeout: 50,
|
|
31
|
+
incubationTimeout: 50,
|
|
32
|
+
timeout: 250,
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
type AutoAuthResult =
|
|
36
|
+
| { status: "skipped" }
|
|
37
|
+
| { status: "success" }
|
|
38
|
+
| { status: "failed"; message: string };
|
|
39
|
+
|
|
40
|
+
function getToolMatches(metadata: ToolMetadata[] | undefined, toolName: string, exact: boolean): ToolMetadata[] {
|
|
41
|
+
if (!metadata) return [];
|
|
42
|
+
if (exact) return metadata.filter(tool => tool.name === toolName);
|
|
43
|
+
const normalizedName = toolName.replace(/-/g, "_");
|
|
44
|
+
return metadata.filter(tool => tool.name.replace(/-/g, "_") === normalizedName);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getEnabledToolMatches(state: McpExtensionState, toolName: string, exact: boolean): { server: string; tool: ToolMetadata }[] {
|
|
48
|
+
const matches: { server: string; tool: ToolMetadata }[] = [];
|
|
49
|
+
for (const [server, metadata] of state.toolMetadata) {
|
|
50
|
+
if (isServerDisabled(state.config.mcpServers[server])) continue;
|
|
51
|
+
for (const tool of getToolMatches(metadata, toolName, exact)) matches.push({ server, tool });
|
|
52
|
+
}
|
|
53
|
+
return matches;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getSingleToolMatch(metadata: ToolMetadata[] | undefined, toolName: string): ToolMetadata | "ambiguous" | undefined {
|
|
57
|
+
const exactMatches = getToolMatches(metadata, toolName, true);
|
|
58
|
+
const matches = exactMatches.length > 0 ? exactMatches : getToolMatches(metadata, toolName, false);
|
|
59
|
+
return matches.length > 1 ? "ambiguous" : matches[0];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function ambiguousToolResult(mode: "call" | "describe", toolName: string): ProxyToolResult {
|
|
63
|
+
const message = `Tool "${toolName}" matches multiple servers. Specify a server.`;
|
|
64
|
+
return {
|
|
65
|
+
content: [{ type: "text" as const, text: message }],
|
|
66
|
+
details: { mode, error: "ambiguous_tool", requestedTool: toolName, message },
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function disabledResult(mode: string, serverName: string): ProxyToolResult {
|
|
71
|
+
const message = `Server "${serverName}" is disabled. Run /mcp enable ${serverName} and /reload to enable it.`;
|
|
72
|
+
return {
|
|
73
|
+
content: [{ type: "text" as const, text: message }],
|
|
74
|
+
details: { mode, error: "server_disabled", server: serverName, message },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getAuthRequiredMessage(
|
|
79
|
+
state: McpExtensionState,
|
|
80
|
+
serverName: string,
|
|
81
|
+
defaultMessage = `Server "${serverName}" requires OAuth authentication. Run mcp({ action: "auth-start", server: "${serverName}" }) to get a browser URL, or /mcp-auth ${serverName} in an interactive local session.`,
|
|
82
|
+
): string {
|
|
83
|
+
return formatAuthRequiredMessage(state.config, serverName, defaultMessage);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getAuthFailedMessage(state: McpExtensionState, serverName: string, message: string): string {
|
|
87
|
+
const customGuidance = state.config.settings?.authRequiredMessage;
|
|
88
|
+
if (customGuidance) {
|
|
89
|
+
return `OAuth authentication failed for "${serverName}": ${message}. ${getAuthRequiredMessage(state, serverName)}`;
|
|
90
|
+
}
|
|
91
|
+
return `OAuth authentication failed for "${serverName}": ${message}. Run mcp({ action: "auth-start", server: "${serverName}" }) to get a browser URL, or /mcp-auth ${serverName} in an interactive local session.`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function getRedirectPort(authorizationUrl: string): number | undefined {
|
|
95
|
+
try {
|
|
96
|
+
const redirectUri = new URL(authorizationUrl).searchParams.get("redirect_uri");
|
|
97
|
+
if (!redirectUri) return undefined;
|
|
98
|
+
const port = Number.parseInt(new URL(redirectUri).port, 10);
|
|
99
|
+
return Number.isInteger(port) ? port : undefined;
|
|
100
|
+
} catch {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function formatManualAuthInstructions(serverName: string, authorizationUrl: string): string {
|
|
106
|
+
const port = getRedirectPort(authorizationUrl);
|
|
107
|
+
const portNote = port
|
|
108
|
+
? `\nThe redirect URL will use local port ${port}. On a remote server it is expected for that localhost page to fail locally; copy the address bar URL anyway.`
|
|
109
|
+
: "";
|
|
110
|
+
|
|
111
|
+
return [
|
|
112
|
+
`MCP OAuth required for "${serverName}".`,
|
|
113
|
+
"",
|
|
114
|
+
"Open this URL in your local browser:",
|
|
115
|
+
"",
|
|
116
|
+
authorizationUrl,
|
|
117
|
+
"",
|
|
118
|
+
"After approving, copy the full redirected localhost URL from your browser address bar and send it back with:",
|
|
119
|
+
`mcp({ action: "auth-complete", server: "${serverName}", args: { redirectUrl: "PASTE_REDIRECT_URL_HERE" } })`,
|
|
120
|
+
"",
|
|
121
|
+
'You can also pass just the `code` query parameter as `args: { code: "PASTE_CODE_HERE" }`. JSON-string args remain supported.',
|
|
122
|
+
portNote.trimEnd(),
|
|
123
|
+
].filter(Boolean).join("\n");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function attemptAutoAuth(
|
|
127
|
+
state: McpExtensionState,
|
|
128
|
+
serverName: string,
|
|
129
|
+
signal?: AbortSignal,
|
|
130
|
+
): Promise<AutoAuthResult> {
|
|
131
|
+
if (state.config.settings?.autoAuth !== true) {
|
|
132
|
+
return { status: "skipped" };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const definition = state.config.mcpServers[serverName];
|
|
136
|
+
if (!definition || isServerDisabled(definition) || !supportsOAuth(definition)) {
|
|
137
|
+
return { status: "skipped" };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let serverUrl: string | undefined;
|
|
141
|
+
try {
|
|
142
|
+
serverUrl = resolveServerUrl(definition);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
145
|
+
return { status: "failed", message: getAuthFailedMessage(state, serverName, message) };
|
|
146
|
+
}
|
|
147
|
+
if (!serverUrl) {
|
|
148
|
+
return { status: "skipped" };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const grantType = definition.oauth ? definition.oauth.grantType ?? "authorization_code" : "authorization_code";
|
|
152
|
+
if (!state.ui && grantType !== "client_credentials") {
|
|
153
|
+
return {
|
|
154
|
+
status: "failed",
|
|
155
|
+
message: getAuthRequiredMessage(
|
|
156
|
+
state,
|
|
157
|
+
serverName,
|
|
158
|
+
`Server "${serverName}" requires OAuth authentication. Run mcp({ action: "auth-start", server: "${serverName}" }) to get a browser URL, or /mcp-auth ${serverName} in an interactive local session.`,
|
|
159
|
+
),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
if (state.authStorageOptions) {
|
|
165
|
+
await authenticate(
|
|
166
|
+
serverName,
|
|
167
|
+
serverUrl,
|
|
168
|
+
definition,
|
|
169
|
+
signal
|
|
170
|
+
? { authStorageOptions: state.authStorageOptions, signal, runtime: state.oauthRuntime }
|
|
171
|
+
: { authStorageOptions: state.authStorageOptions, runtime: state.oauthRuntime },
|
|
172
|
+
);
|
|
173
|
+
} else {
|
|
174
|
+
if (signal) {
|
|
175
|
+
await authenticate(serverName, serverUrl, definition, { signal, runtime: state.oauthRuntime });
|
|
176
|
+
} else {
|
|
177
|
+
await authenticate(serverName, serverUrl, definition, { runtime: state.oauthRuntime });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return { status: "success" };
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (isAbortError(error, signal)) throw error;
|
|
183
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
184
|
+
return {
|
|
185
|
+
status: "failed",
|
|
186
|
+
message: getAuthFailedMessage(state, serverName, message),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function executeUiMessages(state: McpExtensionState): ProxyToolResult {
|
|
192
|
+
const sessions = state.completedUiSessions;
|
|
193
|
+
|
|
194
|
+
if (sessions.length === 0) {
|
|
195
|
+
return {
|
|
196
|
+
content: [{ type: "text" as const, text: "No UI session messages available." }],
|
|
197
|
+
details: { sessions: 0 },
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const output: string[] = [];
|
|
202
|
+
output.push(`UI Session Messages (${sessions.length} session${sessions.length > 1 ? "s" : ""}):\n`);
|
|
203
|
+
|
|
204
|
+
const allPrompts: string[] = [];
|
|
205
|
+
const allIntents = sessions.flatMap((session) => session.messages.intents);
|
|
206
|
+
const allContexts = sessions.flatMap((session) => session.messages.contexts);
|
|
207
|
+
const parsedHandoffs: Array<{ intent: string; params: Record<string, unknown>; raw: string }> = [];
|
|
208
|
+
|
|
209
|
+
for (const session of sessions) {
|
|
210
|
+
const timestamp = session.completedAt.toLocaleTimeString();
|
|
211
|
+
output.push(`\n## ${session.serverName} / ${session.toolName} (${timestamp}, ${session.reason})`);
|
|
212
|
+
|
|
213
|
+
const plainPrompts: string[] = [];
|
|
214
|
+
for (const prompt of session.messages.prompts) {
|
|
215
|
+
allPrompts.push(prompt);
|
|
216
|
+
const handoff = parseUiPromptHandoff(prompt);
|
|
217
|
+
if (handoff) {
|
|
218
|
+
parsedHandoffs.push(handoff);
|
|
219
|
+
} else {
|
|
220
|
+
plainPrompts.push(prompt);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (plainPrompts.length > 0) {
|
|
225
|
+
output.push("\n### Prompts:");
|
|
226
|
+
for (const prompt of plainPrompts) {
|
|
227
|
+
output.push(`- ${prompt}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const intentsForSession = [
|
|
232
|
+
...session.messages.intents,
|
|
233
|
+
...session.messages.prompts
|
|
234
|
+
.map((prompt) => parseUiPromptHandoff(prompt))
|
|
235
|
+
.filter((handoff): handoff is NonNullable<typeof handoff> => !!handoff)
|
|
236
|
+
.map((handoff) => ({ intent: handoff.intent, params: handoff.params })),
|
|
237
|
+
];
|
|
238
|
+
|
|
239
|
+
if (intentsForSession.length > 0) {
|
|
240
|
+
output.push("\n### Intents:");
|
|
241
|
+
for (const intent of intentsForSession) {
|
|
242
|
+
const params = intent.params ? ` (${JSON.stringify(intent.params)})` : "";
|
|
243
|
+
output.push(`- ${intent.intent}${params}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const contexts = session.messages.contexts;
|
|
248
|
+
if (contexts.length > 0) {
|
|
249
|
+
output.push("\n### Context updates:");
|
|
250
|
+
for (const context of contexts) {
|
|
251
|
+
output.push(`- ${context.summary}${context.truncated ? " (truncated)" : ""}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (session.messages.notifications.length > 0) {
|
|
256
|
+
output.push("\n### Notifications:");
|
|
257
|
+
for (const notification of session.messages.notifications) {
|
|
258
|
+
output.push(`- ${notification}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const count = sessions.length;
|
|
264
|
+
state.completedUiSessions = [];
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
content: [{ type: "text" as const, text: output.join("\n") }],
|
|
268
|
+
details: {
|
|
269
|
+
sessions: count,
|
|
270
|
+
prompts: allPrompts,
|
|
271
|
+
intents: [...allIntents, ...parsedHandoffs.map(({ intent, params }) => ({ intent, params }))],
|
|
272
|
+
contexts: allContexts,
|
|
273
|
+
handoffs: parsedHandoffs,
|
|
274
|
+
cleared: true,
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function executeStatus(state: McpExtensionState): ProxyToolResult {
|
|
280
|
+
const servers: Array<{ name: string; status: string; toolCount: number; failedAgo: number | null; disabled?: boolean }> = [];
|
|
281
|
+
|
|
282
|
+
for (const name of Object.keys(state.config.mcpServers)) {
|
|
283
|
+
const definition = state.config.mcpServers[name];
|
|
284
|
+
const disabled = isServerDisabled(definition);
|
|
285
|
+
const connection = disabled ? undefined : state.manager.getConnection(name);
|
|
286
|
+
const metadata = disabled ? undefined : state.toolMetadata.get(name);
|
|
287
|
+
const toolCount = metadata?.length ?? 0;
|
|
288
|
+
const failedAgo = disabled ? null : getFailureAgeSeconds(state, name);
|
|
289
|
+
let status = disabled ? "disabled" : "not connected";
|
|
290
|
+
if (!disabled && connection?.status === "connected") {
|
|
291
|
+
status = "connected";
|
|
292
|
+
} else if (!disabled && connection?.status === "needs-auth") {
|
|
293
|
+
status = "needs-auth";
|
|
294
|
+
} else if (!disabled && failedAgo !== null) {
|
|
295
|
+
status = "failed";
|
|
296
|
+
} else if (!disabled && metadata !== undefined) {
|
|
297
|
+
status = "cached";
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
servers.push({ name, status, toolCount, failedAgo, ...(disabled ? { disabled: true } : {}) });
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const disabledCount = servers.filter(s => s.disabled).length;
|
|
304
|
+
const enabledServers = servers.filter(s => !s.disabled);
|
|
305
|
+
const totalTools = enabledServers.reduce((sum, s) => sum + s.toolCount, 0);
|
|
306
|
+
const connectedCount = enabledServers.filter(s => s.status === "connected").length;
|
|
307
|
+
|
|
308
|
+
let text = `MCP: ${connectedCount}/${enabledServers.length} servers, ${totalTools} tools`;
|
|
309
|
+
if (disabledCount > 0) text += ` (${disabledCount} disabled)`;
|
|
310
|
+
text += "\n\n";
|
|
311
|
+
for (const server of servers) {
|
|
312
|
+
if (server.disabled) {
|
|
313
|
+
text += `⊘ ${server.name} (disabled)\n`;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (server.status === "connected") {
|
|
317
|
+
text += `✓ ${server.name} (${server.toolCount} tools)\n`;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (server.status === "needs-auth") {
|
|
321
|
+
text += `⚠ ${server.name} (needs auth)\n`;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (server.status === "cached") {
|
|
325
|
+
text += `○ ${server.name} (${server.toolCount} tools, cached)\n`;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (server.status === "failed") {
|
|
329
|
+
text += `✗ ${server.name} (failed ${server.failedAgo ?? 0}s ago)\n`;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
text += `○ ${server.name} (not connected)\n`;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (servers.length > 0) {
|
|
336
|
+
text += `\nmcp({ server: "name" }) to list tools, mcp({ search: "..." }) to search`;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
content: [{ type: "text" as const, text: text.trim() }],
|
|
341
|
+
details: { mode: "status", servers, totalTools, connectedCount, disabledCount },
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export async function executeAuthStart(state: McpExtensionState, serverName: string, signal?: AbortSignal): Promise<ProxyToolResult> {
|
|
346
|
+
const ownedSignal = combineAbortSignals(state.owner?.signal, signal);
|
|
347
|
+
throwIfAborted(ownedSignal);
|
|
348
|
+
const definition = state.config.mcpServers[serverName];
|
|
349
|
+
if (!definition) {
|
|
350
|
+
return {
|
|
351
|
+
content: [{ type: "text" as const, text: `Server "${serverName}" not found. Use mcp({}) to see available servers.` }],
|
|
352
|
+
details: { mode: "auth-start", error: "not_found", server: serverName },
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
if (isServerDisabled(definition)) return disabledResult("auth-start", serverName);
|
|
356
|
+
|
|
357
|
+
try {
|
|
358
|
+
const serverUrl = resolveServerUrl(definition);
|
|
359
|
+
if (!serverUrl || !supportsOAuth(definition)) {
|
|
360
|
+
return {
|
|
361
|
+
content: [{ type: "text" as const, text: `Server "${serverName}" is not configured for OAuth over HTTP.` }],
|
|
362
|
+
details: { mode: "auth-start", error: "oauth_not_supported", server: serverName },
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const { authorizationUrl } = state.authStorageOptions
|
|
367
|
+
? ownedSignal
|
|
368
|
+
? await startAuth(serverName, serverUrl, definition, { authStorageOptions: state.authStorageOptions, signal: ownedSignal, runtime: state.oauthRuntime })
|
|
369
|
+
: await startAuth(serverName, serverUrl, definition, { authStorageOptions: state.authStorageOptions, runtime: state.oauthRuntime })
|
|
370
|
+
: ownedSignal
|
|
371
|
+
? await startAuth(serverName, serverUrl, definition, { signal: ownedSignal, runtime: state.oauthRuntime })
|
|
372
|
+
: await startAuth(serverName, serverUrl, definition, { runtime: state.oauthRuntime });
|
|
373
|
+
if (!authorizationUrl) {
|
|
374
|
+
return {
|
|
375
|
+
content: [{ type: "text" as const, text: `OAuth authentication successful for "${serverName}".` }],
|
|
376
|
+
details: { mode: "auth-start", server: serverName, authenticated: true },
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return {
|
|
381
|
+
content: [{ type: "text" as const, text: formatManualAuthInstructions(serverName, authorizationUrl) }],
|
|
382
|
+
details: { mode: "auth-start", server: serverName, authorizationUrl },
|
|
383
|
+
};
|
|
384
|
+
} catch (error) {
|
|
385
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
386
|
+
return {
|
|
387
|
+
content: [{ type: "text" as const, text: `Failed to start OAuth for "${serverName}": ${message}` }],
|
|
388
|
+
details: { mode: "auth-start", error: "auth_start_failed", server: serverName, message },
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export async function executeAuthComplete(state: McpExtensionState, serverName: string, input: string, signal?: AbortSignal): Promise<ProxyToolResult> {
|
|
394
|
+
const ownedSignal = combineAbortSignals(state.owner?.signal, signal);
|
|
395
|
+
throwIfAborted(ownedSignal);
|
|
396
|
+
const definition = state.config.mcpServers[serverName];
|
|
397
|
+
if (!definition) {
|
|
398
|
+
return {
|
|
399
|
+
content: [{ type: "text" as const, text: `Server "${serverName}" not found. Use mcp({}) to see available servers.` }],
|
|
400
|
+
details: { mode: "auth-complete", error: "not_found", server: serverName },
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
if (isServerDisabled(definition)) return disabledResult("auth-complete", serverName);
|
|
404
|
+
|
|
405
|
+
try {
|
|
406
|
+
const status = state.authStorageOptions
|
|
407
|
+
? ownedSignal
|
|
408
|
+
? await completeAuthFromInput(serverName, input, { authStorageOptions: state.authStorageOptions, signal: ownedSignal, runtime: state.oauthRuntime })
|
|
409
|
+
: await completeAuthFromInput(serverName, input, { authStorageOptions: state.authStorageOptions, runtime: state.oauthRuntime })
|
|
410
|
+
: ownedSignal
|
|
411
|
+
? await completeAuthFromInput(serverName, input, { signal: ownedSignal, runtime: state.oauthRuntime })
|
|
412
|
+
: await completeAuthFromInput(serverName, input, { runtime: state.oauthRuntime });
|
|
413
|
+
if (status !== "authenticated") {
|
|
414
|
+
return {
|
|
415
|
+
content: [{ type: "text" as const, text: `OAuth authentication did not complete for "${serverName}".` }],
|
|
416
|
+
details: { mode: "auth-complete", error: "not_authenticated", server: serverName, status },
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
await state.manager.close(serverName);
|
|
421
|
+
clearFailure(state, serverName);
|
|
422
|
+
updateStatusBar(state);
|
|
423
|
+
return {
|
|
424
|
+
content: [{ type: "text" as const, text: `OAuth authentication successful for "${serverName}". Run mcp({ connect: "${serverName}" }) to connect with the new token.` }],
|
|
425
|
+
details: { mode: "auth-complete", server: serverName, authenticated: true },
|
|
426
|
+
};
|
|
427
|
+
} catch (error) {
|
|
428
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
429
|
+
return {
|
|
430
|
+
content: [{ type: "text" as const, text: `Failed to complete OAuth for "${serverName}": ${message}` }],
|
|
431
|
+
details: { mode: "auth-complete", error: "auth_complete_failed", server: serverName, message },
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export function executeDescribe(state: McpExtensionState, toolName: string): ProxyToolResult {
|
|
437
|
+
const exactMatches = getEnabledToolMatches(state, toolName, true);
|
|
438
|
+
if (exactMatches.length > 1) return ambiguousToolResult("describe", toolName);
|
|
439
|
+
if (exactMatches.length === 0 && getEnabledToolMatches(state, toolName, false).length > 1) {
|
|
440
|
+
return ambiguousToolResult("describe", toolName);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
let serverName = exactMatches[0]?.server;
|
|
444
|
+
let toolMeta = exactMatches[0]?.tool;
|
|
445
|
+
let disabledMatch: string | undefined;
|
|
446
|
+
|
|
447
|
+
if (!toolMeta) {
|
|
448
|
+
for (const [server, metadata] of state.toolMetadata.entries()) {
|
|
449
|
+
const found = findToolByName(metadata, toolName);
|
|
450
|
+
if (!found) continue;
|
|
451
|
+
if (isServerDisabled(state.config.mcpServers[server])) {
|
|
452
|
+
disabledMatch ??= server;
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
serverName = server;
|
|
456
|
+
toolMeta = found;
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (!serverName || !toolMeta) {
|
|
462
|
+
if (disabledMatch) return disabledResult("describe", disabledMatch);
|
|
463
|
+
const suggestions = rankSuggestions(state, toolName, 5);
|
|
464
|
+
const suggestionText = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(", ")}` : "";
|
|
465
|
+
return {
|
|
466
|
+
content: [{ type: "text" as const, text: `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.${suggestionText}` }],
|
|
467
|
+
details: { mode: "describe", error: "tool_not_found", requestedTool: toolName, suggestions },
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const approvalMarker = isToolCallApprovalRequired(state.config, serverName, toolMeta, state.toolMetadata)
|
|
472
|
+
? " (requires approval)"
|
|
473
|
+
: "";
|
|
474
|
+
let text = `${toolMeta.name}${approvalMarker}\n`;
|
|
475
|
+
text += `Server: ${serverName}\n`;
|
|
476
|
+
if (toolMeta.resourceUri) {
|
|
477
|
+
text += `Type: Resource (reads from ${toolMeta.resourceUri})\n`;
|
|
478
|
+
}
|
|
479
|
+
text += `\n${toolMeta.description || "(no description)"}\n`;
|
|
480
|
+
|
|
481
|
+
if (toolMeta.inputSchema && !toolMeta.resourceUri) {
|
|
482
|
+
const shape = renderTsShape(toolMeta.inputSchema);
|
|
483
|
+
text += shape === null ? `\nParameters:\n${formatSchema(toolMeta.inputSchema)}` : `\nShape:\n${shape}`;
|
|
484
|
+
} else if (toolMeta.resourceUri) {
|
|
485
|
+
text += `\nNo parameters required (resource tool).`;
|
|
486
|
+
} else {
|
|
487
|
+
text += `\nNo parameters defined.`;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
return {
|
|
491
|
+
content: [{ type: "text" as const, text: text.trim() }],
|
|
492
|
+
details: { mode: "describe", tool: toolMeta, server: serverName },
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export function executeSearch(
|
|
497
|
+
state: McpExtensionState,
|
|
498
|
+
query: string,
|
|
499
|
+
regex?: boolean,
|
|
500
|
+
server?: string,
|
|
501
|
+
includeSchemas?: boolean,
|
|
502
|
+
limit = 12,
|
|
503
|
+
offset = 0,
|
|
504
|
+
): ProxyToolResult {
|
|
505
|
+
const showSchemas = includeSchemas !== false;
|
|
506
|
+
if (server && isServerDisabled(state.config.mcpServers[server])) return disabledResult("search", server);
|
|
507
|
+
|
|
508
|
+
let matches: Array<{ server: string; tool: ToolMetadata; score: number }>;
|
|
509
|
+
if (regex) {
|
|
510
|
+
let pattern: RegExp;
|
|
511
|
+
try {
|
|
512
|
+
if (query.length > MAX_REGEX_SEARCH_QUERY_LENGTH) {
|
|
513
|
+
return {
|
|
514
|
+
content: [{ type: "text" as const, text: `Regex query is too long; maximum length is ${MAX_REGEX_SEARCH_QUERY_LENGTH} characters.` }],
|
|
515
|
+
details: { mode: "search", error: "query_too_long", query, maxLength: MAX_REGEX_SEARCH_QUERY_LENGTH },
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
pattern = new RegExp(query, "i");
|
|
519
|
+
let safety;
|
|
520
|
+
try {
|
|
521
|
+
const { checkSync } = require("recheck") as typeof import("recheck");
|
|
522
|
+
safety = checkSync(query, "i", REGEX_SAFETY_CHECK_PARAMS);
|
|
523
|
+
} catch (error) {
|
|
524
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
525
|
+
return {
|
|
526
|
+
content: [{ type: "text" as const, text: "Regex query rejected because safety analysis failed." }],
|
|
527
|
+
details: { mode: "search", error: "unsafe_pattern", query, reason },
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
if (safety.status !== "safe") {
|
|
531
|
+
return {
|
|
532
|
+
content: [{ type: "text" as const, text: `Regex query rejected as unsafe (${safety.status}).` }],
|
|
533
|
+
details: { mode: "search", error: "unsafe_pattern", query, safetyStatus: safety.status },
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
} catch {
|
|
537
|
+
return {
|
|
538
|
+
content: [{ type: "text" as const, text: `Invalid regex: ${query}` }],
|
|
539
|
+
details: { mode: "search", error: "invalid_pattern", query },
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
matches = [];
|
|
544
|
+
const globalPrefix = state.config.settings?.toolPrefix ?? "server";
|
|
545
|
+
for (const [serverName, metadata] of state.toolMetadata.entries()) {
|
|
546
|
+
const definition = state.config.mcpServers[serverName];
|
|
547
|
+
if (isServerDisabled(definition)) continue;
|
|
548
|
+
if (server && serverName !== server) continue;
|
|
549
|
+
for (const tool of metadata) {
|
|
550
|
+
const matched = pattern.test(tool.name) || pattern.test(tool.description)
|
|
551
|
+
|| resolveSearchKeywords(definition, tool.originalName, serverName, globalPrefix).some(keyword => pattern.test(keyword));
|
|
552
|
+
if (matched) matches.push({ server: serverName, tool, score: 0 });
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
} else if (query.trim().length === 0) {
|
|
556
|
+
if (!server) {
|
|
557
|
+
return {
|
|
558
|
+
content: [{ type: "text" as const, text: "Search query cannot be empty" }],
|
|
559
|
+
details: { mode: "search", error: "empty_query" },
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
matches = (state.toolMetadata.get(server) ?? [])
|
|
563
|
+
.map(tool => ({ server, tool, score: 0 }))
|
|
564
|
+
.sort((a, b) => a.tool.name.localeCompare(b.tool.name));
|
|
565
|
+
} else {
|
|
566
|
+
matches = rankToolMatches(state, query, server);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const page = paginate(matches, offset, limit);
|
|
570
|
+
if (page.total === 0) {
|
|
571
|
+
const connectingServers = server
|
|
572
|
+
? state.config.mcpServers[server] && state.manager.isConnecting(server) ? [server] : []
|
|
573
|
+
: Object.keys(state.config.mcpServers)
|
|
574
|
+
.filter(name => !isServerDisabled(state.config.mcpServers[name]) && state.manager.isConnecting(name))
|
|
575
|
+
.sort((a, b) => a.localeCompare(b));
|
|
576
|
+
const msg = server ? `No tools matching "${query}" in "${server}"` : `No tools matching "${query}"`;
|
|
577
|
+
const connectingMessage = connectingServers.length === 1
|
|
578
|
+
? ` Server "${connectingServers[0]}" is still connecting; retry in a moment.`
|
|
579
|
+
: connectingServers.length > 1
|
|
580
|
+
? ` Servers ${connectingServers.map(name => `"${name}"`).join(", ")} are still connecting; retry in a moment.`
|
|
581
|
+
: "";
|
|
582
|
+
return {
|
|
583
|
+
content: [{ type: "text" as const, text: `${msg}${connectingMessage}` }],
|
|
584
|
+
details: {
|
|
585
|
+
mode: "search",
|
|
586
|
+
matches: [],
|
|
587
|
+
count: 0,
|
|
588
|
+
hasMore: false,
|
|
589
|
+
nextOffset: null,
|
|
590
|
+
query,
|
|
591
|
+
...(connectingServers.length > 0 ? { connectingServers } : {}),
|
|
592
|
+
},
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
let text = `Found ${page.total} tool${page.total === 1 ? "" : "s"} matching "${query}":\n\n`;
|
|
597
|
+
for (const match of page.items) {
|
|
598
|
+
const approvalMarker = isToolCallApprovalRequired(state.config, match.server, match.tool, state.toolMetadata)
|
|
599
|
+
? " (requires approval)"
|
|
600
|
+
: "";
|
|
601
|
+
if (showSchemas) {
|
|
602
|
+
text += `${match.tool.name}${approvalMarker}\n`;
|
|
603
|
+
text += ` ${match.tool.description || "(no description)"}\n`;
|
|
604
|
+
if (match.tool.inputSchema && !match.tool.resourceUri) {
|
|
605
|
+
const shape = renderTsShape(match.tool.inputSchema);
|
|
606
|
+
text += shape === null
|
|
607
|
+
? `\n Parameters:\n${formatSchema(match.tool.inputSchema, " ")}\n`
|
|
608
|
+
: `\n Shape:\n${shape.split("\n").map(line => ` ${line}`).join("\n")}\n`;
|
|
609
|
+
} else if (match.tool.resourceUri) {
|
|
610
|
+
text += " No parameters (resource tool).\n";
|
|
611
|
+
}
|
|
612
|
+
text += "\n";
|
|
613
|
+
} else {
|
|
614
|
+
text += `- ${match.tool.name}${approvalMarker}`;
|
|
615
|
+
if (match.tool.description) text += ` - ${truncateAtWord(match.tool.description, 50)}`;
|
|
616
|
+
text += "\n";
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (page.hasMore) text += `\n${page.items.length} of ${page.total} — offset: ${page.nextOffset} for more\n`;
|
|
620
|
+
|
|
621
|
+
return {
|
|
622
|
+
content: [{ type: "text" as const, text: text.trim() }],
|
|
623
|
+
details: {
|
|
624
|
+
mode: "search",
|
|
625
|
+
matches: page.items.map(match => ({ server: match.server, tool: match.tool.name, score: match.score })),
|
|
626
|
+
count: page.total,
|
|
627
|
+
hasMore: page.hasMore,
|
|
628
|
+
nextOffset: page.nextOffset,
|
|
629
|
+
query,
|
|
630
|
+
},
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export function executeList(state: McpExtensionState, server: string): ProxyToolResult {
|
|
635
|
+
const definition = state.config.mcpServers[server];
|
|
636
|
+
if (!definition) {
|
|
637
|
+
return {
|
|
638
|
+
content: [{ type: "text" as const, text: `Server "${server}" not found. Use mcp({}) to see available servers.` }],
|
|
639
|
+
details: { mode: "list", server, tools: [], count: 0, error: "not_found" },
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
if (isServerDisabled(definition)) return disabledResult("list", server);
|
|
643
|
+
|
|
644
|
+
const metadata = state.toolMetadata.get(server);
|
|
645
|
+
const toolNames = metadata?.map(m => m.name) ?? [];
|
|
646
|
+
const connection = state.manager.getConnection(server);
|
|
647
|
+
const instructions = state.serverInstructions.get(server);
|
|
648
|
+
let instructionsText = "";
|
|
649
|
+
if (instructions) {
|
|
650
|
+
const preview = truncateAtWord(instructions, INSTRUCTIONS_PREVIEW_LENGTH);
|
|
651
|
+
instructionsText = `\n\nServer instructions:\n${preview}`;
|
|
652
|
+
if (preview !== instructions) {
|
|
653
|
+
instructionsText += `\nUse mcp({ instructions: "${server}" }) for the full text.`;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (toolNames.length === 0) {
|
|
658
|
+
if (connection?.status === "connected") {
|
|
659
|
+
return {
|
|
660
|
+
content: [{ type: "text" as const, text: `Server "${server}" has no tools.${instructionsText}` }],
|
|
661
|
+
details: { mode: "list", server, tools: [], count: 0, hasInstructions: Boolean(instructions) },
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
if (metadata !== undefined) {
|
|
665
|
+
return {
|
|
666
|
+
content: [{ type: "text" as const, text: `Server "${server}" has no cached tools (not connected).${instructionsText}` }],
|
|
667
|
+
details: { mode: "list", server, tools: [], count: 0, cached: true, hasInstructions: Boolean(instructions) },
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
content: [{ type: "text" as const, text: `Server "${server}" is configured but not connected. Use mcp({ connect: "${server}" }) or /mcp reconnect ${server} to retry.${instructionsText}` }],
|
|
672
|
+
details: { mode: "list", server, tools: [], count: 0, error: "not_connected", hasInstructions: Boolean(instructions) },
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const cachedNote = connection?.status === "connected" ? "" : " (not connected, cached)";
|
|
677
|
+
let text = `${server} (${toolNames.length} tools${cachedNote}):\n\n`;
|
|
678
|
+
|
|
679
|
+
const descMap = new Map<string, string>();
|
|
680
|
+
if (metadata) {
|
|
681
|
+
for (const m of metadata) {
|
|
682
|
+
descMap.set(m.name, m.description);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
for (const tool of toolNames) {
|
|
687
|
+
const desc = descMap.get(tool) ?? "";
|
|
688
|
+
const truncated = truncateAtWord(desc, 50);
|
|
689
|
+
text += `- ${tool}`;
|
|
690
|
+
if (truncated) text += ` - ${truncated}`;
|
|
691
|
+
text += "\n";
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
text += instructionsText;
|
|
695
|
+
|
|
696
|
+
return {
|
|
697
|
+
content: [{ type: "text" as const, text: text.trim() }],
|
|
698
|
+
details: { mode: "list", server, tools: toolNames, count: toolNames.length, hasInstructions: Boolean(instructions) },
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
export function executeInstructions(state: McpExtensionState, server: string): ProxyToolResult {
|
|
703
|
+
const definition = state.config.mcpServers[server];
|
|
704
|
+
if (!definition) {
|
|
705
|
+
return {
|
|
706
|
+
content: [{ type: "text" as const, text: `Server "${server}" not found. Use mcp({}) to see available servers.` }],
|
|
707
|
+
details: { mode: "instructions", server, error: "not_found" },
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
if (isServerDisabled(definition)) return disabledResult("instructions", server);
|
|
711
|
+
|
|
712
|
+
const instructions = state.serverInstructions.get(server);
|
|
713
|
+
if (instructions) {
|
|
714
|
+
return {
|
|
715
|
+
content: [{ type: "text" as const, text: `${server} instructions:\n\n${instructions}` }],
|
|
716
|
+
details: { mode: "instructions", server, length: instructions.length },
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
const connection = state.manager.getConnection(server);
|
|
721
|
+
if (connection?.status === "connected") {
|
|
722
|
+
return {
|
|
723
|
+
content: [{ type: "text" as const, text: `Server "${server}" does not provide instructions.` }],
|
|
724
|
+
details: { mode: "instructions", server, error: "no_instructions" },
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
return {
|
|
729
|
+
content: [{ type: "text" as const, text: `No instructions cached for "${server}". Use mcp({ connect: "${server}" }) to connect and refresh.` }],
|
|
730
|
+
details: { mode: "instructions", server, error: "not_connected" },
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
export async function executeConnect(state: McpExtensionState, serverName: string, signal?: AbortSignal): Promise<ProxyToolResult> {
|
|
735
|
+
const ownedSignal = combineAbortSignals(state.owner?.signal, signal);
|
|
736
|
+
throwIfAborted(ownedSignal);
|
|
737
|
+
const definition = state.config.mcpServers[serverName];
|
|
738
|
+
if (!definition) {
|
|
739
|
+
return {
|
|
740
|
+
content: [{ type: "text" as const, text: `Server "${serverName}" not found. Use mcp({}) to see available servers.` }],
|
|
741
|
+
details: { mode: "connect", error: "not_found", server: serverName },
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
if (isServerDisabled(definition)) return disabledResult("connect", serverName);
|
|
745
|
+
|
|
746
|
+
try {
|
|
747
|
+
if (state.ui) {
|
|
748
|
+
state.ui.setStatus("mcp", formatMcpStatus(state.config, `connecting to ${serverName}...`));
|
|
749
|
+
}
|
|
750
|
+
const currentConnection = state.manager.getConnection(serverName);
|
|
751
|
+
let connection = currentConnection?.status === "connected"
|
|
752
|
+
? await state.manager.reconnect(serverName, definition, currentConnection, ownedSignal)
|
|
753
|
+
: await state.manager.connect(serverName, definition, ownedSignal);
|
|
754
|
+
if (connection.status === "needs-auth") {
|
|
755
|
+
const autoAuth = await attemptAutoAuth(state, serverName, ownedSignal);
|
|
756
|
+
if (autoAuth.status === "failed") {
|
|
757
|
+
return {
|
|
758
|
+
content: [{ type: "text" as const, text: autoAuth.message }],
|
|
759
|
+
details: { mode: "connect", error: "auth_required", server: serverName, message: autoAuth.message },
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
if (autoAuth.status === "success") {
|
|
763
|
+
await state.manager.close(serverName);
|
|
764
|
+
throwIfAborted(ownedSignal);
|
|
765
|
+
connection = ownedSignal
|
|
766
|
+
? await state.manager.connect(serverName, definition, ownedSignal)
|
|
767
|
+
: await state.manager.connect(serverName, definition);
|
|
768
|
+
}
|
|
769
|
+
if (connection.status === "needs-auth") {
|
|
770
|
+
const message = getAuthRequiredMessage(state, serverName);
|
|
771
|
+
return {
|
|
772
|
+
content: [{ type: "text" as const, text: message }],
|
|
773
|
+
details: { mode: "connect", error: "auth_required", server: serverName, message },
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
const prefix = state.config.settings?.toolPrefix ?? "server";
|
|
778
|
+
const { metadata } = buildToolMetadata(connection.tools, connection.resources, definition, serverName, prefix, state.config.mcpServers, state.toolMetadata);
|
|
779
|
+
state.toolMetadata.set(serverName, metadata);
|
|
780
|
+
if (!connection.promptDiscoveryFailed) {
|
|
781
|
+
state.promptMetadata?.set(serverName, reconstructPromptMetadata(serverName, connection.prompts ?? [], prefix, definition));
|
|
782
|
+
state.promptMetadataLive?.add(serverName);
|
|
783
|
+
}
|
|
784
|
+
if (connection.instructions) {
|
|
785
|
+
state.serverInstructions.set(serverName, connection.instructions);
|
|
786
|
+
} else {
|
|
787
|
+
state.serverInstructions.delete(serverName);
|
|
788
|
+
}
|
|
789
|
+
updateMetadataCache(state, serverName);
|
|
790
|
+
notifyToolMetadataUpdated(state, serverName, "proxy-connect");
|
|
791
|
+
markKeepAliveAfterConnect(state, serverName);
|
|
792
|
+
clearFailure(state, serverName);
|
|
793
|
+
updateStatusBar(state);
|
|
794
|
+
return executeList(state, serverName);
|
|
795
|
+
} catch (error) {
|
|
796
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
797
|
+
if (!isAbortError(error, ownedSignal)) recordFailure(state, serverName, message);
|
|
798
|
+
updateStatusBar(state);
|
|
799
|
+
return {
|
|
800
|
+
content: [{ type: "text" as const, text: `Failed to connect to "${serverName}": ${message}` }],
|
|
801
|
+
details: { mode: "connect", error: isAbortError(error, ownedSignal) ? "aborted" : "connect_failed", server: serverName, message },
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
export async function executeCall(
|
|
807
|
+
state: McpExtensionState,
|
|
808
|
+
toolName: string,
|
|
809
|
+
args?: Record<string, unknown>,
|
|
810
|
+
serverOverride?: string,
|
|
811
|
+
getPiTools?: () => ToolInfo[],
|
|
812
|
+
signal?: AbortSignal,
|
|
813
|
+
origin?: "proxy" | "script",
|
|
814
|
+
): Promise<ProxyToolResult> {
|
|
815
|
+
const ownedSignal = combineAbortSignals(state.owner?.signal, signal);
|
|
816
|
+
throwIfAborted(ownedSignal);
|
|
817
|
+
let serverName: string | undefined = serverOverride;
|
|
818
|
+
let toolMeta: ToolMetadata | undefined;
|
|
819
|
+
let autoAuthAttempted = false;
|
|
820
|
+
const prefixMode = state.config.settings?.toolPrefix ?? "server";
|
|
821
|
+
const disabledCallResult = (disabledServer: string, metadata?: ToolMetadata): ProxyToolResult => {
|
|
822
|
+
if (!metadata) {
|
|
823
|
+
const message = `Server "${disabledServer}" is disabled. Run /mcp enable ${disabledServer} and /reload to enable it.`;
|
|
824
|
+
return {
|
|
825
|
+
content: [{ type: "text" as const, text: message }],
|
|
826
|
+
details: { mode: "call", error: "server_disabled", server: disabledServer, requestedTool: toolName, message },
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
const message = `Server "${disabledServer}" is disabled. Run /mcp enable ${disabledServer} and /reload to enable it.`;
|
|
830
|
+
const identity = metadata.resourceUri
|
|
831
|
+
? { server: disabledServer, resourceUri: metadata.resourceUri }
|
|
832
|
+
: { server: disabledServer, tool: metadata.originalName };
|
|
833
|
+
return {
|
|
834
|
+
content: [{ type: "text" as const, text: message }],
|
|
835
|
+
details: { mode: "call", error: "server_disabled", ...identity, message },
|
|
836
|
+
};
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
if (serverName && !state.config.mcpServers[serverName]) {
|
|
840
|
+
return {
|
|
841
|
+
content: [{ type: "text" as const, text: `Server "${serverName}" not found. Use mcp({}) to see available servers.` }],
|
|
842
|
+
details: { mode: "call", error: "server_not_found", server: serverName, requestedTool: toolName },
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
if (serverName) {
|
|
846
|
+
const match = getSingleToolMatch(state.toolMetadata.get(serverName), toolName);
|
|
847
|
+
if (match === "ambiguous") return ambiguousToolResult("call", toolName);
|
|
848
|
+
toolMeta = match;
|
|
849
|
+
if (isServerDisabled(state.config.mcpServers[serverName])) {
|
|
850
|
+
return disabledCallResult(serverName, toolMeta);
|
|
851
|
+
}
|
|
852
|
+
} else {
|
|
853
|
+
const exactMatches = getEnabledToolMatches(state, toolName, true);
|
|
854
|
+
if (exactMatches.length > 1) return ambiguousToolResult("call", toolName);
|
|
855
|
+
if (exactMatches.length === 0 && getEnabledToolMatches(state, toolName, false).length > 1) {
|
|
856
|
+
return ambiguousToolResult("call", toolName);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
let disabledMatch: { serverName: string; toolMeta: ToolMetadata } | undefined;
|
|
860
|
+
for (const [server, metadata] of state.toolMetadata.entries()) {
|
|
861
|
+
const found = metadata.find(tool => tool.name === toolName);
|
|
862
|
+
if (!found) continue;
|
|
863
|
+
if (isServerDisabled(state.config.mcpServers[server])) {
|
|
864
|
+
disabledMatch ??= { serverName: server, toolMeta: found };
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
serverName = server;
|
|
868
|
+
toolMeta = found;
|
|
869
|
+
break;
|
|
870
|
+
}
|
|
871
|
+
if (!toolMeta && !disabledMatch) {
|
|
872
|
+
for (const [server, metadata] of state.toolMetadata.entries()) {
|
|
873
|
+
const found = findToolByName(metadata, toolName);
|
|
874
|
+
if (!found) continue;
|
|
875
|
+
if (isServerDisabled(state.config.mcpServers[server])) {
|
|
876
|
+
disabledMatch ??= { serverName: server, toolMeta: found };
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
serverName = server;
|
|
880
|
+
toolMeta = found;
|
|
881
|
+
break;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
if (!toolMeta && disabledMatch) return disabledCallResult(disabledMatch.serverName, disabledMatch.toolMeta);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
if (serverName && !toolMeta) {
|
|
888
|
+
const connected = await lazyConnect(state, serverName, ownedSignal);
|
|
889
|
+
if (connected) {
|
|
890
|
+
const match = getSingleToolMatch(state.toolMetadata.get(serverName), toolName);
|
|
891
|
+
if (match === "ambiguous") return ambiguousToolResult("call", toolName);
|
|
892
|
+
toolMeta = match;
|
|
893
|
+
} else {
|
|
894
|
+
const needsAuthConnection = state.manager.getConnection(serverName);
|
|
895
|
+
if (needsAuthConnection?.status === "needs-auth") {
|
|
896
|
+
if (!autoAuthAttempted) {
|
|
897
|
+
autoAuthAttempted = true;
|
|
898
|
+
const autoAuth = await attemptAutoAuth(state, serverName, ownedSignal);
|
|
899
|
+
if (autoAuth.status === "failed") {
|
|
900
|
+
return {
|
|
901
|
+
content: [{ type: "text" as const, text: autoAuth.message }],
|
|
902
|
+
details: { mode: "call", error: "auth_required", server: serverName, requestedTool: toolName, message: autoAuth.message },
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
if (autoAuth.status === "success") {
|
|
906
|
+
await state.manager.close(serverName);
|
|
907
|
+
clearFailure(state, serverName);
|
|
908
|
+
const connectedAfterAuth = await lazyConnect(state, serverName, ownedSignal);
|
|
909
|
+
if (connectedAfterAuth) {
|
|
910
|
+
const match = getSingleToolMatch(state.toolMetadata.get(serverName), toolName);
|
|
911
|
+
if (match === "ambiguous") return ambiguousToolResult("call", toolName);
|
|
912
|
+
toolMeta = match;
|
|
913
|
+
if (!toolMeta) {
|
|
914
|
+
const suggestions = rankSuggestions(state, toolName, 5);
|
|
915
|
+
const suggestionText = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(", ")}` : "";
|
|
916
|
+
return {
|
|
917
|
+
content: [{ type: "text" as const, text: `Tool "${toolName}" not found on "${serverName}" after reconnect.${suggestionText}` }],
|
|
918
|
+
details: { mode: "call", error: "tool_not_found_after_reconnect", server: serverName, requestedTool: toolName, suggestions },
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
if (!toolMeta && state.manager.getConnection(serverName)?.status === "needs-auth") {
|
|
926
|
+
const message = getAuthRequiredMessage(state, serverName);
|
|
927
|
+
return {
|
|
928
|
+
content: [{ type: "text" as const, text: message }],
|
|
929
|
+
details: { mode: "call", error: "auth_required", server: serverName, requestedTool: toolName, message },
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
if (!toolMeta) {
|
|
935
|
+
const failedAgo = getFailureAgeSeconds(state, serverName);
|
|
936
|
+
if (failedAgo !== null) {
|
|
937
|
+
return {
|
|
938
|
+
content: [{ type: "text" as const, text: `Server "${serverName}" not available (last failed ${failedAgo}s ago)` }],
|
|
939
|
+
details: { mode: "call", error: "server_backoff", server: serverName, requestedTool: toolName },
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
let prefixMatchedServer: string | undefined;
|
|
947
|
+
|
|
948
|
+
if (!serverName && !toolMeta && prefixMode !== "none") {
|
|
949
|
+
const lazyExactMatches: { serverName: string; toolMeta: ToolMetadata }[] = [];
|
|
950
|
+
const lazyFallbackMatches: { serverName: string; toolMeta: ToolMetadata }[] = [];
|
|
951
|
+
const candidates = Object.keys(state.config.mcpServers)
|
|
952
|
+
.filter(name => !isServerDisabled(state.config.mcpServers[name]))
|
|
953
|
+
.map(name => ({ name, prefix: getServerPrefix(name, prefixMode) }))
|
|
954
|
+
.filter(c => c.prefix && toolName.startsWith(c.prefix + "_"))
|
|
955
|
+
.sort((a, b) => b.prefix.length - a.prefix.length);
|
|
956
|
+
|
|
957
|
+
for (const { name: configuredServer } of candidates) {
|
|
958
|
+
const existingConnection = state.manager.getConnection(configuredServer);
|
|
959
|
+
const failedAgo = getFailureAgeSeconds(state, configuredServer);
|
|
960
|
+
if (failedAgo !== null && existingConnection?.status !== "needs-auth") continue;
|
|
961
|
+
|
|
962
|
+
let connected = await lazyConnect(state, configuredServer, ownedSignal);
|
|
963
|
+
if (!connected && state.manager.getConnection(configuredServer)?.status === "needs-auth" && !autoAuthAttempted) {
|
|
964
|
+
autoAuthAttempted = true;
|
|
965
|
+
const autoAuth = await attemptAutoAuth(state, configuredServer, ownedSignal);
|
|
966
|
+
if (autoAuth.status === "failed") {
|
|
967
|
+
return {
|
|
968
|
+
content: [{ type: "text" as const, text: autoAuth.message }],
|
|
969
|
+
details: { mode: "call", error: "auth_required", server: configuredServer, requestedTool: toolName, message: autoAuth.message },
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
if (autoAuth.status === "success") {
|
|
973
|
+
await state.manager.close(configuredServer);
|
|
974
|
+
clearFailure(state, configuredServer);
|
|
975
|
+
connected = await lazyConnect(state, configuredServer, ownedSignal);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
if (!connected) continue;
|
|
980
|
+
if (!prefixMatchedServer) prefixMatchedServer = configuredServer;
|
|
981
|
+
const metadata = state.toolMetadata.get(configuredServer);
|
|
982
|
+
const exactMatches = getToolMatches(metadata, toolName, true);
|
|
983
|
+
if (exactMatches.length > 1) return ambiguousToolResult("call", toolName);
|
|
984
|
+
if (exactMatches.length === 1) {
|
|
985
|
+
lazyExactMatches.push({ serverName: configuredServer, toolMeta: exactMatches[0]! });
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
const fallbackMatches = getToolMatches(metadata, toolName, false);
|
|
989
|
+
if (fallbackMatches.length > 1) return ambiguousToolResult("call", toolName);
|
|
990
|
+
if (fallbackMatches.length === 1) lazyFallbackMatches.push({ serverName: configuredServer, toolMeta: fallbackMatches[0]! });
|
|
991
|
+
}
|
|
992
|
+
const lazyMatches = lazyExactMatches.length > 0 ? lazyExactMatches : lazyFallbackMatches;
|
|
993
|
+
if (lazyMatches.length > 1) return ambiguousToolResult("call", toolName);
|
|
994
|
+
if (lazyMatches.length === 1) {
|
|
995
|
+
serverName = lazyMatches[0]!.serverName;
|
|
996
|
+
toolMeta = lazyMatches[0]!.toolMeta;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
if (!serverName || !toolMeta) {
|
|
1001
|
+
const nativeTool = !serverOverride
|
|
1002
|
+
? getPiTools?.().find((tool) => tool.name === toolName && tool.name !== "mcp")
|
|
1003
|
+
: undefined;
|
|
1004
|
+
if (nativeTool) {
|
|
1005
|
+
return {
|
|
1006
|
+
content: [{ type: "text" as const, text: `"${toolName}" is a native Pi tool. Call ${toolName} directly instead of using mcp({ tool: "${toolName}" }).` }],
|
|
1007
|
+
details: { mode: "call", error: "native_tool", requestedTool: toolName },
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
const hintServer = serverName ?? prefixMatchedServer;
|
|
1012
|
+
const available = hintServer ? getToolNames(state, hintServer) : [];
|
|
1013
|
+
let msg = `Tool "${toolName}" not found.`;
|
|
1014
|
+
if (available.length > 0) {
|
|
1015
|
+
msg += ` Server "${hintServer}" has: ${available.join(", ")}`;
|
|
1016
|
+
} else {
|
|
1017
|
+
msg += ` Use mcp({ search: "..." }) to search.`;
|
|
1018
|
+
}
|
|
1019
|
+
const suggestions = rankSuggestions(state, toolName, 5);
|
|
1020
|
+
if (suggestions.length > 0) msg += ` Did you mean: ${suggestions.join(", ")}`;
|
|
1021
|
+
return {
|
|
1022
|
+
content: [{ type: "text" as const, text: msg }],
|
|
1023
|
+
details: { mode: "call", error: "tool_not_found", requestedTool: toolName, hintServer, suggestions },
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
const callIdentity = toolMeta.resourceUri
|
|
1028
|
+
? { server: serverName, resourceUri: toolMeta.resourceUri }
|
|
1029
|
+
: { server: serverName, tool: toolMeta.originalName };
|
|
1030
|
+
|
|
1031
|
+
let connection = state.manager.getConnection(serverName);
|
|
1032
|
+
if (connection?.status === "needs-auth") {
|
|
1033
|
+
if (!autoAuthAttempted) {
|
|
1034
|
+
autoAuthAttempted = true;
|
|
1035
|
+
const autoAuth = await attemptAutoAuth(state, serverName, ownedSignal);
|
|
1036
|
+
if (autoAuth.status === "failed") {
|
|
1037
|
+
return {
|
|
1038
|
+
content: [{ type: "text" as const, text: autoAuth.message }],
|
|
1039
|
+
details: { mode: "call", error: "auth_required", ...callIdentity, message: autoAuth.message },
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
if (autoAuth.status === "success") {
|
|
1043
|
+
await state.manager.close(serverName);
|
|
1044
|
+
clearFailure(state, serverName);
|
|
1045
|
+
connection = state.manager.getConnection(serverName);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
if (connection?.status === "needs-auth") {
|
|
1050
|
+
const message = getAuthRequiredMessage(state, serverName);
|
|
1051
|
+
return {
|
|
1052
|
+
content: [{ type: "text" as const, text: message }],
|
|
1053
|
+
details: { mode: "call", error: "auth_required", ...callIdentity, message },
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if (!connection || connection.status !== "connected") {
|
|
1058
|
+
const failedAgo = getFailureAgeSeconds(state, serverName);
|
|
1059
|
+
if (failedAgo !== null) {
|
|
1060
|
+
return {
|
|
1061
|
+
content: [{ type: "text" as const, text: `Server "${serverName}" not available (last failed ${failedAgo}s ago)` }],
|
|
1062
|
+
details: { mode: "call", error: "server_backoff", ...callIdentity },
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
const definition = state.config.mcpServers[serverName];
|
|
1067
|
+
if (!definition) {
|
|
1068
|
+
return {
|
|
1069
|
+
content: [{ type: "text" as const, text: `Server "${serverName}" not connected` }],
|
|
1070
|
+
details: { mode: "call", error: "server_not_connected", ...callIdentity },
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
try {
|
|
1075
|
+
if (state.ui) {
|
|
1076
|
+
state.ui.setStatus("mcp", formatMcpStatus(state.config, `connecting to ${serverName}...`));
|
|
1077
|
+
}
|
|
1078
|
+
connection = await state.manager.connect(serverName, definition, ownedSignal);
|
|
1079
|
+
if (connection.status === "needs-auth") {
|
|
1080
|
+
if (!autoAuthAttempted) {
|
|
1081
|
+
autoAuthAttempted = true;
|
|
1082
|
+
const autoAuth = await attemptAutoAuth(state, serverName, ownedSignal);
|
|
1083
|
+
if (autoAuth.status === "failed") {
|
|
1084
|
+
return {
|
|
1085
|
+
content: [{ type: "text" as const, text: autoAuth.message }],
|
|
1086
|
+
details: { mode: "call", error: "auth_required", ...callIdentity, message: autoAuth.message },
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
if (autoAuth.status === "success") {
|
|
1090
|
+
await state.manager.close(serverName);
|
|
1091
|
+
connection = await state.manager.connect(serverName, definition, ownedSignal);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
if (connection.status === "needs-auth") {
|
|
1096
|
+
const message = getAuthRequiredMessage(state, serverName);
|
|
1097
|
+
return {
|
|
1098
|
+
content: [{ type: "text" as const, text: message }],
|
|
1099
|
+
details: { mode: "call", error: "auth_required", ...callIdentity, message },
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
clearFailure(state, serverName);
|
|
1104
|
+
updateServerMetadata(state, serverName);
|
|
1105
|
+
updateMetadataCache(state, serverName);
|
|
1106
|
+
notifyToolMetadataUpdated(state, serverName, "proxy-call-reconnect");
|
|
1107
|
+
markKeepAliveAfterConnect(state, serverName);
|
|
1108
|
+
updateStatusBar(state);
|
|
1109
|
+
const match = getSingleToolMatch(state.toolMetadata.get(serverName), toolName);
|
|
1110
|
+
if (match === "ambiguous") return ambiguousToolResult("call", toolName);
|
|
1111
|
+
toolMeta = match;
|
|
1112
|
+
if (!toolMeta) {
|
|
1113
|
+
const available = getToolNames(state, serverName);
|
|
1114
|
+
const hint = available.length > 0
|
|
1115
|
+
? `Available tools on "${serverName}": ${available.join(", ")}`
|
|
1116
|
+
: `Server "${serverName}" has no tools.`;
|
|
1117
|
+
const suggestions = rankSuggestions(state, toolName, 5);
|
|
1118
|
+
const suggestionText = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(", ")}` : "";
|
|
1119
|
+
return {
|
|
1120
|
+
content: [{ type: "text" as const, text: `Tool "${toolName}" not found on "${serverName}" after reconnect. ${hint}${suggestionText}` }],
|
|
1121
|
+
details: { mode: "call", error: "tool_not_found_after_reconnect", server: serverName, requestedTool: toolName, suggestions },
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
} catch (error) {
|
|
1125
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1126
|
+
if (!isAbortError(error, ownedSignal)) recordFailure(state, serverName, message);
|
|
1127
|
+
updateStatusBar(state);
|
|
1128
|
+
return {
|
|
1129
|
+
content: [{ type: "text" as const, text: `Failed to connect to "${serverName}": ${message}` }],
|
|
1130
|
+
details: { mode: "call", error: isAbortError(error, ownedSignal) ? "aborted" : "connect_failed", ...callIdentity, message },
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
if (isServerDisabled(state.config.mcpServers[serverName])) {
|
|
1136
|
+
return disabledCallResult(serverName, toolMeta);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
const approval = await ensureToolCallApproved(
|
|
1140
|
+
state,
|
|
1141
|
+
serverName,
|
|
1142
|
+
toolMeta,
|
|
1143
|
+
args,
|
|
1144
|
+
ownedSignal,
|
|
1145
|
+
origin ?? (toolMeta.resourceUri ? "resource" : "proxy"),
|
|
1146
|
+
);
|
|
1147
|
+
if (approval.ok === false) {
|
|
1148
|
+
const denied = approval.reason === "denied";
|
|
1149
|
+
const message = denied
|
|
1150
|
+
? `The user declined approval to run MCP tool "${toolMeta.originalName}" on server "${serverName}".`
|
|
1151
|
+
: `MCP tool "${toolMeta.originalName}" on server "${serverName}" is approval-gated and requires an interactive session.`;
|
|
1152
|
+
return {
|
|
1153
|
+
content: [{ type: "text" as const, text: message }],
|
|
1154
|
+
details: {
|
|
1155
|
+
mode: "call",
|
|
1156
|
+
error: denied ? "approval_denied" : "approval_required",
|
|
1157
|
+
server: serverName,
|
|
1158
|
+
tool: toolMeta.originalName,
|
|
1159
|
+
},
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
let uiSession: UiSessionRuntime | null = null;
|
|
1164
|
+
const requestOptions = state.manager.getRequestOptions?.(serverName, ownedSignal) ?? (ownedSignal ? { signal: ownedSignal } : undefined);
|
|
1165
|
+
|
|
1166
|
+
const outputGuardOptions = resolveMcpOutputGuardOptions(state.config.settings);
|
|
1167
|
+
const recoverAuthConnection = async () => {
|
|
1168
|
+
const current = state.manager.getConnection(serverName);
|
|
1169
|
+
if (current?.status === "connected") return current;
|
|
1170
|
+
|
|
1171
|
+
if (!autoAuthAttempted) {
|
|
1172
|
+
autoAuthAttempted = true;
|
|
1173
|
+
const autoAuth = await attemptAutoAuth(state, serverName, ownedSignal);
|
|
1174
|
+
if (autoAuth.status === "failed") {
|
|
1175
|
+
throw new SessionRecoveryAuthRequiredError(serverName, autoAuth.message);
|
|
1176
|
+
}
|
|
1177
|
+
if (autoAuth.status === "success") {
|
|
1178
|
+
const definition = state.config.mcpServers[serverName];
|
|
1179
|
+
if (!definition) return undefined;
|
|
1180
|
+
const afterAuth = state.manager.getConnection(serverName);
|
|
1181
|
+
if (afterAuth?.status === "connected") return afterAuth;
|
|
1182
|
+
if (afterAuth?.status === "needs-auth") {
|
|
1183
|
+
await state.manager.close(serverName);
|
|
1184
|
+
}
|
|
1185
|
+
clearFailure(state, serverName);
|
|
1186
|
+
connection = await state.manager.connect(serverName, definition, ownedSignal);
|
|
1187
|
+
return connection;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return state.manager.getConnection(serverName);
|
|
1191
|
+
};
|
|
1192
|
+
|
|
1193
|
+
try {
|
|
1194
|
+
state.manager.touch(serverName);
|
|
1195
|
+
state.manager.incrementInFlight(serverName);
|
|
1196
|
+
|
|
1197
|
+
if (toolMeta.resourceUri) {
|
|
1198
|
+
const result = await withSessionRecovery<ClientReadResourceResult>(
|
|
1199
|
+
{
|
|
1200
|
+
manager: state.manager,
|
|
1201
|
+
config: state.config,
|
|
1202
|
+
...(ownedSignal ? { signal: ownedSignal } : {}),
|
|
1203
|
+
onNeedsAuth: recoverAuthConnection,
|
|
1204
|
+
},
|
|
1205
|
+
serverName,
|
|
1206
|
+
(conn) => conn.client.readResource({ uri: toolMeta.resourceUri! }, requestOptions),
|
|
1207
|
+
);
|
|
1208
|
+
const content = transformMcpResourceContents(result.contents ?? [], state.owner?.signal);
|
|
1209
|
+
const guarded = await guardMcpOutput(content.length > 0 ? content : [{ type: "text" as const, text: "(empty resource)" }], outputGuardOptions);
|
|
1210
|
+
return {
|
|
1211
|
+
content: guarded.content,
|
|
1212
|
+
details: { mode: "call", ...callIdentity, ...guardedMcpDetails(guarded) },
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
uiSession = toolMeta.uiResourceUri
|
|
1217
|
+
? await maybeStartUiSession(state, {
|
|
1218
|
+
serverName,
|
|
1219
|
+
toolName: toolMeta.originalName,
|
|
1220
|
+
toolArgs: args ?? {},
|
|
1221
|
+
uiResourceUri: toolMeta.uiResourceUri,
|
|
1222
|
+
...(toolMeta.uiStreamMode !== undefined ? { streamMode: toolMeta.uiStreamMode } : {}),
|
|
1223
|
+
...(signal ? { signal } : {}),
|
|
1224
|
+
onNeedsAuth: recoverAuthConnection,
|
|
1225
|
+
})
|
|
1226
|
+
: null;
|
|
1227
|
+
|
|
1228
|
+
const result = await withSessionRecovery<ClientCallToolResult>(
|
|
1229
|
+
{
|
|
1230
|
+
manager: state.manager,
|
|
1231
|
+
config: state.config,
|
|
1232
|
+
...(ownedSignal ? { signal: ownedSignal } : {}),
|
|
1233
|
+
onNeedsAuth: recoverAuthConnection,
|
|
1234
|
+
},
|
|
1235
|
+
serverName,
|
|
1236
|
+
(conn) => abortable(conn.client.callTool({
|
|
1237
|
+
name: toolMeta.originalName,
|
|
1238
|
+
arguments: args ?? {},
|
|
1239
|
+
_meta: uiSession?.requestMeta,
|
|
1240
|
+
}, requestOptions), ownedSignal),
|
|
1241
|
+
);
|
|
1242
|
+
|
|
1243
|
+
if (toolMeta.uiResourceUri) {
|
|
1244
|
+
uiSession?.sendToolResult(result as unknown as import("@modelcontextprotocol/client").CallToolResult);
|
|
1245
|
+
|
|
1246
|
+
if (result.isError) {
|
|
1247
|
+
const mcpContent = (result.content ?? []) as McpContent[];
|
|
1248
|
+
const content = transformMcpContent(mcpContent, state.owner?.signal);
|
|
1249
|
+
const outputContent = content.length > 0 ? content : [{ type: "text" as const, text: "(empty result)" }];
|
|
1250
|
+
const schemaText = toolMeta.inputSchema ? `\n\nExpected parameters:\n${formatSchema(toolMeta.inputSchema)}` : "";
|
|
1251
|
+
const guarded = await guardMcpOutput(outputContent, { ...outputGuardOptions, prefix: "Error: ", suffix: schemaText, emptyTextFallback: "Tool execution failed", rawMcpResult: result });
|
|
1252
|
+
return {
|
|
1253
|
+
content: guarded.content,
|
|
1254
|
+
details: { mode: "call", error: "tool_error", ...callIdentity, ...guardedMcpDetails(guarded) },
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
const content = resolveMcpResultContent(result as Record<string, unknown>, state.owner?.signal);
|
|
1259
|
+
const outputContent = content.length > 0 ? content : [{ type: "text" as const, text: "(empty result)" }];
|
|
1260
|
+
const uiSummary = summarizeUiSessionResult(uiSession);
|
|
1261
|
+
const guarded = await guardMcpOutput(outputContent, { ...outputGuardOptions, suffix: `\n\n${uiSummary.message}`, rawMcpResult: result });
|
|
1262
|
+
return {
|
|
1263
|
+
content: guarded.content,
|
|
1264
|
+
details: {
|
|
1265
|
+
mode: "call",
|
|
1266
|
+
...guardedMcpDetails(guarded),
|
|
1267
|
+
...callIdentity,
|
|
1268
|
+
uiOpen: uiSummary.uiOpen,
|
|
1269
|
+
uiViewer: uiSummary.uiViewer,
|
|
1270
|
+
uiUrl: uiSummary.uiUrl,
|
|
1271
|
+
},
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
if (result.isError) {
|
|
1276
|
+
const mcpContent = (result.content ?? []) as McpContent[];
|
|
1277
|
+
const content = transformMcpContent(mcpContent, state.owner?.signal);
|
|
1278
|
+
const outputContent = content.length > 0 ? content : [{ type: "text" as const, text: "(empty result)" }];
|
|
1279
|
+
const schemaText = toolMeta.inputSchema ? `\n\nExpected parameters:\n${formatSchema(toolMeta.inputSchema)}` : "";
|
|
1280
|
+
const guarded = await guardMcpOutput(outputContent, { ...outputGuardOptions, prefix: "Error: ", suffix: schemaText, emptyTextFallback: "Tool execution failed", rawMcpResult: result });
|
|
1281
|
+
return {
|
|
1282
|
+
content: guarded.content,
|
|
1283
|
+
details: { mode: "call", error: "tool_error", ...callIdentity, ...guardedMcpDetails(guarded) },
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
const content = resolveMcpResultContent(result as Record<string, unknown>, state.owner?.signal);
|
|
1288
|
+
const outputContent = content.length > 0 ? content : [{ type: "text" as const, text: "(empty result)" }];
|
|
1289
|
+
const guarded = await guardMcpOutput(outputContent, { ...outputGuardOptions, rawMcpResult: result });
|
|
1290
|
+
return {
|
|
1291
|
+
content: guarded.content,
|
|
1292
|
+
details: { mode: "call", ...guardedMcpDetails(guarded), ...callIdentity },
|
|
1293
|
+
};
|
|
1294
|
+
} catch (error) {
|
|
1295
|
+
if (error instanceof SessionRecoveryAuthRequiredError) {
|
|
1296
|
+
const message = error.authMessage ?? getAuthRequiredMessage(state, serverName);
|
|
1297
|
+
uiSession?.sendToolCancelled(message);
|
|
1298
|
+
return {
|
|
1299
|
+
content: [{ type: "text" as const, text: message }],
|
|
1300
|
+
details: { mode: "call", error: "auth_required", ...callIdentity, message, autoAuthAttempted },
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
if (error instanceof UrlElicitationRequiredError) {
|
|
1304
|
+
const action = await state.manager.handleUrlElicitationRequired(serverName, error);
|
|
1305
|
+
const message = action === "accept"
|
|
1306
|
+
? "The original MCP tool did not run. Complete the opened browser interaction, then retry the tool."
|
|
1307
|
+
: `The URL interaction was ${action === "decline" ? "declined" : "cancelled"}.`;
|
|
1308
|
+
uiSession?.sendToolCancelled(message);
|
|
1309
|
+
return {
|
|
1310
|
+
content: [{ type: "text" as const, text: message }],
|
|
1311
|
+
details: { mode: "call", error: "url_elicitation_required", ...callIdentity, action },
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1315
|
+
uiSession?.sendToolCancelled(message);
|
|
1316
|
+
|
|
1317
|
+
const schemaText = toolMeta.inputSchema ? `\n\nExpected parameters:\n${formatSchema(toolMeta.inputSchema)}` : "";
|
|
1318
|
+
const guarded = await guardMcpOutput([{ type: "text" as const, text: message }], { ...outputGuardOptions, prefix: "Failed to call tool: ", suffix: schemaText });
|
|
1319
|
+
|
|
1320
|
+
return {
|
|
1321
|
+
content: guarded.content,
|
|
1322
|
+
details: { mode: "call", error: isAbortError(error, ownedSignal) ? "aborted" : "call_failed", ...callIdentity, message: guarded.outputGuard ? "output truncated; see outputGuard.fullOutputPath" : message, ...guardedMcpDetails(guarded) },
|
|
1323
|
+
};
|
|
1324
|
+
} finally {
|
|
1325
|
+
if (uiSession?.reused) {
|
|
1326
|
+
uiSession.close();
|
|
1327
|
+
}
|
|
1328
|
+
state.manager.decrementInFlight(serverName);
|
|
1329
|
+
state.manager.touch(serverName);
|
|
1330
|
+
}
|
|
1331
|
+
}
|