Skip to content

[Client] Listen for change notifications on subscriptions/listen - #753

Open
songecko wants to merge 1 commit into
modelcontextprotocol:mainfrom
songecko:client-subscriptions-listen
Open

songecko wants to merge 1 commit into
modelcontextprotocol:mainfrom
songecko:client-subscriptions-listen

Conversation

@songecko

Copy link
Copy Markdown

Adds Client::listen(), which opens a subscriptions/listen stream with a SubscriptionFilter, hands the acknowledged filter and each notification of the subscription to callbacks, and returns when the server ends it. Adds SubscriptionFilter, SubscriptionsListenRequest and SubscriptionsAcknowledgedNotification to Mcp\Schema, and Notification::getMeta().

Motivation and Context

On 2026-07-28 the server answers subscriptions/listen, but the client could not open the stream, so it could not receive notifications/resources/updated or list changes. This is the client side #340 and #185 left open.

Closes #752

How Has This Been Tested?

Unit tests for the schema types and for routing in Protocol (notifications of the open subscription, stray ones dropped, the stdio notifications/cancelled termination). SubscriptionsTest runs the client against the SDK server under php -S with a PSR-16 bus: only subscribed updates arrive after the acknowledgment, cancellation, graceful end at the server's lifetime, an empty agreed filter, and refusal on a handshake-era connection. Also used in a real application that keeps listen streams open to an MCP server and reacts to resource updates.

Breaking Changes

None. listen() and Notification::getMeta() are additions.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

A listen request uses no request timeout: it lasts until the server ends it or the caller cancels. Handshake-era resources/subscribe is out of scope.

Client::listen() opens a subscriptions/listen stream with a SubscriptionFilter,
hands the acknowledgment and each notification of the subscription to
callbacks, and returns when the server ends it. Adds SubscriptionFilter,
SubscriptionsListenRequest and SubscriptionsAcknowledgedNotification to
Mcp\Schema, and Notification::getMeta().

This branch has not been deployed

No deployments
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.

[Client] Support subscriptions/listen (2026-07-28)

1 participant