Skip to content

Conversation

gspencergoog
Copy link

I've added two server-side notification handlers, one for InitializedNotification and one for RootsListChangedNotification.

Motivation and Context

This allows an MCP server to fully implement roots support, since once the initialization is complete, it needs to be able to request roots from clients which support them, and it needs to be able to react to changes in the client's list of roots if they change.

How Has This Been Tested?

I wrote new tests for the notifications, and merged it with the existing progress notification tests.

Breaking Changes

No breaking changes were introduced.

Types of changes

  • New feature (non-breaking change which adds functionality)

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

@gspencergoog gspencergoog requested review from a team and felixweinberger July 25, 2025 16:35
@gspencergoog
Copy link
Author

@felixweinberger I'm new to this repo: do I need to do anything that I haven't done to proceed to a review?

Copy link
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

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

Hi @gspencergoog thank you for this contribution! And apologies for the time it took to get back to you on this, currently getting a handle on managing all the inbound contributions like yours.

I left some comments - I think adding these handlers is correct, but I wonder if we can handle the ServerSession requirement in a simpler way instead of introducing a global context variable and using introspection.

@felixweinberger felixweinberger added needs more work Not ready to be merged yet, needs additional changes. needs more eyes Needs alignment among maintainers whether this is something we want to add improves spec compliance When a change improves ability of SDK users to comply with spec definition labels Sep 22, 2025
This commit refactors the notification handling logic to eliminate the global context variable and introspection. The `ServerSession` is now explicitly passed to notification handlers, simplifying the control flow and improving explicitness.

This addresses the code review feedback to avoid introspection and global state in the low-level server code.
@gspencergoog
Copy link
Author

Hi @gspencergoog thank you for this contribution! And apologies for the time it took to get back to you on this, currently getting a handle on managing all the inbound contributions like yours.

No worries, I know how it is. :-)

Hopefully this is closer to what you were expecting now.

Removes the use of a `global` statement in
`tests/shared/test_notifications.py` to resolve a `PLW0603` linting
error reported by Ruff.

The `serv_sesh` global variable has been replaced with a mutable list
(`server_session_ref`) to share the server session object between the
`run_server` and `handle_call_tool` functions within the test. This
maintains the test's functionality while adhering to better coding
practices.
@felixweinberger felixweinberger removed the needs more work Not ready to be merged yet, needs additional changes. label Sep 26, 2025
@felixweinberger felixweinberger added needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention and removed needs more eyes Needs alignment among maintainers whether this is something we want to add labels Sep 30, 2025
@felixweinberger felixweinberger self-assigned this Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improves spec compliance When a change improves ability of SDK users to comply with spec definition needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants