Skip to content

fix(mcp): stop OAuth callback server after authentication completes#23572

Open
hchangjae wants to merge 2 commits into
anomalyco:devfrom
hchangjae:fix/stop-oauth-callback-after-auth-v2
Open

fix(mcp): stop OAuth callback server after authentication completes#23572
hchangjae wants to merge 2 commits into
anomalyco:devfrom
hchangjae:fix/stop-oauth-callback-after-auth-v2

Conversation

@hchangjae
Copy link
Copy Markdown

Issue for this PR

Closes #23568

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The OAuth callback server (port 19876) stays running after authenticate() completes. When multiple TUI instances run, the first instance holds the port — subsequent instances register state in their own pendingAuths Map but callbacks arrive at the first instance where pendingStates=[], causing CSRF errors.

Adds stopIfIdle() that stops the server only when pendingAuths is empty, called after authenticate() resolves. Safe for concurrent auth flows.

How did you verify your code works?

  • Traced all code paths through authenticate() to confirm cleanup on success and state-mismatch error
  • Verified stopIfIdle() guards on pendingAuths.size === 0 so concurrent flows are unaffected
  • Follows existing cleanup pattern: Effect.tryPromise().pipe(Effect.ignore)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.

[Bug]: OAuth callback server (port 19876) not stopped after authentication, causing cross-instance CSRF failures

1 participant