Repository navigation
test: run the OAuth client steps on the MCP client SDK - #446
Merged
Merged
Conversation
The database tests and the MCP pre-flight now register, authorize, exchange the code, and refresh with the OAuth functions of @modelcontextprotocol/client. The pre-flight reads WWW-Authenticate and the protected resource metadata with the SDK too. The database tests read the authorization server metadata once and cover both a public and a confidential AI client. Refs #418
…the pre-flight Approval compares the redirect state with the authorize request, and the code exchange passes iss to exchangeAuthorization. The OAuth steps take the authorization server metadata and the resource apart. The pre-flight calls discoverAuthorizationServer, checks the issuer at the hosted RFC 8414 URL, and takes every earlier result through fromEarlierCheck. Refs #418
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.
Summary
The database tests and the MCP pre-flight now run the OAuth steps of an AI client with the OAuth functions of
@modelcontextprotocol/client2.3.1. Nothing changes for users or AI clients.How each acceptance criterion is met:
registerClient,startAuthorization,exchangeAuthorization, andrefreshAuthorization. No hand-written PKCE, authorize URL, or token request is left.authorizestill finds the consent page with afetchthat does not follow the redirect. It still throws when the redirect does not go to/oauth/consentwith anauthorization_id.approveis still a Supabase Auth call. It now also checks that the redirect has thestateof the authorize request, and it returnsissfor the code exchange, as an SDK client does.allowAiClienttakes the discovered metadata as an argument, so it cannot read the metadata again for each test user.authorizationServerMetadata()intests/ai-clients.tsdiscovers it once per test run.allowAiClientandrefreshTokens. It checks the token endpoint auth method that each client registered (noneandclient_secret_basic), the audience, theclient_id, and that refresh issues a new access token. The pre-flight still runs both kinds of client.WWW-AuthenticatewithextractWWWAuthenticateParams. It reads the protected resource metadata withdiscoverOAuthProtectedResourceMetadata. The hosted RFC 8414 check is still a plainfetch, and it checks theissuerin that response.assertSecureTokenEndpointexempts127.0.0.1. The SDK refused nothing that the tests did before. It changes three things on the wire:startAuthorizationaddsprompt=consentbecause the scope hasoffline_access. Supabase Auth accepts it and still redirects to the consent page.discoverAuthorizationServerMetadatachecks that the metadata'sissueris the issuer that the URL came from (RFC 8414 §3.3). The pre-flight's ownissuercomparison is gone, because the SDK does it. The local stack answers only at/auth/v1/.well-known/openid-configuration. That is the third URL that the SDK tries, after two 404s.codeandstatebut noiss.exchangeCodepassesissthrough toexchangeAuthorizationwhen it is present. The metadata does not setauthorization_response_iss_parameter_supported, so the SDK's RFC 9207isscheck passes with noiss. The pre-flight printsiss not sent.--hosted, the check still names the RFC 8414 URL when it fails. README says this.Client ID Metadata Documents
Supabase Auth does not support Client ID Metadata Documents yet. The local stack's authorization server metadata has no
client_id_metadata_document_supported. The Supabase OAuth 2.1 server docs (getting started) cover only dynamic client registration and clients that the owner registers. The feature request supabase/auth#2850 (opened 2026-10-02) is open, with no reply. The discussion supabase/supabase#41695 has no answer from the Supabase team. The latest Supabase Auth release, v2.197.0 (2026-09-09), does not add it. MCP spec 2026-07-28 deprecates dynamic client registration in favor of them. The SDK'sregisterClientdoc says it keeps working until at least 2027-07-28. So the tests keepregisterClient.Evidence
bun test tests/ai-client-tokens.test.ts -t 'connecting an AI client'failed withExport named 'authorizationServer' not found.allowAiClienttook a Supabase URL and supported only a public client.After: both cases pass.
bun test tests/ai-client-tokens.test.ts tests/mcp-server.test.ts tests/mcp-calls.test.ts: 78 pass, 0 fail. These files get tokens throughconnectAiClient.bun test tests/mcp-preflight.test.ts: 8 pass, 0 fail.bun run mcp-preflighton the local stack, after the catalog fixture import andbun run test-user:bun run typecheckinsupabasepasses (tsc, anddeno checkon both functions).Merge Danger
Door: two-way
The change touches only test and pre-flight code and README.
Blast Radius: tests
If the SDK's OAuth functions break against Supabase Auth, the database tests that connect an AI client fail, and so does the MCP pre-flight. The app, the MCP server, and the consent page do not change.
Closes #418