Skip to content

fix: add invalid_target to AuthorizationErrorCode per RFC 8707 §2#2758

Closed
ZongrongLi wants to merge 1 commit into
modelcontextprotocol:mainfrom
ZongrongLi:main
Closed

fix: add invalid_target to AuthorizationErrorCode per RFC 8707 §2#2758
ZongrongLi wants to merge 1 commit into
modelcontextprotocol:mainfrom
ZongrongLi:main

Conversation

@ZongrongLi
Copy link
Copy Markdown

Summary

Adds "invalid_target" to AuthorizationErrorCode Literal per RFC 8707 §2.

Problem

mcp/server/auth/provider.py AuthorizationErrorCode is missing invalid_target, the OAuth 2.0 error code for resource-indicator mismatches. When downstream clients (e.g. FastMCP OAuthProxy) raise AuthorizeError(error="invalid_target", ...), pydantic rejects it with ValidationError instead of returning the proper OAuth-compliant error response.

Fix

Added "invalid_target" to the Literal type in provider.py (one line).

Verification

from mcp.server.auth.provider import AuthorizationErrorCode, AuthorizeError
from mcp.server.auth.handlers.authorize import AuthorizationErrorResponse

# invalid_target is now accepted
assert "invalid_target" in AuthorizationErrorCode.__args__
AuthorizationErrorResponse(error="invalid_target", error_description="test")
AuthorizeError(error="invalid_target", error_description="test")

Closes #2641

RFC 8707 defines invalid_target as the OAuth 2.0 error code for
resource-indicator mismatches. The Python SDK AuthorizationErrorCode
Literal was missing this value, causing pydantic ValidationError.

Closes modelcontextprotocol#2641
@Kludex Kludex closed this Jun 2, 2026
@Kludex
Copy link
Copy Markdown
Member

Kludex commented Jun 2, 2026

duplicated

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.

Add invalid_target to AuthorizationErrorCode (RFC 8707)

2 participants