-
Notifications
You must be signed in to change notification settings - Fork 220
FastMCP Stateless OAuth (FastMCP Issue #182) #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
pnpm-workspace.yaml
Outdated
@@ -0,0 +1,4 @@ | |||
ignoredBuiltDependencies: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this file is needed?
src/mcp-proxy.d.ts
Outdated
@@ -0,0 +1,33 @@ | |||
declare module "mcp-proxy" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this file is needed?
I think I have managed to remove the extra files. |
We need to add a test that demonstrates that this works too. |
Sorry for the multiple attempts, a disconnect between GitHub Desktop and git commands. The extra files have been removed, and testing has been added. |
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: true
mode fully functional for modern OAuth flows.Result: Clients send only
Authorization: Bearer <token>
- no session management needed.Changes Overview
mcp-proxy (38 lines added)
authenticate
callback parameterstateless
boolean flagauthenticate()
on every request whenstateless: true
Authorization
headerfastmcp (3 lines added) -(Contained in PR)
stateless?: boolean
to httpStream optionsauthenticate
callback to mcp-proxystateless
flag to mcp-proxyDetailed Changes
1. mcp-proxy:
src/startHTTPStreamServer.ts
Function signature (lines 153-163):
CORS Headers (lines 172-173):
Per-Request Authentication (INSERT after line 192):
2. fastmcp:
src/FastMCP.ts
Start method options (line 1392):
Pass parameters to mcp-proxy (lines 1467, 1501):
Usage Example
Backward Compatibility
✅ 100% Backward Compatible
All changes are additive only:
undefined
stateless
not setBehavior Matrix
undefined
false
true
true
undefined
Testing
Tested Scenarios
✅ OAuth 2.0 Token Exchange (RFC 8693)
contextflow
→mcp-oauth
✅ Backward Compatibility
✅ CORS
Authorization
header allowed in browser✅ Error Handling
Test Commands
Files Modified
mcp-proxy/src/startHTTPStreamServer.ts
mcp-proxy/dist/chunk-43AXMLZU.js
fastmcp/src/FastMCP.ts
fastmcp/dist/FastMCP.js
Total: 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.