Skip to content

feat: support resource subscriptions and list-changed capabilities - #296

Merged
punkpeye merged 1 commit into
punkpeye:mainfrom
amitvijapur:feat/resource-prompt-subscriptions
Jul 21, 2026
Merged

punkpeye merged 1 commit into
punkpeye:mainfrom
amitvijapur:feat/resource-prompt-subscriptions

Conversation

@amitvijapur

Copy link
Copy Markdown
Contributor

Closes #185.

Adds support for MCP resource subscriptions and makes the server's list-changed capabilities discoverable.

What's added

  • Capabilities: advertise resources: { listChanged: true, subscribe: true } and prompts: { listChanged: true } when those features are enabled. The server already emitted notifications/resources/list_changed and notifications/prompts/list_changed, but never advertised the capability, so spec-compliant clients didn't know to expect them.
  • Subscribe/unsubscribe: handlers for resources/subscribe and resources/unsubscribe, tracked per session.
  • Update notifications: server.sendResourceUpdated(uri) emits notifications/resources/updated only to clients that subscribed to that URI (spec).

Example

server.addResource({
  uri: "file:///logs/app.log",
  name: "Application Logs",
  mimeType: "text/plain",
  async load() {
    return { text: await readLogFile() };
  },
});

// When the underlying data changes, notify subscribed clients:
await server.sendResourceUpdated("file:///logs/app.log");

sendResourceUpdated is a no-op for URIs no client has subscribed to, so it's safe to call whenever data changes.

Design note

subscribe: true is advertised for every server that exposes resources rather than being gated behind an opt-in flag, since the subscribe/update plumbing is generic and sendResourceUpdated is a no-op for URIs nobody subscribed to. If you'd rather make it opt-in, happy to gate it behind a flag.

Spec references

Tests

New src/FastMCP.resource-subscriptions.test.ts covers capability advertisement (resources + prompts), notification delivery to a subscribed client, no delivery without a subscription, and unsubscribe stopping delivery. Full suite green: 388 tests passing, plus prettier, eslint, and tsc --noEmit all clean.

Add support for the MCP `resources/subscribe` / `resources/unsubscribe`
methods and per-URI `notifications/resources/updated` notifications, and
advertise the `subscribe` and `listChanged` capabilities so spec-compliant
clients discover them.

- Declare `resources: { listChanged: true, subscribe: true }` and
  `prompts: { listChanged: true }` when those capabilities are enabled
  (the server already emitted list_changed notifications but never
  advertised them).
- Track each session's subscribed URIs and register handlers for
  `resources/subscribe` and `resources/unsubscribe`.
- Add `FastMCP#sendResourceUpdated(uri)` (and the session-level
  equivalent) to notify only the clients subscribed to that URI.

closes punkpeye#185
@punkpeye
punkpeye merged commit f6cc44c into punkpeye:main Jul 21, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Resource and Prompt change subscriptions

2 participants