fix(sse): emit servers.changed event after tool discovery completes#292
Merged
fix(sse): emit servers.changed event after tool discovery completes#292
Conversation
Fix race condition where tool counts in Web UI showed stale data after enabling/disabling servers. The issue was that SSE events were emitted before the asynchronous tool discovery completed, causing the frontend to fetch stats from StateView before it was updated. Changes: - Move emitServersChanged() inside the tool discovery goroutine in both HandleUpstreamServerChange() and RestartServer() - Add "reason": "tool_discovery_complete" to event payload for clarity - Change HandleUpstreamServerChange event type from "upstream_change" to "tools_indexed" to better reflect when it's emitted The frontend now receives the SSE event only after tool counts are accurate, ensuring consistent UI updates within ~3-5 seconds. Fixes #285 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Deploying mcpproxy-docs with
|
| Latest commit: |
cccdfd8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9294710f.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-stale-tool-counts-race-c.mcpproxy-docs.pages.dev |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 21630313261 --repo smart-mcp-proxy/mcpproxy-go
|
Root cause fixes for stale tool counts: - TotalTools stat now excludes disabled servers' tool counts - DeleteServerTools called when server is disabled to remove from index Tests added: - Unit test: TotalTools excludes disabled servers (service_test.go) - Unit test: Disabled server removes tools from index (tool_invalidation_test.go) - E2E test: Full disable/enable cycle with search verification Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The frontend was summing all servers' tool_count regardless of enabled status, causing Total Tools to show stale counts when servers are disabled. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
HandleUpstreamServerChange()andRestartServer()in lifecycle.goRoot Cause
SSE events were emitted before the asynchronous tool discovery goroutine completed. When the frontend received the event and fetched stats from the REST API, StateView hadn't been updated yet, returning stale tool counts.
Solution
Move
emitServersChanged()inside the tool discovery goroutine so it fires afterDiscoverAndIndexTools()completes. The event payload now includes"reason": "tool_discovery_complete"for clarity.Test plan
./scripts/run-linter.sh)go test ./internal/runtime/...)./scripts/test-api-e2e.sh)Fixes #285
🤖 Generated with Claude Code