Repository navigation
feat(mcp): consume server-initiated notifications via standalone SSE (#193) - #195
Merged
Merged
Conversation
…193) Enable the standalone SSE GET stream (remove DisableStandaloneSSE) and wire the three list-changed notification handlers (ToolListChangedHandler, PromptListChangedHandler, ResourceListChangedHandler) in Server.dial — the single construction site reused by Connect and reconnect, so a reconnect re-attaches them automatically. Each handler only sets a dirty flag + logs a WARN; it does NOT re-list eagerly (it runs on the SDK's SSE goroutine, where a network call would stall notification processing and could deadlock against s.mu). The accessors (Tools/Resources/Prompts) lazily re-list on the next read under a bounded context.Background(), swapping in the fresh snapshot. The re-list runs WITHOUT s.mu held across the network (only the check + swap hold it) to avoid deadlocking against reconnect, which re-acquires s.mu. No catalog mutation: the registered remoteTool specs are untouched; a tool the server dropped surfaces a tool-call error on use. Live catalog refresh (Phase 2, needs a tool.Catalog Replace/Unregister seam) is deferred to its own ADR. Lifecycle: the SDK spawns one handleSSE goroutine per connected server, drained by session.Close() → conn.Close() cancelling connCtx. Added a goleak gate (leakmain_test.go) with a targeted ignore list for the SDK + stdlib goroutines that unwind asynchronously after close. The SSE stream composes with #177's reconnect: a transient SSE drop is healed by the SDK's own reconnect loop; when that exhausts, the connection fails → next POST surfaces ErrSessionMissing → #177 reconnects the session. Test teardown ordering fix: with SSE on, httptest.Server.Close() blocks if the SDK's SSE reader is still attached. The test fixtures (newTestServer, newToolsOnlyServer, and the internal/app MCP test helpers) now self-register t.Cleanup(httpSrv.Close) so the listener closes AFTER *Server.Close/ mgr.Close (LIFO), and callers no longer defer stop() (which closed the listener before the session). This is the bulk of the test-file churn. Tests: TestToolListChangedNotificationRefreshesSnapshot + TestResourceListChangedNotificationRefreshesSnapshot (the Phase-1 acceptance gate — drive a notifications/tools/list_changed from an in-process server, assert the handler fires + the lazy re-list picks up the new tool). The goleak gate catches a leaked SSE goroutine. Docs: ADR 0057 (frozen), ADR 0027 List 1 row 28 (SSE goroutine inventory), architecture/extensibility.md, PRODUCTION-READINESS.md, llms.txt regenerated. Phase 2 (live catalog refresh) is referenced in ADR 0057 as the deferred follow-up. Closes #193
This was referenced Jun 26, 2026
JAORMX
added a commit
that referenced
this pull request
Jun 26, 2026
…193) Follow-up to #195 (the pre-review version that merged). Applies the four findings from the panel review that didn't make it into the merged commit: - [Medium] Notification-storm log dedup (secure-code-reviewer): handleListChanged logged a WARN on every notification; a malicious server could flood the diagnostics sink. Now logs only on the false→true transition (first notification since the last re-list). Pinned by TestNotificationStormLogsOncePerRefreshCycle. - [Low] Test-helper footgun (software-architect): newTestServer returned a stop-func that, if defer'd, re-introduced the SSE-teardown wedge. Now returns only the URL (self-registers t.Cleanup). Applied to both internal/adapter/mcp and internal/app test helpers. - [Low] ADR 0057 latency doc gap (software-architect): the bounded synchronous re-list latency on the List* wire surfaces wasn't documented. Added to ADR 0057 Consequences. - QA gap: no prompts/list_changed test. Added TestPromptListChangedNotificationRefreshesSnapshot.
JAORMX
added a commit
that referenced
this pull request
Jun 26, 2026
…193) Follow-up to #195 (the pre-review version that merged). Applies the four findings from the panel review that didn't make it into the merged commit: - [Medium] Notification-storm log dedup (secure-code-reviewer): handleListChanged logged a WARN on every notification; a malicious server could flood the diagnostics sink. Now logs only on the false→true transition (first notification since the last re-list). Pinned by TestNotificationStormLogsOncePerRefreshCycle. - [Low] Test-helper footgun (software-architect): newTestServer returned a stop-func that, if defer'd, re-introduced the SSE-teardown wedge. Now returns only the URL (self-registers t.Cleanup). Applied to both internal/adapter/mcp and internal/app test helpers. - [Low] ADR 0057 latency doc gap (software-architect): the bounded synchronous re-list latency on the List* wire surfaces wasn't documented. Added to ADR 0057 Consequences. - QA gap: no prompts/list_changed test. Added TestPromptListChangedNotificationRefreshesSnapshot.
JAORMX
added a commit
that referenced
this pull request
Jun 26, 2026
…193) Follow-up to #195 (the pre-review version that merged). Applies the four findings from the panel review that didn't make it into the merged commit: - [Medium] Notification-storm log dedup (secure-code-reviewer): handleListChanged logged a WARN on every notification; a malicious server could flood the diagnostics sink. Now logs only on the false→true transition (first notification since the last re-list). Pinned by TestNotificationStormLogsOncePerRefreshCycle. - [Low] Test-helper footgun (software-architect): newTestServer returned a stop-func that, if defer'd, re-introduced the SSE-teardown wedge. Now returns only the URL (self-registers t.Cleanup). Applied to both internal/adapter/mcp and internal/app test helpers. - [Low] ADR 0057 latency doc gap (software-architect): the bounded synchronous re-list latency on the List* wire surfaces wasn't documented. Added to ADR 0057 Consequences. - QA gap: no prompts/list_changed test. Added TestPromptListChangedNotificationRefreshesSnapshot.
JAORMX
added a commit
that referenced
this pull request
Jun 26, 2026
…197) Follow-up to #195. Resolves all panel-review findings: notification-storm log dedup, single + concurrent lost-update (clear-before-fetch + per-list generation counters), unbounded-ingestion cap (maxListEntries), honest ADR/doc comments, de-flaked storm test, added prompts/list_changed test. Also bumps toolhive v0.28.3 -> v0.31.0 (pulls a fixed docker/docker), clearing the govulncheck allowlist entirely.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #193. Phase 1 only — no live catalog mutation (Phase 2 deferred to its own ADR).
Enables the standalone SSE GET stream on the MCP client and wires the three list-changed notification handlers (ToolListChangedHandler/PromptListChangedHandler/ResourceListChangedHandler), so server-initiated notifications/{tools,prompts,resources}/list_changed are no longer dropped.
See ADR 0057 for the full design. Key points:
Tests: TestToolListChangedNotificationRefreshesSnapshot + TestResourceListChangedNotificationRefreshesSnapshot (the acceptance gate), goleak gate. task lint && task test green.