Skip to content

Allow notification handlers post-creation temporary registration #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

stephentoub
Copy link
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
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
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.

2 participants