Skip to content

Add ttlMs and cacheScope to cacheable result records (SEP-2549)#1062

Open
aboullaite wants to merge 2 commits into
modelcontextprotocol:mainfrom
aboullaite:feature/ttl-list-results
Open

Add ttlMs and cacheScope to cacheable result records (SEP-2549)#1062
aboullaite wants to merge 2 commits into
modelcontextprotocol:mainfrom
aboullaite:feature/ttl-list-results

Conversation

@aboullaite

@aboullaite aboullaite commented Jul 16, 2026

Copy link
Copy Markdown

Add ttlMs and cacheScope to cacheable result records (SEP-2549)

Motivation and Context

SEP-2549 introduces TTL caching hints so clients and intermediaries (gateways, proxies) can cache list and read results without re-fetching on every request. The draft spec adds two fields to cacheable result types:

  • ttlMs (integer, >= 0): how long in milliseconds the client may consider the response fresh, analogous to HTTP Cache-Control: max-age
  • cacheScope (enum: "private" / "public"): whether the response may be shared across authorization contexts, analogous to HTTP Cache-Control: private vs public

This PR adds the schema fields and server-side default stamping. The server now emits ttlMs=0 (immediately stale) and cacheScope="public" on all cacheable responses. Server-side configuration hooks for user-defined TTLs are intentionally left out following @Kehrlann's note that those belong with the repositories refactor in #578 (and the related #1034).

Towards #1009

How Has This Been Tested?

UT + IT

Breaking Changes

None. Both fields are optional (nullable), existing constructors are preserved as @Deprecated overloads.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Remaining work for full #1009 coverage (follow-up PRs):

Mohammed Aboullaite added 2 commits July 16, 2026 16:06
The draft spec introduces TTL caching hints on list and read results.
This adds the optional ttlMs (Integer) and cacheScope (CacheScope enum)
fields to ListToolsResult, ListPromptsResult, ListResourcesResult,
ListResourceTemplatesResult, and ReadResourceResult, following the
wire-record evolution rules in CONTRIBUTING.md.

Purely additive, schema-layer only: no server or client behavior changes.
Server-side TTL configuration hooks are deferred to modelcontextprotocol#578.
The draft spec requires cacheable results to carry ttlMs and cacheScope
on the wire. Other SDKs (Go, Python, TypeScript) all stamp defaults
after handlers return: ttlMs=0 (immediately stale) and cacheScope=public.

This adds the same default stamping in McpAsyncServer and
McpStatelessAsyncServer for all five cacheable result types. For list
results the defaults are set at the build site. For ReadResourceResult,
which is built by user handlers, a withCacheDefaults helper stamps
missing fields while preserving any values the handler set explicitly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant