Skip to content

fix(mcp): review fixes for auth-aware gateway MCP#282

Merged
leggetter merged 3 commits intofix/mcp-not-logged-in-errorfrom
claude/review-pr-280-my8PD
Apr 1, 2026
Merged

fix(mcp): review fixes for auth-aware gateway MCP#282
leggetter merged 3 commits intofix/mcp-not-logged-in-errorfrom
claude/review-pr-280-my8PD

Conversation

@leggetter
Copy link
Copy Markdown
Collaborator

Summary

Review fixes for #280. Addresses bugs, adds missing tests, and improves code reuse.

  • ListProjects now returns *APIError: replaced manual fmt.Errorf status check with checkAndPrintError so the errors.As path in shouldSuggestReauthAfterListProjectsFailure matches directly — the string-matching fallback was never being reached for structured API errors
  • Session-level context for login polling: the polling goroutine now selects on srv.sessionCtx (set in Run()) instead of the per-request ctx, which was cancelled when the handler returned — breaking in-MCP authentication
  • Tightened error string matching: "status code: 4xx" instead of bare "401"/"403" to avoid false positives on IDs or timestamps
  • Reverted unrelated formatting: Attempt struct alignment in helpers.go
  • Added maintenance comment on flagNeedsNextArg linking it to init()
  • Documented happens-before guarantee on loginState.err after mutex removal

Tests added

  • TestLoginTool_PollSurvivesAcrossToolCalls — regression test: starts login, mock auth completes between tool calls, verifies client is authenticated on second call (catches the per-request ctx bug)
  • TestShouldSuggestReauthAfterListProjectsFailure — unit tests for reauth hint covering *APIError 401/403, plain error fallback, and false-positive resistance (proj_403_abc)
  • TestArgvContainsGatewayMCP — additional cases for boolean flags before/between subcommands

Test plan

  • Existing unit tests pass (go test ./pkg/...)
  • MCP acceptance tests pass (go test -tags mcp ./test/acceptance/...)
  • Manual: hookdeck gateway mcp without prior auth → hookdeck_login → browser auth → tools work

https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d

claude added 3 commits April 1, 2026 12:19
- tool_projects_errors.go: match "status code: 4xx" instead of bare
  "401"/"403" to avoid false positives on IDs or timestamps
- tool_login.go: remove `_ = ctx` suppression, add TODO for context
  propagation to polling goroutine, document happens-before on
  loginState.err via channel close
- root.go: add maintenance comment linking flagNeedsNextArg to init()
- helpers.go: revert unrelated Attempt struct alignment change

https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
Thread the request context into the login polling goroutine so it
stops promptly when the MCP transport closes, instead of running for
up to ~4 minutes after the client disconnects.

WaitForAPIKey blocks with time.Sleep and doesn't accept a context, so
we run it in an inner goroutine and select on both its result channel
and ctx.Done(). The inner goroutine is bounded by loginMaxAttempts.

https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
The per-request ctx passed to MCP tool handlers is cancelled when the
handler returns. The previous commit selected on that ctx in the login
polling goroutine, which killed the poll immediately after returning
the browser URL — breaking in-MCP authentication.

Fix: add a sessionCtx field to Server, set it in Run() (called by
RunStdio and tests), and select on that instead. The session context
is only cancelled when the MCP transport closes (stdin EOF), which is
the correct signal to abandon login polling.

Also adds TestLoginTool_PollSurvivesAcrossToolCalls: a regression test
that starts a login flow, lets the mock auth complete between tool
calls, and verifies the client is authenticated on the second call.
This would have caught the per-request ctx bug.

https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
@leggetter leggetter force-pushed the claude/review-pr-280-my8PD branch from 325da3f to 0291f9e Compare April 1, 2026 12:19
@leggetter leggetter merged commit 7eae180 into fix/mcp-not-logged-in-error Apr 1, 2026
1 check passed
@leggetter leggetter deleted the claude/review-pr-280-my8PD branch April 1, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants