diff --git a/ui/src/components/mcp/MCPPreview.tsx b/ui/src/components/mcp/MCPPreview.tsx index aa340ef71..9a462a710 100644 --- a/ui/src/components/mcp/MCPPreview.tsx +++ b/ui/src/components/mcp/MCPPreview.tsx @@ -6,7 +6,7 @@ import Badge from '../Badge'; import Button from '../Button'; import { Checkbox } from '../Checkbox'; import { useT } from '../../i18n'; -import { countActions, describeMessage, groupByFile, isResolvable, statusVariant } from './mcpView'; +import { canImportConflict, countActions, describeMessage, groupByFile, isResolvable, statusVariant } from './mcpView'; export type MCPResolve = (target: string, name: string, action: 'import' | 'replace') => void; @@ -49,9 +49,9 @@ export default function MCPPreview({ plan, onResolve, busy = false }: Props) { {change.message ? {describeMessage(t, change.message)} : null} {onResolve && isResolvable(change) ?
- + {canImportConflict(change) ? : null} - {t('mcp.resolveHint', { target: change.target })} + {canImportConflict(change) ? {t('mcp.resolveHint', { target: change.target })} : null}
: null} )} diff --git a/ui/src/components/mcp/mcpView.test.ts b/ui/src/components/mcp/mcpView.test.ts index 26e7d1ff6..fa0b15efd 100644 --- a/ui/src/components/mcp/mcpView.test.ts +++ b/ui/src/components/mcp/mcpView.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import type { MCPPlan } from '../../api/mcp'; -import { buildMatrix, describeError, describeMessage, groupByFile, isResolvable, joinCommand, splitCommand, switchTargets, targetLabel } from './mcpView'; +import { buildMatrix, describeError, describeMessage, canImportConflict, groupByFile, isResolvable, joinCommand, splitCommand, switchTargets, targetLabel } from './mcpView'; import { mcpTargets } from '../../api/mcp'; const change = (name: string, target: string, action: string, message?: string) => ({ name, target, action, message, path: `/${target}.json` }); @@ -81,3 +81,11 @@ describe('groupByFile', () => { expect(groups.map((g) => g.offListFor)).toEqual([undefined, '/work/app', undefined]); }); }); + +describe('canImportConflict', () => { + // Import reads the Agent's global file, which holds the server and never the project's switch. + it('offers no import for a changed switch, which only a replace can settle', () => { + const changed = { target: 'opencode', path: '/work/app/opencode.json', name: 'docs', action: 'conflict', message: 'Agent configuration changed; import it or explicitly replace this entry' }; + expect([canImportConflict(changed), canImportConflict({ ...changed, root: '/work/app', switch: true })]).toEqual([true, false]); + }); +}); diff --git a/ui/src/components/mcp/mcpView.ts b/ui/src/components/mcp/mcpView.ts index 4c8c7a94b..eff07b28f 100644 --- a/ui/src/components/mcp/mcpView.ts +++ b/ui/src/components/mcp/mcpView.ts @@ -111,6 +111,9 @@ export const isResolvable = (change: MCPChange) => change.action === 'conflict' && ['mcp.conflictChanged', 'mcp.conflictUnmanaged', 'mcp.conflictOrphaned'].includes(conflictKeys[conflictPrefix(change.message ?? '')]); +/** Whether importing can settle a conflict. It reads the Agent's global file, which never holds a project's switch. */ +export const canImportConflict = (change: MCPChange) => isResolvable(change) && !change.switch; + /** Agents a project can turn a global server off for: those it uses, that the server reaches and that have a switch. */ export const switchTargets = (server: MCPServer, defaults: string[], projectTargets: readonly string[]) => (server.targets ?? defaults).filter((x) => mcpOffTargets.includes(x) && projectTargets.includes(x) && (x !== 'pi' || server.piExtension === 'pi-mcp-adapter')); diff --git a/ui/src/pages/MCPPage.tsx b/ui/src/pages/MCPPage.tsx index c821e59af..fe9a8c340 100644 --- a/ui/src/pages/MCPPage.tsx +++ b/ui/src/pages/MCPPage.tsx @@ -22,7 +22,7 @@ import { MCPConfigDialog } from '../components/mcp/MCPConfigView'; import MCPRemoveDialog from '../components/mcp/MCPRemoveDialog'; import MCPRestoreDialog from '../components/mcp/MCPRestoreDialog'; import MCPServerDialog from '../components/mcp/MCPServerDialog'; -import { buildMatrix, describeError, describeMessage, isShadowed, isResolvable, targetLabel, type MCPChange } from '../components/mcp/mcpView'; +import { buildMatrix, canImportConflict, describeError, describeMessage, isShadowed, isResolvable, projectOf, targetLabel, type MCPChange } from '../components/mcp/mcpView'; import { useT } from '../i18n'; import { shortenHome } from '../lib/paths'; import { queryKeys } from '../lib/queryKeys'; @@ -214,13 +214,15 @@ export default function MCPPage() {
{conflicts.map((c, i) => ( -
+
{i === 0 && {t(conflicts.length === 1 ? 'mcp.conflictLead.one' : 'mcp.conflictLead.other', { count: conflicts.length })} } {conflictText(c)} + {/* One server can conflict in several folders, so a project's row says which. */} + {projectOf(roots, c) && ยท {shortenHome(projectOf(roots, c)!)}} {isResolvable(c) && <> - + {canImportConflict(c) && } }