mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
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
This commit is contained in:
@@ -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<HTMLButtonElement>, n: string) => {
|
||||
@@ -128,10 +133,10 @@ export default function MCPProjectView({ data, root, offered, onChanged, onRemov
|
||||
</div>
|
||||
|
||||
<section className="mt-3 flex flex-col">
|
||||
<div className="ss-sec"><h2>{t('mcp.projects.globalServers')}</h2><span className="ss-cnt">{Object.keys(globals).length}</span><span className="text-[13px] text-ink-2">{t('mcp.projects.globalHint')}</span></div>
|
||||
{Object.keys(globals).length > 0 ? (
|
||||
<div className="ss-sec"><h2>{t('mcp.projects.globalServers')}</h2><span className="ss-cnt">{shownGlobals.length}</span><span className="text-[13px] text-ink-2">{t('mcp.projects.globalHint')}</span></div>
|
||||
{shownGlobals.length > 0 ? (
|
||||
<div className="ss-list">
|
||||
{Object.keys(globals).sort().map((n) => {
|
||||
{shownGlobals.map((n) => {
|
||||
const server = globals[n];
|
||||
const entry = servers[n];
|
||||
const off = Boolean(entry?.disabled);
|
||||
|
||||
@@ -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'] };
|
||||
|
||||
@@ -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 ? <div className="df"><Button variant="secondary" onClick={() => setViewing(false)}>{t('common.back')}</Button></div> : <div className="df">
|
||||
<span className="flex-1 text-[13px]">
|
||||
{targets.length === 0
|
||||
? <span className="ss-st warn">{t('mcp.pickTarget')}</span>
|
||||
? (off ? <span className="ss-st warn">{t('mcp.pickTarget')}</span> : <span className="text-ink-2">{t('mcp.noTargetsNote')}</span>)
|
||||
: <span className="text-ink-2">{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 && <button type="button" className="ss-more ml-1.5" onClick={() => setViewing(true)}>{t('mcp.viewConfigShort')}</button>}</span>}
|
||||
</span>
|
||||
<Button variant="ghost" onClick={onClose} disabled={saving}>{t('common.cancel')}</Button>
|
||||
|
||||
@@ -39,6 +39,7 @@ export default function MCPServerList({ rows, targets, targetsOf, onToggle, onMe
|
||||
<span className="flex items-center gap-2">
|
||||
<span title={row.name} className={`truncate font-mono font-semibold ${row.server ? '' : 'text-ink-3 line-through'}`}>{row.name}</span>
|
||||
{row.server && Object.values(row.cells).some((c) => c.action === 'add' || c.action === 'update' || c.action === 'remove') && <span className="ss-tag warn">{t('plugins.pending')}</span>}
|
||||
{row.server && !row.server.disabled && row.server.targets?.length === 0 && <span className="ss-tag">{t('plugins.noAgentsYet')}</span>}
|
||||
{!row.server && <span className="ss-st bad">{t('mcp.removedFromSource')}</span>}
|
||||
</span>
|
||||
{/* Transport and endpoint on one quiet line, the same shape as a plugin row. */}
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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 هنوز مدیریتش نمیکند.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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} の項目がすでにあります。",
|
||||
|
||||
@@ -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} 항목이 이미 있습니다.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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 管理。",
|
||||
|
||||
@@ -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 管理。",
|
||||
|
||||
@@ -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<MCPList>(queryKeys.mcp);
|
||||
cache.setQueryData<MCPList>(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');
|
||||
|
||||
Reference in New Issue
Block a user