openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

feat(mcp): connection health toolbar with bulk Retry All / Disconnect All actions

Open aashir-athar opened this issue 6 months ago • 1 comments

Summary

  • New MCP Connection Health Toolbar in the left pane of Channels → ChannelConfigPanel → McpServersTab. Surfaces aggregate per-state counts (connected / connecting / error / idle) and exposes two bulk actions that previously required clicking into each server one at a time.
  • Retry All (N) — visible only when there are errored servers. Iterates through them via mcpClientsApi.connect(id) wrapped in Promise.allSettled so one bad apple doesn't abort the batch, then refreshes statuses once at the end.
  • Disconnect All (N) — visible only when there are connected servers. Gated behind a role="dialog" aria-modal confirmation dialog before the bulk RPC fires.
  • The status summary is announced through a role="status" aria-live="polite" region so screen-reader users hear updates as the 5-second polling loop refreshes. Status dots are aria-hidden. Buttons have descriptive aria-labels with interpolated counts.
  • 15 new i18n keys under mcp.health.* mirrored across all 13 locale chunks (English values used as untranslated placeholders per the repo's standard pattern).
  • 17 new Vitest tests covering count aggregation, conditional button rendering, dialog open/cancel/confirm flow, partial-failure orchestration via Promise.allSettled, error surfacing through role="alert", and the a11y attribute contract on every interactive element.

Problem

MCP servers in this app can drift into error state for legitimate reasons — a key expired, a managed runtime restart cycle, a flaky upstream HTTP-remote server. Today, recovering means clicking each errored server individually in the list, navigating to its detail view, and hitting connect. With three or four servers it's tedious; with the ten-plus shape that real Smithery users hit, it's a chore.

Disconnect-all is symmetric — useful during debugging ("what changes if I cut all MCP connections?"), useful during shutdown, useful for the user who just installed a server with bad env vars and wants a clean reset across the board.

There's also no aggregate at-a-glance status. The list shows per-server dots, but counting "how many am I currently connected to?" requires scanning. For users with a dozen servers, that scan happens visually every time they open the tab.

Solution

New component McpConnectionHealthToolbar.tsx

Renders only when statuses.length > 0 — preserves the existing "empty install + Browse catalog CTA" empty state by not competing for vertical space.

Layout (compact, fits the 224px left pane):

┌────────────────────────────────────────┐
│ HEALTH       Retry all (1)  Disconnect │
│                                all (3) │
│ ● 3 connected  ● 1 error  ● 2 idle    │
└────────────────────────────────────────┘

Status pills use the existing color vocabulary from McpStatusBadge (sage/amber/coral/stone). Dots flow on a flex flex-wrap row so the layout doesn't break at narrower widths.

Aggregation (in computeHealthCounts, exported as a pure helper):

  • Single pass over statuses producing connectedIds, errorIds, and counts for connecting / disconnected. useMemo keyed on statuses so the bulk action targets don't recompute on unrelated re-renders.
  • connectedIds and errorIds are arrays (not just counts) — the same memoization payload powers both the visual badges and the bulk-action callbacks, so there's no risk of the displayed count diverging from the IDs that would be acted on.

Bulk action flow (Retry All):

  1. Click Retry all (N) — calls onReconnect(errorIds); sets isOperating=true to disable both buttons.
  2. Parent (McpServersTab.handleBulkReconnect) does Promise.allSettled(errorIds.map(id => mcpClientsApi.connect(id))) followed by fetchStatuses().
  3. On resolve, isOperating=false; the next render reflects the new statuses; the buttons re-enable.
  4. On parent throw: setOpError(err.message) displays the failure in a role="alert" paragraph below the summary. Falls back to t('mcp.health.opErrorGeneric') for non-Error throws.

Bulk action flow (Disconnect All):

  1. Click Disconnect all (N) — opens confirmation dialog with role="dialog" aria-modal="true" and explicit aria-labelledby / aria-describedby referencing the title and body IDs.
  2. Cancel → close dialog, onDisconnect never fires.
  3. Confirm → close dialog, then run the same Promise.allSettled orchestration via onDisconnect(connectedIds).

Wiring in McpServersTab.tsx

  • Imports the new component.
  • Adds handleBulkReconnect and handleBulkDisconnect as useCallbacks alongside the existing handleInstallSuccess / handleUninstalled handlers. Both call Promise.allSettled on per-server RPC then fetchStatuses() for one round-trip refresh.
  • Renders <McpConnectionHealthToolbar> above <InstalledServerList> in the left pane, after the existing loadError block.

i18n

15 new keys under the mcp.health.* namespace added to app/src/lib/i18n/en.ts AND to app/src/lib/i18n/chunks/en-1.ts (the runtime chunk that already holds the existing mcp.* keys). All 12 non-English locale chunks (ar-1.ts … zh-CN-1.ts) get the same six keys with the English value as the untranslated placeholder, per the project pattern that scripts/i18n-coverage.ts enforces.

Verified locally:

$ pnpm i18n:check
…
## zh-CN  (2997 keys)
  missing: 0   extra: 0   drifted chunks: 0
  per-chunk: 1:1206/1206  2:387/387  3:389/389  4:391/391  5:629/629
(same shape for ar, bn, de, es, fr, hi, id, it, ko, pt, ru)
EXIT: 0

Submission Checklist

  • [x] Tests added — 17 new tests in McpConnectionHealthToolbar.test.tsx. Cover: empty-state return-null path; correct count aggregation across mixed status sets; conditional rendering of connecting / error pills only when non-zero; conditional rendering of Retry All only when errors exist; conditional rendering of Disconnect All only when connected exist; "Retry all" calls onReconnect with exactly the errored IDs; "Disconnect all" opens a confirmation dialog rather than firing directly; cancel closes the dialog without calling onDisconnect; confirm fires onDisconnect with exactly the connected IDs and closes the dialog; both action buttons are disabled during a pending bulk operation; errors thrown from onReconnect surface via role="alert"; non-Error throws fall back to a generic message; the summary region has role="status" + aria-live="polite" + a descriptive aria-label; the confirmation dialog body interpolates the correct connected count.
  • [x] Diff coverage ≥ 80% — every branch in McpConnectionHealthToolbar.tsx and the new handleBulkReconnect / handleBulkDisconnect callbacks in McpServersTab.tsx are exercised by the test suite. Local Vitest: 91/91 passing across the full MCP suite (8 test files); no regression in any pre-existing test.
  • [x] Coverage matrix updated — N/A: enhancement to existing MCP feature row, no new feature ID added or removed.
  • [x] All affected feature IDs listed under ## Related — N/A.
  • [x] No new external network dependencies introduced — uses the existing mcpClientsApi.connect / mcpClientsApi.disconnect round-tripped through the existing JSON-RPC.
  • [x] Manual smoke checklist updated if release-cut surfaces touched — N/A.
  • [x] Linked issue closed via Closes #NNN in ## Related — no specific issue; organic UX improvement on the MCP surface.

Impact

  • Runtime/platform: Desktop only — McpServersTab is desktop-only via ChannelConfigPanel. No iOS / web impact.
  • Performance: Status aggregation is O(n) per render, memoized. Bulk actions are N parallel RPCs via Promise.allSettled — strictly equivalent to a user manually triggering N connects/disconnects, just dispatched together. No new polling loop.
  • Security: Disconnect is gated behind a confirmation dialog (role="dialog" aria-modal). The dialog body explicitly states secrets and configurations are preserved, addressing the "did I just lose my install state?" anxiety.
  • Backward compatibility: The toolbar returns null when statuses.length === 0, preserving the existing zero-installed flow byte-for-byte. All pre-existing MCP tests still pass unchanged.
  • i18n: English values everywhere by default; the same 15 keys exist in every locale's chunks as untranslated placeholders, ready for native-speaker translation in follow-up PRs (they count toward each locale's untranslated total).
  • A11y: Live region for status changes; explicit aria-labels with interpolated counts on action buttons; role="dialog" aria-modal aria-labelledby aria-describedby on the confirmation modal; decorative aria-hidden status dots; role="alert" for operation errors.

Related

  • Closes:
  • Follow-up PR(s)/TODOs:
    • Native-speaker translation of the 15 new mcp.health.* keys across the 12 non-English locales (currently fall back to English placeholders; flagged in each locale's untranslated count).
    • Optional future: a "Refresh now" button next to the toolbar for users who want an immediate poll instead of waiting up to 5 seconds for the next tick. Skipped here to keep scope tight.

AI Authored PR Metadata

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: feat/mcp-connection-health-toolbar
  • Commit SHA: (filled by GitHub after push)

Validation Run

All four key gates passed locally:

  • [x] pnpm --filter openhuman-app compile — clean (tsc --noEmit, no output = success).
  • [x] pnpm --filter openhuman-app lint — clean for new files. The full repo currently produces 62 warnings (0 errors), of which zero are in the files this PR adds or modifies; the single warning at McpServersTab.tsx:70:18 is the pre-existing setLoading(false) inside the initial-load useEffect, untouched by this PR.
  • [x] pnpm vitest run src/components/channels/mcp/ — 91/91 passing including the 17 new tests and all pre-existing MCP component tests (no regression).
  • [x] pnpm i18n:check — exit 0, every locale at 1:1206/1206 parity, 0 missing keys, 0 extra keys, 0 drift.

Validation Blocked

  • command: pnpm --filter openhuman-app format:check (chains cargo fmt --check via the workspace script) and the husky pre-push hook (which runs pnpm format → cargo fmt).
  • error: 'cargo' is not recognized as an internal or external command, operable program or batch file. — no Rust toolchain installed on the dev machine.
  • impact: Used git push --no-verify per CLAUDE.md's allowance for unrelated pre-existing breakage. This PR touches zero Rust files, so cargo fmt --check would have been a no-op for the changed files. Prettier on the changed TS files runs in CI on a clean Linux checkout with LF line endings; verified locally that the new files were written with LF.

Behavior Changes

  • Intended behavior change: Surfaces aggregate MCP connection health in the tab pane; introduces bulk Retry All / Disconnect All as new user actions gated behind appropriate state (errors exist / connections exist) and confirmation (for disconnect).
  • User-visible effect: At-a-glance health for power users with many MCP servers; one-click recovery of bulk error states; one-confirmation cut-all-connections for debugging or reset.

Parity Contract

  • Legacy behavior preserved: When statuses.length === 0, the toolbar returns null — the existing layout renders exactly as before. All pre-existing MCP tests pass unchanged. Per-server connect/disconnect via the existing detail view is untouched.
  • Guard/fallback/dispatch parity checks: Promise.allSettled ensures partial failures within a bulk action don't abort the rest; the next poll tick reconciles any drift; thrown errors at the orchestration boundary surface through role="alert" rather than being swallowed.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): None known.
  • Canonical PR: This one.
  • Resolution: N/A.

Summary by CodeRabbit

  • New Features

    • MCP connection health toolbar showing live connected/connecting/error/disconnected counts
    • "Retry all" bulk reconnect and "Disconnect all" bulk disconnect (with confirmation) actions
  • Accessibility

    • Live status announcements and accessible confirmation dialog/alerts
  • Localization

    • Added MCP health UI translations in 15 languages
  • Tests

    • Comprehensive tests covering rendering, actions, error states, and accessibility behavior

Review Change Stack

aashir-athar avatar May 25 '26 14:05 aashir-athar

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e10bb09f-b26c-4661-b6ab-a5092f98f519

📥 Commits

Reviewing files that changed from the base of the PR and between 7c132817f3335c3021b06f28672b89d2512a7732 and 3301101c17f5ace3ebd83afc718aad517e0925fe.

📒 Files selected for processing (16)
  • app/src/components/channels/mcp/McpServersTab.test.tsx
  • app/src/components/channels/mcp/McpServersTab.tsx
  • app/src/lib/i18n/chunks/ar-1.ts
  • app/src/lib/i18n/chunks/bn-1.ts
  • app/src/lib/i18n/chunks/de-1.ts
  • app/src/lib/i18n/chunks/en-1.ts
  • app/src/lib/i18n/chunks/es-1.ts
  • app/src/lib/i18n/chunks/fr-1.ts
  • app/src/lib/i18n/chunks/hi-1.ts
  • app/src/lib/i18n/chunks/id-1.ts
  • app/src/lib/i18n/chunks/it-1.ts
  • app/src/lib/i18n/chunks/ko-1.ts
  • app/src/lib/i18n/chunks/pt-1.ts
  • app/src/lib/i18n/chunks/ru-1.ts
  • app/src/lib/i18n/chunks/zh-CN-1.ts
  • app/src/lib/i18n/en.ts
✅ Files skipped from review due to trivial changes (5)
  • app/src/lib/i18n/chunks/en-1.ts
  • app/src/lib/i18n/chunks/id-1.ts
  • app/src/lib/i18n/chunks/hi-1.ts
  • app/src/lib/i18n/chunks/zh-CN-1.ts
  • app/src/lib/i18n/chunks/ar-1.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • app/src/lib/i18n/chunks/fr-1.ts
  • app/src/lib/i18n/chunks/it-1.ts
  • app/src/lib/i18n/chunks/pt-1.ts
  • app/src/lib/i18n/chunks/de-1.ts
  • app/src/lib/i18n/chunks/ru-1.ts
  • app/src/lib/i18n/chunks/ko-1.ts
  • app/src/lib/i18n/en.ts

📝 Walkthrough

Walkthrough

This PR introduces McpConnectionHealthToolbar, a new React component that aggregates MCP server connection health and provides bulk reconnect and disconnect capabilities. The component integrates into McpServersTab with handlers that run parallel operations and report partial failures. Includes comprehensive test coverage and i18n strings across 14 locales.

Changes

MCP Connection Health Toolbar

Layer / File(s) Summary
Component interface and health computation
app/src/components/channels/mcp/McpConnectionHealthToolbar.tsx (lines 1–41)
Public props (statuses, onReconnect, onDisconnect) and HealthCounts shape; computeHealthCounts() derives per-state counts and server ID lists from statuses.
Component state and async bulk action handlers
app/src/components/channels/mcp/McpConnectionHealthToolbar.tsx (lines 73–127)
Internal state for operation guard, confirm dialog, and error storage; async handlers for "Retry all" and "Disconnect all" with try/catch and operation gating.
UI rendering with dialogs and accessibility
app/src/components/channels/mcp/McpConnectionHealthToolbar.tsx (lines 129–245)
Conditional action buttons, role="status" aria-live="polite" live region for counts, role="alert" error messaging, and accessible disconnect confirmation modal with aria attributes.
McpConnectionHealthToolbar test suite
app/src/components/channels/mcp/McpConnectionHealthToolbar.test.tsx
Rendering, count display, conditional buttons, bulk-action flows (confirm/cancel/Escape), async disabling, error handling, and accessibility assertions.
Integration into McpServersTab
app/src/components/channels/mcp/McpServersTab.tsx (lines 16, 143–189, 222–233)
Import toolbar; implement handleBulkReconnect and handleBulkDisconnect using Promise.allSettled for parallel operations with status refresh and partial-failure error reporting.
McpServersTab bulk-action integration tests
app/src/components/channels/mcp/McpServersTab.test.tsx (lines 69–78, 450–496)
STATUSES_ERROR fixture and two tests verifying API calls and partial-failure alert surfacing for retry and disconnect operations.
Internationalization translations
app/src/lib/i18n/chunks/{ar,bn,de,en-1,es,fr,hi,id,it,ko,pt,ru,zh-CN}-*.ts, app/src/lib/i18n/en.ts
mcp.health.* keys for 14 locales covering health title/aria, connection-state counts, bulk action labels/aria, disconnect confirmation dialog, and bulk operation error messages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • graycyrus
  • oxoxDev

🐰 A toolbar springs to health,
Counting servers, retrying all,
With dialogs so wise—
Async guards do their dance,
Translations bloom worldwide! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a connection health toolbar component with bulk Retry All and Disconnect All actions for MCP servers. It is specific, clear, and directly reflects the primary objective of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 25 '26 14:05 coderabbitai[bot]

I see @oxoxDev has requested changes — deferring to their feedback. Will review once those are addressed.

graycyrus avatar May 28 '26 19:05 graycyrus

Thanks @oxoxDev! Addressed in the latest push:

Nit — Esc on the Disconnect-all dialog: added an Escape handler that closes the confirmation without firing the bulk RPC, matching the modal-dismiss affordance of the other MCP dialogs. The listener attaches only while the dialog is open and is declared before the component's early return (rules of hooks). New test pins Esc → dialog closed + onDisconnect not called.

Major — i18n parity (pl): rebased onto current main. pl-1.ts uses a ...en1 spread so it inherits every key with English fallback automatically — i18n:check passes EXIT 0 with 0 missing (incl. pl), no per-key edits needed. (My #2655 inventory feature landed on main in the meantime, so the merge also reconciles the toolbar + inventory wiring/keys as a union.)

The Retry-All success/failure-count nit and the dialog-snapshot question are good follow-ups; happy to take them in a focused PR so this one stays scoped to the toolbar.

Validation: i18n:check EXIT 0, 18 toolbar tests pass, tsc clean, eslint clean, prettier clean.

aashir-athar avatar May 29 '26 02:05 aashir-athar

I see @oxoxDev has requested changes — deferring to their feedback. Will review once those are addressed.

graycyrus avatar May 29 '26 03:05 graycyrus