Repository navigation
Description
vMCP: backend health/set changes are not propagated to live sessions (stale tool catalog until client reconnect; no tools/list_changed)
Type: bug / enhancement · Area: vMCP (aggregator / server / health) · Version: v0.34.0 (latest release; also on main)
Related: companion to the SSRF-allowlist request (co-located backends) — same deployment.
Summary
When a vMCP backend's availability changes at runtime — a backend recovers (unhealthy→healthy), or is added/removed from the group — already-connected client sessions do not see the change. Their tool catalog stays as it was when the session was created, and the vMCP never emits notifications/tools/list_changed. Clients must reconnect (re-initialize the session) to pick up a newly-healthy backend's tools. New sessions are fine; existing ones are stuck.
Repro
- Run a vMCP fronting ≥2 backends; connect a client (session A).
- A backend that was unhealthy at A's connect time becomes healthy (fix its endpoint, restart it, etc.). The vMCP re-aggregates — logs
capability aggregation complete backends:N tools:Mwith the new backend included. - From session A: the new backend's tools are not callable (
call_tool→tool not found) and don't appear in discovery. A freshly connected session B sees them. - Only reconnecting session A surfaces them.
(In optimizer mode this is extra-confusing: the client's advertised tools are the stable find_tool/call_tool meta-tools, so even a client that honors tools/list_changed has nothing new to re-fetch — the staleness lives inside the optimizer catalog that find_tool/call_tool resolve against.)
Root cause (verified, v0.34.0)
- Per-session snapshot, taken once at registration.
pkg/vmcp/server/serve_handlers.go→injectCoreSessionCapabilities→coreSessionToolscallss.core.ListTools(...)only when the session is registered, and installs the result viasetSessionToolsDirect. In optimizer modeserveSessionToolsbuilds thefind_tool/call_toolmeta-tools over that same one-time snapshot. - Aggregation has no downstream notification.
pkg/vmcp/aggregator/default_aggregator.go(AggregateCapabilities) andpkg/vmcp/aggregator/caching_aggregator.gocompute/refresh the merged set, but neither notifies sessions nor the server of a change. - Health monitor detects transitions but doesn't fan out.
pkg/vmcp/health/monitor.gotracks status (statusTracker,UpdateBackends,StatusProvider/Reporterinterfaces) and logsstarting health monitoring for new backend, but there is no callback/subscription that re-injects live sessions or triggers a client notification on a state change. - No
tools/list_changedis ever emitted on the vMCP path. The method is parsed (pkg/mcp/parser.go) and the primitive exists (pkg/transport/bridge.go→SendNotificationToAllClients), but it is only used by the single-server proxy bridge, not wired into the vMCP aggregation/session layer.
Net: health monitor → re-aggregate is a dead end w.r.t. connected sessions.
Proposal
On a backend-set change (health transition, or group add/remove), propagate to live sessions:
- Passthrough mode (optimizer off): update each connected session's advertised tools (the go-sdk supports per-session
AddSessionTools/SetSessionTools/DeleteSessionTools) and emitnotifications/tools/list_changedto all clients via theMCPServer(the same primitive the bridge already uses). Requires the server to advertisetools.listChanged: true. - Optimizer mode (optimizer on): rebuild the optimizer catalog/index that
find_tool/call_toolresolve against so existing sessions resolve the new backend without reconnect (either refresh the per-session optimizer state, or have the optimizer resolve against the live core catalog on each call / on a change signal). - Wiring: give
health.Monitora change-callback / subscription (it already centralizes status viastatusTracker); the core/server subscribes, re-aggregates, and performs (1)/(2). Debounce to the existingstatusReportingIntervalso a flapping backend doesn't storm sessions.
Notes
- Gate strictly on the server advertising
tools.listChanged; no behavior change otherwise. - The debounce already present for health (
healthCheckInterval×unhealthyThreshold) keeps this from firing on transient blips. - Happy to help / open a PR — a sketch of the integration points is written up alongside this.
Activity
premctl commentedon Jul 13, 2026
PR sketch — propagate vMCP backend-set changes to live sessions
Addresses #5786 (companion to #5784). Goal: when the healthy backend set changes at runtime (unhealthy→healthy, or group add/remove), connected sessions see the new/removed tools without reconnecting, and the vMCP emits
notifications/tools/list_changed.Current flow (verified, v0.34.0)
SendNotificationToAllClientsexists (pkg/transport/bridge.go) andtools/list_changedis parsed (pkg/mcp/parser.go), but neither is wired to the aggregation/session path.Proposed flow
Changes by file
1.
pkg/vmcp/health/monitor.go— surface transitionsMonitor(it already centralizes state instatusTrackerand handles group edits inUpdateBackends):statusTrackeron a healthy⇄unhealthy transition and fromUpdateBackendson add/remove. Coalesce/debounce tostatusReportingIntervalso a flapping backend doesn't storm.2.
pkg/vmcp/core/core_vmcp.go— re-aggregate on signalOnChange, recomputeaggregator.AggregateCapabilities(ctx, healthyBackends)and swap the core's catalog + routing table atomically; bump ageneration. (ThecachingAggregatorcache must be keyed on / invalidated by the healthy-set generation so it doesn't serve the stale merge.)<-chan generation.3.
pkg/vmcp/server/serve_handlers.go(+ session registry) — apply to live sessionsinjectCoreSessionCapabilities/coreSessionToolsinto anapplySessionCapabilities(session)that diffs current vs new.coreSessionToolsand re-apply via the existingsetSessionToolsDirect(add new, remove gone).find_tool/call_toolmeta-catalog for that session from the newcore.ListTools(this is the half that actually fixes optimizer mode — advertised tools stay{find_tool, call_tool}, but their backing index refreshes).s.mcpServer.SendNotificationToAllClients("notifications/tools/list_changed", nil).tools.listChanged: truein server capabilities (gate: only notify if advertised).Concurrency / correctness
generation; sessions are updated under their existing session lock. Skip a session whose applied generation already == current.call_toolnever resolves a name against a mismatched route.Backward compatibility
tools.listChanged. Optimizer-catalog refresh is internal (no protocol change). Existing debounce keeps blips from propagating.Tests
OnChangeexactly once per debounced transition; core re-aggregates and bumps generation;cachingAggregatorinvalidates on new generation.SendNotificationToAllClientscalled once.test/e2e/thv-operator/virtualmcp/): connect session A; flip a stub backend unhealthy→healthy; assert (a) A receivestools/list_changed, (b) the new backend's tool is callable on A without reconnect — run the matrix in both passthrough and optimizer modes.Scope / risk
listChangedcapability so it's opt-in by server config.aponcedeleonch commentedon Jul 14, 2026
Thanks for the incredibly thorough writeup. I walked all four paths on current main (75b3ed7) and the root-cause analysis holds up:
injectCoreSessionCapabilities->coreSessionTools->core.ListToolsruns once per session fromhandleSessionRegistrationImpl, and the optimizerfind_tool/call_toolmeta-tools inserveSessionToolsget built over that same one-time snapshot.setSessionToolsDirecteven bypassesAddSessionToolson purpose to avoid notifications.default_aggregator.AggregateCapabilities,caching_aggregator) only log and cache. No downstream notify.statusTracker.RecordSuccess/RecordFailureare log-only, andUpdateBackendsis only called from the periodicreportStatus, which never re-injects sessions.SendNotificationToAllClientsis wired only into the single-server proxy bridge (pkg/transport/bridge.go), not the vMCP path.So health monitor -> re-aggregate really is a dead end for connected sessions. I didn't stand up a live multi-backend vMCP to reproduce the flap, since the gap is structural and the code paths settle it, but flagging that the repro here is by code inspection, not a live run.
Confirming this as a valid open issue. Your integration sketch lines up with how the code is actually structured.
One suggestion on implementation: I'd split this into two PRs rather than one, since the two modes have pretty different blast radius.
notifications/tools/list_changed, gated on the server advertisingtools.listChanged. This is the more contained change and a good place to start.find_tool/call_toolresolve against so existing sessions pick up the new backend without reconnect. This one has more implications, so it's worth isolating. The catalog/routing swap needs to be atomic so an in-flightcall_toolnever resolves against a mismatched route, plus there's the per-session optimizer state to think through.Happy to review both if you're up for taking them up.
premctl commentedon Jul 15, 2026
Thanks for walking all four paths — and good catch that
setSessionToolsDirectbypassesAddSessionToolsspecifically to suppress notifications; that's the exact seam PR1 has to change.The two-PR split makes sense — the blast radius is very different:
health.Monitorchange-callback → core re-aggregate → per-session re-apply advertised tools +SendNotificationToAllClients("notifications/tools/list_changed", …), gated on the server advertisingtools.listChanged. Contained and independently useful.find_tool/call_toolcatalog for live sessions, with the atomic catalog/routing swap so an in-flightcall_toolnever resolves against a mismatched route.One design question for PR1: do you want the change signal modeled as a callback registered on
Monitor, or a<-chanthe core selects on (fits the existingreportStatusloop)? I'll match whatever suits the codebase.Assuming we take these up, I'd start with PR1.
aponcedeleonch commentedon Jul 17, 2026
Both PR summaries look right to me, and starting with PR1 is the way to go.
On the design question: I'd lean toward a callback registered on
Monitorrather than a<-chanthe core selects on. Two reasons, and they come out of double-checking the current wiring.First, the
reportStatusloop isn't in the core, it's in the server layer (pkg/vmcp/server/status_reporting.go,periodicStatusReporting/reportStatus). And it's a polling ticker that pulls from the monitor (BuildStatus(),UpdateBackends()), not a select loop. So a push channel wouldn't slot into it as cleanly as it might look. A callback onMonitor, fired from thestatusTrackertransition points and fromUpdateBackends, keeps the monitor as the single source of truth and lets the core subscribe without either side owning a channel lifecycle. Debounce still lives in the monitor, same as your sketch.One small correction on the
setSessionToolsDirectpoint, since it shapes PR1. It does bypassAddSessionTools, but the documented reason is narrower than suppressinglist_changedfor clients. The comment atserver.go:1020says the bypass avoids notifications that would accumulate as stale messages during registration, because the notification goroutine from the initialize request has already exited by then. So for PR1 the seam isn't "re-enable the notification that was being suppressed", it's "install the updated tools post-init, when the notification channel is live, and then emittools/list_changedexplicitly". Same seam you identified, just worth being precise about what the bypass was for so the re-apply path handles the channel state correctly.And confirming the gating half: vMCP builds its Serve-path server with
WithToolCapabilities(false)today (serve.go:217), so PR1 does need to flip that to advertisetools.listChangedbefore the notify has any effect.That's all detail. The plan holds. Happy to review PR1 when you have it up.
RaviTharuma commentedon Jul 17, 2026
Inverse symptom of the same per-session snapshot architecture, filed #5861 - that one is about new sessions still paying the full per-backend blocking-init cost against a backend the health monitor already knows is flaky/slow, rather than existing sessions going stale. Cross-linking since both point at the same caching_aggregator.go/health monitor interaction from different angles.
premctl commentedon Aug 5, 2026
PR 1 (passthrough mode) is up: #6196.
One note before you dive in: the codebase moved after our discussion here — #5748/#5969 landed the per-session tools resync workers (identity/header capture, replace semantics, coalescing) and flipped
WithToolCapabilities(true)— so the PR wires the health monitor'sOnChange(debounced callback registered onMonitor, exactly as agreed above) into that existing machinery rather than re-implementing the re-apply/notify steps. The PR description's "Special notes for reviewers" maps each step of the design we agreed here to where it now lives, including why no explicitSendNotificationToAllClientscall is needed anymore.E2E-verified on a Kind cluster: a session initialized while a backend was down receives
notifications/tools/list_changedon its standalone stream when the backend recovers, then lists and calls the recovered backend's tool on the same session without reconnecting.PR 2 (optimizer-mode
find_tool/call_toolcatalog rebuild) to follow.Resync session tools when backend health changes
Resync session tools when backend health changes
Resync session tools when backend health changes
Resync session tools when backend health changes (#6196)
aponcedeleonch commentedon Nov 12, 2026
Sorry for the slow response on this one, @premctl. Quick status: the passthrough half landed in #6196 and shipped in v0.45.0, so with the optimizer off, live sessions now pick up backend health changes without reconnecting. The optimizer half in #6419 got review feedback on two lifecycle cases and has been quiet since, so we've closed that PR for inactivity.
The optimizer-mode part is still a good candidate for a contribution. If you or anyone else wants to pick #6419 back up and address those review comments, a reopened or fresh PR is welcome and we'll help with direction. It isn't something we're prioritizing ourselves right now, but we're leaving this issue open so it stays visible.
Thanks again for the thorough work on this.