Fix multi-user credential switching in same session #253
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a critical bug where the MCP server was unable to switch between multiple Google account credentials within the same session. The server would bind to the first authenticated user and ignore the
user_google_emailparameter on subsequent requests.Problem
The
get_credentials()function inauth/google_auth.pyhas two credential lookup paths:Both paths were returning cached credentials based solely on
session_id, without validating that the cached credentials matched the requesteduser_google_emailparameter. This caused all tool calls within a session to use the first authenticated user's credentials, even when a differentuser_google_emailwas specified.Solution
Added user validation to both credential lookup paths:
Changes to
auth/google_auth.pyPath 1: OAuth21SessionStore lookup (lines 546-590)
credentials = Noneto force reload from credential storePath 2: Session cache lookup (lines 623-648)
credentials = Noneto force reload from credential storeBoth validations use
OAuth21SessionStore.get_user_by_mcp_session()to determine the cached user email and compare it with the requesteduser_google_emailparameter.Testing
Verified the fix works correctly:
✅ Create operations - Can create tasks on different accounts:
✅ List operations - Returns correct data for each account:
✅ Account switching - Can alternate between accounts seamlessly without re-authentication
Impact
This fix enables:
user_google_emailparameterFiles Changed
auth/google_auth.py- Modifiedget_credentials()function to validate cached credentials match requested userCommits
1975ffd- Initial fix for session cache credential validation6b006c9- Complete fix for OAuth21SessionStore credential validation🤖 Generated with Claude Code