MCP plugin: prompt=login flow loses OAuth query (invalid_client) #2580

Closed
opened 2026-03-13 10:04:34 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @VikashLoomba on GitHub (Dec 20, 2025).

Summary

When the MCP plugin resumes an auth flow after prompt=login, the oidc_login_prompt cookie is read but the original OAuth query parameters are not restored on ctx.query. As a result, authorizeMCPOAuth runs with missing fields (e.g., client_id) and redirects to /error?error=invalid_client.

Steps to reproduce

  1. Configure the MCP plugin with an OIDC provider.
  2. Start an authorization request that includes prompt=login along with the required params (client_id, redirect_uri, response_type=code, scope).
  3. Complete login so the flow resumes via the oidc_login_prompt cookie.
  4. Observe redirect to /error?error=invalid_client because the query params are missing.

Expected behavior

The flow should resume with the original OAuth query parameters and proceed to authorize successfully.

Suggested fix

Restore the query from the cookie before parsing prompt and authorizing, e.g.:

ctx.query = JSON.parse(cookie);

Right now the hook reads the cookie but continues using the callback request's query (which doesn't include the original OAuth params).

Impact

Any MCP OAuth flow that uses prompt=login fails after login with invalid_client. This makes login prompting unusable and can cause hard-to-debug auth loops for MCP clients.

Version

Observed in better-auth@1.4.7 (likely affects newer versions too).

Originally created by @VikashLoomba on GitHub (Dec 20, 2025). ## Summary When the MCP plugin resumes an auth flow after `prompt=login`, the `oidc_login_prompt` cookie is read but the original OAuth query parameters are not restored on `ctx.query`. As a result, `authorizeMCPOAuth` runs with missing fields (e.g., `client_id`) and redirects to `/error?error=invalid_client`. ## Steps to reproduce 1. Configure the MCP plugin with an OIDC provider. 2. Start an authorization request that includes `prompt=login` along with the required params (`client_id`, `redirect_uri`, `response_type=code`, `scope`). 3. Complete login so the flow resumes via the `oidc_login_prompt` cookie. 4. Observe redirect to `/error?error=invalid_client` because the query params are missing. ## Expected behavior The flow should resume with the original OAuth query parameters and proceed to authorize successfully. ## Suggested fix Restore the query from the cookie before parsing `prompt` and authorizing, e.g.: ```js ctx.query = JSON.parse(cookie); ``` Right now the hook reads the cookie but continues using the callback request's query (which doesn't include the original OAuth params). ## Impact Any MCP OAuth flow that uses `prompt=login` fails after login with `invalid_client`. This makes login prompting unusable and can cause hard-to-debug auth loops for MCP clients. ## Version Observed in `better-auth@1.4.7` (likely affects newer versions too).
GiteaMirror added the plugin label 2026-03-13 10:04:34 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 20, 2025):

The issue you're facing with the MCP plugin losing query parameters during the OAuth login flow appears to be a known concern where the OAuth query parameters are not properly restored upon resumption of the authentication flow.

To troubleshoot this issue, you can try the following steps:

  1. Check MCP Plugin Configuration: Ensure that your MCP plugin is correctly configured, including all necessary OAuth parameters during the initial authorization request.

  2. Restore Query Parameters: It's suggested to modify the implementation so that the original OAuth query parameters are restored from the session or cookie before continuing with the authorization process. Review how the cookie handling is done in your implementation—make sure the parameters are stored and retrieved as needed.

  3. Monitoring Version Changes: Make sure you are on the latest version of Better Auth. Sometimes, issues can be fixed in newer releases, so keeping the package updated might help.

  4. Open Issues/PRs: Look into existing issues or pull requests related to this matter in the Better Auth GitHub repository to see if a fix or workaround has been proposed by the community.

If the problem persists, it may be best to tag the Better Auth team members, @bekacru and @ping__, for more personalized help and to track the progress of any related fixes.

Is there a specific aspect of your implementation you would like to discuss further or any additional information on the error?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Dec 20, 2025): The issue you're facing with the MCP plugin losing query parameters during the OAuth `login` flow appears to be a known concern where the OAuth query parameters are not properly restored upon resumption of the authentication flow. To troubleshoot this issue, you can try the following steps: 1. **Check MCP Plugin Configuration**: Ensure that your MCP plugin is correctly configured, including all necessary OAuth parameters during the initial authorization request. 2. **Restore Query Parameters**: It's suggested to modify the implementation so that the original OAuth query parameters are restored from the session or cookie before continuing with the authorization process. Review how the cookie handling is done in your implementation—make sure the parameters are stored and retrieved as needed. 3. **Monitoring Version Changes**: Make sure you are on the latest version of Better Auth. Sometimes, issues can be fixed in newer releases, so keeping the package updated might help. 4. **Open Issues/PRs**: Look into existing issues or pull requests related to this matter in the Better Auth GitHub repository to see if a fix or workaround has been proposed by the community. If the problem persists, it may be best to tag the Better Auth team members, @bekacru and @ping__, for more personalized help and to track the progress of any related fixes. Is there a specific aspect of your implementation you would like to discuss further or any additional information on the error? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dvanmali commented on GitHub (Dec 24, 2025):

Please try the new OAuth Provider Plugin. Cookies are no longer utilized :)

@dvanmali commented on GitHub (Dec 24, 2025): Please try the new [OAuth Provider Plugin](https://www.better-auth.com/docs/plugins/oauth-provider). Cookies are no longer utilized :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2580