Skip to content

mcp: add ServerOptions.DefaultCacheable - #1128

Open
arimu1 wants to merge 1 commit into
modelcontextprotocol:mainfrom
arimu1:fix/1094-default-cacheable
Open

mcp: add ServerOptions.DefaultCacheable#1128
arimu1 wants to merge 1 commit into
modelcontextprotocol:mainfrom
arimu1:fix/1094-default-cacheable

Conversation

@arimu1

@arimu1 arimu1 commented Aug 1, 2026

Copy link
Copy Markdown

Summary

Adds ServerOptions.DefaultCacheable *Cacheable so multi-tenant / private servers can override the SDK's forced cacheable defaults (cacheScope: "public", ttlMs: 0) on SDK-generated results.

  • Nil keeps today's historical defaults (no behavior change).
  • Non-nil values are stamped by setDefaultCacheableValues on server/discover, tools/list, prompts/list, resources/list, resources/templates/list, and resources/read (after the handler returns).
  • Receiving middleware can still overwrite Cacheable per result after the SDK stamps values (useful for per-request / per-tenant policy).

Fixes #1094

Motivation

Servers whose list/discover payloads are tenant-scoped want private (and a real TTL) as the SDK baseline, not only via post-hoc middleware type-switches. A single option covers all current SDK stamp sites and any future call sites that use the same helper.

Test plan

  • go test ./mcp/ -run 'TestServerDefaultCacheable|TestSetDefaultCacheableValues' -count=1
  • go test ./mcp/ -count=1
  • go test ./... -count=1
  • Confirmed historical defaults when DefaultCacheable is nil
  • Confirmed private/60s stamped on list + read results when set
  • Confirmed nil-defaults path still preserves pre-set TTLMs (read handler) while forcing CacheScope: "public"

Allow servers to override the Cacheable defaults stamped on
SDK-generated results (discover, list methods, resources/read).
Nil keeps historical public/0 defaults.

Fixes modelcontextprotocol#1094
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.

No option to override forced Cacheable defaults (cacheScope public, ttlMs 0) on SDK-generated results

1 participant