Cache TTL normalization changes non-cacheable extension retention values before validation
維護者通常 1 天內回覆
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 58/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
研究方向
Start at ClientSession.send_request() and inspect where _clamp_inbound_ttl(raw) runs before result parsing. Check how CACHEABLE_METHODS distinguishes core cacheable results and how the native Skills extension handles cache hints. Add regressions for non-cacheable extension results preserving values for validation, while confirming existing cache normalization still works.
由索引模型根據 Issue 內容生成。
描述
ClientSession.send_request() applies _clamp_inbound_ttl(raw) to every result before parsing it. A ClientExtension claiming a non-cacheable tools/call result therefore cannot preserve its own ttlMs semantics.
Reproduced through public Client(MCPServer(...)), ClientExtension, and ResultClaim, on published 2.3.0 (Python 3.14) and current main 77001c96f9507be0f4d009b83210a384a5e08bda (Python 3.13). Each row makes exactly one tools/call:
| Server value | Expected extension validation | Actual parsed value |
|---|---|---|
-1 |
Preserve -1 |
0 |
-1.5 |
Reject fractional retention | 0, accepted |
-9007199254740992 |
Reject outside signed safe-integer range | 0, accepted |
This blocks Kestrel's implementation of the published Tasks extension: its retention schema is different from core cache freshness. The SDK's own CACHEABLE_METHODS excludes tools/call and extension task verbs. Ordinary extension requests using session.send_request also pass through the unconditional normalization. Declaring the extension's validation more strictly cannot recover values already changed by the SDK.
Expected: normalize cache hints only for cacheable results; leave other extension values intact for their own models to validate. Existing core cache normalization (including resources/read) and the native Skills cacheable extension must keep working. We can contribute a narrow correction and native regressions if useful; no new Tasks API is requested here.
Complete in-memory reproducer
from collections.abc import Sequence
from typing import Annotated, Any, Literal
import importlib.metadata
import json
import anyio
import mcp_types as types
from pydantic import Field, ValidationError
from mcp import Client
from mcp.client import ClaimContext, ClientExtension, ResultClaim
from mcp.server.context import ServerRequestContext
from mcp.server.context import CallNext, HandlerResult
from mcp.server.extension import Extension
from mcp.server.mcpserver import MCPServer
class RetentionResult(types.Result):
result_type: Literal["task"] = "task"
ttl_ms: Annotated[int, Field(strict=True, ge=-9007199254740991, le=9007199254740991)] | None
async def unresolved(result: RetentionResult, ctx: ClaimContext) -> types.CallToolResult:
raise NotImplementedError
class RetentionClient(ClientExtension):
identifier = "com.example/retention"
def claims(self) -> Sequence[ResultClaim[Any]]:
return [ResultClaim(result_type="task", model=RetentionResult, resolve=unresolved)]
class Issuer(Extension):
identifier = "com.example/retention"
def __init__(self, value: int | float) -> None:
self.value = value
self.calls = 0
async def intercept_tool_call(self, params: types.CallToolRequestParams, ctx: ServerRequestContext[Any, Any], call_next: CallNext) -> HandlerResult:
assert params.name == "issue"
self.calls += 1
return {"resultType": "task", "ttlMs": self.value}
async def main() -> None:
rows = []
for value in [-1, -1.5, -9007199254740992]:
issuer = Issuer(value)
server = MCPServer("retention", extensions=[issuer])
@server.tool()
def issue() -> types.CallToolResult:
raise NotImplementedError
with anyio.fail_after(5):
async with Client(server, extensions=[RetentionClient()]) as client:
try:
result = await client.session.call_tool("issue", allow_claimed=True)
except ValidationError:
observed: int | None | str = "ValidationError"
else:
assert isinstance(result, RetentionResult)
observed = result.ttl_ms
assert issuer.calls == 1
rows.append({"wire_ttl": value, "native_observed": observed, "tools_call_count": issuer.calls})
print(json.dumps({"sdk": importlib.metadata.version("mcp"), "rows": rows}))
if __name__ == "__main__":
anyio.run(main)
AI disclosure: Codex prepared this report and reproducer and ran the reproductions, under explicit authorization from Kestrel's human maintainer. No response rewriting or installed SDK modification was used.
- 主要語言
- Python
- 星號
- 25k
- 分支
- 4.2k
- 平均合併
- 10 分鐘
- 30 天內合併 PR
- 1
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/python-sdk 的其他 Issue
-
v2
難度 1/5 1 小時以內 新手友好度 86/100
modelcontextprotocol/python-sdk#3978 · 2 則留言 ·
維護者通常 1 天內回覆
-
Client serves cached tools after its context exits with an exception可能已有人在做 @jonxsong 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 65/100
modelcontextprotocol/python-sdk#3968 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
modelcontextprotocol/python-sdk#3957 ·
維護者通常 1 天內回覆
-
v2
難度 1/5 1 小時以內 新手友好度 91/100
modelcontextprotocol/python-sdk#3934 · 2 則留言 ·
維護者通常 1 天內回覆
-
bug v1
難度 2/5 1-3 小時 新手友好度 79/100
modelcontextprotocol/python-sdk#3929 · 2 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
auto-reported bug
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
-
backend bug
難度 2/5 1-3 小時 新手友好度 86/100
nolte/kamerplanter#3193 ·
維護者通常 1 天內回覆
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwise可能已有人在做 @abdulwaarith0 今天認領。 未關閉needs-triage
難度 2/5 1-3 小時 新手友好度 84/100
MakazhanAlpamys/Soup#3690 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆