Add cache_hints constructor map for SEP-2549 caching hints (#3015)

This commit is contained in:
Max 2026-06-29 16:11:15 +02:00 • committed by GitHub
commit 533c6a8226
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,15 @@
from mcp import Client
from mcp.server import CacheHint, MCPServer
mcp = MCPServer("Weather", cache_hints={"tools/list": CacheHint(ttl_ms=60_000, scope="public")})
@mcp.tool()
def forecast(city: str) -> str:
return f"Sunny in {city}"
async def main() -> None:
async with Client(mcp) as client:
tools = await client.list_tools()
print(f"{len(tools.tools)} tools, fresh for {tools.ttl_ms / 1000:.0f}s, scope={tools.cache_scope}")