-
Notifications
You must be signed in to change notification settings - Fork 2k
get_access_token returns None in background tasks (task=True) #3095
Copy link
Copy link
Closed
cristiangreco94/fastmcp
#1Labels
authRelated to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.Something isn't working. Reports of errors, unexpected behavior, or broken functionality.duplicateDuplicates an existing open issue. Reference the original issue when applying.Duplicates an existing open issue. Reference the original issue when applying.serverRelated to FastMCP server implementation or server-side functionality.Related to FastMCP server implementation or server-side functionality.
Metadata
Metadata
Assignees
Labels
authRelated to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.Something isn't working. Reports of errors, unexpected behavior, or broken functionality.duplicateDuplicates an existing open issue. Reference the original issue when applying.Duplicates an existing open issue. Reference the original issue when applying.serverRelated to FastMCP server implementation or server-side functionality.Related to FastMCP server implementation or server-side functionality.
Enhancement
I'm experiencing an issue where the get_access_token dependency returns None when used in tools marked with task=True, even though authentication is properly configured and
working.
Setup:
Problem:
When a tool is marked with task=True, the access_token parameter injected via Depends(get_access_token) is always None, even when the request is properly authenticated. The
same dependency works fine in non-background tools.
Minimal reproducible example:
Expected behavior:
Dependencies should be resolved in the request context before the background task is spawned, so access_token should contain the authenticated user's token.
Actual behavior:
access_token is None in background tasks, making it impossible to access authenticated user information in task=True functions.
Questions:
Any guidance would be appreciated! Thanks for the great framework.