Skip to content

fix: add 'invalid_target' to AuthorizationErrorCode (RFC 8707)#2642

Merged
Kludex merged 2 commits into
modelcontextprotocol:mainfrom
siddhirajkatkar:fix/add-invalid-target-auth-error-code
Jun 2, 2026
Merged

fix: add 'invalid_target' to AuthorizationErrorCode (RFC 8707)#2642
Kludex merged 2 commits into
modelcontextprotocol:mainfrom
siddhirajkatkar:fix/add-invalid-target-auth-error-code

Conversation

@siddhirajkatkar
Copy link
Copy Markdown
Contributor

Fixes #2641

RFC 8707 §2 defines invalid_target as the error code for resource
indicator mismatches. Without it, AuthorizeError(error="invalid_target")
triggers a pydantic ValidationError instead of an OAuth-compliant
error response, masking the real cause with a generic server_error.

Change

Added "invalid_target" to AuthorizationErrorCode in
src/mcp/server/auth/provider.py:

AuthorizationErrorCode = Literal[
    ...
    "temporarily_unavailable",
    "invalid_target",  # RFC 8707 §2 — resource indicator mismatch
]

No other changes required — AuthorizationErrorResponse and
AuthorizeError already accept the Literal type by reference.

This also removes the # type: ignore annotations in FastMCP's
OAuthProxy that worked around this gap.

RFC 8707 §2 defines 'invalid_target' as the error code for resource
indicator mismatches. Without it, AuthorizeError(error='invalid_target')
triggers a pydantic ValidationError instead of an OAuth-compliant response.

Fixes modelcontextprotocol#2641
Comment thread src/mcp/server/auth/provider.py Outdated
@Kludex Kludex enabled auto-merge (squash) June 2, 2026 15:57
@Kludex Kludex merged commit 453cafb into modelcontextprotocol:main Jun 2, 2026
28 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.

Add invalid_target to AuthorizationErrorCode (RFC 8707)

2 participants