fix: implement RFC 6750 Section 3.1 compliance for missing authentication #785
+23
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The MCP SDK's
requireBearerAuth
middleware was incorrectly treating missing Authorization headers as invalid tokens, violating RFC 6750 Section 3.1 compliance.Motivation and Context
The current implementation violates RFC 6750 Section 3.1, which states:
Current behavior (non-compliant):
RFC 6750 compliant behavior:
This fix improves interoperability with OAuth 2.0 clients that expect standards-compliant bearer token authentication.
How Has This Been Tested?
Test scenarios covered:
Bearer realm="protected"
Bearer error="invalid_token"
Bearer error="insufficient_scope"
Breaking Changes
None. This is a compliance fix that only changes the WWW-Authenticate header format for missing authentication. All other authentication error scenarios remain unchanged.
Types of changes
Checklist
Additional context
Implementation approach:
MissingAuthenticationError
class following existing error patternsrequireBearerAuth
middleware to throwMissingAuthenticationError
for missing headersStandards reference:
Files changed:
src/server/auth/errors.ts
- Added MissingAuthenticationError classsrc/server/auth/middleware/bearerAuth.ts
- Updated middleware logicsrc/server/auth/middleware/bearerAuth.test.ts
- Updated test expectations