Drive MCP connection login (RFC 8707 resource) from ucode mcp-proxy - #548
Open
sunishsheth2009 wants to merge 1 commit into
Open
Drive MCP connection login (RFC 8707 resource) from ucode mcp-proxy#548sunishsheth2009 wants to merge 1 commit into
sunishsheth2009 wants to merge 1 commit into
Conversation
When an AI Gateway MCP service is backed by a per-user connection (e.g. system.ai.github) with no stored credential, the gateway answers a tools call with an RFC 9728 challenge (HTTP 401 + WWW-Authenticate resource_metadata). The proxy currently forwards that to the coding agent as a plain "tools fetch failed" — the connection login never happens. Teach the proxy's httpx auth to detect that challenge and drive an interactive resource-scoped OAuth login: authorization-code + PKCE against /oidc using the published databricks-cli app, with the MCP endpoint URL sent as the RFC 8707 resource indicator so /oidc routes through the connection's /mcp-service-login page. After login the connection credential exists, so the same request is retried and succeeds. - resource_login.py: standalone stdlib OAuth-with-resource flow + loopback callback. - mcp_proxy.py: async_auth_flow detects the challenge, runs the login off the event loop, and retries once. Skipped under DATABRICKS_BEARER (headless/CI). - Tests for authorize-URL/PKCE construction and challenge detection. Co-authored-by: Isaac <no-reply@databricks.com>
sunishsheth2009
force-pushed
the
mcp-connection-login
branch
from
September 10, 2026 00:14
8320c21 to
237d409
Compare
sunishsheth2009
marked this pull request as ready for review
September 10, 2026 00:21
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.
What did you change, and why?
Change: Teach
ucode mcp-proxyto complete an MCP connection login when the AI Gateway asks for one.Why: When an AI Gateway MCP service is backed by a per-user connection (e.g.
system.ai.github) and the user hasn't logged in to that connection yet, the gateway answers a tools call with an RFC 9728 challenge — HTTP 401 +WWW-Authenticate: Bearer resource_metadata="…". A valid Databricks workspace token isn't enough; the connection needs its own login. Today the proxy just forwards that response to the coding agent, which showsconnected · tools fetch failedand the user is stuck with no way to log in.The proxy's
httpxauth now detects that challenge and drives an interactive resource-scoped OAuth login: authorization-code + PKCE against the workspace/oidc, using the publisheddatabricks-cliapp, sending the MCP endpoint URL as the RFC 8707resourceindicator. That indicator makes/oidcroute the browser through the connection's/mcp-service-loginpage → the user signs in to the backing SaaS → the connection credential is stored server-side → the flow returns → the proxy retries the original request, which now succeeds. No coding-agent OAuth (RFC 9728 / dynamic client registration) support required.How do you know it works?
Testing:
uv run pytest tests/test_resource_login.py tests/test_mcp_proxy.py— 35 passing. New tests cover the authorize-URL + PKCE construction and the401/resource_metadatachallenge detection; existing proxy tests still pass.ruff check/formatclean. The interactive browser + token-exchange path is validated end-to-end against staging separately (it requires the gateway-side RFC 9728 challenge to be enabled for the connection).Notes:
DATABRICKS_BEARER(headless/CI) — no browser to drive.resource_login.pyis stdlib-only (no new dependency).This pull request and its description were written by Isaac.