Skip to content

variants: redirect inner server sending methods to fix dropping notifications in stateless mode#7

Open
StevenRChen wants to merge 7 commits intomainfrom
notifications
Open

variants: redirect inner server sending methods to fix dropping notifications in stateless mode#7
StevenRChen wants to merge 7 commits intomainfrom
notifications

Conversation

@StevenRChen
Copy link
Collaborator

@StevenRChen StevenRChen commented Mar 19, 2026

Registers a sending middleware on each inner server that intercepts all outgoing messages and routes them through the front session using a session-swapped request wrapper. Replaces the previous proxy client handler approach which dropped log messages in stateless mode.

Motivation and Context

Tool handlers in variant servers use req.Session (the inner session) to send notifications. Previously, log messages were silently dropped in stateless mode because the inner session is not aware of the front session.
This change injects the sendingMethodHandler from the frontSession into the context and adds a sending middleware to redirect all sending requests to the frontSession handler directly.
A few considerations in this implementation:

  • All the operations before the sending method will still happen in the backend. Most notable impact is in stateless mode, requests from one client could change the log level for other clients. For this reason, I default the logging level to debug for now.
  • This implementation relies on the MCP Go SDK sendingMethodHandler taking a generic Request not one that tied to specific function. Based on the current SDK implementation this is unlikely to change.
  • The same generic method forwarding mechanism could work for receiving methods too, but with some caveat. That can be addressed in separate PR.

How Has This Been Tested?

TestNotificationDelivery — verifies progress and log messages arrive at the front clients with multiple clients making concurrent request.

New tests added for context preservation that was added in #6. Context preservation is required to make the notification forwarding work anyway. Since we use the context to carry frontSession handler to the backend session.

All existing tests pass

Breaking Changes

None. Tool handlers continue to use req.Session normally.

Types of changes

Bug fix (non-breaking change which fixes an issue)

@StevenRChen StevenRChen marked this pull request as draft March 19, 2026 11:15
@StevenRChen StevenRChen marked this pull request as ready for review March 19, 2026 17:50
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.

1 participant