diff --git a/packages/tfcode/src/cli/cmd/tui/component/dialog-tf-mcp.tsx b/packages/tfcode/src/cli/cmd/tui/component/dialog-tf-mcp.tsx index 03c1d5a58..2e412edd6 100644 --- a/packages/tfcode/src/cli/cmd/tui/component/dialog-tf-mcp.tsx +++ b/packages/tfcode/src/cli/cmd/tui/component/dialog-tf-mcp.tsx @@ -143,9 +143,17 @@ export function DialogTfMcp() { duration: 3000, }) } - const status = await sdk.client.mcp.status() - if (status.data) { - sync.set("mcp", reconcile(status.data)) + + // Poll until status reflects the change (MCP SSE handshake is async) + const wantConnected = !isEnabled() + for (let i = 0; i < 10; i++) { + await new Promise((r) => setTimeout(r, 500)) + const status = await sdk.client.mcp.status() + if (status.data) { + sync.set("mcp", reconcile(status.data)) + const current = status.data[TF_MCP_NAME]?.status === "connected" + if (current === wantConnected) break + } } } catch (error) { toast.show({