Skip to content

Conversation

trungutt
Copy link
Contributor

Fixed #485.

When remote MCP servers require OAuth authentication AND the OAuth flow is triggered during the MCP session initialization handshake. This caused the session state to become corrupted because:

  1. client.Connect() starts the MCP protocol handshake
  2. Initial HTTP request returns 401 Unauthorized
  3. oauthTransport intercepts and runs the full OAuth flow
  4. After OAuth succeeds, the retry finds the MCP session in a broken state
  5. Subsequent requests fail with "400 Bad Request: broken session"

This fix adds retry logic that detects "broken session" errors during initialization and automatically retries once after OAuth completes, ensuring:

  • OAuth completes at the HTTP transport layer first
  • MCP session initialization happens with authentication already in place
  • No permanent session corruption from the OAuth interruption

The retry is limited to OAuth-related "broken session" errors to avoid masking other legitimate connection failures.

Fixes the issue where OAuth-protected MCP servers (like mcp.prisma.io) would fail to initialize despite successful user authentication.

Note: An attempt to fix the same issue was #486, but that fix broken other MCP server like atlassian.

When remote MCP servers require OAuth authentication, the OAuth flow
was being triggered during the MCP session initialization handshake.
This caused the session state to become corrupted because:

1. client.Connect() starts the MCP protocol handshake
2. Initial HTTP request returns 401 Unauthorized
3. oauthTransport intercepts and runs the full OAuth flow
4. After OAuth succeeds, the retry finds the MCP session in a broken state
5. Subsequent requests fail with "400 Bad Request: broken session"

This fix adds retry logic that detects "broken session" errors during
initialization and automatically retries once after OAuth completes,
ensuring:

- OAuth completes at the HTTP transport layer first
- MCP session initialization happens with authentication already in place
- No permanent session corruption from the OAuth interruption

The retry is limited to OAuth-related "broken session" errors to avoid
masking other legitimate connection failures.

Fixes the issue where OAuth-protected MCP servers (like mcp.prisma.io)
would fail to initialize despite successful user authentication.
@trungutt trungutt requested a review from a team as a code owner October 13, 2025 15:49
@rumpl
Copy link
Member

rumpl commented Oct 14, 2025

#485 should be updated. Or we can close it and open a new issue only for prisma

@trungutt
Copy link
Contributor Author

@rumpl #485 has been changed

@trungutt trungutt merged commit f93dca4 into docker:main Oct 15, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth flow failure Prisma MCP Server

3 participants