From bd3a9cf228acf9b5b55832d8603192249b4b41ce Mon Sep 17 00:00:00 2001 From: Willie Date: Mon, 21 Sep 2026 23:21:24 +0800 Subject: [PATCH] feat(ui): let an MCP server have no Agent selected The dialog refused to save without an Agent, and both the global list and a project's list refused to untick the last one. With servers now allowed to stay in Skillshare only, those blocks are gone: the dialog explains what saving with no Agent means, unticking the last Agent says that the next sync removes the server everywhere, and such a server is tagged in the list. With empty defaults an empty selection looked inherited and left targets out, which the server refuses; the empty list is now always sent. A project's list of global servers leaves out one no Agent receives, as there is nothing there to turn off. A switch-only entry still needs an Agent. Refs #289 --- ui/src/components/mcp/MCPProjectView.tsx | 15 ++++++++---- .../components/mcp/MCPServerDialog.test.tsx | 24 +++++++++++++++++++ ui/src/components/mcp/MCPServerDialog.tsx | 6 ++--- ui/src/components/mcp/MCPServerList.tsx | 1 + ui/src/i18n/locales/de.json | 2 ++ ui/src/i18n/locales/en.json | 2 ++ ui/src/i18n/locales/es.json | 2 ++ ui/src/i18n/locales/fa.json | 2 ++ ui/src/i18n/locales/fr.json | 2 ++ ui/src/i18n/locales/id.json | 2 ++ ui/src/i18n/locales/ja.json | 2 ++ ui/src/i18n/locales/ko.json | 2 ++ ui/src/i18n/locales/pt-BR.json | 2 ++ ui/src/i18n/locales/zh-CN.json | 2 ++ ui/src/i18n/locales/zh-TW.json | 2 ++ ui/src/pages/MCPPage.tsx | 6 ++--- 16 files changed, 62 insertions(+), 12 deletions(-) diff --git a/ui/src/components/mcp/MCPProjectView.tsx b/ui/src/components/mcp/MCPProjectView.tsx index eb4595403..4291ad925 100644 --- a/ui/src/components/mcp/MCPProjectView.tsx +++ b/ui/src/components/mcp/MCPProjectView.tsx @@ -50,6 +50,8 @@ export default function MCPProjectView({ data, root, offered, onChanged, onRemov const defaults = data.source.targets ?? []; const targets = project.targets ?? defaults; const servers = project.servers ?? {}; + // A global server no Agent receives is active nowhere, so a project has nothing to turn off. + const shownGlobals = Object.keys(globals).filter((n) => servers[n] || globals[n].targets?.length !== 0).sort(); const roots = Object.keys(data.source.projects ?? {}); const changes = (data.plan?.changes ?? []).filter((c) => projectOf(roots, c) === root); const name = shortenHome(root); @@ -63,8 +65,10 @@ export default function MCPProjectView({ data, root, offered, onChanged, onRemov try { await mcpApi.save({ ...mutation, project: root }); onChanged(); + return true; } catch (e) { toast(describeError(t, (e as Error).message), 'error'); + return false; } finally { setBusy(false); } @@ -81,9 +85,10 @@ export default function MCPProjectView({ data, root, offered, onChanged, onRemov const toggleOwn = (n: string, target: string, on: boolean) => { const next = mcpTargets.filter((x) => (x === target ? on : targetsOf(n).includes(x))); - if (next.length === 0) return toast(t('mcp.needTarget'), 'warning'); + // A switch-only entry needs an Agent to turn the server off for; a server may have none. + if (next.length === 0 && own[n].disabled) return toast(t('mcp.needTarget'), 'warning'); if (target === 'pi' && on && !own[n].piExtension && !own[n].disabled) return setEditing(n); - void save({ name: n, replace: true, server: { ...own[n], targets: next } }); + void save({ name: n, replace: true, server: { ...own[n], targets: next } }).then((saved) => { if (saved && next.length === 0) toast(t('mcp.noTargetsToast', { name: n }), 'info'); }); }; const openMenu = (e: React.MouseEvent, n: string) => { @@ -128,10 +133,10 @@ export default function MCPProjectView({ data, root, offered, onChanged, onRemov
-

{t('mcp.projects.globalServers')}

{Object.keys(globals).length}{t('mcp.projects.globalHint')}
- {Object.keys(globals).length > 0 ? ( +

{t('mcp.projects.globalServers')}

{shownGlobals.length}{t('mcp.projects.globalHint')}
+ {shownGlobals.length > 0 ? (
- {Object.keys(globals).sort().map((n) => { + {shownGlobals.map((n) => { const server = globals[n]; const entry = servers[n]; const off = Boolean(entry?.disabled); diff --git a/ui/src/components/mcp/MCPServerDialog.test.tsx b/ui/src/components/mcp/MCPServerDialog.test.tsx index b3372c386..c2604ac6f 100644 --- a/ui/src/components/mcp/MCPServerDialog.test.tsx +++ b/ui/src/components/mcp/MCPServerDialog.test.tsx @@ -65,6 +65,30 @@ describe('MCP server dialog', () => { await waitFor(() => expect(mcpApi.save).toHaveBeenCalledWith(expect.objectContaining({ server: { url: 'https://docs.example/mcp', targets: ['claude', 'codex'] } }))); }); + // Refs: #289. With no Agent the server is kept in Skillshare and written nowhere. + it('saves a server with no Agent selected as an explicit empty list', async () => { + const user = userEvent.setup(); + renderDialog(); + await user.type(screen.getByLabelText('Name'), 'docs'); + await user.click(screen.getByRole('button', { name: 'streamable-http' })); + await user.type(screen.getByLabelText('URL'), 'https://docs.example/mcp'); + await user.click(screen.getByRole('checkbox', { name: 'Claude' })); + expect(screen.getByText('With no Agent selected, it is only kept in Skillshare, not written to any config file')).toBeInTheDocument(); + await user.click(screen.getByRole('button', { name: 'Save' })); + await waitFor(() => expect(mcpApi.save).toHaveBeenCalledWith(expect.objectContaining({ server: { url: 'https://docs.example/mcp', targets: [] } }))); + }); + + // An empty selection equals empty defaults, but leaving targets out would inherit them and be refused. + it('sends the empty list even when the defaults are empty too', async () => { + const user = userEvent.setup(); + renderDialog({ defaultTargets: [] }); + await user.type(screen.getByLabelText('Name'), 'docs'); + await user.click(screen.getByRole('button', { name: 'streamable-http' })); + await user.type(screen.getByLabelText('URL'), 'https://docs.example/mcp'); + await user.click(screen.getByRole('button', { name: 'Save' })); + await waitFor(() => expect(mcpApi.save).toHaveBeenCalledWith(expect.objectContaining({ server: { url: 'https://docs.example/mcp', targets: [] } }))); + }); + it('keeps explicit targets and existing headers when editing', async () => { const user = userEvent.setup(); const server = { url: 'https://docs.example/mcp', headers: { 'X-Team': 'core' }, targets: ['claude'] }; diff --git a/ui/src/components/mcp/MCPServerDialog.tsx b/ui/src/components/mcp/MCPServerDialog.tsx index 6b1dc6717..81361b478 100644 --- a/ui/src/components/mcp/MCPServerDialog.tsx +++ b/ui/src/components/mcp/MCPServerDialog.tsx @@ -104,7 +104,7 @@ export default function MCPServerDialog({ initial, defaultTargets, defaultPiExte const taken = !initial && existingNames.includes(trimmed); const nameError = trimmed && !NAME.test(trimmed) ? t('mcp.nameHint') : taken ? t('mcp.nameTaken') : ''; const words = splitCommand(command); - const canSave = Boolean(trimmed) && !nameError && targets.length > 0 && (off || (http ? url.trim() !== '' : words.length > 0)) && (!targets.includes('pi') || off || Boolean(piExtension)) && (piExtension !== 'pi-mcp-adapter' || directToolsComplete(directTools)) && !saving; + const canSave = Boolean(trimmed) && !nameError && (targets.length > 0 || !off) && (off || (http ? url.trim() !== '' : words.length > 0)) && (!targets.includes('pi') || off || Boolean(piExtension)) && (piExtension !== 'pi-mcp-adapter' || directToolsComplete(directTools)) && !saving; const title = t(off ? (initial ? 'mcp.editOff' : 'mcp.addOff') : (initial ? 'mcp.editServer' : 'mcp.addServer')); const visibleTargets = new Set([...availableTargets, ...targets].filter((x) => !off || offTargets.includes(x))); @@ -138,7 +138,7 @@ export default function MCPServerDialog({ initial, defaultTargets, defaultPiExte if (!canSave) return; const next = build(); // A server without its own targets keeps inheriting while the selection matches - const inherited = !server?.targets && targets.length === defaultTargets.length && targets.every((x) => defaultTargets.includes(x)); + const inherited = !server?.targets && targets.length > 0 && targets.length === defaultTargets.length && targets.every((x) => defaultTargets.includes(x)); if (!inherited || off) next.targets = ordered; setSaving(true); setError(''); @@ -252,7 +252,7 @@ export default function MCPServerDialog({ initial, defaultTargets, defaultPiExte {viewing ?
:
{targets.length === 0 - ? {t('mcp.pickTarget')} + ? (off ? {t('mcp.pickTarget')} : {t('mcp.noTargetsNote')}) : {t(targets.length === 1 ? 'mcp.writes.one' : 'mcp.writes.other', { count: targets.length })}{/* ponytail: the preview renders global paths only; give /api/mcp/render a project to show it here too. */}{complete && !project && }} diff --git a/ui/src/components/mcp/MCPServerList.tsx b/ui/src/components/mcp/MCPServerList.tsx index bf34995e9..6cde03bb9 100644 --- a/ui/src/components/mcp/MCPServerList.tsx +++ b/ui/src/components/mcp/MCPServerList.tsx @@ -39,6 +39,7 @@ export default function MCPServerList({ rows, targets, targetsOf, onToggle, onMe {row.name} {row.server && Object.values(row.cells).some((c) => c.action === 'add' || c.action === 'update' || c.action === 'remove') && {t('plugins.pending')}} + {row.server && !row.server.disabled && row.server.targets?.length === 0 && {t('plugins.noAgentsYet')}} {!row.server && {t('mcp.removedFromSource')}} {/* Transport and endpoint on one quiet line, the same shape as a plugin row. */} diff --git a/ui/src/i18n/locales/de.json b/ui/src/i18n/locales/de.json index ddd93cc0c..7ae1eb6b0 100644 --- a/ui/src/i18n/locales/de.json +++ b/ui/src/i18n/locales/de.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "Vorschau", "mcp.moreActions": "Weitere Aktionen für {name}", "mcp.needTarget": "Ein Server braucht mindestens ein Target.", + "mcp.noTargetsNote": "Ohne ausgewählten Agent bleibt er nur in Skillshare und wird in keine Konfigurationsdatei geschrieben", + "mcp.noTargetsToast": "{name} bleibt in Skillshare. Beim nächsten Sync wird er aus allen Agents entfernt.", "mcp.conflictLead.one": "Zuerst 1 Konflikt lösen.", "mcp.conflictLead.other": "Zuerst {count} Konflikte lösen.", "mcp.conflict.unmanaged": "{target} hat bereits einen eigenen Eintrag {name}, den skillshare noch nicht verwaltet.", diff --git a/ui/src/i18n/locales/en.json b/ui/src/i18n/locales/en.json index 13722cd59..83aafc5a3 100644 --- a/ui/src/i18n/locales/en.json +++ b/ui/src/i18n/locales/en.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "Preview", "mcp.moreActions": "More actions for {name}", "mcp.needTarget": "A server needs at least one target.", + "mcp.noTargetsNote": "With no Agent selected, it is only kept in Skillshare, not written to any config file", + "mcp.noTargetsToast": "{name} stays in Skillshare. The next sync removes it from every Agent.", "mcp.conflictLead.one": "1 conflict to resolve first.", "mcp.conflictLead.other": "{count} conflicts to resolve first.", "mcp.conflict.unmanaged": "{target} already has its own {name} entry that skillshare does not manage yet.", diff --git a/ui/src/i18n/locales/es.json b/ui/src/i18n/locales/es.json index 0226fbd58..bb3fef4ab 100644 --- a/ui/src/i18n/locales/es.json +++ b/ui/src/i18n/locales/es.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "Vista previa", "mcp.moreActions": "Más acciones para {name}", "mcp.needTarget": "Un servidor necesita al menos un target.", + "mcp.noTargetsNote": "Sin ningún Agent seleccionado, solo se guarda en Skillshare y no se escribe en ningún archivo de configuración", + "mcp.noTargetsToast": "{name} se queda en Skillshare. La próxima sincronización lo quita de todos los Agents.", "mcp.conflictLead.one": "Primero resuelve 1 conflicto.", "mcp.conflictLead.other": "Primero resuelve {count} conflictos.", "mcp.conflict.unmanaged": "{target} ya tiene su propia entrada {name} que skillshare aún no gestiona.", diff --git a/ui/src/i18n/locales/fa.json b/ui/src/i18n/locales/fa.json index 8dc786b61..5dbed7a4d 100644 --- a/ui/src/i18n/locales/fa.json +++ b/ui/src/i18n/locales/fa.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "پیش‌نمایش", "mcp.moreActions": "کارهای بیشتر برای {name}", "mcp.needTarget": "هر سرور دست‌کم یک target لازم دارد.", + "mcp.noTargetsNote": "اگر Agentی انتخاب نشود، فقط در Skillshare نگه داشته می‌شود و در هیچ فایل پیکربندی نوشته نمی‌شود", + "mcp.noTargetsToast": "{name} در Skillshare می‌ماند. همگام‌سازی بعدی آن را از همهٔ Agentها حذف می‌کند.", "mcp.conflictLead.one": "ابتدا ۱ تعارض را حل کنید.", "mcp.conflictLead.other": "ابتدا {count} تعارض را حل کنید.", "mcp.conflict.unmanaged": "{target} از قبل ورودی {name} خودش را دارد که skillshare هنوز مدیریتش نمی‌کند.", diff --git a/ui/src/i18n/locales/fr.json b/ui/src/i18n/locales/fr.json index e4fd8f9a3..264cd91b7 100644 --- a/ui/src/i18n/locales/fr.json +++ b/ui/src/i18n/locales/fr.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "Aperçu", "mcp.moreActions": "Plus d’actions pour {name}", "mcp.needTarget": "Un serveur a besoin d’au moins un target.", + "mcp.noTargetsNote": "Sans Agent sélectionné, il est seulement conservé dans Skillshare, sans être écrit dans aucun fichier de configuration", + "mcp.noTargetsToast": "{name} reste dans Skillshare. La prochaine synchronisation le retire de tous les Agents.", "mcp.conflictLead.one": "1 conflit à résoudre d’abord.", "mcp.conflictLead.other": "{count} conflits à résoudre d’abord.", "mcp.conflict.unmanaged": "{target} a déjà sa propre entrée {name}, que skillshare ne gère pas encore.", diff --git a/ui/src/i18n/locales/id.json b/ui/src/i18n/locales/id.json index 60f9509de..0c302a61b 100644 --- a/ui/src/i18n/locales/id.json +++ b/ui/src/i18n/locales/id.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "Pratinjau", "mcp.moreActions": "Tindakan lain untuk {name}", "mcp.needTarget": "Server butuh setidaknya satu target.", + "mcp.noTargetsNote": "Tanpa Agent yang dipilih, server hanya disimpan di Skillshare, tidak ditulis ke file konfigurasi mana pun", + "mcp.noTargetsToast": "{name} tetap di Skillshare. Sinkronisasi berikutnya menghapusnya dari semua Agent.", "mcp.conflictLead.one": "Selesaikan 1 konflik dulu.", "mcp.conflictLead.other": "Selesaikan {count} konflik dulu.", "mcp.conflict.unmanaged": "{target} sudah punya entri {name} sendiri yang belum dikelola skillshare.", diff --git a/ui/src/i18n/locales/ja.json b/ui/src/i18n/locales/ja.json index 56018732b..29d6c7b0b 100644 --- a/ui/src/i18n/locales/ja.json +++ b/ui/src/i18n/locales/ja.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "プレビュー", "mcp.moreActions": "{name} のその他の操作", "mcp.needTarget": "サーバーには target が 1 つ以上必要です。", + "mcp.noTargetsNote": "Agent を選ばない場合は Skillshare に保存するだけで、どの設定ファイルにも書き込みません", + "mcp.noTargetsToast": "{name} は Skillshare に残ります。次の同期ですべての Agent から削除されます。", "mcp.conflictLead.one": "先に解決する競合が 1 件あります。", "mcp.conflictLead.other": "先に解決する競合が {count} 件あります。", "mcp.conflict.unmanaged": "{target} には skillshare がまだ管理していない {name} の項目がすでにあります。", diff --git a/ui/src/i18n/locales/ko.json b/ui/src/i18n/locales/ko.json index ffd8c3ccc..392c2882f 100644 --- a/ui/src/i18n/locales/ko.json +++ b/ui/src/i18n/locales/ko.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "미리보기", "mcp.moreActions": "{name} 추가 작업", "mcp.needTarget": "서버에는 target이 하나 이상 필요합니다.", + "mcp.noTargetsNote": "Agent를 선택하지 않으면 Skillshare에만 보관되고 어떤 설정 파일에도 기록되지 않습니다", + "mcp.noTargetsToast": "{name}은(는) Skillshare에 남습니다. 다음 동기화 때 모든 Agent에서 제거됩니다.", "mcp.conflictLead.one": "먼저 해결할 충돌이 1개 있습니다.", "mcp.conflictLead.other": "먼저 해결할 충돌이 {count}개 있습니다.", "mcp.conflict.unmanaged": "{target}에 skillshare가 아직 관리하지 않는 {name} 항목이 이미 있습니다.", diff --git a/ui/src/i18n/locales/pt-BR.json b/ui/src/i18n/locales/pt-BR.json index 3731dff0b..4eb544b03 100644 --- a/ui/src/i18n/locales/pt-BR.json +++ b/ui/src/i18n/locales/pt-BR.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "Prévia", "mcp.moreActions": "Mais ações para {name}", "mcp.needTarget": "Um servidor precisa de pelo menos um target.", + "mcp.noTargetsNote": "Sem nenhum Agent selecionado, ele só fica no Skillshare, sem ser escrito em nenhum arquivo de configuração", + "mcp.noTargetsToast": "{name} continua no Skillshare. A próxima sincronização o remove de todos os Agents.", "mcp.conflictLead.one": "Resolva 1 conflito primeiro.", "mcp.conflictLead.other": "Resolva {count} conflitos primeiro.", "mcp.conflict.unmanaged": "{target} já tem sua própria entrada {name}, que o skillshare ainda não gerencia.", diff --git a/ui/src/i18n/locales/zh-CN.json b/ui/src/i18n/locales/zh-CN.json index 2af495b60..9dea330d2 100644 --- a/ui/src/i18n/locales/zh-CN.json +++ b/ui/src/i18n/locales/zh-CN.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "预览", "mcp.moreActions": "{name} 的更多操作", "mcp.needTarget": "服务器至少需要一个 target。", + "mcp.noTargetsNote": "未选 Agent 时,只会保留在 Skillshare,不会写入任何配置文件", + "mcp.noTargetsToast": "{name} 会保留在 Skillshare。下次同步时会从所有 Agent 移除。", "mcp.conflictLead.one": "需要先解决 1 个冲突。", "mcp.conflictLead.other": "需要先解决 {count} 个冲突。", "mcp.conflict.unmanaged": "{target} 已有自己的 {name} 条目,尚未由 skillshare 管理。", diff --git a/ui/src/i18n/locales/zh-TW.json b/ui/src/i18n/locales/zh-TW.json index 45890e355..0a3973e13 100644 --- a/ui/src/i18n/locales/zh-TW.json +++ b/ui/src/i18n/locales/zh-TW.json @@ -1050,6 +1050,8 @@ "mcp.restorePreview": "預覽", "mcp.moreActions": "{name} 的更多操作", "mcp.needTarget": "伺服器至少要有一個 target。", + "mcp.noTargetsNote": "未選 Agent 時,只會保留在 Skillshare,不會寫入任何設定檔", + "mcp.noTargetsToast": "{name} 會保留在 Skillshare。下次同步時會從所有 Agent 移除。", "mcp.conflictLead.one": "需要先解決 1 個衝突。", "mcp.conflictLead.other": "需要先解決 {count} 個衝突。", "mcp.conflict.unmanaged": "{target} 已經有自己的 {name} 項目,還沒交給 skillshare 管理。", diff --git a/ui/src/pages/MCPPage.tsx b/ui/src/pages/MCPPage.tsx index d2ebeefee..c821e59af 100644 --- a/ui/src/pages/MCPPage.tsx +++ b/ui/src/pages/MCPPage.tsx @@ -85,16 +85,14 @@ export default function MCPPage() { if (target === 'pi' && on && !servers[name].piExtension) { setPiSetupName(name); setEditing(name); return; } const current = targetsOf(name); const next = mcpTargets.filter((x) => (x === target ? on : current.includes(x))); - if (next.length === 0) { - toast(t('mcp.needTarget'), 'warning'); - return; - } const server = { ...servers[name], targets: next }; // Tick right away; saving only touches the source, Sync writes the files const prev = cache.getQueryData(queryKeys.mcp); cache.setQueryData(queryKeys.mcp, (old) => old && { ...old, source: { ...old.source, servers: { ...old.source.servers, [name]: server } } }); try { await mcpApi.save({ name, server, replace: true }); + // Not blocked, but said out loud: the next sync takes the server out of every Agent. + if (next.length === 0) toast(t('mcp.noTargetsToast', { name }), 'info'); } catch (e) { if (prev) cache.setQueryData(queryKeys.mcp, prev); toast(describeError(t, (e as Error).message), 'error');