AI Hints
Home›MCP Tutorial›Caching and Changes
MCP · Lesson 82 of 120

Caching Hints

Ttl for lists.

⏱ 2 min read▶ Video at 1:13:16🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

Clients often ask for the same lists again and again. A server can say how long a reply stays fresh. Then the client can reuse it, instead of asking again.

Caching Hints
From the video: Caching Hints
  • Same lists again
  • How long it's fresh
  • Reuse it

A caching hint

Cache hints maps a method to a hint. Here, the tool list stays fresh for one minute, and can be shared between users. The client sees the hint on the result. Run it. A time to live of sixty thousand milliseconds, with public scope.

cache_hints.pypython
import asyncio
from mcp import Client
from mcp.server.caching import CacheHint
from mcp.server.mcpserver import MCPServer

mcp = MCPServer("northwind", cache_hints={"tools/list": CacheHint(ttl_ms=60_000, scope="public")})

@mcp.tool()
def order_status(order_id: int) -> str:
    """Look up an order."""
    return "shipped"

async def main():
    async with Client(mcp) as client:
        page = await client.list_tools()
        print("ttl:", page.ttl_ms, "ms | scope:", page.cache_scope)

asyncio.run(main())
Output
ttl: 60000 ms | scope: public

Scopes

Public means any user may share the cached reply. Private means it's only reused for the same user. Use private when replies depend on who's asking. A time to live of zero means don't reuse it.

keyvalue
publicshared by all
privatesame user only
Per-user dataprivate
ttl 0always fresh

Summary

Caching hints tell clients how long lists stay fresh, and who may share them. Next, roots.

Key takeaways
  • cache_hints
  • ttl_ms
  • scope
Next up: Roots — where the client allows