Skip to content

Commit 76a0de9

Browse files
olaservoclaude
andcommitted
feat(everything): add a per-registration cacheHint to the static doc resources
The 2026-07-28 cache fields resolve most-specific-author-first: fields the handler returns, then a per-registration `cacheHint`, then the server-level `ServerOptions.cacheHints`, then the conservative default (`ttlMs: 0`, `cacheScope: "private"`). Only the server level was in use, so reads of the static `docs/` resources fell through to that default and were never cacheable. They are the one genuinely static surface here - the files ship inside the package and change only when it is rebuilt - so they now carry `{ ttlMs: 3_600_000, cacheScope: "public" }`. `public` is correct because the content is identical for every caller. The dynamic and session-scoped resources deliberately keep no hint and continue to fall through to the conservative default. Verified on the wire: a modern client reading a static document now sees ttlMs=3600000 / cacheScope=public (vs the server-level 60s on tools/list), and a legacy client still sees no cache fields at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 85bd7b9 commit 76a0de9

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎src/everything/docs/features.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@
3939
- Dynamic Text: `demo://resource/dynamic/text/{index}` (content generated on the fly)
4040
- Dynamic Blob: `demo://resource/dynamic/blob/{index}` (base64 payload generated on the fly)
4141
- Static Documents: `demo://resource/static/document/<filename>` (serves files from `src/everything/docs/` as static file-based resources)
42+
43+
### Result caching (2026-07-28)
44+
45+
The revision requires `ttlMs` and `cacheScope` on cacheable results. Values resolve
46+
most-specific-author-first: fields the handler puts on the result, then a
47+
per-registration `cacheHint`, then the server-level `ServerOptions.cacheHints`, then the
48+
conservative default (`ttlMs: 0`, `cacheScope: "private"`). These fields are emitted only
49+
toward modern-era clients — legacy responses are byte-for-byte unchanged.
50+
51+
This server exercises two of those layers:
52+
53+
| Surface | Hint | Why |
54+
| ---------------------------------------------------------- | --------------------------------- | --------------------------------------------------------- |
55+
| `tools/list`, `prompts/list`, `resources/list`, `resources/templates/list`, `server/discover` | server-level, 60s `public` | static for the process lifetime and identical per caller |
56+
| Static Documents (`resources/read`) | per-registration, 1h `public` | ship inside the package; only change when it is rebuilt |
57+
| Dynamic, Session Scoped (`resources/read`) | none — falls through to the default | generated per call, or scoped to one caller |
4258
- Session Scoped: `demo://resource/session/<name>` (per-session resources registered dynamically; available only for the lifetime of the session)
4359

4460
## Resource Subscriptions and Notifications

‎src/everything/resources/files.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,30 @@ export const registerFileResources = (server: McpServer) => {
4242
const mimeType = getMimeType(name);
4343
const description = `Static document file exposed from /docs: ${name}`;
4444

45-
// Register file resource
45+
// Register file resource.
46+
//
47+
// These are the one genuinely static surface this server exposes: the
48+
// files ship inside the package and only change when it is rebuilt. So
49+
// they carry a per-registration `cacheHint`, which wins over the
50+
// server-level `cacheHints` for their own `resources/read` result.
51+
//
52+
// Cache fields resolve most-specific-author-first: fields the handler puts
53+
// on the result, then this `cacheHint`, then `ServerOptions.cacheHints`,
54+
// then the conservative default (`ttlMs: 0`, `cacheScope: "private"`).
55+
// Without this, reads of these files would fall through to that default
56+
// and never be cached. `public` is safe here because the content is
57+
// identical for every caller -- unlike the dynamic and session-scoped
58+
// resources, which deliberately carry no hint.
59+
//
60+
// Emitted only toward modern-era clients; legacy responses are unchanged.
4661
server.registerResource(
4762
name,
4863
uri,
49-
{ mimeType, description },
64+
{
65+
mimeType,
66+
description,
67+
cacheHint: { ttlMs: 3_600_000, cacheScope: "public" },
68+
},
5069
async (uri) => {
5170
const text = readFileSafe(fullPath);
5271
return {

0 commit comments

Comments
 (0)