OAuth token expiry equality boundary causes intermittent downstream test failures
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #3730 来自 @pei711 —— 已关闭,未合并
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 74/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
先阅读 mcp/client/auth/oauth2.py 中的 OAuthContext.is_token_valid() 和 update_token_expiry(),然后检查令牌过期测试。使用提供的固定时钟示例复现相等边界。完成标准是:令牌在其过期时间戳时无效,并且测试覆盖相等的情况以及刚过期后的时间点。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Python
- 星标
- 24.6k
- 派生
- 4.2k
- 平均合并
- 10 小时 37 分钟
- 30 天内合并 PR
- 38
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/python-sdk 的其他 Issue
-
Bare `dict` / `list` / `tuple` return annotations silently produce no structured output可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug v1 v2
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/python-sdk#3725 · 4 条评论 ·
维护者通常 1 天内回复
-
bug v1 v2
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/python-sdk#3698 · 2 条评论 ·
维护者通常 1 天内回复
-
Streamable HTTP: Content-Type handling is order dependent and accepts invalid values可能重新可做 @jayzuccarelli 于 9 天前认领,目前没有进行中的 PR。 未关闭bug v1 v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/python-sdk#3691 · 1 条评论 ·
维护者通常 1 天内回复
-
Skills: URI traversal validation skips percent-encoded dot-segments可能重新可做 @Varshith-Kali 于 8 天前认领,目前没有进行中的 PR。 未关闭bug v2
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/python-sdk#3685 · 2 条评论 ·
维护者通常 1 天内回复
-
Type annotation gaps and unhandled FileNotFoundError in src/mcp/cli/cli.py可能重新可做 关联的 PR 已关闭且未合并。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 84/100
modelcontextprotocol/python-sdk#3673 · 4 条评论 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
pgvector/pgvector-python#169 ·
-
ChaosEngine: backup-remote doctor row passes while consumer mode hides bot memory from git可能已有人在做 @MohabMohie 今天认领。 未关闭agentic
难度 2/5 1-3 小时 新手友好度 76/100
ShaftHQ/SHAFT_ENGINE#7263 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 87/100
huggingface/smolagents#3045 ·
维护者通常 1 天内回复