experimental-ext-variants/go/sdk/examples/server/research
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Steven Chen e5e8f117e8
variants: redirect inner server sending methods to fix dropping notifications in stateless mode (#7)
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:
* Having frontSession in the context allows notifications to be sent to
the correct frontSession, when the same backend session could be used by
multiple front sessions.
* This solution will work for synchronous notifications that happen
within the same context (progress, log, sampling, elicitation) but not
working for asynchronous notifications (tool list changed, resource
updated etc), because asynchronous notifications are sent with a new
context.
* 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
https://github.com/modelcontextprotocol/experimental-ext-variants/pull/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)
2026-03-23 15:39:57 +00:00
..
main.go variants: redirect inner server sending methods to fix dropping notifications in stateless mode (#7) 2026-03-23 15:39:57 +00:00
README.md variants: redirect inner server sending methods to fix dropping notifications in stateless mode (#7) 2026-03-23 15:39:57 +00:00
tools.go variants: redirect inner server sending methods to fix dropping notifications in stateless mode (#7) 2026-03-23 15:39:57 +00:00

Research Assistant

A variant-aware MCP server that manages context budget by providing the same research tools (search_papers, get_paper, summarize) at different verbosity levels.

Each tool sends progress notifications and log messages as it works, simulating a deep-research workflow where the client can observe each step (e.g. "Searching arXiv", "Resolving references", "Generating summary").

Patterns demonstrated: Context budget management with description verbosity control, notification streaming.

Variants

Variant Verbosity Status Use Case
deep-research Multi-paragraph with usage examples Stable Literature reviews, large context windows
quick-lookup Single-sentence descriptions Stable Fast Q&A, limited token budgets
synthesis Balanced, moderate detail Experimental Report generation workflows

All three variants expose the same three tools with the same behavior — only the description detail level differs.

Custom Ranking

Clients send a "contextSize" hint ("verbose", "compact", or "standard"). The ranking function matches the hint to the appropriate variant, falling back to priority order.

Run

go run ./examples/server/research

The server listens on http://localhost:8080.