Skip to content

fix: seed MCP sidebar state on a timer to fix stuck "None" panel#3289

Open
albatrossflyon-coder wants to merge 1 commit into
charmbracelet:mainfrom
albatrossflyon-coder:fix-mcp-sidebar-none-3279
Open

fix: seed MCP sidebar state on a timer to fix stuck "None" panel#3289
albatrossflyon-coder wants to merge 1 commit into
charmbracelet:mainfrom
albatrossflyon-coder:fix-mcp-sidebar-none-3279

Conversation

@albatrossflyon-coder

Copy link
Copy Markdown

Summary

  • mcp.Initialize runs in a goroutine concurrently with the TUI starting up (internal/app/app.go:140)
  • A fast-connecting MCP server can reach StateConnected and publish its one and only EventStateChanged before the TUI's event subscription is live, so the event is missed
  • mcpStates is never seeded any other way (Init() doesn't seed it, and for a stable connection no further state event ever fires), so the sidebar shows None for that server for the rest of the session even though its tools work fine (they're registered in a separate global registry, independent of mcpStates)
  • Adds a 2-second re-seed tick that re-reads MCPGetStates() into mcpStates via a new refreshMCPStates() (deliberately skips handleStateChanged's UpdateAgentModel side effect, so it's safe to call on a timer) — self-heals a missed initial event within a couple of seconds, and also picks up later connects/disconnects the same way

Fixes #3279

Root-caused by the issue reporter with exact file/line references and a manually-verified patch; this PR implements their proposed periodic re-seed approach.

Test plan

  • go build ./...
  • go test ./internal/ui/... — all packages pass, no regressions
  • Added TestRefreshMCPStates — confirms refreshMCPStates() returns a mcpStateChangedMsg reflecting the workspace's current MCPGetStates(), simulating a state that was set before the sidebar's mcpStates map was ever seeded
  • Semgrep (p/security-audit, p/secrets, p/golang, Trail of Bits Go rules) on the changed files — 0 findings

mcp.Initialize runs in a goroutine concurrently with the TUI starting
up. A fast-connecting MCP server can reach StateConnected and publish
its one and only EventStateChanged before the TUI's event subscription
is live, so the event is missed. mcpStates is never seeded any other
way, so the sidebar shows "None" for that server for the rest of the
session even though its tools work fine (they're registered in a
separate global registry, independent of mcpStates).

Adds a 2-second re-seed tick that re-reads MCPGetStates() into
mcpStates, so a missed initial event self-heals within a couple of
seconds instead of never recovering. Also picks up later
connects/disconnects the same way.

Fixes charmbracelet#3279
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP servers show as “None” in the sidebar even when connected and their tools work

1 participant