From 3d0b11129403240eabebc5cec09c32d11cc28086 Mon Sep 17 00:00:00 2001 From: lxcong Date: Fri, 15 May 2026 17:18:05 +0800 Subject: [PATCH] fix(install): always run auth-login, drop stale already_authed check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The installer was sniffing config files for "agentkey" + an "AGENTKEY_API_KEY": "ak_..." env-shaped pair to short-circuit MCP auth. After --auth-login switched to writing a remote-HTTP MCP block ("Authorization": "Bearer ak_...") in #47 / 1.7.0, the check went stale in both directions: - users still holding a stdio-shaped config from older releases matched the regex and were told "AgentKey is already configured in an MCP client config — skipping auth", but their MCP block no longer works because the stdio runtime is gone — calling the MCP tools post-install errors out - users who had successfully re-authed into the new HTTP shape no longer matched and got asked to re-auth on every installer run The simplest fix is to delete the heuristic. `@agentkey/cli --auth-login` is the source of truth for whether a fresh device-code round-trip is needed; the installer should hand control to the CLI instead of guessing from on-disk shape. Removes: - already_authed() in install.sh, Test-AlreadyAuthed in install.ps1 - --force-mcp / -ForceMcp flags (no longer meaningful) - "Re-authenticate even if AgentKey is already configured locally" documentation in README.md / docs/README_zh.md Co-Authored-By: Claude Opus 4.7 (1M context) --- README.md | 5 +---- docs/README_zh.md | 5 +---- scripts/install.ps1 | 28 ++++------------------------ scripts/install.sh | 29 ++++------------------------- 4 files changed, 10 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 26ee33d..d2e5d00 100644 --- a/README.md +++ b/README.md @@ -285,12 +285,9 @@ curl -fsSL https://agentkey.app/install.sh | bash -s -- --all-agents # Only the skill, or only the MCP auth curl -fsSL https://agentkey.app/install.sh | bash -s -- --skip-mcp curl -fsSL https://agentkey.app/install.sh | bash -s -- --skip-skill - -# Re-authenticate even if AgentKey is already configured locally -curl -fsSL https://agentkey.app/install.sh | bash -s -- --force-mcp ``` -PowerShell equivalents: `-Yes`, `-ListAgents`, `-Only`, `-AllAgents`, `-SkipMcp`, `-SkipSkill`, `-ForceMcp`. +PowerShell equivalents: `-Yes`, `-ListAgents`, `-Only`, `-AllAgents`, `-SkipMcp`, `-SkipSkill`. **Manual two-step install** (if you'd rather run the two underlying commands yourself, or the one-line installer can't reach your machine): diff --git a/docs/README_zh.md b/docs/README_zh.md index a0e2605..4510463 100644 --- a/docs/README_zh.md +++ b/docs/README_zh.md @@ -285,12 +285,9 @@ curl -fsSL https://agentkey.app/install.sh | bash -s -- --all-agents # 只装 Skill 或只做 MCP 授权 curl -fsSL https://agentkey.app/install.sh | bash -s -- --skip-mcp curl -fsSL https://agentkey.app/install.sh | bash -s -- --skip-skill - -# 即使本机已经配置过 AgentKey 也强制重新走一次授权 -curl -fsSL https://agentkey.app/install.sh | bash -s -- --force-mcp ``` -PowerShell 对应参数:`-Yes`、`-ListAgents`、`-Only`、`-AllAgents`、`-SkipMcp`、`-SkipSkill`、`-ForceMcp`。 +PowerShell 对应参数:`-Yes`、`-ListAgents`、`-Only`、`-AllAgents`、`-SkipMcp`、`-SkipSkill`。 **手动两步安装**(想自己跑两条底层命令,或一键脚本在你的环境里跑不起来): diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 4bb74f7..b5fccd1 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -26,7 +26,6 @@ param( [switch]$ListAgents, [switch]$Remote, [switch]$Local, - [switch]$ForceMcp, [switch]$SkipSkill, [switch]$SkipMcp, [switch]$NoTelemetry, @@ -120,24 +119,6 @@ function Test-RemoteInstall { return $false } -# Cheap "is AgentKey already configured?" check across known MCP config files. -function Test-AlreadyAuthed { - $configs = @( - "$env:USERPROFILE\.claude.json", - "$env:USERPROFILE\.cursor\mcp.json", - "$env:APPDATA\Claude\claude_desktop_config.json" - ) - foreach ($cfg in $configs) { - if (-not (Test-Path -LiteralPath $cfg)) { continue } - $content = Get-Content -Raw -LiteralPath $cfg -ErrorAction SilentlyContinue - if (-not $content) { continue } - if ($content -match '"agentkey"' -and $content -match '"AGENTKEY_API_KEY"\s*:\s*"ak_[A-Za-z0-9_-]+"') { - return $true - } - } - return $false -} - # ── Help ────────────────────────────────────────────────────────────────── if ($Help) { @' @@ -158,7 +139,6 @@ Parameters: SSH, in WinRM, in a container, or via OpenClaw / Claude Code remote channels. -Local Force local mode (auto-open browser) and bypass remote heuristics - -ForceMcp Re-run MCP auth even if AgentKey is already configured -SkipSkill Skip the skill install step (only run MCP auth) -SkipMcp Skip the MCP auth step (only install the skill) -NoTelemetry Disable anonymous usage telemetry (writes @@ -347,13 +327,13 @@ if (-not $SkipSkill) { } # ── 3. MCP authentication ──────────────────────────────────────────────── +# Always run auth-login. The CLI itself decides whether the existing token +# can be reused or a fresh device-code flow is needed — the installer no +# longer second-guesses by sniffing config files (which produced false +# positives across the stdio → HTTP schema change). if ($SkipMcp) { Write-Step '3. Register the MCP server' Write-Muted 'Skipped (-SkipMcp)' -} elseif ((Test-AlreadyAuthed) -and -not $ForceMcp) { - Write-Step '3. Register the MCP server' - Write-Ok 'AgentKey is already configured in an MCP client config — skipping auth.' - Write-Muted 'Re-run with -ForceMcp to authenticate again.' } else { $isRemote = Test-RemoteInstall $authArgs = @('--auth-login') diff --git a/scripts/install.sh b/scripts/install.sh index a0be721..06cc24d 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -108,7 +108,6 @@ Options: do NOT auto-open a local browser. Use this when running over SSH, in Docker, or via OpenClaw / Claude Code remote channels. --local Force local mode (auto-open browser) and bypass remote heuristics - --force-mcp Re-run MCP auth even if AgentKey is already configured --skip-skill Skip the skill install step (only run MCP auth) --skip-mcp Skip the MCP auth step (only install the skill) --no-telemetry Disable anonymous usage telemetry (writes @@ -193,24 +192,6 @@ detect_remote() { return 1 } -# Cheap "is AgentKey already configured?" check across known MCP config files. -# Greps for an agentkey block + a non-empty AGENTKEY_API_KEY of the expected -# shape. Returns 0 if at least one config has both. -already_authed() { - local cfg - for cfg in "$HOME/.claude.json" \ - "$HOME/.cursor/mcp.json" \ - "$HOME/Library/Application Support/Claude/claude_desktop_config.json" \ - "$HOME/.config/Claude/claude_desktop_config.json"; do - [ -f "$cfg" ] || continue - if grep -q '"agentkey"' "$cfg" 2>/dev/null \ - && grep -qE '"AGENTKEY_API_KEY"[^"]*"ak_[A-Za-z0-9_-]+"' "$cfg" 2>/dev/null; then - return 0 - fi - done - return 1 -} - install_node() { local platform="$1" ui_info "Installing Node.js v$NODE_MIN_MAJOR+ ..." @@ -272,7 +253,6 @@ main() { local PRINT_HELP=false local LIST_AGENTS=false local ALL_AGENTS=false - local FORCE_MCP=false # FORCE_REMOTE / FORCE_LOCAL are read by detect_remote(). Declared as # plain (non-`local`) so the helpers see them — they're dynamic-scope # accessible either way in bash, but explicit assignment here keeps @@ -295,7 +275,6 @@ main() { --list-agents) LIST_AGENTS=true; shift ;; --remote) FORCE_REMOTE=true; shift ;; --local) FORCE_LOCAL=true; shift ;; - --force-mcp) FORCE_MCP=true; shift ;; --skip-skill) SKIP_SKILL=true; shift ;; --skip-mcp) SKIP_MCP=true; shift ;; --no-telemetry) NO_TELEMETRY=true; shift ;; @@ -481,13 +460,13 @@ main() { fi # ── 3. MCP authentication ──────────────────────────────────────────── + # Always run auth-login. The CLI itself decides whether the existing + # token can be reused or a fresh device-code flow is needed — the + # installer no longer second-guesses by sniffing config files (which + # produced false positives across the stdio → HTTP schema change). if $SKIP_MCP; then ui_step "3. Register the MCP server" ui_muted "Skipped (--skip-mcp)" - elif already_authed && ! $FORCE_MCP; then - ui_step "3. Register the MCP server" - ui_ok "AgentKey is already configured in an MCP client config — skipping auth." - ui_muted "Re-run with --force-mcp to authenticate again." else # Decide local-vs-remote and route the MCP CLI flags accordingly. local IS_REMOTE=false