Skip to content

Conversation

@jlowin
Copy link
Owner

@jlowin jlowin commented Oct 23, 2025

OAuth error messages are now clearer and more actionable by introducing custom authorization handlers and authentication middleware that wrap the MCP SDK defaults.

When clients encounter authentication errors (unregistered client ID, invalid tokens), they now receive:

Browser users: Styled HTML error pages with step-by-step recovery instructions

image

API clients: JSON responses with helpful context and registration endpoint hints

Example JSON error:

{
  "error": "invalid_request",
  "error_description": "Client ID 'xxx' is not registered with this server. MCP clients should automatically re-register...",
  "registration_endpoint": "https://server.com/register"
}

The implementations use content negotiation to serve appropriate formats and maintain full OAuth 2.1 compliance.

OAuth Proxy authentication errors now show styled HTML error pages in browsers
instead of raw JSON, with content negotiation for API clients. Enhanced error
messages explain common causes (ephemeral storage, server restarts) and provide
clear remediation steps.

Changes:
- Created enhanced authorization handler that extends SDK's AuthorizationHandler
- Created enhanced auth middleware that extends SDK's RequireAuthMiddleware
- HTML error pages use server branding (icon, name) from FastMCP instance
- Added comprehensive troubleshooting section to OAuth Proxy docs
- Added FAQ entry linking to detailed troubleshooting
Tests cover:
- HTML error pages for browser requests with server branding
- Enhanced JSON responses with registration endpoint hints
- Content negotiation between HTML and JSON
- Enhanced middleware error messages for invalid_token
- WWW-Authenticate header format consistency with SDK
@marvin-context-protocol marvin-context-protocol bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. auth Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server. labels Oct 23, 2025
@jlowin jlowin merged commit 562e51b into main Oct 23, 2025
8 checks passed
@jlowin jlowin deleted the enhance-oauth-error-responses branch October 23, 2025 01:29
@jlowin jlowin added this to the 2.13.0 milestone Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server. enhancement Improvement to existing functionality. For issues and smaller PR improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants