MCP-Proxy changes to support FastMCP Stateless OAuth (fastMCP Issue #182) #37
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.
Pull Request Submission Guide - FastMCP Stateless OAuth
Executive Summary
Two minimal, backward-compatible fixes (41 lines total) enable FastMCP to support OAuth 2.0 JWT Bearer token authentication with per-request validation. The changes make
stateless: truemode fully functional for modern OAuth flows.Result: Clients send only
Authorization: Bearer <token>- no session management needed.Changes Overview
mcp-proxy (38 lines added) - 'Contained In this PR'
authenticatecallback parameterstatelessboolean flagauthenticate()on every request whenstateless: trueAuthorizationheaderfastmcp (3 lines added)
stateless?: booleanto httpStream optionsauthenticatecallback to mcp-proxystatelessflag to mcp-proxyDetailed Changes
1. mcp-proxy:
src/startHTTPStreamServer.tsFunction signature (lines 153-163):
CORS Headers (lines 172-173):
Per-Request Authentication (INSERT after line 192):
2. fastmcp:
src/FastMCP.tsStart method options (line 1392):
Pass parameters to mcp-proxy (lines 1467, 1501):
Usage Example
Backward Compatibility
✅ 100% Backward Compatible
All changes are additive only:
undefinedstatelessnot setBehavior Matrix
undefinedfalsetruetrueundefinedTesting
Tested Scenarios
✅ OAuth 2.0 Token Exchange (RFC 8693)
contextflow→mcp-oauth✅ Backward Compatibility
✅ CORS
Authorizationheader allowed in browser✅ Error Handling
Test Commands
Files Modified
mcp-proxy/src/startHTTPStreamServer.tsmcp-proxy/dist/chunk-43AXMLZU.jsfastmcp/src/FastMCP.tsfastmcp/dist/FastMCP.jsTotal: 41 lines added, 1 line changed
PR Checklist
Before Submitting:
PR Description Template:
Migration Guide (for users)
Enabling Stateless Mode
That's it! Your
authenticate()callback will now be called on every request.Client Changes
None required! Clients already sending
Authorization: Bearer <token>on every request will just work. The server now validates those tokens properly.Repository Links
Next Steps
Questions or Issues
See ROOT-CAUSE-ANALYSIS.md for detailed technical analysis or create an issue in the FastMCP repository.
Contact: This fix was developed and tested by the community. For questions, please open a GitHub issue.