Skip to content

mcp: support custom notifications - #1146

Open
delaneyj wants to merge 5 commits into
modelcontextprotocol:mainfrom
delaneyj:custom-notifications
Open

mcp: support custom notifications#1146
delaneyj wants to merge 5 commits into
modelcontextprotocol:mainfrom
delaneyj:custom-notifications

Conversation

@delaneyj

@delaneyj delaneyj commented Aug 5, 2026

Copy link
Copy Markdown

Protocol extensions need to send and receive custom JSON-RPC notifications. The SDK session APIs currently support only standard notification methods.

This change adds:

  • SendNotification to ClientSession and ServerSession.
  • Generic AddReceivingCustomNotification registration for typed client handlers.
  • SendSubscriptionNotification for custom notifications on subscriptions/listen streams.
  • Automatic io.modelcontextprotocol/subscriptionId metadata on subscription notifications.
  • Carrier cancellation for Streamable HTTP listen streams without a separate cancellation notification.
  • Exact preservation of custom parameter objects.
  • Empty object encoding for nil parameters.

Sending middleware processes custom notifications before transmission. Typed receiving handlers use parameter structs that embed ParamsBase.

The tests cover:

  • Client-to-server custom notifications.
  • Server-to-client custom notifications.
  • Typed client-side receipt.
  • Exact wire method names.
  • Arbitrary parameter objects.
  • Nil parameters.
  • Subscription metadata.
  • Streamable HTTP unsubscribe cleanup and subsequent client requests.

Validation:

go test ./mcp -run '^(TestSendNotification|TestResourceSubscriptions_Streamable|TestResourceSubscriptions_InMemory)$'
go test ./...

This PR supersedes #844.

Fixes #745

Protocol extensions can define custom JSON-RPC notifications, but the SDK only exposes helpers for standard notifications.

Add SendNotification to client and server sessions. Route custom notifications through sending middleware and preserve arbitrary parameters.

Fixes modelcontextprotocol#745.
@delaneyj
delaneyj force-pushed the custom-notifications branch from 99154e6 to 6863d59 Compare August 5, 2026 14:37
@delaneyj
delaneyj marked this pull request as ready for review August 5, 2026 15:16
@delaneyj delaneyj changed the title WIP: mcp: support custom notifications mcp: support custom notifications Aug 6, 2026
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.

Expose generic SendNotification on ServerSession for custom protocol extensions

1 participant