Skip to content

Allow notification handlers post-creation temporary registration#223

Merged
stephentoub merged 1 commit intomodelcontextprotocol:mainfrom
stephentoub:notificationregistration
Apr 7, 2025
Merged

Allow notification handlers post-creation temporary registration#223
stephentoub merged 1 commit intomodelcontextprotocol:mainfrom
stephentoub:notificationregistration

Conversation

@stephentoub
Copy link
Copy Markdown
Contributor

  • We still allow notification handlers to be configured pre-creation, eliminating any race conditions that may result from missed notifications. But now we also allow for post-creation notification handler registration.
  • Handlers may now also be removed. This permits temporary registrations that may be created in a scoped manner.
  • Registration handling is thread-safe.
  • Handlers are now cancelable.
  • Exceptions from notification handlers trigger all normal exception handling in the dispatch pipeline.

This also:

  • Adds a WithStreamServerTransport as a counterpart to WithStdioServerTransport. The latter was used in several tests in a hacky way, and that's now simplified via the former's existence.

#207 (comment)

- We still allow notification handlers to be configured pre-creation, eliminating any race conditions that may result from missed notifications. But now we also allow for post-creation notification handler registration.
- Handlers may now also be removed. This permits temporary registrations that may be created in a scoped manner.
- Registration handling is thread-safe.
- Handlers are now cancelable.
- Exceptions from notification handlers trigger all normal exception handling in the dispatch pipeline.

This also:
- Adds a WithStreamServerTransport as a counterpart to WithStdioServerTransport. The latter was used in several tests in a hacky way, and that's now simplified via the former's existence.
Copy link
Copy Markdown
Contributor

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what convinced you that registering notification handlers post session initialization was worthwhile? You seemed convinced that it wasn't too important before, and I'll admit, I couldn't come up with a super compelling use case.

Edit: Nvm, I just read #207 (comment)

@stephentoub stephentoub merged commit 848c9df into modelcontextprotocol:main Apr 7, 2025
8 checks passed
@stephentoub stephentoub deleted the notificationregistration branch April 7, 2025 01:17
@jeffhandley jeffhandley added the breaking-change This issue or PR introduces a breaking change label Feb 20, 2026
@jeffhandley
Copy link
Copy Markdown
Contributor

Adding the breaking-change label retroactively during release notes revision.

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

Labels

breaking-change This issue or PR introduces a breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants