@duckmind/dm-linux-x64 0.65.8 → 0.66.2
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/dm +2 -2
- package/extensions/.dm-extensions.json +14 -548
- package/extensions/dm-lens/clients/dispatch/runners/utils/runner-helpers.js +1 -1
- package/extensions/dm-mcp-adapter/mcp-keyring-helper.cjs +1 -1
- package/extensions/dm-ponytail/hooks/ponytail-activate.js +1 -1
- package/extensions/dm-ponytail/hooks/ponytail-instructions.js +1 -1
- package/extensions/dm-subagents/src/extension/tool-activation.js +7 -2
- package/extensions/dm-subagents/src/runs/background/runner-aliases.js +2 -2
- package/extensions/dm-subagents/src/runs/foreground/prompt-audit.js +4 -1
- package/extensions/dm-subagents/src/runs/shared/child-session.js +8 -6
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +5 -1
- package/extensions/dm-subagents/src/watchdog/permission-arbiter.js +9 -1
- package/extensions/dm-subagents/src/watchdog/review.js +4 -1
- package/extensions/dm-web-access/tool-activation.js +0 -1
- package/package.json +1 -1
- package/extensions/dm-lens/dist/clients/actionable-warnings-logger.js +0 -24
- package/extensions/dm-lens/dist/clients/actionable-warnings.js +0 -1014
- package/extensions/dm-lens/dist/clients/advisory-provenance.js +0 -385
- package/extensions/dm-lens/dist/clients/agent-behavior-client.js +0 -94
- package/extensions/dm-lens/dist/clients/agent-nudge.js +0 -151
- package/extensions/dm-lens/dist/clients/analysed-root.js +0 -1
- package/extensions/dm-lens/dist/clients/ast-grep-client.js +0 -576
- package/extensions/dm-lens/dist/clients/ast-grep-rule-manager.js +0 -114
- package/extensions/dm-lens/dist/clients/ast-grep-tool-logger.js +0 -85
- package/extensions/dm-lens/dist/clients/ast-grep-types.js +0 -1
- package/extensions/dm-lens/dist/clients/ast-grep-yaml-synth.js +0 -109
- package/extensions/dm-lens/dist/clients/atomic-write-staging.js +0 -66
- package/extensions/dm-lens/dist/clients/atomic-write.js +0 -37
- package/extensions/dm-lens/dist/clients/availability-probe-flight.js +0 -11
- package/extensions/dm-lens/dist/clients/bash-file-access.js +0 -830
- package/extensions/dm-lens/dist/clients/biome-client.js +0 -221
- package/extensions/dm-lens/dist/clients/blocker-freshness.js +0 -385
- package/extensions/dm-lens/dist/clients/blocker-past-eof.js +0 -49
- package/extensions/dm-lens/dist/clients/bootstrap.js +0 -246
- package/extensions/dm-lens/dist/clients/bounded-cache.js +0 -105
- package/extensions/dm-lens/dist/clients/bounded-pid-file-lock.js +0 -173
- package/extensions/dm-lens/dist/clients/bounded-telemetry.js +0 -104
- package/extensions/dm-lens/dist/clients/build-identity.js +0 -45
- package/extensions/dm-lens/dist/clients/bundled-resource-health.js +0 -41
- package/extensions/dm-lens/dist/clients/bus-events-logger.js +0 -48
- package/extensions/dm-lens/dist/clients/bus-publish.js +0 -117
- package/extensions/dm-lens/dist/clients/cache/rule-cache.js +0 -103
- package/extensions/dm-lens/dist/clients/cache-manager.js +0 -340
- package/extensions/dm-lens/dist/clients/cache-observability.js +0 -847
- package/extensions/dm-lens/dist/clients/call-graph.js +0 -628
- package/extensions/dm-lens/dist/clients/cargo-manifest.js +0 -151
- package/extensions/dm-lens/dist/clients/cascade-budget.js +0 -52
- package/extensions/dm-lens/dist/clients/cascade-format.js +0 -160
- package/extensions/dm-lens/dist/clients/cascade-logger.js +0 -22
- package/extensions/dm-lens/dist/clients/cascade-types.js +0 -1
- package/extensions/dm-lens/dist/clients/child-unref.js +0 -59
- package/extensions/dm-lens/dist/clients/code-quality-warnings.js +0 -192
- package/extensions/dm-lens/dist/clients/codebase-model.js +0 -110
- package/extensions/dm-lens/dist/clients/collateral-test-role.js +0 -8
- package/extensions/dm-lens/dist/clients/complexity-client.js +0 -398
- package/extensions/dm-lens/dist/clients/config-core/deny.js +0 -117
- package/extensions/dm-lens/dist/clients/config-core/index.js +0 -2
- package/extensions/dm-lens/dist/clients/config-core/merge.js +0 -228
- package/extensions/dm-lens/dist/clients/config-core/normalize.js +0 -217
- package/extensions/dm-lens/dist/clients/config-core/process-spec.js +0 -147
- package/extensions/dm-lens/dist/clients/config-core/provenance.js +0 -54
- package/extensions/dm-lens/dist/clients/config-core/records.js +0 -79
- package/extensions/dm-lens/dist/clients/config-core/resolve.js +0 -48
- package/extensions/dm-lens/dist/clients/config-core/safe-object.js +0 -22
- package/extensions/dm-lens/dist/clients/config-core/schema.js +0 -90
- package/extensions/dm-lens/dist/clients/config-diagnostic-codes.js +0 -90
- package/extensions/dm-lens/dist/clients/config-locations.js +0 -175
- package/extensions/dm-lens/dist/clients/config-resolve.js +0 -359
- package/extensions/dm-lens/dist/clients/config-schema.js +0 -128
- package/extensions/dm-lens/dist/clients/config-warn.js +0 -146
- package/extensions/dm-lens/dist/clients/console-guard-install.js +0 -4
- package/extensions/dm-lens/dist/clients/cooperative-budget.js +0 -36
- package/extensions/dm-lens/dist/clients/dead-code-client.js +0 -342
- package/extensions/dm-lens/dist/clients/dead-code-logger.js +0 -18
- package/extensions/dm-lens/dist/clients/deadline-utils.js +0 -117
- package/extensions/dm-lens/dist/clients/debug-handles.js +0 -121
- package/extensions/dm-lens/dist/clients/debug-heap.js +0 -80
- package/extensions/dm-lens/dist/clients/deferred-lsp-work.js +0 -33
- package/extensions/dm-lens/dist/clients/degradation-ledger.js +0 -272
- package/extensions/dm-lens/dist/clients/demoted-finding-render.js +0 -61
- package/extensions/dm-lens/dist/clients/dependency-checker.js +0 -525
- package/extensions/dm-lens/dist/clients/deps/ast-grep-napi.js +0 -17
- package/extensions/dm-lens/dist/clients/deps/dm-host-deps.js +0 -10
- package/extensions/dm-lens/dist/clients/deps/dm-tui-compat.js +0 -58
- package/extensions/dm-lens/dist/clients/deps/js-yaml.js +0 -7
- package/extensions/dm-lens/dist/clients/deps/minimatch.js +0 -6
- package/extensions/dm-lens/dist/clients/deps/pidusage.js +0 -5
- package/extensions/dm-lens/dist/clients/deps/typebox.js +0 -5
- package/extensions/dm-lens/dist/clients/deps/vscode-jsonrpc.js +0 -8
- package/extensions/dm-lens/dist/clients/deps/web-tree-sitter.js +0 -11
- package/extensions/dm-lens/dist/clients/diagnostic-dispositions.js +0 -318
- package/extensions/dm-lens/dist/clients/diagnostic-line-freshness.js +0 -144
- package/extensions/dm-lens/dist/clients/diagnostic-logger.js +0 -60
- package/extensions/dm-lens/dist/clients/diagnostic-tracker.js +0 -89
- package/extensions/dm-lens/dist/clients/diagnostics-publish.js +0 -134
- package/extensions/dm-lens/dist/clients/dispatch/ast-grep-catalog.js +0 -16
- package/extensions/dm-lens/dist/clients/dispatch/auxiliary-lsp.js +0 -158
- package/extensions/dm-lens/dist/clients/dispatch/collect-later-tier.js +0 -25
- package/extensions/dm-lens/dist/clients/dispatch/diagnostic-taxonomy.js +0 -58
- package/extensions/dm-lens/dist/clients/dispatch/dispatcher.js +0 -953
- package/extensions/dm-lens/dist/clients/dispatch/fact-provider-types.js +0 -1
- package/extensions/dm-lens/dist/clients/dispatch/fact-rule-runner.js +0 -17
- package/extensions/dm-lens/dist/clients/dispatch/fact-runner.js +0 -18
- package/extensions/dm-lens/dist/clients/dispatch/fact-scheduler.js +0 -52
- package/extensions/dm-lens/dist/clients/dispatch/fact-store.js +0 -199
- package/extensions/dm-lens/dist/clients/dispatch/facts/comment-facts.js +0 -20
- package/extensions/dm-lens/dist/clients/dispatch/facts/file-content.js +0 -18
- package/extensions/dm-lens/dist/clients/dispatch/facts/function-facts.js +0 -281
- package/extensions/dm-lens/dist/clients/dispatch/facts/import-facts.js +0 -169
- package/extensions/dm-lens/dist/clients/dispatch/facts/tree-sitter-facts.js +0 -19
- package/extensions/dm-lens/dist/clients/dispatch/facts/try-catch-facts.js +0 -95
- package/extensions/dm-lens/dist/clients/dispatch/finding-policy.js +0 -159
- package/extensions/dm-lens/dist/clients/dispatch/indent-detect.js +0 -227
- package/extensions/dm-lens/dist/clients/dispatch/inline-suppressions.js +0 -52
- package/extensions/dm-lens/dist/clients/dispatch/integration.js +0 -1463
- package/extensions/dm-lens/dist/clients/dispatch/lazy.js +0 -8
- package/extensions/dm-lens/dist/clients/dispatch/pending-runner-findings.js +0 -75
- package/extensions/dm-lens/dist/clients/dispatch/plan.js +0 -278
- package/extensions/dm-lens/dist/clients/dispatch/priorities.js +0 -14
- package/extensions/dm-lens/dist/clients/dispatch/rule-id-normalize.js +0 -42
- package/extensions/dm-lens/dist/clients/dispatch/rule-ignores.js +0 -21
- package/extensions/dm-lens/dist/clients/dispatch/rule-policy.js +0 -73
- package/extensions/dm-lens/dist/clients/dispatch/rules/async-noise.js +0 -31
- package/extensions/dm-lens/dist/clients/dispatch/rules/async-unnecessary-wrapper.js +0 -27
- package/extensions/dm-lens/dist/clients/dispatch/rules/cors-wildcard.js +0 -35
- package/extensions/dm-lens/dist/clients/dispatch/rules/error-obscuring.js +0 -29
- package/extensions/dm-lens/dist/clients/dispatch/rules/error-swallowing.js +0 -29
- package/extensions/dm-lens/dist/clients/dispatch/rules/framework-call-noise.js +0 -31
- package/extensions/dm-lens/dist/clients/dispatch/rules/high-complexity.js +0 -56
- package/extensions/dm-lens/dist/clients/dispatch/rules/high-fan-out.js +0 -45
- package/extensions/dm-lens/dist/clients/dispatch/rules/high-import-coupling.js +0 -31
- package/extensions/dm-lens/dist/clients/dispatch/rules/missing-error-propagation.js +0 -45
- package/extensions/dm-lens/dist/clients/dispatch/rules/no-commented-credentials.js +0 -46
- package/extensions/dm-lens/dist/clients/dispatch/rules/pass-through-wrappers.js +0 -38
- package/extensions/dm-lens/dist/clients/dispatch/rules/placeholder-comments.js +0 -40
- package/extensions/dm-lens/dist/clients/dispatch/rules/unsafe-boundary.js +0 -101
- package/extensions/dm-lens/dist/clients/dispatch/runner-context.js +0 -46
- package/extensions/dm-lens/dist/clients/dispatch/runners/actionlint.js +0 -98
- package/extensions/dm-lens/dist/clients/dispatch/runners/ast-grep-napi.js +0 -690
- package/extensions/dm-lens/dist/clients/dispatch/runners/biome-check.js +0 -202
- package/extensions/dm-lens/dist/clients/dispatch/runners/cpp-check.js +0 -190
- package/extensions/dm-lens/dist/clients/dispatch/runners/credo.js +0 -66
- package/extensions/dm-lens/dist/clients/dispatch/runners/cue-vet.js +0 -167
- package/extensions/dm-lens/dist/clients/dispatch/runners/dart-analyze.js +0 -151
- package/extensions/dm-lens/dist/clients/dispatch/runners/detekt.js +0 -157
- package/extensions/dm-lens/dist/clients/dispatch/runners/dotnet-build.js +0 -157
- package/extensions/dm-lens/dist/clients/dispatch/runners/elixir-check.js +0 -153
- package/extensions/dm-lens/dist/clients/dispatch/runners/eslint.js +0 -99
- package/extensions/dm-lens/dist/clients/dispatch/runners/fact-rules.js +0 -20
- package/extensions/dm-lens/dist/clients/dispatch/runners/fish-indent.js +0 -65
- package/extensions/dm-lens/dist/clients/dispatch/runners/gleam-check.js +0 -107
- package/extensions/dm-lens/dist/clients/dispatch/runners/go-vet.js +0 -51
- package/extensions/dm-lens/dist/clients/dispatch/runners/golangci-lint.js +0 -89
- package/extensions/dm-lens/dist/clients/dispatch/runners/hadolint.js +0 -83
- package/extensions/dm-lens/dist/clients/dispatch/runners/helm-lint.js +0 -144
- package/extensions/dm-lens/dist/clients/dispatch/runners/helm-render.js +0 -593
- package/extensions/dm-lens/dist/clients/dispatch/runners/htmlhint.js +0 -103
- package/extensions/dm-lens/dist/clients/dispatch/runners/index.js +0 -100
- package/extensions/dm-lens/dist/clients/dispatch/runners/javac.js +0 -82
- package/extensions/dm-lens/dist/clients/dispatch/runners/ktlint.js +0 -93
- package/extensions/dm-lens/dist/clients/dispatch/runners/lsp.js +0 -206
- package/extensions/dm-lens/dist/clients/dispatch/runners/markdownlint.js +0 -129
- package/extensions/dm-lens/dist/clients/dispatch/runners/mypy.js +0 -70
- package/extensions/dm-lens/dist/clients/dispatch/runners/oxlint.js +0 -305
- package/extensions/dm-lens/dist/clients/dispatch/runners/php-lint.js +0 -70
- package/extensions/dm-lens/dist/clients/dispatch/runners/phpstan.js +0 -90
- package/extensions/dm-lens/dist/clients/dispatch/runners/prisma-validate.js +0 -56
- package/extensions/dm-lens/dist/clients/dispatch/runners/psscriptanalyzer.js +0 -307
- package/extensions/dm-lens/dist/clients/dispatch/runners/pyright.js +0 -118
- package/extensions/dm-lens/dist/clients/dispatch/runners/rubocop.js +0 -79
- package/extensions/dm-lens/dist/clients/dispatch/runners/ruff.js +0 -69
- package/extensions/dm-lens/dist/clients/dispatch/runners/rust-clippy.js +0 -147
- package/extensions/dm-lens/dist/clients/dispatch/runners/shellcheck.js +0 -111
- package/extensions/dm-lens/dist/clients/dispatch/runners/shfmt.js +0 -81
- package/extensions/dm-lens/dist/clients/dispatch/runners/spellcheck.js +0 -74
- package/extensions/dm-lens/dist/clients/dispatch/runners/spotbugs.js +0 -208
- package/extensions/dm-lens/dist/clients/dispatch/runners/sqlfluff.js +0 -136
- package/extensions/dm-lens/dist/clients/dispatch/runners/stylelint.js +0 -118
- package/extensions/dm-lens/dist/clients/dispatch/runners/swiftlint.js +0 -143
- package/extensions/dm-lens/dist/clients/dispatch/runners/taplo.js +0 -97
- package/extensions/dm-lens/dist/clients/dispatch/runners/terragrunt.js +0 -110
- package/extensions/dm-lens/dist/clients/dispatch/runners/tflint.js +0 -104
- package/extensions/dm-lens/dist/clients/dispatch/runners/tree-sitter.js +0 -516
- package/extensions/dm-lens/dist/clients/dispatch/runners/trivy-config.js +0 -155
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/availability-policy.js +0 -285
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/candidate-probe.js +0 -61
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/diagnostic-parsers.js +0 -61
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/lazy-installer.js +0 -130
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +0 -1067
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/spawn-outcome.js +0 -40
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/tool-failure.js +0 -117
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/toolchain-availability.js +0 -88
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils.js +0 -8
- package/extensions/dm-lens/dist/clients/dispatch/runners/vale.js +0 -106
- package/extensions/dm-lens/dist/clients/dispatch/runners/yaml-rule-parser.js +0 -163
- package/extensions/dm-lens/dist/clients/dispatch/runners/yamllint.js +0 -83
- package/extensions/dm-lens/dist/clients/dispatch/runners/zig-check.js +0 -72
- package/extensions/dm-lens/dist/clients/dispatch/suppress-writer.js +0 -57
- package/extensions/dm-lens/dist/clients/dispatch/tool-profile.js +0 -30
- package/extensions/dm-lens/dist/clients/dispatch/types.js +0 -7
- package/extensions/dm-lens/dist/clients/dispatch/utils/format-utils.js +0 -45
- package/extensions/dm-lens/dist/clients/dispatch/utils/lsp-diagnostics.js +0 -31
- package/extensions/dm-lens/dist/clients/disposition-logger.js +0 -19
- package/extensions/dm-lens/dist/clients/disposition-publish.js +0 -88
- package/extensions/dm-lens/dist/clients/durable-store.js +0 -77
- package/extensions/dm-lens/dist/clients/effective-config.js +0 -160
- package/extensions/dm-lens/dist/clients/env-utils.js +0 -26
- package/extensions/dm-lens/dist/clients/error-class.js +0 -3
- package/extensions/dm-lens/dist/clients/eval-timestamp.js +0 -2
- package/extensions/dm-lens/dist/clients/event-loop-hold.js +0 -119
- package/extensions/dm-lens/dist/clients/event-loop-monitor.js +0 -84
- package/extensions/dm-lens/dist/clients/extension-log.js +0 -230
- package/extensions/dm-lens/dist/clients/extension-mode.js +0 -20
- package/extensions/dm-lens/dist/clients/feature-hints.js +0 -88
- package/extensions/dm-lens/dist/clients/file-kinds.js +0 -304
- package/extensions/dm-lens/dist/clients/file-role.js +0 -50
- package/extensions/dm-lens/dist/clients/file-time.js +0 -112
- package/extensions/dm-lens/dist/clients/file-utils.js +0 -630
- package/extensions/dm-lens/dist/clients/finding-delivery-gate.js +0 -129
- package/extensions/dm-lens/dist/clients/finding-identity.js +0 -23
- package/extensions/dm-lens/dist/clients/fix-worklog.js +0 -75
- package/extensions/dm-lens/dist/clients/format-events-publish.js +0 -230
- package/extensions/dm-lens/dist/clients/format-service.js +0 -154
- package/extensions/dm-lens/dist/clients/formatters-lazy.js +0 -8
- package/extensions/dm-lens/dist/clients/formatters.js +0 -1351
- package/extensions/dm-lens/dist/clients/freshness-cadence.js +0 -1
- package/extensions/dm-lens/dist/clients/freshness.js +0 -8
- package/extensions/dm-lens/dist/clients/generated-artifacts.js +0 -209
- package/extensions/dm-lens/dist/clients/generation-guard.js +0 -105
- package/extensions/dm-lens/dist/clients/git-guard.js +0 -770
- package/extensions/dm-lens/dist/clients/git-tracked-ignore.js +0 -120
- package/extensions/dm-lens/dist/clients/gitleaks-client.js +0 -282
- package/extensions/dm-lens/dist/clients/go-client.js +0 -47
- package/extensions/dm-lens/dist/clients/govulncheck-client.js +0 -411
- package/extensions/dm-lens/dist/clients/gradle-ktfmt-style.js +0 -177
- package/extensions/dm-lens/dist/clients/grammar-source.js +0 -224
- package/extensions/dm-lens/dist/clients/gzip-stage-write.js +0 -85
- package/extensions/dm-lens/dist/clients/hashline-anchor.js +0 -222
- package/extensions/dm-lens/dist/clients/hook-budgets.js +0 -16
- package/extensions/dm-lens/dist/clients/host-edit-normalize.js +0 -87
- package/extensions/dm-lens/dist/clients/host-ports.js +0 -35
- package/extensions/dm-lens/dist/clients/indent-retarget.js +0 -102
- package/extensions/dm-lens/dist/clients/inline-blocker-dispositions.js +0 -103
- package/extensions/dm-lens/dist/clients/install-diagnostics.js +0 -123
- package/extensions/dm-lens/dist/clients/installer/index.js +0 -3770
- package/extensions/dm-lens/dist/clients/installer/managed-tool-refresh-session.js +0 -17
- package/extensions/dm-lens/dist/clients/installer/managed-tool-refresh.js +0 -522
- package/extensions/dm-lens/dist/clients/instance-reaper-state.js +0 -3
- package/extensions/dm-lens/dist/clients/instance-reaper.js +0 -577
- package/extensions/dm-lens/dist/clients/instance-registry-lock.js +0 -131
- package/extensions/dm-lens/dist/clients/instance-registry.js +0 -452
- package/extensions/dm-lens/dist/clients/jscpd-client.js +0 -252
- package/extensions/dm-lens/dist/clients/json-cache-read.js +0 -25
- package/extensions/dm-lens/dist/clients/knip-client.js +0 -472
- package/extensions/dm-lens/dist/clients/language-policy.js +0 -242
- package/extensions/dm-lens/dist/clients/language-profile.js +0 -261
- package/extensions/dm-lens/dist/clients/language-registry.js +0 -424
- package/extensions/dm-lens/dist/clients/latency-logger.js +0 -192
- package/extensions/dm-lens/dist/clients/lazy-import.js +0 -14
- package/extensions/dm-lens/dist/clients/ledger-bounds.js +0 -21
- package/extensions/dm-lens/dist/clients/lens-config.js +0 -237
- package/extensions/dm-lens/dist/clients/lens-engine.js +0 -181
- package/extensions/dm-lens/dist/clients/lens-events.js +0 -105
- package/extensions/dm-lens/dist/clients/lens-flag-registry.js +0 -302
- package/extensions/dm-lens/dist/clients/lens-map.js +0 -980
- package/extensions/dm-lens/dist/clients/live-bus-emitter.js +0 -53
- package/extensions/dm-lens/dist/clients/log-cleanup.js +0 -138
- package/extensions/dm-lens/dist/clients/lsp/aggregation.js +0 -88
- package/extensions/dm-lens/dist/clients/lsp/cascade-tier.js +0 -203
- package/extensions/dm-lens/dist/clients/lsp/client.js +0 -2709
- package/extensions/dm-lens/dist/clients/lsp/config.js +0 -252
- package/extensions/dm-lens/dist/clients/lsp/content-limits.js +0 -21
- package/extensions/dm-lens/dist/clients/lsp/diagnostic-binding.js +0 -79
- package/extensions/dm-lens/dist/clients/lsp/document-drift.js +0 -312
- package/extensions/dm-lens/dist/clients/lsp/edits.js +0 -930
- package/extensions/dm-lens/dist/clients/lsp/index.js +0 -4448
- package/extensions/dm-lens/dist/clients/lsp/inferred-project.js +0 -121
- package/extensions/dm-lens/dist/clients/lsp/jvm-runtime.js +0 -194
- package/extensions/dm-lens/dist/clients/lsp/language.js +0 -23
- package/extensions/dm-lens/dist/clients/lsp/launch.js +0 -468
- package/extensions/dm-lens/dist/clients/lsp/lombok.js +0 -146
- package/extensions/dm-lens/dist/clients/lsp/path-utils.js +0 -1
- package/extensions/dm-lens/dist/clients/lsp/pending-aux-coverage.js +0 -90
- package/extensions/dm-lens/dist/clients/lsp/position-encoding.js +0 -28
- package/extensions/dm-lens/dist/clients/lsp/ruby-drive-dirs.js +0 -42
- package/extensions/dm-lens/dist/clients/lsp/server.js +0 -2422
- package/extensions/dm-lens/dist/clients/lsp/session-roots.js +0 -52
- package/extensions/dm-lens/dist/clients/lsp/spawn-history.js +0 -15
- package/extensions/dm-lens/dist/clients/lsp/sync-kind.js +0 -30
- package/extensions/dm-lens/dist/clients/lsp/tsserver-sync.js +0 -156
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/capability-snapshot.js +0 -1
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/classification.js +0 -36
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/index.js +0 -3
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/strategies.js +0 -175
- package/extensions/dm-lens/dist/clients/lsp/watch-queue.js +0 -40
- package/extensions/dm-lens/dist/clients/lsp/workspace-diagnostics-cache.js +0 -267
- package/extensions/dm-lens/dist/clients/lsp/workspace-diagnostics-session.js +0 -7
- package/extensions/dm-lens/dist/clients/lsp/workspace-sweep-hold.js +0 -93
- package/extensions/dm-lens/dist/clients/lsp-budget.js +0 -83
- package/extensions/dm-lens/dist/clients/lsp-document-symbols.js +0 -93
- package/extensions/dm-lens/dist/clients/lsp-lazy.js +0 -8
- package/extensions/dm-lens/dist/clients/lsp-mutation.js +0 -273
- package/extensions/dm-lens/dist/clients/lsp-status.js +0 -37
- package/extensions/dm-lens/dist/clients/map-with-concurrency.js +0 -20
- package/extensions/dm-lens/dist/clients/mcp/analyze.js +0 -251
- package/extensions/dm-lens/dist/clients/mcp/host-shim.js +0 -14
- package/extensions/dm-lens/dist/clients/mcp/ipc.js +0 -302
- package/extensions/dm-lens/dist/clients/mcp/review.js +0 -137
- package/extensions/dm-lens/dist/clients/mcp/session.js +0 -305
- package/extensions/dm-lens/dist/clients/memory-sampler.js +0 -107
- package/extensions/dm-lens/dist/clients/message-end-attribution.js +0 -18
- package/extensions/dm-lens/dist/clients/metrics-client.js +0 -80
- package/extensions/dm-lens/dist/clients/metrics-history.js +0 -255
- package/extensions/dm-lens/dist/clients/middle-man-analysis.js +0 -161
- package/extensions/dm-lens/dist/clients/model-provider.js +0 -31
- package/extensions/dm-lens/dist/clients/module-report-lsp.js +0 -140
- package/extensions/dm-lens/dist/clients/module-report.js +0 -1642
- package/extensions/dm-lens/dist/clients/mutating-tool.js +0 -377
- package/extensions/dm-lens/dist/clients/mutation-attribution.js +0 -168
- package/extensions/dm-lens/dist/clients/mutation-bridge.js +0 -102
- package/extensions/dm-lens/dist/clients/ndjson-logger.js +0 -471
- package/extensions/dm-lens/dist/clients/observed-mutation-sources.js +0 -43
- package/extensions/dm-lens/dist/clients/observed-mutation.js +0 -709
- package/extensions/dm-lens/dist/clients/oldtext-autopatch.js +0 -100
- package/extensions/dm-lens/dist/clients/opaque-mutation-scan.js +0 -313
- package/extensions/dm-lens/dist/clients/opengrep-client.js +0 -216
- package/extensions/dm-lens/dist/clients/opengrep-config.js +0 -52
- package/extensions/dm-lens/dist/clients/package-manager.js +0 -303
- package/extensions/dm-lens/dist/clients/package-root.js +0 -25
- package/extensions/dm-lens/dist/clients/partial-edit-apply.js +0 -337
- package/extensions/dm-lens/dist/clients/path-attribution-telemetry.js +0 -31
- package/extensions/dm-lens/dist/clients/path-keyed-map.js +0 -57
- package/extensions/dm-lens/dist/clients/path-utils.js +0 -476
- package/extensions/dm-lens/dist/clients/performance-report.js +0 -291
- package/extensions/dm-lens/dist/clients/persist-debounce.js +0 -37
- package/extensions/dm-lens/dist/clients/persistent-reverify.js +0 -165
- package/extensions/dm-lens/dist/clients/php-cs-fixer-config.js +0 -15
- package/extensions/dm-lens/dist/clients/pipeline.js +0 -1091
- package/extensions/dm-lens/dist/clients/post-autofix-notice.js +0 -19
- package/extensions/dm-lens/dist/clients/print-mode.js +0 -3
- package/extensions/dm-lens/dist/clients/probe-home-state.js +0 -62
- package/extensions/dm-lens/dist/clients/process-bridge.js +0 -20
- package/extensions/dm-lens/dist/clients/process-singletons.js +0 -69
- package/extensions/dm-lens/dist/clients/process-snapshot.js +0 -22
- package/extensions/dm-lens/dist/clients/project-changes.js +0 -112
- package/extensions/dm-lens/dist/clients/project-conventions.js +0 -152
- package/extensions/dm-lens/dist/clients/project-diagnostics/cache.js +0 -91
- package/extensions/dm-lens/dist/clients/project-diagnostics/extractors.js +0 -53
- package/extensions/dm-lens/dist/clients/project-diagnostics/fresh-fetch.js +0 -408
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/call-graph-impact.js +0 -64
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/dead-code.js +0 -38
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/gitleaks.js +0 -21
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/govulncheck.js +0 -23
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/jscpd.js +0 -28
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/knip.js +0 -45
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/madge.js +0 -34
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/opengrep.js +0 -32
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +0 -79
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/trivy.js +0 -41
- package/extensions/dm-lens/dist/clients/project-diagnostics/scanner.js +0 -349
- package/extensions/dm-lens/dist/clients/project-diagnostics/types.js +0 -1
- package/extensions/dm-lens/dist/clients/project-lens-config.js +0 -437
- package/extensions/dm-lens/dist/clients/project-report.js +0 -527
- package/extensions/dm-lens/dist/clients/project-scale.js +0 -60
- package/extensions/dm-lens/dist/clients/project-scan-policy.js +0 -4
- package/extensions/dm-lens/dist/clients/project-snapshot-fingerprint.js +0 -39
- package/extensions/dm-lens/dist/clients/project-snapshot-persist-worker.js +0 -14
- package/extensions/dm-lens/dist/clients/project-snapshot.js +0 -1178
- package/extensions/dm-lens/dist/clients/project-trust.js +0 -104
- package/extensions/dm-lens/dist/clients/python-environment.js +0 -120
- package/extensions/dm-lens/dist/clients/python-provenance.js +0 -551
- package/extensions/dm-lens/dist/clients/quiet-window-config.js +0 -16
- package/extensions/dm-lens/dist/clients/quiet-window.js +0 -126
- package/extensions/dm-lens/dist/clients/read-bridge.js +0 -46
- package/extensions/dm-lens/dist/clients/read-expansion.js +0 -218
- package/extensions/dm-lens/dist/clients/read-guard-logger.js +0 -178
- package/extensions/dm-lens/dist/clients/read-guard-tool-lines.js +0 -1042
- package/extensions/dm-lens/dist/clients/read-guard.js +0 -1096
- package/extensions/dm-lens/dist/clients/recent-touches.js +0 -126
- package/extensions/dm-lens/dist/clients/redact/secrets.js +0 -386
- package/extensions/dm-lens/dist/clients/resource-sampler.js +0 -344
- package/extensions/dm-lens/dist/clients/reverse-deps.js +0 -227
- package/extensions/dm-lens/dist/clients/review-graph/builder.js +0 -3635
- package/extensions/dm-lens/dist/clients/review-graph/format.js +0 -30
- package/extensions/dm-lens/dist/clients/review-graph/git-identity.js +0 -115
- package/extensions/dm-lens/dist/clients/review-graph/import-resolvers.js +0 -325
- package/extensions/dm-lens/dist/clients/review-graph/persist-worker.js +0 -8
- package/extensions/dm-lens/dist/clients/review-graph/query.js +0 -195
- package/extensions/dm-lens/dist/clients/review-graph/revision-drift.js +0 -3
- package/extensions/dm-lens/dist/clients/review-graph/service.js +0 -60
- package/extensions/dm-lens/dist/clients/review-graph/shared-extraction-ir.js +0 -54
- package/extensions/dm-lens/dist/clients/review-graph/symbol-id.js +0 -29
- package/extensions/dm-lens/dist/clients/review-graph/tsconfig-paths.js +0 -253
- package/extensions/dm-lens/dist/clients/review-graph/types.js +0 -1
- package/extensions/dm-lens/dist/clients/review-graph/workspace-modules.js +0 -374
- package/extensions/dm-lens/dist/clients/review-graph-logger.js +0 -51
- package/extensions/dm-lens/dist/clients/ruff-client.js +0 -109
- package/extensions/dm-lens/dist/clients/rules-scanner.js +0 -113
- package/extensions/dm-lens/dist/clients/run-duration.js +0 -9
- package/extensions/dm-lens/dist/clients/runtime-agent-end.js +0 -608
- package/extensions/dm-lens/dist/clients/runtime-config.js +0 -39
- package/extensions/dm-lens/dist/clients/runtime-context.js +0 -155
- package/extensions/dm-lens/dist/clients/runtime-coordinator.js +0 -817
- package/extensions/dm-lens/dist/clients/runtime-session.js +0 -1625
- package/extensions/dm-lens/dist/clients/runtime-tool-call.js +0 -868
- package/extensions/dm-lens/dist/clients/runtime-tool-result.js +0 -1317
- package/extensions/dm-lens/dist/clients/runtime-turn.js +0 -2333
- package/extensions/dm-lens/dist/clients/rust-client.js +0 -48
- package/extensions/dm-lens/dist/clients/safe-spawn.js +0 -1267
- package/extensions/dm-lens/dist/clients/sanitize.js +0 -174
- package/extensions/dm-lens/dist/clients/scan-utils.js +0 -7
- package/extensions/dm-lens/dist/clients/scratch-tree-policy.js +0 -57
- package/extensions/dm-lens/dist/clients/search-read-registration.js +0 -59
- package/extensions/dm-lens/dist/clients/secret-findings.js +0 -69
- package/extensions/dm-lens/dist/clients/security-scan-client.js +0 -208
- package/extensions/dm-lens/dist/clients/session-event-guard.js +0 -111
- package/extensions/dm-lens/dist/clients/session-lifecycle.js +0 -173
- package/extensions/dm-lens/dist/clients/session-start-observability.js +0 -47
- package/extensions/dm-lens/dist/clients/session-state-store.js +0 -63
- package/extensions/dm-lens/dist/clients/session-summary.js +0 -8
- package/extensions/dm-lens/dist/clients/sessionstart-logger.js +0 -22
- package/extensions/dm-lens/dist/clients/sg-runner.js +0 -627
- package/extensions/dm-lens/dist/clients/sgconfig.js +0 -280
- package/extensions/dm-lens/dist/clients/shared-checkout-guard.js +0 -177
- package/extensions/dm-lens/dist/clients/single-flight.js +0 -52
- package/extensions/dm-lens/dist/clients/situational-tool-telemetry.js +0 -85
- package/extensions/dm-lens/dist/clients/skills-resolver.js +0 -38
- package/extensions/dm-lens/dist/clients/slow-fs.js +0 -77
- package/extensions/dm-lens/dist/clients/smells-rollup.js +0 -118
- package/extensions/dm-lens/dist/clients/source-filter.js +0 -320
- package/extensions/dm-lens/dist/clients/source-walker.js +0 -96
- package/extensions/dm-lens/dist/clients/spawn-output-cap.js +0 -35
- package/extensions/dm-lens/dist/clients/spawn-timeout-cooldown.js +0 -51
- package/extensions/dm-lens/dist/clients/stale-marker.js +0 -1
- package/extensions/dm-lens/dist/clients/startup-scan.js +0 -222
- package/extensions/dm-lens/dist/clients/startup-timing.js +0 -67
- package/extensions/dm-lens/dist/clients/string-utils.js +0 -6
- package/extensions/dm-lens/dist/clients/subagent-mode.js +0 -40
- package/extensions/dm-lens/dist/clients/symbol-containment.js +0 -16
- package/extensions/dm-lens/dist/clients/symbol-types.js +0 -1
- package/extensions/dm-lens/dist/clients/test-runner-client.js +0 -1504
- package/extensions/dm-lens/dist/clients/test-runner-delivery.js +0 -260
- package/extensions/dm-lens/dist/clients/todo-scanner.js +0 -164
- package/extensions/dm-lens/dist/clients/tool-agreement.js +0 -377
- package/extensions/dm-lens/dist/clients/tool-config.js +0 -218
- package/extensions/dm-lens/dist/clients/tool-cwd.js +0 -235
- package/extensions/dm-lens/dist/clients/tool-definition.js +0 -22
- package/extensions/dm-lens/dist/clients/tool-event.js +0 -18
- package/extensions/dm-lens/dist/clients/tool-policy.js +0 -2393
- package/extensions/dm-lens/dist/clients/tool-probe.js +0 -5
- package/extensions/dm-lens/dist/clients/tool-render.js +0 -79
- package/extensions/dm-lens/dist/clients/tool-set-policy.js +0 -70
- package/extensions/dm-lens/dist/clients/tree-sitter-cache.js +0 -206
- package/extensions/dm-lens/dist/clients/tree-sitter-client.js +0 -2787
- package/extensions/dm-lens/dist/clients/tree-sitter-logger.js +0 -77
- package/extensions/dm-lens/dist/clients/tree-sitter-navigator.js +0 -198
- package/extensions/dm-lens/dist/clients/tree-sitter-query-loader.js +0 -318
- package/extensions/dm-lens/dist/clients/tree-sitter-shared.js +0 -87
- package/extensions/dm-lens/dist/clients/tree-sitter-symbol-extractor.js +0 -957
- package/extensions/dm-lens/dist/clients/trivy-client.js +0 -305
- package/extensions/dm-lens/dist/clients/tui-fit.js +0 -26
- package/extensions/dm-lens/dist/clients/turn-context.js +0 -48
- package/extensions/dm-lens/dist/clients/turn-end/lane.js +0 -1
- package/extensions/dm-lens/dist/clients/turn-end/lanes/govulncheck.js +0 -54
- package/extensions/dm-lens/dist/clients/turn-end/lanes/secrets.js +0 -131
- package/extensions/dm-lens/dist/clients/turn-summary-render.js +0 -56
- package/extensions/dm-lens/dist/clients/turn-summary.js +0 -84
- package/extensions/dm-lens/dist/clients/typos-config.js +0 -9
- package/extensions/dm-lens/dist/clients/user-notify.js +0 -15
- package/extensions/dm-lens/dist/clients/vanished-instance-marker.js +0 -18
- package/extensions/dm-lens/dist/clients/warm-attach.js +0 -210
- package/extensions/dm-lens/dist/clients/widget-state.js +0 -963
- package/extensions/dm-lens/dist/clients/word-index-logger.js +0 -21
- package/extensions/dm-lens/dist/clients/word-index-store.js +0 -222
- package/extensions/dm-lens/dist/clients/word-index.js +0 -1426
- package/extensions/dm-lens/dist/clients/workspace-topology.js +0 -261
- package/extensions/dm-lens/dist/clients/write-ordering-guard.js +0 -24
- package/extensions/dm-lens/dist/clients/zizmor-config.js +0 -160
- package/extensions/dm-lens/dist/i18n.js +0 -67
- package/extensions/dm-lens/dist/index.js +0 -1782
- package/extensions/dm-lens/dist/mcp/analyze-cli.js +0 -178
- package/extensions/dm-lens/dist/mcp/build-staleness.js +0 -55
- package/extensions/dm-lens/dist/mcp/cli.js +0 -78
- package/extensions/dm-lens/dist/mcp/server.js +0 -1208
- package/extensions/dm-lens/dist/mcp/worker.js +0 -33
- package/extensions/dm-lens/dist/scripts/lib/process-scan.mjs +0 -256
- package/extensions/dm-lens/dist/scripts/lib/skills-predicate.mjs +0 -53
- package/extensions/dm-lens/dist/scripts/lib/web-tree-sitter-dir.mjs +0 -45
- package/extensions/dm-lens/dist/tools/activate-tools.js +0 -61
- package/extensions/dm-lens/dist/tools/ast-grep-outline.js +0 -127
- package/extensions/dm-lens/dist/tools/ast-grep-replace.js +0 -226
- package/extensions/dm-lens/dist/tools/ast-grep-search.js +0 -687
- package/extensions/dm-lens/dist/tools/effective-config.js +0 -59
- package/extensions/dm-lens/dist/tools/lens-diagnostic-mark.js +0 -240
- package/extensions/dm-lens/dist/tools/lens-diagnostics.js +0 -1484
- package/extensions/dm-lens/dist/tools/lsp-diagnostics.js +0 -1088
- package/extensions/dm-lens/dist/tools/lsp-navigation.js +0 -1194
- package/extensions/dm-lens/dist/tools/lsp-structured-output.js +0 -277
- package/extensions/dm-lens/dist/tools/module-report.js +0 -332
- package/extensions/dm-lens/dist/tools/project-report.js +0 -72
- package/extensions/dm-lens/dist/tools/render-compact.js +0 -272
- package/extensions/dm-lens/dist/tools/scan-progress.js +0 -31
- package/extensions/dm-lens/dist/tools/shared.js +0 -26
- package/extensions/dm-lens/dist/tools/symbol-search.js +0 -133
- package/extensions/dm-mcp-adapter/dist/abort.js +0 -35
- package/extensions/dm-mcp-adapter/dist/agent-dir.js +0 -45
- package/extensions/dm-mcp-adapter/dist/agent-plugin-loader.js +0 -392
- package/extensions/dm-mcp-adapter/dist/agent-plugin-provenance.js +0 -26
- package/extensions/dm-mcp-adapter/dist/bearer-command-resolver.js +0 -182
- package/extensions/dm-mcp-adapter/dist/claude-plugin-loader.js +0 -350
- package/extensions/dm-mcp-adapter/dist/config.js +0 -1310
- package/extensions/dm-mcp-adapter/dist/consent-manager.js +0 -84
- package/extensions/dm-mcp-adapter/dist/elicitation-handler.js +0 -308
- package/extensions/dm-mcp-adapter/dist/errors.js +0 -225
- package/extensions/dm-mcp-adapter/dist/http-ca.js +0 -71
- package/extensions/dm-mcp-adapter/dist/jev-client.js +0 -359
- package/extensions/dm-mcp-adapter/dist/jev-contracts.js +0 -1
- package/extensions/dm-mcp-adapter/dist/jev-key-store.js +0 -176
- package/extensions/dm-mcp-adapter/dist/json-schema-validator.js +0 -70
- package/extensions/dm-mcp-adapter/dist/lifecycle.js +0 -387
- package/extensions/dm-mcp-adapter/dist/logger.js +0 -115
- package/extensions/dm-mcp-adapter/dist/mcp-auth-fetch.js +0 -86
- package/extensions/dm-mcp-adapter/dist/mcp-auth-flow.js +0 -949
- package/extensions/dm-mcp-adapter/dist/mcp-auth.js +0 -997
- package/extensions/dm-mcp-adapter/dist/mcp-bearer-store.js +0 -182
- package/extensions/dm-mcp-adapter/dist/mcp-callback-server.js +0 -381
- package/extensions/dm-mcp-adapter/dist/mcp-oauth-provider.js +0 -524
- package/extensions/dm-mcp-adapter/dist/mcp-probe.js +0 -151
- package/extensions/dm-mcp-adapter/dist/mcp-tasks.js +0 -300
- package/extensions/dm-mcp-adapter/dist/mcp-trace.js +0 -215
- package/extensions/dm-mcp-adapter/dist/metadata-cache.js +0 -267
- package/extensions/dm-mcp-adapter/dist/npx-resolver.js +0 -465
- package/extensions/dm-mcp-adapter/dist/package-mcp-loader.js +0 -135
- package/extensions/dm-mcp-adapter/dist/request-headers-command.js +0 -294
- package/extensions/dm-mcp-adapter/dist/resource-tools.js +0 -7
- package/extensions/dm-mcp-adapter/dist/runtime-owner.js +0 -94
- package/extensions/dm-mcp-adapter/dist/sampling-handler.js +0 -213
- package/extensions/dm-mcp-adapter/dist/secure-keyring.js +0 -191
- package/extensions/dm-mcp-adapter/dist/server-manager.js +0 -1514
- package/extensions/dm-mcp-adapter/dist/session-approvals.js +0 -127
- package/extensions/dm-mcp-adapter/dist/session-recovery.js +0 -82
- package/extensions/dm-mcp-adapter/dist/state.js +0 -1
- package/extensions/dm-mcp-adapter/dist/types.js +0 -286
- package/extensions/dm-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -36
- package/extensions/dm-mcp-adapter/dist/ui-resource-handler.js +0 -204
- package/extensions/dm-mcp-adapter/dist/ui-stream-types.js +0 -58
- package/extensions/dm-mcp-adapter/dist/ui-tool-visibility.js +0 -26
- package/extensions/dm-mcp-adapter/dist/unix-socket-transport.js +0 -83
- package/extensions/dm-mcp-adapter/dist/utils.js +0 -382
|
@@ -1,949 +0,0 @@
|
|
|
1
|
-
import { auth as runSdkAuth, extractWWWAuthenticateParams, LATEST_PROTOCOL_VERSION, UnauthorizedError, validateClientMetadataUrl } from "@modelcontextprotocol/client";
|
|
2
|
-
import open from "open";
|
|
3
|
-
import { getOAuthCallbackPort, McpOAuthProvider } from "./mcp-oauth-provider.js";
|
|
4
|
-
import { ensureCallbackServer, waitForCallback, cancelPendingCallback, stopCallbackServer, stopCallbackServerIfIdle, releaseCallbackServer } from "./mcp-callback-server.js";
|
|
5
|
-
import { getAuthForUrl, getAuthEntry, clearAllCredentials, clearClientInfo, clearCodeVerifier, getOAuthState, clearOAuthState, getAuthBaseDir, beginOAuthRevocation, captureOAuthAuthority, OAuthCredentialStoreError } from "./mcp-auth.js";
|
|
6
|
-
import { isServerDisabled } from "./types.js";
|
|
7
|
-
import { formatTerminalError, interpolateEnvVars } from "./utils.js";
|
|
8
|
-
import { createOAuthFetch, oauthHeaderResolver, resolveOAuthHeaders } from "./mcp-auth-fetch.js";
|
|
9
|
-
import { isBuiltInAgentPlugin } from "./agent-plugin-provenance.js";
|
|
10
|
-
import { abortable, throwIfAborted } from "./abort.js";
|
|
11
|
-
import { combineAbortSignals, isAbortError } from "./runtime-owner.js";
|
|
12
|
-
function pluginAwareOAuthHeaders(definition) {
|
|
13
|
-
return oauthHeaderResolver(definition?.headers, {
|
|
14
|
-
literal: definition ? isBuiltInAgentPlugin(definition, "headers") : false
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function applyOAuthConfig(discovery, config) {
|
|
18
|
-
return {
|
|
19
|
-
...discovery,
|
|
20
|
-
...config.scope !== undefined ? { scope: config.scope } : {},
|
|
21
|
-
...config.skipIssuerMetadataValidation === true ? { skipIssuerMetadataValidation: true } : {}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
const runtimeStates = new WeakMap;
|
|
25
|
-
const activeRuntimes = new Set;
|
|
26
|
-
export function createOAuthRuntime(signal) {
|
|
27
|
-
const controller = new AbortController;
|
|
28
|
-
const runtime = { signal: combineAbortSignals(signal, controller.signal) };
|
|
29
|
-
runtimeStates.set(runtime, {
|
|
30
|
-
controller,
|
|
31
|
-
generation: 0,
|
|
32
|
-
pendingAuths: new Map,
|
|
33
|
-
pendingAuthStates: new Map,
|
|
34
|
-
pendingAuthCleanupTimers: new Map,
|
|
35
|
-
pendingAuthentications: new Map
|
|
36
|
-
});
|
|
37
|
-
activeRuntimes.add(runtime);
|
|
38
|
-
return runtime;
|
|
39
|
-
}
|
|
40
|
-
let legacyRuntime = createOAuthRuntime();
|
|
41
|
-
activeRuntimes.delete(legacyRuntime);
|
|
42
|
-
function getRuntime(options) {
|
|
43
|
-
if (options?.runtime) {
|
|
44
|
-
options.runtime.signal.throwIfAborted();
|
|
45
|
-
activeRuntimes.add(options.runtime);
|
|
46
|
-
return options.runtime;
|
|
47
|
-
}
|
|
48
|
-
if (legacyRuntime.signal.aborted)
|
|
49
|
-
legacyRuntime = createOAuthRuntime();
|
|
50
|
-
activeRuntimes.add(legacyRuntime);
|
|
51
|
-
return legacyRuntime;
|
|
52
|
-
}
|
|
53
|
-
function getRuntimeState(runtime) {
|
|
54
|
-
const state = runtimeStates.get(runtime);
|
|
55
|
-
if (!state)
|
|
56
|
-
throw new Error("Unknown OAuth runtime");
|
|
57
|
-
return state;
|
|
58
|
-
}
|
|
59
|
-
function getAuthStorageIdentity(options) {
|
|
60
|
-
return options.credentialStore === "encrypted-file" ? ["encrypted-file"] : ["os", getAuthBaseDir(options)];
|
|
61
|
-
}
|
|
62
|
-
function getPendingAuthKey(serverName, options) {
|
|
63
|
-
return JSON.stringify([serverName, ...getAuthStorageIdentity(options)]);
|
|
64
|
-
}
|
|
65
|
-
function hasOAuthAuthority(authority) {
|
|
66
|
-
try {
|
|
67
|
-
authority();
|
|
68
|
-
return true;
|
|
69
|
-
} catch {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
export function hasPendingAuth(serverName, options, runtime) {
|
|
74
|
-
const state = getRuntimeState(runtime ?? legacyRuntime);
|
|
75
|
-
if (options) {
|
|
76
|
-
return state.pendingAuths.has(getPendingAuthKey(serverName, options));
|
|
77
|
-
}
|
|
78
|
-
return Array.from(state.pendingAuths.values()).some((pendingAuth) => pendingAuth.serverName === serverName);
|
|
79
|
-
}
|
|
80
|
-
const MANUAL_AUTH_TIMEOUT_MS = 5 * 60 * 1000;
|
|
81
|
-
function generateState() {
|
|
82
|
-
return Array.from(crypto.getRandomValues(new Uint8Array(32))).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
83
|
-
}
|
|
84
|
-
export function extractOAuthConfig(definition) {
|
|
85
|
-
if (definition.oauth === false) {
|
|
86
|
-
return {};
|
|
87
|
-
}
|
|
88
|
-
const config = {};
|
|
89
|
-
if (definition.oauth?.grantType !== undefined)
|
|
90
|
-
config.grantType = definition.oauth.grantType;
|
|
91
|
-
if (definition.oauth?.clientId !== undefined) {
|
|
92
|
-
if (typeof definition.oauth.clientId !== "string")
|
|
93
|
-
throw new Error("OAuth clientId must be a string");
|
|
94
|
-
config.clientId = interpolateEnvVars(definition.oauth.clientId);
|
|
95
|
-
}
|
|
96
|
-
if (definition.oauth?.clientSecret !== undefined) {
|
|
97
|
-
if (typeof definition.oauth.clientSecret !== "string")
|
|
98
|
-
throw new Error("OAuth clientSecret must be a string");
|
|
99
|
-
config.clientSecret = definition.oauth.clientSecret.startsWith("!") ? definition.oauth.clientSecret : interpolateEnvVars(definition.oauth.clientSecret);
|
|
100
|
-
}
|
|
101
|
-
if (definition.oauth?.clientMetadataUrl !== undefined) {
|
|
102
|
-
if (typeof definition.oauth.clientMetadataUrl !== "string") {
|
|
103
|
-
throw new Error("OAuth clientMetadataUrl must be a string");
|
|
104
|
-
}
|
|
105
|
-
const clientMetadataUrl = interpolateEnvVars(definition.oauth.clientMetadataUrl).trim();
|
|
106
|
-
if (!clientMetadataUrl) {
|
|
107
|
-
throw new Error("OAuth clientMetadataUrl must not be empty");
|
|
108
|
-
}
|
|
109
|
-
validateClientMetadataUrl(clientMetadataUrl);
|
|
110
|
-
config.clientMetadataUrl = clientMetadataUrl;
|
|
111
|
-
}
|
|
112
|
-
if (config.clientMetadataUrl !== undefined && config.clientSecret !== undefined && !config.clientId) {
|
|
113
|
-
throw new Error("OAuth clientSecret requires an explicit clientId when clientMetadataUrl is configured");
|
|
114
|
-
}
|
|
115
|
-
if (definition.oauth?.scope !== undefined) {
|
|
116
|
-
if (typeof definition.oauth.scope !== "string")
|
|
117
|
-
throw new Error("OAuth scope must be a string");
|
|
118
|
-
config.scope = interpolateEnvVars(definition.oauth.scope);
|
|
119
|
-
}
|
|
120
|
-
if (definition.oauth?.authorizationParams !== undefined) {
|
|
121
|
-
const params = definition.oauth.authorizationParams;
|
|
122
|
-
if (!params || typeof params !== "object" || Array.isArray(params)) {
|
|
123
|
-
throw new Error("OAuth authorizationParams must be an object");
|
|
124
|
-
}
|
|
125
|
-
config.authorizationParams = {};
|
|
126
|
-
for (const [key, value] of Object.entries(params)) {
|
|
127
|
-
if (!key)
|
|
128
|
-
throw new Error("OAuth authorizationParams keys must not be empty");
|
|
129
|
-
if (typeof value !== "string")
|
|
130
|
-
throw new Error(`OAuth authorizationParams.${key} must be a string`);
|
|
131
|
-
config.authorizationParams[key] = interpolateEnvVars(value);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (definition.oauth?.redirectUri !== undefined) {
|
|
135
|
-
if (typeof definition.oauth.redirectUri !== "string") {
|
|
136
|
-
throw new Error("OAuth redirectUri must be a string");
|
|
137
|
-
}
|
|
138
|
-
const redirectUri = interpolateEnvVars(definition.oauth.redirectUri).trim();
|
|
139
|
-
if (!redirectUri) {
|
|
140
|
-
throw new Error("OAuth redirectUri must not be empty");
|
|
141
|
-
}
|
|
142
|
-
config.redirectUri = redirectUri;
|
|
143
|
-
}
|
|
144
|
-
if (definition.oauth?.clientName !== undefined) {
|
|
145
|
-
if (typeof definition.oauth.clientName !== "string") {
|
|
146
|
-
throw new Error("OAuth clientName must be a string");
|
|
147
|
-
}
|
|
148
|
-
const clientName = interpolateEnvVars(definition.oauth.clientName).trim();
|
|
149
|
-
if (!clientName) {
|
|
150
|
-
throw new Error("OAuth clientName must not be empty");
|
|
151
|
-
}
|
|
152
|
-
config.clientName = clientName;
|
|
153
|
-
}
|
|
154
|
-
if (definition.oauth?.clientUri !== undefined) {
|
|
155
|
-
if (typeof definition.oauth.clientUri !== "string") {
|
|
156
|
-
throw new Error("OAuth clientUri must be a string");
|
|
157
|
-
}
|
|
158
|
-
const clientUri = interpolateEnvVars(definition.oauth.clientUri).trim();
|
|
159
|
-
if (!clientUri) {
|
|
160
|
-
throw new Error("OAuth clientUri must not be empty");
|
|
161
|
-
}
|
|
162
|
-
config.clientUri = clientUri;
|
|
163
|
-
}
|
|
164
|
-
if (definition.oauth?.logoUri !== undefined) {
|
|
165
|
-
if (typeof definition.oauth.logoUri !== "string") {
|
|
166
|
-
throw new Error("OAuth logoUri must be a string");
|
|
167
|
-
}
|
|
168
|
-
const logoUri = interpolateEnvVars(definition.oauth.logoUri).trim();
|
|
169
|
-
if (!logoUri) {
|
|
170
|
-
throw new Error("OAuth logoUri must not be empty");
|
|
171
|
-
}
|
|
172
|
-
let parsed;
|
|
173
|
-
try {
|
|
174
|
-
parsed = new URL(logoUri);
|
|
175
|
-
} catch {
|
|
176
|
-
throw new Error("OAuth logoUri must be an absolute http(s) URL");
|
|
177
|
-
}
|
|
178
|
-
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
179
|
-
throw new Error("OAuth logoUri must be an absolute http(s) URL");
|
|
180
|
-
}
|
|
181
|
-
config.logoUri = logoUri;
|
|
182
|
-
}
|
|
183
|
-
if (definition.oauth?.authServerMetadataUrl !== undefined) {
|
|
184
|
-
if (typeof definition.oauth.authServerMetadataUrl !== "string") {
|
|
185
|
-
throw new Error("OAuth authServerMetadataUrl must be a string");
|
|
186
|
-
}
|
|
187
|
-
const authServerMetadataUrl = interpolateEnvVars(definition.oauth.authServerMetadataUrl).trim();
|
|
188
|
-
if (!authServerMetadataUrl) {
|
|
189
|
-
throw new Error("OAuth authServerMetadataUrl must not be empty");
|
|
190
|
-
}
|
|
191
|
-
let parsed;
|
|
192
|
-
try {
|
|
193
|
-
parsed = new URL(authServerMetadataUrl);
|
|
194
|
-
} catch {
|
|
195
|
-
throw new Error("OAuth authServerMetadataUrl must be an absolute https:// URL");
|
|
196
|
-
}
|
|
197
|
-
if (parsed.protocol !== "https:") {
|
|
198
|
-
throw new Error("OAuth authServerMetadataUrl must be an absolute https:// URL");
|
|
199
|
-
}
|
|
200
|
-
config.authServerMetadataUrl = authServerMetadataUrl;
|
|
201
|
-
}
|
|
202
|
-
if (definition.oauth?.skipIssuerMetadataValidation !== undefined) {
|
|
203
|
-
if (typeof definition.oauth.skipIssuerMetadataValidation !== "boolean") {
|
|
204
|
-
throw new Error("OAuth skipIssuerMetadataValidation must be a boolean");
|
|
205
|
-
}
|
|
206
|
-
config.skipIssuerMetadataValidation = definition.oauth.skipIssuerMetadataValidation;
|
|
207
|
-
}
|
|
208
|
-
return config;
|
|
209
|
-
}
|
|
210
|
-
async function probeAuthDiscovery(serverUrl, definition, signal) {
|
|
211
|
-
const serviceHeaders = resolveOAuthHeaders(definition?.headers, {
|
|
212
|
-
commands: false,
|
|
213
|
-
literal: definition ? isBuiltInAgentPlugin(definition, "headers") : false
|
|
214
|
-
});
|
|
215
|
-
const probeFetch = createOAuthFetch(serverUrl, () => serviceHeaders, signal, { timeout: false });
|
|
216
|
-
const headers = new Headers({ "content-type": "application/json" });
|
|
217
|
-
const controller = new AbortController;
|
|
218
|
-
const discoverySignal = combineAbortSignals(signal, controller.signal);
|
|
219
|
-
const timer = setTimeout(() => controller.abort(), 5000);
|
|
220
|
-
try {
|
|
221
|
-
headers.set("accept", "application/json, text/event-stream");
|
|
222
|
-
const response = await probeFetch(new URL(serverUrl), {
|
|
223
|
-
method: "POST",
|
|
224
|
-
headers,
|
|
225
|
-
body: JSON.stringify({
|
|
226
|
-
jsonrpc: "2.0",
|
|
227
|
-
id: 0,
|
|
228
|
-
method: "initialize",
|
|
229
|
-
params: {
|
|
230
|
-
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
231
|
-
capabilities: {},
|
|
232
|
-
clientInfo: { name: "dm-mcp-adapter", version: "2.11.0" }
|
|
233
|
-
}
|
|
234
|
-
}),
|
|
235
|
-
...discoverySignal ? { signal: discoverySignal } : {}
|
|
236
|
-
});
|
|
237
|
-
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
238
|
-
await response.body?.cancel().catch(() => {});
|
|
239
|
-
return { ...resourceMetadataUrl ? { resourceMetadataUrl } : {}, ...scope ? { scope } : {} };
|
|
240
|
-
} catch (error) {
|
|
241
|
-
if (signal?.aborted)
|
|
242
|
-
throwIfAborted(signal);
|
|
243
|
-
return {};
|
|
244
|
-
} finally {
|
|
245
|
-
clearTimeout(timer);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function parseOAuthRedirectUri(redirectUri) {
|
|
249
|
-
const dynamicPortPlaceholder = "{port}";
|
|
250
|
-
const placeholderCount = redirectUri.split(dynamicPortPlaceholder).length - 1;
|
|
251
|
-
if (placeholderCount > 1) {
|
|
252
|
-
throw new Error("OAuth redirectUri may contain at most one {port} placeholder");
|
|
253
|
-
}
|
|
254
|
-
let parsedRedirectUri = redirectUri;
|
|
255
|
-
const dynamicPort = placeholderCount === 1;
|
|
256
|
-
if (dynamicPort) {
|
|
257
|
-
const authorityStart = redirectUri.indexOf("://") + 3;
|
|
258
|
-
const pathStart = redirectUri.slice(authorityStart).search(/[/?#]/);
|
|
259
|
-
const authorityEnd = pathStart === -1 ? redirectUri.length : authorityStart + pathStart;
|
|
260
|
-
const authority = redirectUri.slice(authorityStart, authorityEnd);
|
|
261
|
-
if (authorityStart < 3 || !authority.endsWith(`:${dynamicPortPlaceholder}`)) {
|
|
262
|
-
throw new Error("OAuth redirectUri {port} placeholder must be the loopback URI port");
|
|
263
|
-
}
|
|
264
|
-
parsedRedirectUri = redirectUri.replace(dynamicPortPlaceholder, "1");
|
|
265
|
-
}
|
|
266
|
-
let url;
|
|
267
|
-
try {
|
|
268
|
-
url = new URL(parsedRedirectUri);
|
|
269
|
-
} catch (error) {
|
|
270
|
-
throw new Error(`Invalid OAuth redirectUri: ${redirectUri}`, { cause: error });
|
|
271
|
-
}
|
|
272
|
-
if (url.username || url.password) {
|
|
273
|
-
throw new Error("OAuth redirectUri must not include username or password");
|
|
274
|
-
}
|
|
275
|
-
if (url.hash) {
|
|
276
|
-
throw new Error("OAuth redirectUri must not include a fragment");
|
|
277
|
-
}
|
|
278
|
-
const hostname = url.hostname.toLowerCase();
|
|
279
|
-
const isLocalhost = hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
|
|
280
|
-
if (dynamicPort && (url.protocol !== "http:" || !isLocalhost)) {
|
|
281
|
-
throw new Error("OAuth redirectUri {port} placeholder is allowed only for an http:// localhost or loopback URI");
|
|
282
|
-
}
|
|
283
|
-
if (url.port) {
|
|
284
|
-
const parsedPort = Number.parseInt(url.port, 10);
|
|
285
|
-
if (!Number.isInteger(parsedPort) || parsedPort <= 0 || parsedPort > 65535) {
|
|
286
|
-
throw new Error("OAuth redirectUri port must be a positive numeric port");
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
if (url.protocol === "https:" && !isLocalhost) {
|
|
290
|
-
return { mode: "manual" };
|
|
291
|
-
}
|
|
292
|
-
if (url.protocol !== "http:" || !isLocalhost) {
|
|
293
|
-
throw new Error("OAuth redirectUri must be an https:// URI or an http:// localhost or loopback URI");
|
|
294
|
-
}
|
|
295
|
-
if (!url.port) {
|
|
296
|
-
throw new Error("OAuth localhost redirectUri must include an explicit numeric port");
|
|
297
|
-
}
|
|
298
|
-
const port = Number.parseInt(url.port, 10);
|
|
299
|
-
const callbackHost = hostname === "[::1]" ? "::1" : hostname;
|
|
300
|
-
return {
|
|
301
|
-
mode: "local",
|
|
302
|
-
...dynamicPort ? {} : { port },
|
|
303
|
-
callbackHost,
|
|
304
|
-
callbackPath: url.pathname,
|
|
305
|
-
dynamicPort,
|
|
306
|
-
resolveRedirectUri: (assignedPort) => dynamicPort ? redirectUri.replace(dynamicPortPlaceholder, String(assignedPort)) : redirectUri
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
export async function startAuth(serverName, serverUrl, definition, options = {}, operationAuthority) {
|
|
310
|
-
if (isServerDisabled(definition))
|
|
311
|
-
throw new Error(`MCP server "${serverName}" is disabled`);
|
|
312
|
-
const authority = operationAuthority ?? captureOAuthAuthority(serverName);
|
|
313
|
-
authority();
|
|
314
|
-
const runtime = getRuntime(options);
|
|
315
|
-
const runtimeState = getRuntimeState(runtime);
|
|
316
|
-
const config = definition ? extractOAuthConfig(definition) : {};
|
|
317
|
-
const authStorageOptions = options.authStorageOptions ?? {};
|
|
318
|
-
const signal = combineAbortSignals(runtime.signal, options.signal);
|
|
319
|
-
const generation = runtimeState.generation;
|
|
320
|
-
throwIfAborted(signal);
|
|
321
|
-
if (config.grantType === "client_credentials") {
|
|
322
|
-
const storedAuth = await getAuthForUrl(serverName, serverUrl, authStorageOptions);
|
|
323
|
-
authority();
|
|
324
|
-
if (storedAuth?.clientInfo && !storedAuth.tokens && !config.clientId) {
|
|
325
|
-
clearClientInfo(serverName, authStorageOptions);
|
|
326
|
-
clearCodeVerifier(serverName, authStorageOptions);
|
|
327
|
-
clearOAuthState(serverName, authStorageOptions);
|
|
328
|
-
}
|
|
329
|
-
authority();
|
|
330
|
-
const authProvider = new McpOAuthProvider(serverName, serverUrl, config, {
|
|
331
|
-
onRedirect: async () => {
|
|
332
|
-
throw new Error("Browser redirect is not used for client_credentials flow");
|
|
333
|
-
}
|
|
334
|
-
}, authStorageOptions, runtime.signal, undefined, authority);
|
|
335
|
-
try {
|
|
336
|
-
const fetchFn = createOAuthFetch(serverUrl, pluginAwareOAuthHeaders(definition), signal);
|
|
337
|
-
authProvider.setAuthFetch(fetchFn);
|
|
338
|
-
const discovery = applyOAuthConfig(await probeAuthDiscovery(serverUrl, definition, signal), config);
|
|
339
|
-
authority();
|
|
340
|
-
throwIfAborted(signal);
|
|
341
|
-
const result = await abortable(runSdkAuth(authProvider, { serverUrl, ...discovery, fetchFn }), signal);
|
|
342
|
-
authority();
|
|
343
|
-
throwIfAborted(signal);
|
|
344
|
-
if (result !== "AUTHORIZED") {
|
|
345
|
-
throw new UnauthorizedError("Failed to authorize");
|
|
346
|
-
}
|
|
347
|
-
return { authorizationUrl: "" };
|
|
348
|
-
} finally {
|
|
349
|
-
authProvider.deactivate();
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
const existingPendingAuth = runtimeState.pendingAuths.get(getPendingAuthKey(serverName, authStorageOptions));
|
|
353
|
-
if (existingPendingAuth?.serverUrl === serverUrl) {
|
|
354
|
-
existingPendingAuth.authority();
|
|
355
|
-
return { authorizationUrl: existingPendingAuth.authorizationUrl };
|
|
356
|
-
}
|
|
357
|
-
const redirectTarget = config.redirectUri !== undefined ? parseOAuthRedirectUri(config.redirectUri) : undefined;
|
|
358
|
-
const manualRedirect = redirectTarget?.mode === "manual";
|
|
359
|
-
const oauthState = generateState();
|
|
360
|
-
if (!manualRedirect) {
|
|
361
|
-
try {
|
|
362
|
-
await ensureCallbackServer({
|
|
363
|
-
strictPort: redirectTarget?.mode === "local" ? !redirectTarget.dynamicPort : Boolean(config.clientId),
|
|
364
|
-
oauthState,
|
|
365
|
-
reserveState: true,
|
|
366
|
-
...redirectTarget?.mode === "local" ? {
|
|
367
|
-
...redirectTarget.port !== undefined ? { port: redirectTarget.port } : {},
|
|
368
|
-
callbackHost: redirectTarget.callbackHost,
|
|
369
|
-
callbackPath: redirectTarget.callbackPath
|
|
370
|
-
} : {}
|
|
371
|
-
});
|
|
372
|
-
authority();
|
|
373
|
-
throwIfAborted(signal);
|
|
374
|
-
if (redirectTarget?.mode === "local" && redirectTarget.dynamicPort) {
|
|
375
|
-
config.redirectUri = redirectTarget.resolveRedirectUri(getOAuthCallbackPort());
|
|
376
|
-
}
|
|
377
|
-
} catch (error) {
|
|
378
|
-
releaseCallbackServer(oauthState);
|
|
379
|
-
try {
|
|
380
|
-
await cleanupAndReleaseCallbackServerIfIdle(() => {
|
|
381
|
-
if (hasOAuthAuthority(authority))
|
|
382
|
-
clearOAuthState(serverName, authStorageOptions);
|
|
383
|
-
});
|
|
384
|
-
} catch (cleanupError) {
|
|
385
|
-
throw new AggregateError([error, cleanupError], "OAuth startup cleanup failed");
|
|
386
|
-
}
|
|
387
|
-
throw error;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
let capturedUrl;
|
|
391
|
-
authority();
|
|
392
|
-
const authProvider = new McpOAuthProvider(serverName, serverUrl, config, {
|
|
393
|
-
onRedirect: async (url) => {
|
|
394
|
-
capturedUrl = url;
|
|
395
|
-
}
|
|
396
|
-
}, authStorageOptions, runtime.signal, oauthState, authority);
|
|
397
|
-
try {
|
|
398
|
-
const storedAuth = await getAuthForUrl(serverName, serverUrl, authStorageOptions);
|
|
399
|
-
authority();
|
|
400
|
-
if (storedAuth?.clientInfo && !config.clientId) {
|
|
401
|
-
if (!storedAuth.tokens) {
|
|
402
|
-
clearClientInfo(serverName, authStorageOptions);
|
|
403
|
-
clearCodeVerifier(serverName, authStorageOptions);
|
|
404
|
-
clearOAuthState(serverName, authStorageOptions);
|
|
405
|
-
} else {
|
|
406
|
-
const redirectUris = storedAuth.clientInfo.redirectUris;
|
|
407
|
-
const redirectUriMatches = Array.isArray(redirectUris) && redirectUris.includes(authProvider.redirectUrl ?? "");
|
|
408
|
-
if (!redirectUriMatches && !storedAuth.tokens.refreshToken) {
|
|
409
|
-
clearClientInfo(serverName, authStorageOptions);
|
|
410
|
-
clearCodeVerifier(serverName, authStorageOptions);
|
|
411
|
-
clearOAuthState(serverName, authStorageOptions);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
throwIfAborted(signal);
|
|
416
|
-
const getHeaders = pluginAwareOAuthHeaders(definition);
|
|
417
|
-
const fetchFn = createOAuthFetch(serverUrl, getHeaders, signal);
|
|
418
|
-
authProvider.setAuthFetch(fetchFn);
|
|
419
|
-
const discovery = applyOAuthConfig(await probeAuthDiscovery(serverUrl, definition, signal), config);
|
|
420
|
-
authority();
|
|
421
|
-
throwIfAborted(signal);
|
|
422
|
-
const result = await abortable(runSdkAuth(authProvider, { serverUrl, ...discovery, fetchFn }), signal);
|
|
423
|
-
authority();
|
|
424
|
-
throwIfAborted(signal);
|
|
425
|
-
if (result === "AUTHORIZED") {
|
|
426
|
-
authProvider.deactivate();
|
|
427
|
-
releaseCallbackServer(oauthState);
|
|
428
|
-
clearOAuthState(serverName, authStorageOptions);
|
|
429
|
-
await stopCallbackServerIfIdle();
|
|
430
|
-
authority();
|
|
431
|
-
return { authorizationUrl: "" };
|
|
432
|
-
}
|
|
433
|
-
if (!capturedUrl) {
|
|
434
|
-
throw new UnauthorizedError("OAuth authorization URL was not provided");
|
|
435
|
-
}
|
|
436
|
-
await setPendingAuth(runtime, serverName, {
|
|
437
|
-
serverName,
|
|
438
|
-
authProvider,
|
|
439
|
-
serverUrl,
|
|
440
|
-
authorizationUrl: capturedUrl.toString(),
|
|
441
|
-
manualRedirect,
|
|
442
|
-
...manualRedirect ? { manualCompletionController: new AbortController } : {},
|
|
443
|
-
discovery,
|
|
444
|
-
getHeaders,
|
|
445
|
-
authStorageOptions,
|
|
446
|
-
authority
|
|
447
|
-
}, oauthState, signal, generation);
|
|
448
|
-
authority();
|
|
449
|
-
return { authorizationUrl: capturedUrl.toString() };
|
|
450
|
-
} catch (error) {
|
|
451
|
-
authProvider.deactivate();
|
|
452
|
-
try {
|
|
453
|
-
await clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, authStorageOptions);
|
|
454
|
-
} catch (cleanupError) {
|
|
455
|
-
throw new AggregateError([error, cleanupError], "OAuth startup cleanup failed");
|
|
456
|
-
}
|
|
457
|
-
throw error;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
async function setPendingAuth(runtime, serverName, pendingAuth, oauthState, signal, generation = getRuntimeState(runtime).generation) {
|
|
461
|
-
const state = getRuntimeState(runtime);
|
|
462
|
-
const key = getPendingAuthKey(serverName, pendingAuth.authStorageOptions);
|
|
463
|
-
pendingAuth.authority();
|
|
464
|
-
await clearPendingAuth(runtime, serverName, undefined, pendingAuth.authStorageOptions);
|
|
465
|
-
pendingAuth.authority();
|
|
466
|
-
throwIfAborted(signal);
|
|
467
|
-
if (generation !== state.generation)
|
|
468
|
-
throw new Error("OAuth runtime stopped");
|
|
469
|
-
state.pendingAuths.set(key, pendingAuth);
|
|
470
|
-
state.pendingAuthStates.set(key, oauthState);
|
|
471
|
-
const cleanupTimer = setTimeout(() => {
|
|
472
|
-
clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, pendingAuth.authStorageOptions, new Error("OAuth authorization timeout - authorization took too long")).catch((error) => {
|
|
473
|
-
console.error(`MCP Auth: Timed-out flow cleanup failed: ${formatTerminalError(error)}`);
|
|
474
|
-
});
|
|
475
|
-
}, MANUAL_AUTH_TIMEOUT_MS);
|
|
476
|
-
cleanupTimer.unref?.();
|
|
477
|
-
state.pendingAuthCleanupTimers.set(key, cleanupTimer);
|
|
478
|
-
}
|
|
479
|
-
async function clearPendingAuth(runtime, serverName, oauthState, fallbackStorageOptions = {}, reason = new Error("Authorization cancelled")) {
|
|
480
|
-
const state = getRuntimeState(runtime);
|
|
481
|
-
const key = getPendingAuthKey(serverName, fallbackStorageOptions);
|
|
482
|
-
const pendingState = state.pendingAuthStates.get(key);
|
|
483
|
-
if (oauthState && pendingState !== oauthState) {
|
|
484
|
-
cancelPendingCallback(oauthState);
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
const { pendingAuth } = detachPending(state, key, reason);
|
|
488
|
-
const authStorageOptions = pendingAuth?.authStorageOptions ?? fallbackStorageOptions;
|
|
489
|
-
const stateToRelease = pendingState ?? oauthState;
|
|
490
|
-
if (stateToRelease) {
|
|
491
|
-
if (!pendingState)
|
|
492
|
-
cancelPendingCallback(stateToRelease);
|
|
493
|
-
if (pendingAuth && hasOAuthAuthority(pendingAuth.authority)) {
|
|
494
|
-
const storedState = getOAuthState(serverName, authStorageOptions);
|
|
495
|
-
if (storedState === stateToRelease)
|
|
496
|
-
clearOAuthState(serverName, authStorageOptions);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
function detachPending(state, key, reason) {
|
|
501
|
-
const pendingAuth = state.pendingAuths.get(key);
|
|
502
|
-
const oauthState = state.pendingAuthStates.get(key);
|
|
503
|
-
const timer = state.pendingAuthCleanupTimers.get(key);
|
|
504
|
-
if (timer)
|
|
505
|
-
clearTimeout(timer);
|
|
506
|
-
state.pendingAuthCleanupTimers.delete(key);
|
|
507
|
-
state.pendingAuths.delete(key);
|
|
508
|
-
state.pendingAuthStates.delete(key);
|
|
509
|
-
pendingAuth?.manualCompletionController?.abort(reason);
|
|
510
|
-
pendingAuth?.authProvider.deactivate();
|
|
511
|
-
if (oauthState)
|
|
512
|
-
cancelPendingCallback(oauthState);
|
|
513
|
-
return { pendingAuth, oauthState };
|
|
514
|
-
}
|
|
515
|
-
async function clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, fallbackStorageOptions = {}, reason) {
|
|
516
|
-
await cleanupAndReleaseCallbackServerIfIdle(() => clearPendingAuth(runtime, serverName, oauthState, fallbackStorageOptions, reason));
|
|
517
|
-
}
|
|
518
|
-
async function cleanupAndReleaseCallbackServerIfIdle(cleanup) {
|
|
519
|
-
let cleanupFailure;
|
|
520
|
-
try {
|
|
521
|
-
await cleanup();
|
|
522
|
-
} catch (error) {
|
|
523
|
-
cleanupFailure = { error };
|
|
524
|
-
}
|
|
525
|
-
try {
|
|
526
|
-
await stopCallbackServerIfIdle();
|
|
527
|
-
} catch (releaseError) {
|
|
528
|
-
if (cleanupFailure) {
|
|
529
|
-
throw new AggregateError([cleanupFailure.error, releaseError], "OAuth callback cleanup failed");
|
|
530
|
-
}
|
|
531
|
-
throw releaseError;
|
|
532
|
-
}
|
|
533
|
-
if (cleanupFailure)
|
|
534
|
-
throw cleanupFailure.error;
|
|
535
|
-
}
|
|
536
|
-
function detachPendingAuthsForServer(serverName, reason) {
|
|
537
|
-
for (const runtime of activeRuntimes) {
|
|
538
|
-
const state = getRuntimeState(runtime);
|
|
539
|
-
for (const [key, pendingAuth] of state.pendingAuths) {
|
|
540
|
-
if (pendingAuth.serverName !== serverName)
|
|
541
|
-
continue;
|
|
542
|
-
if (state.pendingAuths.get(key) !== pendingAuth)
|
|
543
|
-
continue;
|
|
544
|
-
detachPending(state, key, reason);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
function getSearchParamsFromInput(input) {
|
|
549
|
-
try {
|
|
550
|
-
const url = new URL(input);
|
|
551
|
-
const params = new URLSearchParams(url.search);
|
|
552
|
-
if (url.hash) {
|
|
553
|
-
const hash = url.hash.startsWith("#") ? url.hash.slice(1) : url.hash;
|
|
554
|
-
const hashParams = new URLSearchParams(hash);
|
|
555
|
-
for (const [key, value] of hashParams) {
|
|
556
|
-
if (!params.has(key))
|
|
557
|
-
params.set(key, value);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
return params;
|
|
561
|
-
} catch {
|
|
562
|
-
const query = input.includes("?") ? input.slice(input.indexOf("?") + 1) : input;
|
|
563
|
-
const params = new URLSearchParams(query.startsWith("#") ? query.slice(1) : query);
|
|
564
|
-
return params.has("code") || params.has("state") || params.has("error") ? params : undefined;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
export function parseAuthorizationRedirectInput(input, expectedState) {
|
|
568
|
-
const trimmed = input.trim();
|
|
569
|
-
if (!trimmed) {
|
|
570
|
-
throw new Error("Authorization code or redirect URL is required");
|
|
571
|
-
}
|
|
572
|
-
const params = getSearchParamsFromInput(trimmed);
|
|
573
|
-
if (params) {
|
|
574
|
-
const error = params.get("error");
|
|
575
|
-
if (error) {
|
|
576
|
-
const description = params.get("error_description");
|
|
577
|
-
throw new Error(description ? `${error}: ${description}` : error);
|
|
578
|
-
}
|
|
579
|
-
const state = params.get("state");
|
|
580
|
-
if (expectedState && !state) {
|
|
581
|
-
throw new Error("OAuth state missing from redirect URL");
|
|
582
|
-
}
|
|
583
|
-
if (expectedState && state !== expectedState) {
|
|
584
|
-
throw new Error("OAuth state mismatch - potential CSRF attack");
|
|
585
|
-
}
|
|
586
|
-
const code = params.get("code");
|
|
587
|
-
if (code) {
|
|
588
|
-
const iss = params.get("iss");
|
|
589
|
-
return { code, ...iss !== null ? { iss } : {} };
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
if (/^[A-Za-z0-9._~+/=-]+$/.test(trimmed)) {
|
|
593
|
-
return { code: trimmed };
|
|
594
|
-
}
|
|
595
|
-
throw new Error("Could not find an OAuth authorization code in the provided input");
|
|
596
|
-
}
|
|
597
|
-
export function parseAuthorizationCodeInput(input, expectedState) {
|
|
598
|
-
return parseAuthorizationRedirectInput(input, expectedState).code;
|
|
599
|
-
}
|
|
600
|
-
function waitForManualCompletionCancellation(signal) {
|
|
601
|
-
return new Promise((_, reject) => {
|
|
602
|
-
const rejectFromSignal = () => {
|
|
603
|
-
reject(signal.reason instanceof Error ? signal.reason : new Error("Authorization cancelled"));
|
|
604
|
-
};
|
|
605
|
-
if (signal.aborted) {
|
|
606
|
-
rejectFromSignal();
|
|
607
|
-
return;
|
|
608
|
-
}
|
|
609
|
-
signal.addEventListener("abort", rejectFromSignal, { once: true });
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
export async function waitForAuthorizationResponse(callbackPromise, authorizationUrl, expectedState, onAuthorizationInput, signal) {
|
|
613
|
-
if (!onAuthorizationInput) {
|
|
614
|
-
return {
|
|
615
|
-
input: await abortable(callbackPromise, signal),
|
|
616
|
-
source: "callback"
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
const inputController = new AbortController;
|
|
620
|
-
try {
|
|
621
|
-
const response = await abortable(Promise.race([
|
|
622
|
-
callbackPromise.then((input) => ({ input, source: "callback" })),
|
|
623
|
-
onAuthorizationInput(authorizationUrl, inputController.signal).then((input) => ({
|
|
624
|
-
input,
|
|
625
|
-
source: "manual"
|
|
626
|
-
}))
|
|
627
|
-
]), signal);
|
|
628
|
-
if (response.source === "callback")
|
|
629
|
-
return response;
|
|
630
|
-
if (!response.input?.trim())
|
|
631
|
-
throw new Error("OAuth authentication cancelled");
|
|
632
|
-
if (!getSearchParamsFromInput(response.input.trim())) {
|
|
633
|
-
throw new Error("Paste the full OAuth callback URL, including its code and state parameters");
|
|
634
|
-
}
|
|
635
|
-
return {
|
|
636
|
-
input: parseAuthorizationRedirectInput(response.input, expectedState),
|
|
637
|
-
source: "manual"
|
|
638
|
-
};
|
|
639
|
-
} finally {
|
|
640
|
-
inputController.abort();
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
export async function completeAuthFromInput(serverName, input, options = {}) {
|
|
644
|
-
const runtime = getRuntime(options);
|
|
645
|
-
const runtimeState = getRuntimeState(runtime);
|
|
646
|
-
const fallbackAuthStorageOptions = options.authStorageOptions ?? {};
|
|
647
|
-
const signal = combineAbortSignals(runtime.signal, options.signal);
|
|
648
|
-
throwIfAborted(signal);
|
|
649
|
-
const key = getPendingAuthKey(serverName, fallbackAuthStorageOptions);
|
|
650
|
-
const oauthState = runtimeState.pendingAuthStates.get(key);
|
|
651
|
-
const pendingAuth = runtimeState.pendingAuths.get(key);
|
|
652
|
-
throwIfAborted(signal);
|
|
653
|
-
if (pendingAuth?.manualRedirect && !getSearchParamsFromInput(input.trim())) {
|
|
654
|
-
throw new Error("Paste the full OAuth callback URL, including its code and state parameters");
|
|
655
|
-
}
|
|
656
|
-
const parsed = parseAuthorizationRedirectInput(input, oauthState);
|
|
657
|
-
return completeAuth(serverName, parsed, options);
|
|
658
|
-
}
|
|
659
|
-
export async function completeAuth(serverName, authorizationCode, options = {}) {
|
|
660
|
-
const runtime = getRuntime(options);
|
|
661
|
-
const runtimeState = getRuntimeState(runtime);
|
|
662
|
-
const { code, iss } = typeof authorizationCode === "string" ? { code: authorizationCode, iss: undefined } : authorizationCode;
|
|
663
|
-
const fallbackAuthStorageOptions = options.authStorageOptions ?? {};
|
|
664
|
-
const signal = combineAbortSignals(runtime.signal, options.signal);
|
|
665
|
-
throwIfAborted(signal);
|
|
666
|
-
const key = getPendingAuthKey(serverName, fallbackAuthStorageOptions);
|
|
667
|
-
const pendingAuth = runtimeState.pendingAuths.get(key);
|
|
668
|
-
const authStorageOptions = pendingAuth?.authStorageOptions ?? fallbackAuthStorageOptions;
|
|
669
|
-
if (!pendingAuth) {
|
|
670
|
-
throw new Error(`No pending OAuth flow for server: ${serverName}`);
|
|
671
|
-
}
|
|
672
|
-
pendingAuth.authority();
|
|
673
|
-
const oauthState = runtimeState.pendingAuthStates.get(key);
|
|
674
|
-
throwIfAborted(signal);
|
|
675
|
-
let keepPendingForRetry = false;
|
|
676
|
-
let caughtError;
|
|
677
|
-
try {
|
|
678
|
-
const fetchFn = createOAuthFetch(pendingAuth.serverUrl, pendingAuth.getHeaders, signal);
|
|
679
|
-
pendingAuth.authProvider.setAuthFetch(fetchFn);
|
|
680
|
-
const discoveryState = await pendingAuth.authProvider.discoveryState();
|
|
681
|
-
pendingAuth.authority();
|
|
682
|
-
const metadata = discoveryState?.authorizationServerMetadata;
|
|
683
|
-
const expectedIssuer = metadata?.issuer ?? discoveryState?.authorizationServerUrl;
|
|
684
|
-
const requiresIssuer = metadata?.authorization_response_iss_parameter_supported === true;
|
|
685
|
-
if (expectedIssuer !== undefined && iss === undefined && requiresIssuer) {
|
|
686
|
-
keepPendingForRetry = true;
|
|
687
|
-
throw new Error(`The authorization server for ${serverName} requires the RFC 9207 "iss" parameter. ` + "Paste the full redirect URL from the browser address bar (not just the authorization code).");
|
|
688
|
-
}
|
|
689
|
-
if (expectedIssuer !== undefined && iss !== undefined && iss !== expectedIssuer) {
|
|
690
|
-
throw new Error(`The OAuth authorization response issuer does not match the discovered issuer for ${serverName}.`);
|
|
691
|
-
}
|
|
692
|
-
const result = await abortable(runSdkAuth(pendingAuth.authProvider, {
|
|
693
|
-
serverUrl: pendingAuth.serverUrl,
|
|
694
|
-
authorizationCode: code,
|
|
695
|
-
...iss !== undefined ? { iss } : {},
|
|
696
|
-
...pendingAuth.discovery,
|
|
697
|
-
fetchFn
|
|
698
|
-
}), signal);
|
|
699
|
-
pendingAuth.authority();
|
|
700
|
-
throwIfAborted(signal);
|
|
701
|
-
if (result !== "AUTHORIZED") {
|
|
702
|
-
throw new UnauthorizedError("Failed to authorize");
|
|
703
|
-
}
|
|
704
|
-
return "authenticated";
|
|
705
|
-
} catch (error) {
|
|
706
|
-
caughtError = error;
|
|
707
|
-
throw error;
|
|
708
|
-
} finally {
|
|
709
|
-
if (!keepPendingForRetry) {
|
|
710
|
-
try {
|
|
711
|
-
await clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, authStorageOptions);
|
|
712
|
-
} catch (cleanupError) {
|
|
713
|
-
if (caughtError !== undefined) {
|
|
714
|
-
throw new AggregateError([caughtError, cleanupError], "OAuth completion cleanup failed");
|
|
715
|
-
}
|
|
716
|
-
throw cleanupError;
|
|
717
|
-
}
|
|
718
|
-
if (caughtError === undefined)
|
|
719
|
-
pendingAuth.authority();
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
export async function authenticate(serverName, serverUrl, definition, options = {}) {
|
|
724
|
-
if (isServerDisabled(definition))
|
|
725
|
-
throw new Error(`MCP server "${serverName}" is disabled`);
|
|
726
|
-
const authority = captureOAuthAuthority(serverName);
|
|
727
|
-
const runtime = getRuntime(options);
|
|
728
|
-
const runtimeState = getRuntimeState(runtime);
|
|
729
|
-
const authStorageOptions = options.authStorageOptions ?? {};
|
|
730
|
-
const signal = combineAbortSignals(runtime.signal, options.signal);
|
|
731
|
-
throwIfAborted(signal);
|
|
732
|
-
const authKey = JSON.stringify([serverName, serverUrl, ...getAuthStorageIdentity(authStorageOptions)]);
|
|
733
|
-
const inFlight = runtimeState.pendingAuthentications.get(authKey);
|
|
734
|
-
if (inFlight) {
|
|
735
|
-
try {
|
|
736
|
-
inFlight.authority();
|
|
737
|
-
return inFlight.promise;
|
|
738
|
-
} catch {
|
|
739
|
-
if (runtimeState.pendingAuthentications.get(authKey) === inFlight) {
|
|
740
|
-
runtimeState.pendingAuthentications.delete(authKey);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
const operation = (async () => {
|
|
745
|
-
const { authorizationUrl } = await startAuth(serverName, serverUrl, definition, {
|
|
746
|
-
...options,
|
|
747
|
-
...signal ? { signal } : {},
|
|
748
|
-
runtime
|
|
749
|
-
}, authority);
|
|
750
|
-
authority();
|
|
751
|
-
if (!authorizationUrl) {
|
|
752
|
-
return "authenticated";
|
|
753
|
-
}
|
|
754
|
-
let oauthState;
|
|
755
|
-
try {
|
|
756
|
-
oauthState = runtimeState.pendingAuthStates.get(getPendingAuthKey(serverName, authStorageOptions));
|
|
757
|
-
throwIfAborted(signal);
|
|
758
|
-
if (!oauthState) {
|
|
759
|
-
throw new Error("OAuth state not found - this should not happen");
|
|
760
|
-
}
|
|
761
|
-
const pendingAuth = runtimeState.pendingAuths.get(getPendingAuthKey(serverName, authStorageOptions));
|
|
762
|
-
if (!pendingAuth) {
|
|
763
|
-
throw new Error(`No pending OAuth flow for server: ${serverName}`);
|
|
764
|
-
}
|
|
765
|
-
if (pendingAuth.manualRedirect && !options.onAuthorizationInput) {
|
|
766
|
-
throw new Error(`OAuth for ${serverName} uses a remote redirect URI. Complete it with auth-start/auth-complete or /mcp-auth.`);
|
|
767
|
-
}
|
|
768
|
-
const callbackPromise = pendingAuth.manualRedirect ? waitForManualCompletionCancellation(pendingAuth.manualCompletionController.signal) : waitForCallback(oauthState);
|
|
769
|
-
callbackPromise.catch(() => {});
|
|
770
|
-
if (options.onAuthorizationUrl) {
|
|
771
|
-
await abortable(Promise.resolve(options.onAuthorizationUrl(authorizationUrl)), signal);
|
|
772
|
-
} else {
|
|
773
|
-
console.log(`MCP Auth: Open this URL to authenticate ${serverName}:
|
|
774
|
-
${authorizationUrl}`);
|
|
775
|
-
}
|
|
776
|
-
try {
|
|
777
|
-
await abortable(Promise.resolve(options.openAuthorizationUrl ? options.openAuthorizationUrl(authorizationUrl) : open(authorizationUrl)), signal);
|
|
778
|
-
} catch (error) {
|
|
779
|
-
if (isAbortError(error, signal))
|
|
780
|
-
throw error;
|
|
781
|
-
console.warn(`MCP Auth: Failed to open browser for ${serverName}; waiting for manual callback`, { error });
|
|
782
|
-
}
|
|
783
|
-
const authorizationResponse = await waitForAuthorizationResponse(callbackPromise, authorizationUrl, oauthState, options.onAuthorizationInput, signal);
|
|
784
|
-
if (authorizationResponse.source === "manual") {
|
|
785
|
-
cancelPendingCallback(oauthState);
|
|
786
|
-
}
|
|
787
|
-
throwIfAborted(signal);
|
|
788
|
-
return await completeAuth(serverName, authorizationResponse.input, {
|
|
789
|
-
...options,
|
|
790
|
-
...signal ? { signal } : {},
|
|
791
|
-
runtime
|
|
792
|
-
});
|
|
793
|
-
} catch (error) {
|
|
794
|
-
if (oauthState)
|
|
795
|
-
cancelPendingCallback(oauthState);
|
|
796
|
-
try {
|
|
797
|
-
await clearPendingAuthAndReleaseIfIdle(runtime, serverName, oauthState, authStorageOptions);
|
|
798
|
-
} catch (cleanupError) {
|
|
799
|
-
throw new AggregateError([error, cleanupError], "OAuth cancellation cleanup failed");
|
|
800
|
-
}
|
|
801
|
-
throw error;
|
|
802
|
-
}
|
|
803
|
-
})();
|
|
804
|
-
const pendingAuthentication = { promise: operation, authority };
|
|
805
|
-
runtimeState.pendingAuthentications.set(authKey, pendingAuthentication);
|
|
806
|
-
try {
|
|
807
|
-
const result = await operation;
|
|
808
|
-
authority();
|
|
809
|
-
return result;
|
|
810
|
-
} finally {
|
|
811
|
-
if (runtimeState.pendingAuthentications.get(authKey) === pendingAuthentication) {
|
|
812
|
-
runtimeState.pendingAuthentications.delete(authKey);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
export async function getValidToken(serverName, serverUrl, options = {}) {
|
|
817
|
-
const authority = captureOAuthAuthority(serverName);
|
|
818
|
-
const runtime = getRuntime(options);
|
|
819
|
-
const authStorageOptions = options.authStorageOptions ?? {};
|
|
820
|
-
const signal = combineAbortSignals(runtime.signal, options.signal);
|
|
821
|
-
throwIfAborted(signal);
|
|
822
|
-
const entry = await getAuthForUrl(serverName, serverUrl, authStorageOptions);
|
|
823
|
-
if (!hasOAuthAuthority(authority))
|
|
824
|
-
return null;
|
|
825
|
-
throwIfAborted(signal);
|
|
826
|
-
if (!entry?.tokens) {
|
|
827
|
-
return null;
|
|
828
|
-
}
|
|
829
|
-
const expired = entry.tokens.expiresAt ? entry.tokens.expiresAt < Date.now() / 1000 : false;
|
|
830
|
-
if (expired === false) {
|
|
831
|
-
authority();
|
|
832
|
-
return entry.tokens;
|
|
833
|
-
}
|
|
834
|
-
if (expired === true && entry.tokens.refreshToken) {
|
|
835
|
-
console.log(`MCP Auth: Token expired for ${serverName}, attempting refresh`);
|
|
836
|
-
try {
|
|
837
|
-
const config = options.definition ? extractOAuthConfig(options.definition) : {};
|
|
838
|
-
const fetchFn = createOAuthFetch(serverUrl, pluginAwareOAuthHeaders(options.definition), signal);
|
|
839
|
-
authority();
|
|
840
|
-
const authProvider = new McpOAuthProvider(serverName, serverUrl, config, {
|
|
841
|
-
onRedirect: async () => {}
|
|
842
|
-
}, authStorageOptions, runtime.signal, undefined, authority);
|
|
843
|
-
try {
|
|
844
|
-
authProvider.setAuthFetch(fetchFn);
|
|
845
|
-
const clientInfo = await authProvider.clientInformation();
|
|
846
|
-
authority();
|
|
847
|
-
throwIfAborted(signal);
|
|
848
|
-
if (!clientInfo) {
|
|
849
|
-
console.log(`MCP Auth: No client info for refresh for ${serverName}`);
|
|
850
|
-
return null;
|
|
851
|
-
}
|
|
852
|
-
const discovery = applyOAuthConfig(await probeAuthDiscovery(serverUrl, options.definition, signal), config);
|
|
853
|
-
authority();
|
|
854
|
-
throwIfAborted(signal);
|
|
855
|
-
const result = await abortable(runSdkAuth(authProvider, {
|
|
856
|
-
serverUrl,
|
|
857
|
-
...discovery,
|
|
858
|
-
...options.skipIssuerMetadataValidation === true ? { skipIssuerMetadataValidation: true } : {},
|
|
859
|
-
fetchFn
|
|
860
|
-
}), signal);
|
|
861
|
-
authority();
|
|
862
|
-
throwIfAborted(signal);
|
|
863
|
-
if (result !== "AUTHORIZED") {
|
|
864
|
-
return null;
|
|
865
|
-
}
|
|
866
|
-
const refreshed = await getAuthForUrl(serverName, serverUrl, authStorageOptions);
|
|
867
|
-
authority();
|
|
868
|
-
throwIfAborted(signal);
|
|
869
|
-
return refreshed?.tokens ?? null;
|
|
870
|
-
} finally {
|
|
871
|
-
authProvider.deactivate();
|
|
872
|
-
}
|
|
873
|
-
} catch (error) {
|
|
874
|
-
if (isAbortError(error, signal) || error instanceof OAuthCredentialStoreError)
|
|
875
|
-
throw error;
|
|
876
|
-
console.error(`MCP Auth: Token refresh failed for ${serverName}`);
|
|
877
|
-
return null;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
authority();
|
|
881
|
-
return null;
|
|
882
|
-
}
|
|
883
|
-
export async function getAuthStatus(serverName, options = {}) {
|
|
884
|
-
getRuntime(options);
|
|
885
|
-
const authStorageOptions = options.authStorageOptions ?? {};
|
|
886
|
-
const entry = getAuthEntry(serverName, authStorageOptions);
|
|
887
|
-
if (!entry?.tokens)
|
|
888
|
-
return "not_authenticated";
|
|
889
|
-
return entry.tokens.expiresAt && entry.tokens.expiresAt < Date.now() / 1000 ? "expired" : "authenticated";
|
|
890
|
-
}
|
|
891
|
-
export async function removeAuth(serverName, options = {}) {
|
|
892
|
-
const runtime = getRuntime(options);
|
|
893
|
-
const signal = combineAbortSignals(runtime.signal, options.signal);
|
|
894
|
-
throwIfAborted(signal);
|
|
895
|
-
const authStorageOptions = options.authStorageOptions ?? {};
|
|
896
|
-
const releaseRevocation = beginOAuthRevocation(serverName);
|
|
897
|
-
try {
|
|
898
|
-
detachPendingAuthsForServer(serverName, new Error("Authorization cancelled by logout"));
|
|
899
|
-
const storedOAuthState = getOAuthState(serverName, authStorageOptions);
|
|
900
|
-
if (storedOAuthState)
|
|
901
|
-
cancelPendingCallback(storedOAuthState);
|
|
902
|
-
await stopCallbackServerIfIdle();
|
|
903
|
-
throwIfAborted(signal);
|
|
904
|
-
clearAllCredentials(serverName, authStorageOptions);
|
|
905
|
-
console.log(`MCP Auth: Removed credentials for ${serverName}`);
|
|
906
|
-
} finally {
|
|
907
|
-
releaseRevocation();
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
export function supportsOAuth(definition) {
|
|
911
|
-
if (!definition.url)
|
|
912
|
-
return false;
|
|
913
|
-
if (definition.auth === false)
|
|
914
|
-
return false;
|
|
915
|
-
if (definition.oauth === false)
|
|
916
|
-
return false;
|
|
917
|
-
if (definition.auth === "oauth")
|
|
918
|
-
return true;
|
|
919
|
-
if (definition.headers && Object.keys(definition.headers).length > 0)
|
|
920
|
-
return false;
|
|
921
|
-
return definition.auth === undefined;
|
|
922
|
-
}
|
|
923
|
-
export async function initializeOAuth(runtimeOrSignal) {
|
|
924
|
-
if (runtimeOrSignal && "signal" in runtimeOrSignal) {
|
|
925
|
-
runtimeOrSignal.signal.throwIfAborted();
|
|
926
|
-
activeRuntimes.add(runtimeOrSignal);
|
|
927
|
-
return runtimeOrSignal;
|
|
928
|
-
}
|
|
929
|
-
await shutdownOAuth(legacyRuntime);
|
|
930
|
-
legacyRuntime = createOAuthRuntime(runtimeOrSignal);
|
|
931
|
-
return legacyRuntime;
|
|
932
|
-
}
|
|
933
|
-
export async function shutdownOAuth(runtime = legacyRuntime) {
|
|
934
|
-
const state = getRuntimeState(runtime);
|
|
935
|
-
if (state.controller.signal.aborted)
|
|
936
|
-
return;
|
|
937
|
-
state.generation += 1;
|
|
938
|
-
state.controller.abort(new Error("OAuth runtime stopped"));
|
|
939
|
-
for (const callbackState of Array.from(state.pendingAuthStates.values()))
|
|
940
|
-
cancelPendingCallback(callbackState);
|
|
941
|
-
for (const pendingAuth of Array.from(state.pendingAuths.values())) {
|
|
942
|
-
await clearPendingAuth(runtime, pendingAuth.serverName, undefined, pendingAuth.authStorageOptions);
|
|
943
|
-
}
|
|
944
|
-
state.pendingAuthentications.clear();
|
|
945
|
-
activeRuntimes.delete(runtime);
|
|
946
|
-
if (activeRuntimes.size === 0) {
|
|
947
|
-
await stopCallbackServer();
|
|
948
|
-
}
|
|
949
|
-
}
|