Commit e027484
fix(mcp): auth-aware gateway MCP, stdio stderr, login reauth (#280)
* fix(mcp): auth-aware gateway MCP, stderr for Execute, login reauth
- Skip requireGatewayProject for gateway mcp when no API key; enforce when key present
- Route gateway mcp errors and login-required messages to stderr; no interactive login
- argvContainsGatewayMCP skips global flags (e.g. --profile, -p)
- Always register hookdeck_login with optional reauth; clear credentials then device login
- Hedged list-projects failure hint suggesting reauth for 401/403-style errors
- ClearMCPProfileCredentials for memory-only or persisted config
- Acceptance: subprocess gateway mcp with stdin pipe; stdout JSON-RPC hygiene
Made-with: Cursor
* refactor(config): centralize silent credential clear for logout and MCP
- Rename ClearMCPProfileCredentials to ClearActiveProfileCredentials; document disk vs memory paths
- Logout uses the same helper as MCP reauth; zeroProfileCredentialFields helper
- RemoveAllProfiles clears in-memory credential fields after wiping the file (parity with logout -a)
- Rename config test to match new API
Made-with: Cursor
* Tighten error matching, improve login context handling, and tests (#281)
* fix(review): tighten error matching, add safety comments, revert noise
- 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
* fix(review): ListProjects returns *APIError, add reauth + argv tests
- projects.go: use checkAndPrintError instead of manual status check so
ListProjects errors are structured *APIError — the errors.As path in
shouldSuggestReauthAfterListProjectsFailure now matches directly
- tool_projects_errors_test.go: unit tests for reauth hint logic covering
APIError 401/403, plain error fallback, and false-positive resistance
- root_argv_test.go: document boolean-flag-between-subcommands limitation
https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
* fix(mcp): cancel login polling goroutine on MCP session close
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
---------
Co-authored-by: Claude <noreply@anthropic.com>
* fix(mcp): review fixes for auth-aware gateway MCP (#282)
* fix(review): tighten error matching, add safety comments, revert noise
- 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
* fix(mcp): cancel login polling goroutine on MCP session close
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
* fix(mcp): use session-level context for login polling, not per-request
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
---------
Co-authored-by: Claude <noreply@anthropic.com>
* fix(test): MCP login poll timing, profile save guard, retry API 500
- Wait loginPollInterval before second hookdeck_login in PollSurvives test
- SaveActiveProfileAfterLogin: skip disk persist when viper nil (tests)
- CLIRunner: retry transient HTTP 500 like 502 for acceptance flakes
Made-with: Cursor
* fix(cli): validate without stale project headers; sync profile from API
Omit X-Team-ID/X-Project-ID on GET /cli-auth/validate via clientForCLIAuthValidate
so a valid CLI key is not rejected when config.toml has a stale project_id.
After successful validate on the existing-key login path, persist project_id,
project_mode, and project_type from the response.
Add Profile Apply* helpers for validate, poll, and CI responses; use them from
login, interactive login, and MCP hookdeck_login. requireGatewayProject now
applies the full validate response (including project_id) without clearing
guest_url.
Tests: auth validate headers, profile apply helpers, LoadConfigFromFile,
gateway resolve-from-validate integration.
Made-with: Cursor
* docs(agents): go test in Cursor, module cache, out-of-sandbox runs
Document GOMODCACHE for agent shells, prompt-first elevated execution, and
point CLAUDE.md at AGENTS.md as the single source for agent instructions.
Made-with: Cursor
* chore: send command flag names in CLI telemetry
Include changed flag names (not values) as command_flags in
X-Hookdeck-CLI-Telemetry JSON. Wire CollectChangedFlagNames from root
initTelemetry. Add unit tests and acceptance test for login --api-key
and --cli-key over the recording proxy.
Made-with: Cursor
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent fa7cf93 commit e027484
File tree
33 files changed
+1264
-128
lines changed- pkg
- cmd
- config
- gateway/mcp
- hookdeck
- login
- logout
- test/acceptance
33 files changed
+1264
-128
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
231 | 240 | | |
232 | 241 | | |
233 | 242 | | |
234 | 243 | | |
235 | 244 | | |
236 | | - | |
| 245 | + | |
237 | 246 | | |
238 | 247 | | |
239 | 248 | | |
| |||
243 | 252 | | |
244 | 253 | | |
245 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
246 | 293 | | |
247 | 294 | | |
248 | 295 | | |
249 | 296 | | |
250 | | - | |
| 297 | + | |
251 | 298 | | |
252 | 299 | | |
253 | 300 | | |
254 | 301 | | |
255 | 302 | | |
256 | | - | |
| 303 | + | |
257 | 304 | | |
258 | 305 | | |
259 | 306 | | |
| |||
277 | 324 | | |
278 | 325 | | |
279 | 326 | | |
280 | | - | |
281 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
282 | 330 | | |
283 | 331 | | |
284 | 332 | | |
285 | | - | |
| 333 | + | |
286 | 334 | | |
287 | 335 | | |
288 | 336 | | |
| |||
358 | 406 | | |
359 | 407 | | |
360 | 408 | | |
361 | | - | |
| 409 | + | |
362 | 410 | | |
363 | 411 | | |
364 | 412 | | |
| |||
384 | 432 | | |
385 | 433 | | |
386 | 434 | | |
387 | | - | |
| 435 | + | |
| 436 | + | |
388 | 437 | | |
389 | 438 | | |
390 | 439 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
16 | 36 | | |
17 | 37 | | |
18 | 38 | | |
| |||
31 | 51 | | |
32 | 52 | | |
33 | 53 | | |
34 | | - | |
| 54 | + | |
| 55 | + | |
35 | 56 | | |
36 | 57 | | |
37 | 58 | | |
38 | 59 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 60 | + | |
| 61 | + | |
42 | 62 | | |
43 | 63 | | |
44 | 64 | | |
| |||
69 | 89 | | |
70 | 90 | | |
71 | 91 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 92 | + | |
76 | 93 | | |
77 | 94 | | |
78 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
7 | 12 | | |
| 13 | + | |
8 | 14 | | |
9 | 15 | | |
10 | 16 | | |
| |||
86 | 92 | | |
87 | 93 | | |
88 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
| |||
0 commit comments