Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(mcp): restore server list after tab navigation

Steven Enamakel4002e971a8a3
diff --git a/app/src/components/channels/mcp/McpServersPage.tsx b/app/src/components/channels/mcp/McpServersPage.tsx
index 7bdce4eed2..98a30b7e92 100644
--- a/app/src/components/channels/mcp/McpServersPage.tsx
+++ b/app/src/components/channels/mcp/McpServersPage.tsx
@@ -12,7 +12,7 @@ import { useState } from 'react';
import { useT } from '../../../lib/i18n/I18nContext';
import SettingsTabbedPage from '../../settings/layout/SettingsTabbedPage';
-import { BetaIndicator } from '../../ui/BetaIndicator';
+import BetaIndicator from '../../ui/BetaIndicator';
import McpServersTab, { type McpPageTab } from './McpServersTab';
interface McpServersPageProps {
diff --git a/app/src/components/channels/mcp/McpServersTab.tsx b/app/src/components/channels/mcp/McpServersTab.tsx
index 3f5eee0aef..0baf18b45e 100644
--- a/app/src/components/channels/mcp/McpServersTab.tsx
+++ b/app/src/components/channels/mcp/McpServersTab.tsx
@@ -1,34 +1,26 @@
/**
- * Top-level MCP Servers tab: the user's tool servers, said three ways.
+ * The body of the MCP page: one of its three notations, as `McpServersPage`
+ * picked it in the header.
*
- * **Servers** is the list — a row per declared server with its status, and a
- * detail view with the credential form (sign-in or token) and the tool list.
- * **mcp.json** is the same configuration as one document, in the shape a user
- * already has in a desktop config: paste a block of servers, or read the whole
- * set at once instead of expanding rows. **Registry** is the upstream
- * directories, browse-only: a row opens the server's own page, where its
- * install instructions live, and the user declares it in mcp.json.
- *
- * The first two are tabs and not two pages because they are not two things.
- * Both go through the same core RPCs into the same store, so an edit made in
- * one is visible in the other on its next read, and neither is an import
- * format that can drift from "what is actually configured".
+ * **Servers** is the rows (`McpServerRows`) and, once a row is opened, that
+ * server's detail with the credential form and its tools. **mcp.json** is the
+ * same configuration as one document. **Registry** is the browse-only
+ * directories. The rows and their statuses are read here rather than in the
+ * rows component so a save in the document tab can re-read them, and so the
+ * directory can hide what is already declared.
*/
import debug from 'debug';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useT } from '../../../lib/i18n/I18nContext';
import { mcpClientsApi } from '../../../services/api/mcpClientsApi';
-import ChipTabs from '../../layout/ChipTabs';
import Button from '../../ui/Button';
-import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../../ui/Table';
-import TextField from '../../ui/TextField';
import InstalledServerDetail from './InstalledServerDetail';
import McpConnectionHealthToolbar from './McpConnectionHealthToolbar';
import McpJsonEditor from './McpJsonEditor';
import McpRegistryBrowser from './McpRegistryBrowser';
-import { deriveAuthor } from './McpServerCard';
-import type { ConnStatus, InstalledServer, ServerStatus } from './types';
+import McpServerRows from './McpServerRows';
+import type { ConnStatus, InstalledServer } from './types';
const log = debug('mcp-clients:tab');
const POLL_INTERVAL_MS = 5_000;
@@ -54,43 +46,19 @@ const dedupeInstalledByQualifiedName = (servers: InstalledServer[]): InstalledSe
return out;
};
-const STATUS_DOT: Record<ServerStatus, string> = {
- connected: 'bg-sage-500',
- connecting: 'bg-amber-400',
- disconnected: 'bg-surface-strong',
- unauthorized: 'bg-amber-500',
- error: 'bg-coral-500',
- disabled: 'bg-surface-strong',
-};
-
-/** The dial column: the hosted endpoint's host, or the local command. */
-const dialOf = (server: InstalledServer): string => {
- if (server.transport?.kind === 'http_remote') {
- try {
- return new URL(server.transport.url).host;
- } catch {
- return server.transport.url;
- }
- }
- return [server.command, ...server.args].filter(Boolean).join(' ');
-};
-
interface McpServersTabProps {
- /** The tab to open on. Defaults to the server rows. */
- initialTab?: McpPageTab;
+ tab: McpPageTab;
+ onTabChange: (tab: McpPageTab) => void;
}
-const McpServersTab = ({ initialTab = 'servers' }: McpServersTabProps) => {
+const McpServersTab = ({ tab, onTabChange }: McpServersTabProps) => {
const { t } = useT();
- const [tab, setTab] = useState<McpPageTab>(initialTab);
const [servers, setServers] = useState<InstalledServer[]>([]);
const [statuses, setStatuses] = useState<ConnStatus[]>([]);
const [loading, setLoading] = useState(true);
const [loadError, setLoadError] = useState<string | null>(null);
const [view, setView] = useState<View>({ mode: 'home' });
- const [searchQuery, setSearchQuery] = useState('');
const pollTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
-
const loadInstalled = useCallback(async () => {
log('loading installed servers');
try {
@@ -213,24 +181,24 @@ const McpServersTab = ({ initialTab = 'servers' }: McpServersTabProps) => {
const selectedConnStatus =
view.mode === 'detail' ? statuses.find(s => s.server_id === view.serverId) : undefined;
- // One installed row per service; raw `servers` is kept for server_id-keyed
- // detail/status lookups. Memoized so the 5s status poll doesn't rebuild +
- // refilter the list.
- const filteredInstalled = useMemo(() => {
- const rows = dedupeInstalledByQualifiedName(servers);
- const q = searchQuery.trim().toLowerCase();
- if (!q) return rows;
- return rows.filter(
- s =>
- s.display_name.toLowerCase().includes(q) ||
- s.qualified_name.toLowerCase().includes(q) ||
- (s.description ?? '').toLowerCase().includes(q)
- );
- }, [servers, searchQuery]);
-
+ // One row per service; raw `servers` is kept for server_id-keyed
+ // detail/status lookups.
+ const rows = useMemo(() => dedupeInstalledByQualifiedName(servers), [servers]);
const installedNames = useMemo(() => new Set(servers.map(s => s.qualified_name)), [servers]);
- const statusMap = new Map(statuses.map(s => [s.server_id, s]));
+ // Leaving the Servers tab closes any open detail, so coming back lands on the
+ // rows rather than on a server the user has stopped looking at.
+ useEffect(() => {
+ if (tab !== 'servers') setView({ mode: 'home' });
+ }, [tab]);
+
+ if (tab === 'json') {
+ return <McpJsonEditor onSaved={() => void handleDocumentSaved()} />;
+ }
+
+ if (tab === 'registry') {
+ return <McpRegistryBrowser installedNames={installedNames} />;
+ }
if (loading) {
return (
@@ -238,7 +206,7 @@ const McpServersTab = ({ initialTab = 'servers' }: McpServersTabProps) => {
);
}
- // Detail view — a server's own page, reached from the rows.
+ // Detail view — a server's own page, reached from a row's name.
if (view.mode === 'detail' && selectedServer) {
return (
<div className="space-y-3">
@@ -269,152 +237,32 @@ const McpServersTab = ({ initialTab = 'servers' }: McpServersTabProps) => {
}
return (
- <div className="space-y-3">
- <ChipTabs<McpPageTab>
- className="flex flex-wrap items-center gap-1.5"
- ariaLabel={t('mcp.tab.tablistAria')}
- testIdPrefix="mcp-page-tab"
- value={tab}
- onChange={setTab}
- items={[
- {
- id: 'servers',
- label: t('mcp.tab.section.servers').replace(
- '{count}',
- String(dedupeInstalledByQualifiedName(servers).length)
- ),
- },
- { id: 'json', label: t('mcp.tab.section.json') },
- { id: 'registry', label: t('mcp.tab.section.registry') },
- ]}
- />
-
- {tab === 'servers' && (
- <div className="space-y-3" data-testid="mcp-servers-section">
- <TextField
- type="search"
- value={searchQuery}
- onChange={e => setSearchQuery(e.target.value)}
- placeholder={t('mcp.installed.search.placeholder')}
- aria-label={t('mcp.installed.search.inputAria')}
- />
-
- {loadError && (
- <div className="rounded-lg border border-coral-200 dark:border-coral-500/30 bg-coral-50 dark:bg-coral-500/10 px-3 py-2 text-xs text-coral-700 dark:text-coral-300">
- {loadError}
- </div>
- )}
-
- {/* Connection health + bulk lifecycle actions. Only meaningful once
- servers are declared; reads the polled statuses — no extra
- fetches. */}
- {statuses.length > 0 && (
- <McpConnectionHealthToolbar
- statuses={statuses}
- onReconnect={handleReconnectAll}
- onDisconnect={handleDisconnectAll}
- />
- )}
-
- <Table className="min-w-[640px] rounded-lg border border-line">
- <TableHeader>
- <TableRow className="bg-surface-muted">
- <TableHead>{t('mcp.tab.column.name')}</TableHead>
- <TableHead className="hidden sm:table-cell">{t('mcp.tab.column.dial')}</TableHead>
- <TableHead className="hidden w-36 sm:table-cell">
- {t('mcp.tab.column.author')}
- </TableHead>
- <TableHead className="w-28 text-right">{t('mcp.tab.column.action')}</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {filteredInstalled.map(server => {
- const status: ServerStatus =
- statusMap.get(server.server_id)?.status ?? 'disconnected';
- return (
- <TableRow
- key={`installed-${server.server_id}`}
- className="cursor-pointer"
- tabIndex={0}
- role="button"
- data-testid="mcp-installed-row"
- aria-label={t('mcp.tab.aria.viewDetails').replace(
- '{name}',
- server.display_name
- )}
- onClick={() => handleSelectServer(server.server_id)}
- onKeyDown={e => {
- if (e.key === 'Enter' || e.key === ' ') {
- e.preventDefault();
- handleSelectServer(server.server_id);
- }
- }}>
- <TableCell>
- <div className="flex items-center gap-2.5">
- <span
- className={`w-2 h-2 rounded-full shrink-0 ${STATUS_DOT[status]}`}
- title={status}
- />
- <div className="min-w-0">
- <span className="font-medium text-content truncate block">
- {server.display_name}
- </span>
- {server.description && (
- <span className="text-xs text-content-faint line-clamp-4 block">
- {server.description}
- </span>
- )}
- </div>
- </div>
- </TableCell>
- <TableCell className="hidden sm:table-cell">
- <span className="text-[11px] font-mono text-content-muted truncate block max-w-64">
- {dialOf(server)}
- </span>
- </TableCell>
- <TableCell className="hidden sm:table-cell">
- <span className="text-xs text-content-muted truncate block">
- {deriveAuthor(server.qualified_name) ?? '—'}
- </span>
- </TableCell>
- <TableCell className="text-right">
- <span className="text-xs text-primary-600 dark:text-primary-400 font-medium">
- {t('mcp.tab.action.manage')}
- </span>
- </TableCell>
- </TableRow>
- );
- })}
- </TableBody>
- </Table>
-
- {filteredInstalled.length === 0 && (
- <div
- data-testid="mcp-installed-empty"
- className="rounded-b-lg border border-t-0 border-line py-8 text-center text-sm text-content-faint space-y-2">
- <p>
- {searchQuery
- ? t('mcp.installed.search.noMatches').replace('{query}', searchQuery)
- : t('mcp.installed.empty')}
- </p>
- {!searchQuery && (
- <p className="flex items-center justify-center gap-3">
- <Button variant="tertiary" size="xs" onClick={() => setTab('json')}>
- {t('mcp.installed.emptyAddInJson')}
- </Button>
- <Button variant="tertiary" size="xs" onClick={() => setTab('registry')}>
- {t('mcp.installed.emptyBrowseRegistry')}
- </Button>
- </p>
- )}
- </div>
- )}
- </div>
+ <div className="space-y-6">
+ {loadError && (
+ <p
+ role="alert"
+ className="rounded-md border border-coral-500/30 bg-coral-500/10 px-3 py-2 text-xs text-coral-700 dark:text-coral-300">
+ {loadError}
+ </p>
)}
- {tab === 'json' && <McpJsonEditor onSaved={() => void handleDocumentSaved()} />}
+ {/* Connection health + bulk lifecycle actions. Reads the polled statuses
+ — no extra fetches. */}
+ {statuses.length > 0 && (
+ <McpConnectionHealthToolbar
+ statuses={statuses}
+ onReconnect={handleReconnectAll}
+ onDisconnect={handleDisconnectAll}
+ />
+ )}
- {tab === 'registry' && <McpRegistryBrowser installedNames={installedNames} />}
+ <McpServerRows
+ servers={rows}
+ statuses={statuses}
+ onOpen={handleSelectServer}
+ onChanged={handleDocumentSaved}
+ onAddInJson={() => onTabChange('json')}
+ />
</div>
);
};