Repository navigation
Description
Context
Spun out of #177 (MCP client reconnect on connection drop) — see this PR comment thread.
The MCP adapter (internal/adapter/mcp/mcp.go) sets DisableStandaloneSSE: true on the StreamableClientTransport (line ~332). This is pre-existing v1 behavior, with an honest comment:
// This adapter only issues request/response tool calls; it does not
// consume server-initiated notifications (e.g. tool-list-changed).
// Disabling the standalone SSE GET stream avoids holding a persistent
// connection open, which lets sessions (and test servers) close cleanly.
DisableStandaloneSSE: true,The result: the harness never opens the persistent SSE GET stream that the MCP Streamable HTTP transport uses for server-initiated messages. A server that fires notifications/tools/list_changed (or the prompts/resources equivalents) finds no live SSE listener and the notification is dropped. The client also doesn't advertise the listChanged capability to servers, so a well-behaved server may not even bother sending the notification.
What the SDK supports (verified against v1.6.1)
The Go SDK fully supports server-initiated notifications on the client side:
ClientOptions(mcp/client.go:151-156) exposesToolListChangedHandler,PromptListChangedHandler,ResourceListChangedHandler,ResourceUpdatedHandler,LoggingMessageHandler,ProgressNotificationHandler.- These are already wired into the SDK's
clientMethodInfostable (mcp/client.go:909-916) — they route through the receiving method handler when the matchingnotifications/*method arrives. - The SDK's
StreamableClientTransport.DisableStandaloneSSEdoc (mcp/streamable.go:1512-1530) states: whenfalse(the default), the client opens a persistent SSE GET afterinitialize; the connection automatically reconnects if interrupted, with a bounded retry loop (handleSSE,maxRetries,retriesWithoutProgress—mcp/streamable.go:1979-2070). When the SSE reconnect exhausts, it callsc.fail(...)which fails the whole connection → the next POST surfacesErrSessionMissing— which MCP client: reconnect/restart session on connection drop instead of hard-failing #177's reconnect now catches. So the two features compose cleanly.
So enabling notifications is a two-part change:
- Set
DisableStandaloneSSE: false(or remove the line — false is the SDK default). - Wire the
*ListChangedHandlercallbacks onmcpsdk.NewClient(...)so the notifications do something useful.
Why it was off
The comment's stated reason — "lets sessions (and test servers) close cleanly" — is the real constraint. The standalone SSE GET holds a persistent connection open for the life of the session (a background handleSSE goroutine per connected server). That means:
- Lifecycle:
Server.Close()and theManager.Close()teardown now must drain/abort the SSE goroutine too. The SDK cancels it onsession.Close()(via theconnCtx), so it's bounded, but it's a goroutine that outlives any single tool call — it belongs in thedocs/adr/0027-cloud-native.mdList 1 resource inventory per the AGENTS.md "outlives-a-call resource" gotcha. - Reconnect interaction: MCP client: reconnect/restart session on connection drop instead of hard-failing #177's reconnect path (
internal/adapter/mcp/reconnect.go) re-establishes the session viadial, which re-opens the SSE GET, so the notification handlers re-attach automatically (they live onClientOptions, rebuilt indial). The SDK's SSE-stream reconnect and MCP client: reconnect/restart session on connection drop instead of hard-failing #177's session reconnect are complementary: a transient SSE drop is healed by the SDK's own reconnect loop; only when that exhausts does the whole session fail withErrSessionMissing, which MCP client: reconnect/restart session on connection drop instead of hard-failing #177 then catches at the tool-call layer. - Tool-list refresh (the hard part): enabling
ToolListChangedHandleris the natural complement to ADR 0056's "no tool-list re-fetch on reconnect" decision. A server that re-advertises a different tool set after restart could push a list-changed, and the handler would re-list. But re-registering into the live catalog mid-run crosses a harder boundary: the catalog is shared/process-wide (catalogAssetsininternal/app/catalog.go), tools are registered ONCE atbuildCatalog/assembleCatalog, andtool.Catalog.Register(engine/tool/catalog.go:28) is append-only — there is noReplace/Unregister/Remove. So a first cut could wire the notification to just invalidate the snapshot + log a WARN (so a stale tool surfaces a clear error on call instead of silently failing), and leave live catalog re-registration as a follow-up.
Proposed scope
Phase 1 — enable the SSE stream + notification plumbing (no catalog mutation)
- Set
DisableStandaloneSSE: falseinServer.dial(internal/adapter/mcp/mcp.go). - Wire
ClientOptions{ToolListChangedHandler, PromptListChangedHandler, ResourceListChangedHandler}onmcpsdk.NewClient(...)— each handler logs aport.DiagnosticsWARN naming the server + the changed list, and invalidates the cachedServer.tools/resources/promptssnapshot so the NEXT read ofTools()/Resources()re-lists. No catalog mutation yet (the registeredremoteToolspecs stay as-is; a tool that the server dropped will surface as a tool-call error on use, which the model can react to). - Verify the
connectStandaloneSSEgoroutine is drained onServer.Close()and on MCP client: reconnect/restart session on connection drop instead of hard-failing #177's reconnect path (confirm the SDK'sconnCtxcancel joins it; add a test thatClosedoesn't leak the SSE goroutine —goleak-style or a goroutine count assertion). - Add the standalone-SSE goroutine to
docs/adr/0027-cloud-native.mdList 1 (resource inventory): owner =*Server, scope = per connected server, cleanup =session.Close()cancelsconnCtx→handleSSEreturns, re-attach = none (the SDK reconnects the stream itself; MCP client: reconnect/restart session on connection drop instead of hard-failing #177 reconnects the session).
Phase 2 — live catalog refresh (separate, harder)
- Add a
tool.Catalogmutation seam (Replace/Unregisteror aReloadthat swaps the tool set atomically), OR a per-*Serverindirection layer soremoteToolresolves its spec through the*Server's current snapshot instead of a frozen catalog entry. - On
ToolListChangedHandler, re-list and reconcile the catalog: add new tools, remove dropped tools, update changed specs. Decide the concurrency story (the catalog is read by the dispatch path on every turn; a swap must be atomic). - This is gated on Phase 1 and on a design decision about catalog mutation — defer to its own ADR.
Phase 3 — ResourceUpdatedHandler + LoggingMessageHandler (optional, lower priority)
-
ResourceUpdatedHandlercould invalidate a cached resource read;LoggingMessageHandlercould route server log messages toport.Diagnostics. Neither is load-bearing; file if/when there's operator demand.
Acceptance criteria (Phase 1)
- A server that fires
notifications/tools/list_changedmid-session no longer has its notification dropped — the harness logs it and the nextTools()re-lists. DisableStandaloneSSEisfalse; the standalone SSE GET is established at connect and drained at close (no goroutine leak; tested).- The cloud-native resource inventory (ADR 0027 List 1) has a row for the per-server SSE goroutine.
- MCP client: reconnect/restart session on connection drop instead of hard-failing #177's reconnect path still works (a server restart still triggers a session reconnect; the SSE stream re-establishes on the fresh session).
task lint && task testgreen; a new test drives anotifications/tools/list_changedfrom an in-process MCP server and asserts the handler fires + the snapshot refreshes.
Out of scope
- Live catalog mutation / tool replacement (Phase 2 — separate ADR).
- Server-side resilience.
- Changes to the MCP protocol or the streaming-HTTP transport decision (no stdio MCP, ever — ADR constraint).
Priority
Low-Medium — this is an operational improvement (stale tool lists after a server-side change stop being silent), not a correctness bug. The #177 reconnect path already recovers from a dead session; this is about proactive freshness, not reactive recovery. The two are complementary.
References
- MCP client: reconnect/restart session on connection drop instead of hard-failing #177 — MCP client reconnect on connection drop (the reactive-recovery sibling).
- feat(mcp): reconnect client session on connection drop (#177) #191 — the PR that landed reconnect + the
Server.dialextraction this would build on. docs/adr/0056-mcp-client-reconnect.md— the "no tool-list re-fetch on reconnect" decision this would revisit (Phase 2).docs/adr/0027-cloud-native.md— List 1 resource inventory (the SSE goroutine row).- SDK:
StreamableClientTransport.DisableStandaloneSSE(mcp/streamable.go:1512),ClientOptions.*ListChangedHandler(mcp/client.go:151-156),handleSSEreconnect loop (mcp/streamable.go:1979).
Activity
feat(mcp): consume server-initiated notifications via standalone SSE (#…
fix(mcp): apply panel-review fixes to server-initiated notifications (#…
fix(mcp): apply panel-review fixes to server-initiated notifications (#…
fix(mcp): apply panel-review fixes to server-initiated notifications (#…