OAuth token expiry equality boundary causes intermittent downstream test failures
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #3730 by @pei711 — closed without merging
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- authentication, backend
Research direction
Start by reading OAuthContext.is_token_valid() and update_token_expiry() in mcp/client/auth/oauth2.py, then check the token expiry tests. Reproduce the equality boundary with the provided fixed-clock example. Done when a token is invalid at its expiry timestamp and the tests cover both equality and a time just after expiry.
Written by the indexing model from the issue text.
Description
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Release line
2.x (current stable)
Description
While running FastMCP's stored-token expiry tests on Windows, I observed intermittent failures with expires_in=0: the client sometimes reused the stored token instead of acquiring a fresh one.
I reproduced the behavior in isolated environments using MCP SDK 2.3.0 alone and FastMCP 4.1.1 with MCP SDK 2.3.0.
OAuthContext.is_token_valid() returns True when the current time exactly equals token_expiry_time, because it uses <=. Once the clock advances past that timestamp, it correctly returns False. The same equality behavior occurs with a normal 3600-second token checked exactly at expiry.
I expected the token to be invalid at its expiration timestamp. Could you confirm whether the inclusive boundary is intentional, or whether it should be considered expired at equality?
The observed impact is intermittent downstream test failures, not a demonstrated production authentication failure. The example below uses a fixed nonzero clock to make the boundary deterministic; it needs no network or real credentials.
Prepared with AI assistance; the reproductions were executed locally and reviewed before submission.
Example Code
from unittest.mock import Mock, patch
from mcp.client.auth.oauth2 import OAuthContext, TokenStorage
from mcp.shared.auth import OAuthClientMetadata, OAuthToken
context = OAuthContext(
server_url="https://mcp.example.test/mcp",
client_metadata=OAuthClientMetadata(
redirect_uris=["http://localhost/callback"]
),
storage=Mock(spec=TokenStorage),
redirect_handler=None,
callback_handler=None,
)
with patch("time.time", return_value=1_800_000_000.0):
token = OAuthToken(
access_token="example-token",
token_type="Bearer",
expires_in=0,
)
context.current_tokens = token
context.update_token_expiry(token)
print("At expiry:", context.is_token_valid()) # True
with patch("time.time", return_value=1_800_000_000.001):
print("After expiry:", context.is_token_valid()) # False
Python & MCP Python SDK
Windows
Python 3.12.15
MCP SDK 2.3.0
Pydantic 2.14.1
Also reproduced through FastMCP 4.1.1's client-credentials auth flow
with MCP SDK 2.3.0 in a separate environment.
- Dominant language
- Python
- Stars
- 24.6k
- Forks
- 4.2k
- Avg merge
- 10h 37m
- Merged PRs (30d)
- 38
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/python-sdk
-
bug v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
modelcontextprotocol/python-sdk#3725 · 4 comments ·
Maintainers usually reply within 1 day
-
bug v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelcontextprotocol/python-sdk#3698 · 2 comments ·
Maintainers usually reply within 1 day
-
Streamable HTTP: Content-Type handling is order dependent and accepts invalid valuesMay be free again @jayzuccarelli claimed this 8 days ago, and no pull request is open. Openbug v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
modelcontextprotocol/python-sdk#3691 · 1 comment ·
Maintainers usually reply within 1 day
-
Skills: URI traversal validation skips percent-encoded dot-segmentsMay be free again @Varshith-Kali claimed this 7 days ago, and no pull request is open. Openbug v2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelcontextprotocol/python-sdk#3685 · 2 comments ·
Maintainers usually reply within 1 day
-
Type annotation gaps and unhandled FileNotFoundError in src/mcp/cli/cli.pyMay be free again A pull request for this issue was closed without being merged. Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
modelcontextprotocol/python-sdk#3673 · 4 comments ·
Maintainers usually reply within 1 day
All issues in modelcontextprotocol/python-sdk
Similar issues
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
good first issue module-baseline needs triage ux
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
darnitdevorg/darnit#650 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
nyjc-computing/campus#938 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
nf-osi/nf-metadata-dictionary#1027 ·
Maintainers usually reply within 1 day
-
bug documentation
Difficulty 1/5 Under an hour Newbie friendliness 92/100
qatrackplus/qatrackplus#913 ·
Maintainers usually reply within 3 days