All Agent Engineering

MCP resource changes: refresh context caches by URI

Separate subscriptions, content updates and list changes under the 2025-11-25 resource specification, with client routing and acceptance checks.

AINavWritten / Updated
On this page

At a glance

An MCP resource update notification says content at a URI changed; it does not carry new text. Keeping the old cache can still give a model stale context. This task designs refresh routing for a synthetic release-notes resource: inspect capabilities, select a subscription target, reread on updates and route list changes to directory refresh. It delivers a handling policy and frame-by-frame acceptance sheet, not a running MCP service. Its version scope is the 2025-11-25 resource specification.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • MCP Resource notifications and context-refresh routing

Execution locations and responsibilities

  • MCP client resource module Inspect capabilities, route notifications and select context after successful reads.
  • MCP resource server Declare capabilities, emit supported notifications and check URI access.

When to use

  • A client has read a resource and needs to refresh selected context after changes. Resource support and subscription support need separate checks.

When not to use

  • Without subscribe, subscription support cannot be assumed. Resource notifications are not tool calls, model sampling or a requirement for automatic context selection.
  • Transport, full initialization and subscription cancellation belong to the existing client lifecycle. This task imports no unexamined interface from another revision.

Fix the version, resource and cache record

Prepare an initialized session with actual server capabilities, a user-selected URI and cached content in the client resource module. file:///demo/release-notes.txt identifies a resource; it does not prove access to a physical file. File resources can behave like a filesystem without mapping to disk files. The application cache should associate a URI with content and a pending-refresh marker. Those are this design’s application fields, not protocol fields.

Check both optional capabilities separately

A server supporting resources MUST declare resources. subscribe and listChanged are optional and can be absent, supported individually or supported together. The JSON illustrates both; it must not replace actual negotiation. A one-time read does not require a subscription, which is an optional mechanism for later notifications.

Example: capability declaration and negotiation checks
json
{
  "capabilities": {
    "resources": {
      "subscribe": true,
      "listChanged": true
    }
  }
}
Capability branches
DeclarationPossible handlingWhat it does not establish
resources: {}Read resources; the application owns refresh strategySubscriptions cannot be assumed
subscribe: trueSubscribe to a selected URI and handle updatedDirectory notifications may be unsupported
listChanged: trueRefresh the directory on list_changedAn existing body need not have changed

Route refreshes by message type

This local teaching sequence represents separate frames, not a JSON-RPC batch to send to a server. It shows a subscription, an imagined body update, a client reread and a separate directory notification. None is an observed response. Mark a subscription active only after actual support and successful requests. The page does not show the complete subscription response and cancellation flow, so this fixture cannot prove a completed lifecycle.

Example: separate teaching frames, not sent
json
[
  {
    "jsonrpc": "2.0",
    "id": 11,
    "method": "resources/subscribe",
    "params": {
      "uri": "file:///demo/release-notes.txt"
    }
  },
  {
    "jsonrpc": "2.0",
    "method": "notifications/resources/updated",
    "params": {
      "uri": "file:///demo/release-notes.txt"
    }
  },
  {
    "jsonrpc": "2.0",
    "id": 12,
    "method": "resources/read",
    "params": {
      "uri": "file:///demo/release-notes.txt"
    }
  },
  {
    "jsonrpc": "2.0",
    "method": "notifications/resources/list_changed"
  }
]

On notifications/resources/updated, locate the URI cache, mark its old body pending refresh and issue resources/read. Replace content only after a successful, parseable read, then apply context-selection policy before passing it to a model. Notification receipt does not establish fresh text or require automatic model inclusion. Resources are application-driven.

Keep directory changes separate from body changes

notifications/resources/list_changed does not identify a body URI. Servers declaring listChanged SHOULD emit it when their list changes. Route it to the existing directory-refresh logic and finish every page before deciding a selected URI no longer exists. Adding or removing a resource differs from updating an existing body. One directory notification cannot prove all bodies were refreshed. Full paginated discovery has its own article, so this task does not repeat that loop.

Keep read failures visible

Servers SHOULD use standard JSON-RPC errors: -32002 for missing resources and -32603 for internal errors. This does not promise that all failures use only those codes. A failed refresh must not label old text current or replace a body with error text. Old content may remain for reference if its failed refresh is visible. This acceptance policy blocks consumption under a “latest context” claim until refresh succeeds.

  • For unknown URIs, check the session, subscription record and ownership instead of adding context automatically.
  • For -32002, mark unavailable and inspect the directory; do not invent an empty body.
  • For internal errors or timeouts, record request ID, URI and cause, retaining pending refresh without an unlimited retry loop.
  • On user session closure, stop downstream refresh and retain diagnostics. The source does not establish cross-session subscription retention.

Use message walkthroughs to complete acceptance

Refresh acceptance
Input or eventInspectable result
Only resources: {}No subscription is sent; unsupported capability recorded
updated for selected URICache becomes pending; read uses the same URI
Successful readParsed content replaces cache before selection
Failed readNo latest-content claim; prior content and cause traceable
list_changedDirectory branch runs; incomplete pagination cannot prove absence
Unknown URI or closureExplicit stop branch; no automatic context addition

An offline dispatcher walkthrough should record the branch, emitted request and point where content becomes usable. No walkthrough or server connection was executed here, so the table is a requirement rather than a passing receipt. Readable content needs application-specific inspection; URI accessibility does not establish trust.

Access boundaries and verification scope

Servers MUST validate URIs; sensitive resources SHOULD have access controls; permissions SHOULD be checked before operations; binary data MUST be correctly encoded. Caching cannot replace these server checks. The fixed resource revision was read and its capabilities, messages and errors checked. No SDK was installed, MCP service run, reconnection exercised or model output observed.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. MCP · Resources — MCP specification 2025-11-25

Found an error? Tell us →