Repository navigation
fix(mcp): start the OAuth sign-in when the MCP server never answers 401 (OHE-3880) - #1170
Merged
Merged
Conversation
…01 (OHE-3880) The OAuth sign-in job (POST /api/v1/mcp/oauth/start) runs the SDK probe (initialize and tools/list) and relied on the server answering 401 to start the authorization. Google's Drive MCP server answers both without credentials and only asks for a login on tool calls, so the job finished as a success with a state that held only the static client info, and Connect on Settings > MCP failed with "OAuth state carries no access token". - The app server's OAuth client now starts the authorization itself when it holds no usable token: it answers its own unauthenticated request with a 401, so the upstream client runs its normal discovery and consent flow. Valid or refreshable stored tokens still skip the consent. - A job whose probe ends without an access token is stored as failed with a clear message instead of as a success.
hieptl
marked this pull request as ready for review
November 4, 2026 05:30
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Contributor
|
🚀 Released in 1.86.0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
HUMAN:
AGENT:
Why
Clicking Connect on a user-managed Google Drive OAuth listing on Settings > MCP shows "OAuth state carries no access token" and the Google sign-in never opens. The sign-in job (
POST /api/v1/mcp/oauth/start) runs the SDK probe (initializeandtools/list) and relied on the server answering 401 to start the authorization. Google's Drive MCP server answers both without credentials (200, 8 tools) and only asks for a login on tool calls (401 withWWW-Authenticate: Bearer resource_metadata=...), so the job finished as a success with a state that held only the static client info, and the connection route refused it. The MCP Library install on Settings > MCP had the same gap and saved that token-less state.Summary
_CloudCoordinatedOAuth) now starts the authorization itself when it holds no usable token: it answers its own unauthenticated request with a 401, so the upstreammcpclient runs its normal flow unchanged (well-known metadata discovery, consent through the public callback, token exchange). Valid or refreshable stored tokens still skip the consent.Issue Number
OHE-3880 (bug bash OHE-3866 for OHE-3091). Backend of #1140.
How to Test
uv run --group test pytest tests/unit/app_server/test_mcp_oauth_router.py tests/unit/server/routes/test_org_mcp_servers.py55 tests pass. Two of the three new ones fail without the change; the stored-tokens one guards the "no consent needed" behaviour that must stay.
ruff,ruff-formatandmypy(dev_config/python/mypy.ini) are clean on the touched files.Against Google's Drive MCP server (
https://drivemcp.googleapis.com/mcp/v1) with a fake client id: onmainthe probe lists 8 tools, never calls the redirect handler and exports a state with onlyclient_info; with this change the client publishes the consent URL athttps://accounts.google.com/o/oauth2/v2/authwith the app server's callback asredirect_uri.Manual, on shared-5 (not done yet): add an organization server for Google Drive (the URL above, OAuth, the client id and client secret of a Google Cloud "Web application" OAuth client whose authorized redirect URIs include
https://app.shared-5.replicated.all-hands-testing.dev/api/v1/mcp/oauth/callback, "Each member signs in") and click Connect: Google's consent opens, and the row shows Connected afterwards.Video/Screenshots
Backend only.
Type
Notes
scopes_supported(Google:drive,drive.readonly,drive.file), after a real 401 as much as after this one. Unchanged here.<origin>/authorize) instead of a token-less success, the same as the upstream client's handling of a real 401 from such a server._BrowserCoordinatedOAuth(canvas install) shares the probe and has the same gap; to be handled in the SDK separately.Enterprise server image for this PR: