You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: pkg/gateway/mcp/server.go
+16-2Lines changed: 16 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,12 @@ type Server struct {
18
18
client*hookdeck.Client
19
19
cfg*config.Config
20
20
mcpServer*mcpsdk.Server
21
+
22
+
// sessionCtx is the context passed to RunStdio. It is cancelled when the
23
+
// MCP transport closes (stdin EOF). Background goroutines (e.g. login
24
+
// polling) should select on this — NOT on the per-request ctx passed to
25
+
// tool handlers, which is cancelled when the handler returns.
26
+
sessionCtx context.Context
21
27
}
22
28
23
29
// NewServer creates an MCP server with all Hookdeck tools registered.
@@ -56,7 +62,7 @@ func (s *Server) registerTools() {
56
62
"reauth": {Type: "boolean", Desc: "If true, clear stored credentials and start a new browser login. Use when project listing fails — complete login in the browser, then retry hookdeck_projects."},
0 commit comments