Blog · · 8 min read
Keep product-agent context live with MCP resource subscriptions

Your support agent verified a ticket, loaded the account balance, and started drafting a refund. Two minutes later a human changed the ticket status and policy flags. Your run kept talking from the old snapshot. Customers notice. Operators blame the model. The host never ran an MCP resource subscription loop, so mid-run context stayed frozen after the record moved.
This guide is for product and platform engineers who embed tool-using agents in an existing SaaS. You will expose mutable facts as MCP resources, open a filtered listen stream, treat update notices as invalidation, re-read under current authority, bind revisions into the context envelope, and fail closed on serverless platforms that cannot hold streams.
Direct answer: the live-context contract
Use one product-owned lifecycle instead of a one-off SDK demo:
- Expose mutable product facts (ticket, deal, config, schema) as MCP resources. Keep mutations as tools.
- Negotiate
resources.subscribeandresources.listChangedexplicitly. Do not infer support fromresources/listalone (MCP Resources). - Listen with
subscriptions/listenon protocol 2026-07-28, or legacyresources/subscribeon older connections (MCP Subscriptions). - Invalidate on
notifications/resources/updated. Never treat the notice as the new body (QASkills subscription testing). - Re-read under the current user and tenant authority, coalesce bursts, and stamp URI plus revision into the context envelope before the next model turn.
- Rediscover on
notifications/resources/list_changed. - Restore after reconnect: re-listen and refetch. Nothing is replayed across streams (MCP Python SDK subscriptions).
- Opt out of listen advertising on serverless hosts that cannot observe client disconnect (python-sdk#3493).
Why mid-run context goes stale
Three mechanisms stack.
Tools are a weak default for reads. Teams wrap get_ticket as a tool because the agent can call it. Every call burns tokens, invites side effects in "read" handlers, and still depends on the model remembering to refresh. MCP resources exist for application-driven, side-effect-free context (AgentDevPro on MCP resources).
Notifications are cues, not payloads. The protocol sends a URI on notifications/resources/updated. The client must call resources/read again. Hosts that only flip a UI badge leave the model on revision N while the system of record is on N+1 (QASkills; Stanza resource subscriptions).
Listen streams have deployment cost. On 2026-07-28, subscriptions/listen holds a long-lived response stream. Servers that advertise subscribe/listChanged without publishing changes still accept listen. On AWS Lambda-style platforms where disconnect never reaches the app, each stream can pin an invocation until platform timeout. One production report measured listen traffic dominating billed GB-seconds after an SDK upgrade (python-sdk#3493).
Choose resources versus tools for product data
| Product need | Prefer | Why |
|---|---|---|
| Current ticket fields, deal stage, policy text, schema snapshot | Resource | Read-only, cacheable, subscribable |
| Search with a dynamic query | Tool | Computed result, not a stable URI |
| Update status, send email, charge card | Tool | Side effects and authorization |
| Help-center article corpus with publish lag | Resource plus freshness pipeline | Corpus sync is a separate job; still use subscribe for the live record the agent holds open |
URI design should be tenant-exact. Prefer tenant://acme/tickets/8821 over fuzzy paths. Do not normalize away query parameters that encode locale or version unless your server contract says they are equivalent (QASkills isolation matrix).
Implement the MCP resource subscription loop
1. Advertise capabilities honestly
Servers that support live updates declare:
{
"capabilities": {
"resources": {
"subscribe": true,
"listChanged": true
}
}
}
Both flags are optional and independent (MCP Resources). A client must treat missing subscribe as "poll or fail," not as "try subscribe anyway" (Stanza).
2. Open one filtered listen stream
On 2026-07-28, open subscriptions/listen with an explicit filter. Register handlers before the stream is live so early notices are not dropped (MCP TypeScript SDK).
client.setNotificationHandler(
"notifications/resources/updated",
async (notification) => {
await envelope.invalidate(notification.params.uri);
},
);
const subscription = await client.listen({
resourceSubscriptions: [
`tenant://${tenantId}/tickets/${ticketId}`,
`tenant://${tenantId}/accounts/${accountId}`,
],
resourcesListChanged: true,
});
// Honor only what the server acknowledged.
for (const uri of subscription.honoredFilter.resourceSubscriptions ?? []) {
await envelope.prime(uri);
}
Check honoredFilter (TypeScript) or sub.honored (Python). If the server omitted a URI you need, fall back to polling that URI or block consequential actions that depend on it (MCP Subscriptions; Python SDK).
3. Invalidate, then authorize a re-read
class ContextEnvelope {
private gen = 0;
private revisions = new Map<string, string>();
private stale = new Set<string>();
async invalidate(uri: string): Promise<void> {
this.stale.add(uri);
await this.coalescedRefresh(uri);
}
async coalescedRefresh(uri: string): Promise<void> {
// single-flight + trailing refresh pattern from QASkills
const myGen = this.gen;
const contents = await this.authorizedRead(uri);
if (myGen !== this.gen) return; // fenced by reconnect
const revision = hash(contents);
this.revisions.set(uri, revision);
this.stale.delete(uri);
this.attachToNextTurn(uri, contents, revision);
}
canStartModelTurn(): boolean {
return this.stale.size === 0;
}
}
QASkills names the failure mode "notification received equals current context" and requires a causal record: notice observed, read issued, newer body stored, then the next agent turn begins (QASkills). Put that gate in the host, not in the prompt.
4. Bind revisions into the context envelope
When you assemble the model prompt, include stable resource metadata the runtime can assert:
resource_uri: tenant://acme/tickets/8821
resource_revision: sha256:9f86d081884c7d659a2feaa0c55ad015
fetched_at: 2026-09-28T01:12:04Z
auth_principal: user:42
If a tool mutation or human edit lands during the turn, the next turn must not reuse the previous block. Conversation memory can still mention old facts in earlier assistant messages; your oracle should say which wins when the resource contradicts history (QASkills). For product agents, prefer this rule: authoritative resource revision wins for factual fields, and the assistant restates from the fresh block rather than from prior dialogue.
5. Handle list_changed separately
notifications/resources/list_changed means the catalog moved. Re-run resources/list and resources/templates/list, drop subscriptions to URIs that disappeared, and subscribe to new URIs your product policy requires. Do not assume content updates and catalog updates share a handler path (MCP Resources).
Implementation constraints
Gate the next model turn on an authorized re-read after every resources/updated notice; the notification is never the new body. Put that host gate in front of prompt assembly so a UI badge or log line cannot satisfy the contract.
On serverless or disconnect-blind hosts, refuse to advertise subscribe/listChanged rather than holding listen streams until platform timeout. Prefer a revision-token resource and polling on those deployments until the platform delivers disconnect.
Treat reconnect as a new session: re-listen, refetch every subscribed URI, and fence completions with a generation token so old reads cannot overwrite new cache. Missed notices are never replayed across streams.
Handle failure and recovery
Capability lie. If initialize advertises subscribe: true but listen or subscribe returns method-not-found, record a server defect and fall back to explicit polling. Do not silently relabel it as unsupported (QASkills).
Unauthorized URI. Subscribe and read must use the same authorization as product APIs. An unauthorized subscribe must not become an existence oracle for secret URIs. Mutate a forbidden resource in tests and prove the low-privilege connection receives nothing (QASkills).
Burst updates. File watchers and DB transactions emit storms. Coalesce while a read is in flight and always perform a trailing refresh if a notice arrived during the read. Assert final revision and bounded concurrent reads, not exact notice-to-read counts (QASkills).
Reconnect with no replay. Streams end gracefully or with SubscriptionLost. Either way: back off, re-listen, refetch. Enter listen, wait for acknowledgment, then take a snapshot so you cannot miss later events (Python SDK; TypeScript SDK). Bump a generation token on reconnect so an in-flight read from the old transport cannot overwrite the new cache (QASkills).
Cross-worker HTTP. If subscribe POST and the SSE/listen owner can land on different workers, subscription state will flake until you fence ownership or persist routing. HarperFast's open work on fenced stream owners exists because sticky routing alone was not enough (HarperFast#2436).
Serverless hold-open. If your MCP server runs on a platform that does not deliver disconnect, do not advertise subscribe/listChanged and do not register subscriptions/listen. Prefer a documented polling resource (revision token) for those deployments, as calendar MCP maintainers did while blocked on SDK listen support (macos-calendar-mcp#5; python-sdk#3493).
Verify the solution
Run these checks before you claim live context:
- Capability matrix: client against servers with subscribe true, listChanged only, empty resources object, and absent resources. Subscribe requests must not fire when
subscribe !== true. - Happy path: mutate a subscribed ticket resource; observe
notifications/resources/updatedwith the same URI; observe a followingresources/read; assert the next model prompt contains the new revision hash. - Payload myth: assert the notification has no resource body field and that the host does not invent one.
- Auth isolation: two tenants, deceptively similar URIs; only the subscriber for the exact URI receives notices.
- Burst: fire overlapping updates during a slow read; final revision matches the last write; concurrent reads stay bounded.
- Reconnect: sever the stream mid-subscription, mutate while down, reconnect; host re-listens once per desired URI and refetches; old completion cannot clobber new cache.
- Serverless policy: in disconnect-blind mode, initialize must report
subscribe: false/listChanged: false, and listen must return a clear method-not-supported error that does not fail overall connect (python-sdk#3493; TypeScript SDK).
Common mistakes
- Wrapping every CRM read as a tool for flexibility, then wondering why context is stale and spend is high.
- Calling
subscribeResourcebefore registering the update handler and missing the first notice (Stanza). - Counting notifications in CI while the agent still answers from an old prompt block.
- Normalizing URIs until tenant A and tenant B collapse into one subscription set.
- Advertising listen on a stateless Lambda because the SDK defaulted the handler on (python-sdk#3493).
- Assuming conversation memory will notice the resource changed without a host-level revision gate.
What to do next
Pick one high-traffic product record your agent already loads mid-run (usually a ticket or account). Expose it as an MCP resource with a tenant-exact URI, advertise subscribe only on hosts that can hold streams, open a filtered listen subscription from your agent host, and block the next model turn until an authorized re-read lands a new revision in the context envelope. Wire the seven verification checks above into CI before you expand to the rest of the catalog.
If you are evaluating platforms that turn your existing content and product APIs into grounded agents, Make Your Agent is built for knowledge-base and persona agents with retrieval, streaming chat, and intent routes into tools such as Pipedrive and Intercom. Use the same live-context rules when those agents hold open customer records.