Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
MCP UI: servers on for every kwant by default, per-kwant opt-out
Lin (kwant bot)5fda613930cd
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex a6d60b7c..4379cc96 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -668,10 +668,9 @@ export const App: React.FC = () => {if (res.ok) {const created: Kwant = await res.json();setKwants((prev) => [...prev, created]);- if (agentData.mcp_server_ids?.length) {- const mcpError = await saveKwantMcpServers(created.id, agentData.mcp_server_ids);- if (mcpError) console.error(mcpError);- }+ // Saved even when empty: switching every server off means none.+ const mcpError = await saveKwantMcpServers(created.id, agentData.mcp_server_ids);+ if (mcpError) console.error(mcpError);setIsNewAgentOpen(false);playSfx('fanfare');const team = newAgentTeam && (teams.find((t) => t.id === newAgentTeam.id) ?? newAgentTeam);@@ -1178,7 +1177,7 @@ export const App: React.FC = () => {{/* MCP tool servers (opened last so it sits above the agent modal) */}<Suspense fallback={null}>- <McpServersModal isOpen={isMcpOpen} onClose={() => setIsMcpOpen(false)} />+ <McpServersModal isOpen={isMcpOpen} onClose={() => setIsMcpOpen(false)} kwants={kwants} /></Suspense></div>);diff --git a/frontend/src/components/KwantToolsPicker.tsx b/frontend/src/components/KwantToolsPicker.tsxindex 6e406c93..d59e329f 100644--- a/frontend/src/components/KwantToolsPicker.tsx+++ b/frontend/src/components/KwantToolsPicker.tsx@@ -10,7 +10,11 @@ interface KwantToolsPickerProps {onManageServers?: () => void;}-/** "Tools this kwant can use": one switch per registered MCP server. */+/**+ * "Tools this kwant can use": one switch per registered MCP server. Every server is on for every+ * kwant unless switched off here. A server paused in Tools shows greyed and keeps this kwant's+ * choice, so turning it back on there restores it.+ */export const KwantToolsPicker: React.FC<KwantToolsPickerProps> = ({ model, selected, onChange, onManageServers }) => {const [servers, setServers] = useState<McpServer[] | null>(null);const [keys, setKeys] = useState<EngineKeys>({ anthropic: false, openai: false, xai: false });@@ -37,6 +41,7 @@ export const KwantToolsPicker: React.FC<KwantToolsPickerProps> = ({ model, selecconst support = mcpSupportFor(model, keys);const toggle = (id: string) =>onChange(selected.includes(id) ? selected.filter((s) => s !== id) : [...selected, id]);+ const offCount = servers ? servers.filter((s) => s.enabled && !selected.includes(s.id)).length : 0;return (<div>@@ -51,6 +56,13 @@ export const KwantToolsPicker: React.FC<KwantToolsPickerProps> = ({ model, selec)}</div>+ {servers && servers.length > 0 && (+ <p className="mb-1.5 text-[11px] text-zinc-500 leading-snug">+ Every tool server is on by default, including ones you add later. Switch off any this kwant shouldn’t have+ {offCount > 0 && <span className="text-zinc-400"> · {offCount} off</span>}.+ </p>+ )}+{support.note && (<pclassName={`mb-1.5 flex items-start gap-1.5 px-2.5 py-2 rounded-lg border text-[11px] leading-snug ${@@ -83,20 +95,30 @@ export const KwantToolsPicker: React.FC<KwantToolsPickerProps> = ({ model, selec) : (<ul className={`rounded-lg border border-zinc-800 divide-y divide-zinc-800/80 bg-zinc-950/60 ${support.supported ? '' : 'opacity-60'}`}>{servers.map((s) => {- const on = selected.includes(s.id);+ const paused = !s.enabled;+ const on = !paused && selected.includes(s.id);return (<li key={s.id}><buttontype="button"role="switch"aria-checked={on}+ aria-disabled={paused || undefined}+ disabled={paused}+ aria-label={paused ? `${s.name}, paused in Tools` : undefined}onClick={() => toggle(s.id)}- className="w-full flex items-center gap-2.5 px-3 py-2 text-left hover:bg-zinc-900/60 transition-colors"+ className={`w-full flex items-center gap-2.5 px-3 py-2 text-left transition-colors ${+ paused ? 'cursor-not-allowed opacity-60' : 'hover:bg-zinc-900/60'+ }`}><span className="text-zinc-500">{s.transport === 'stdio' ? <Terminal size={13} /> : <Globe size={13} />}</span><span className="flex-1 min-w-0"><span className="block text-xs text-zinc-200 truncate">{s.name}</span>- {!s.enabled && <span className="block text-[10px] text-zinc-500">Paused, so it won’t be offered until it’s turned on</span>}+ {paused && (+ <span className="block text-[10px] text-zinc-500">+ Paused in Tools{selected.includes(s.id) ? '. This kwant gets it once it’s on.' : ''}+ </span>+ )}</span><span className={`relative flex-shrink-0 w-8 h-[18px] rounded-full transition-colors ${on ? 'bg-sky-600' : 'bg-zinc-700'}`}><span className={`absolute top-0.5 w-3.5 h-3.5 rounded-full bg-white shadow transition-all ${on ? 'left-[16px]' : 'left-0.5'}`} />diff --git a/frontend/src/components/McpServersModal.tsx b/frontend/src/components/McpServersModal.tsxindex 91611b25..b6e36e6f 100644--- a/frontend/src/components/McpServersModal.tsx+++ b/frontend/src/components/McpServersModal.tsx@@ -22,9 +22,11 @@ import {KeyRound,ShieldCheck,LogOut,+ Users,} from 'lucide-react';import { playSfx } from '../audio/chiptune';import {+ kwantUsage,McpServer,McpFormState,McpTestResult,@@ -50,6 +52,8 @@ import {interface McpServersModalProps {isOpen: boolean;onClose: () => void;+ /** For "Off for: …" on each card. */+ kwants?: Array<{ id: string; name: string }>;}const inputCls =@@ -187,7 +191,7 @@ const ToolChips: React.FC<{ tools: Array<{ name: string; description?: string }>);};-export const McpServersModal: React.FC<McpServersModalProps> = ({ isOpen, onClose }) => {+export const McpServersModal: React.FC<McpServersModalProps> = ({ isOpen, onClose, kwants = [] }) => {const [servers, setServers] = useState<McpServer[] | null>(null);const [loadError, setLoadError] = useState<string | null>(null);const [statuses, setStatuses] = useState<Record<string, StoredStatus>>({});@@ -474,7 +478,7 @@ export const McpServersModal: React.FC<McpServersModalProps> = ({ isOpen, onClos<h3 className="text-sm font-semibold text-zinc-100">Give your kwants new abilities</h3><p className="text-xs text-zinc-400 leading-relaxed">MCP servers are small add-ons that hand your kwants tools, like reading files, browsing the web or working with GitHub.- Add one here, then choose which kwants may use it. They always ask you before using a tool.+ Add one here and every kwant can use it; switch it off for a kwant in that kwant’s edit screen. They always ask you before using a tool.</p></div><div className="grid grid-cols-1 sm:grid-cols-3 gap-2 text-left">@@ -514,6 +518,7 @@ export const McpServersModal: React.FC<McpServersModalProps> = ({ isOpen, onClosconst signedIn = isSignedIn(server);const isConnecting = connecting === server.id;const oauthError = oauthErrors[server.id];+ const usage = kwantUsage(server, kwants);return (<likey={server.id}@@ -542,6 +547,21 @@ export const McpServersModal: React.FC<McpServersModalProps> = ({ isOpen, onClos<p className="text-[11px] font-mono text-zinc-400 truncate" title={serverTarget(server)}>{serverTarget(server)}</p>+ {kwants.length > 0 && (+ <p className="flex items-start gap-1 text-[11px] text-zinc-400">+ <Users size={11} className="flex-shrink-0 mt-[3px] text-zinc-500" aria-hidden="true" />+ <span className="min-w-0 break-words">+ {usage.allKwants ? (+ server.enabled ? 'Used by all kwants' : 'All kwants get it once it’s on'+ ) : (+ <>+ {server.enabled ? 'Off for: ' : 'Once it’s on, off for: '}+ <span className="text-zinc-300">{usage.offFor.join(', ')}</span>+ </>+ )}+ </span>+ </p>+ )}</div></div>@@ -712,7 +732,7 @@ export const McpServersModal: React.FC<McpServersModalProps> = ({ isOpen, onClos<div className="space-y-3"><div className="flex items-center justify-between gap-2"><p className="text-[11px] text-zinc-500">- {servers.length} {servers.length === 1 ? 'server' : 'servers'} · assign them to a kwant from its edit screen+ {servers.length} {servers.length === 1 ? 'server' : 'servers'}</p><buttontype="button"diff --git a/frontend/src/components/NewAgentModal.tsx b/frontend/src/components/NewAgentModal.tsxindex b00bc096..990b55dd 100644--- a/frontend/src/components/NewAgentModal.tsx+++ b/frontend/src/components/NewAgentModal.tsx@@ -4,6 +4,7 @@ import { ModernAvatar, AVATAR_STYLES } from './ModernAvatar';import { AGENT_PRESETS, AgentPreset, PRESET_GROUPS, PresetGroup, uniqueAgentName } from '../agentPresets';import { playSfx } from '../audio/chiptune';import { KwantToolsPicker } from './KwantToolsPicker';+import { McpServer, defaultKwantServerIds } from '../mcp';export interface AgentFormData {name: string;@@ -75,13 +76,25 @@ export const NewAgentModal: React.FC<NewAgentModalProps> = ({setSubmitting(false);setError(null);setPresetId(null);- setMcpIds(kwantId ? undefined : []);+ setMcpIds(undefined);+ let cancelled = false;+ // If a list can't load, the picker stays hidden and nothing is saved: saving an empty+ // list would switch every server off for this kwant.if (kwantId) {fetch(`/api/kwants/${kwantId}/mcp-servers`)- .then((r) => (r.ok ? r.json() : { server_ids: [] }))- .then((d) => setMcpIds(d.server_ids ?? []))- .catch(() => setMcpIds([]));+ .then((r) => (r.ok ? r.json() : Promise.reject()))+ .then((d) => !cancelled && Array.isArray(d.server_ids) && setMcpIds(d.server_ids))+ .catch(() => undefined);+ } else {+ // Every server starts on, like the backend default.+ fetch('/api/mcp/servers')+ .then((r) => (r.ok ? r.json() : Promise.reject()))+ .then((list: McpServer[]) => !cancelled && setMcpIds(defaultKwantServerIds(list)))+ .catch(() => undefined);}+ return () => {+ cancelled = true;+ };}, [isOpen, initial, kwantId]);const applyPreset = (preset: AgentPreset | null) => {diff --git a/frontend/src/mcp.ts b/frontend/src/mcp.tsindex 3aa3c55c..985c8445 100644--- a/frontend/src/mcp.ts+++ b/frontend/src/mcp.ts@@ -17,6 +17,8 @@ export interface McpServer {created_at: string | null;/** Sign-in state for URL servers; never carries tokens. */oauth?: { connected: boolean; expires_at: string | null };+ /** Kwants that switched this server off, sorted by name. Empty: every kwant gets it. */+ disabled_for_kwants?: string[];}export interface McpTool {@@ -420,3 +422,20 @@ export const readOAuthMessage = (...(typeof d.error === 'string' && d.error ? { error: d.error.slice(0, 300) } : {}),};};++/**+ * Which kwants a server reaches, for its card. Servers are on for every kwant unless a kwant+ * switches one off. Ids of kwants this screen doesn't know about are left out of the names.+ */+export const kwantUsage = (+ server: Pick<McpServer, 'disabled_for_kwants'>,+ kwants: Array<{ id: string; name: string }>,+): { allKwants: boolean; offFor: string[] } => {+ const off = server.disabled_for_kwants ?? [];+ const names = new Map(kwants.map((k) => [k.id, k.name]));+ const offFor = off.map((id) => names.get(id)).filter((n): n is string => !!n);+ return { allKwants: offFor.length === 0, offFor };+};++/** A new kwant starts with every server on, the same as the backend default. */+export const defaultKwantServerIds = (servers: Array<Pick<McpServer, 'id'>>): string[] => servers.map((s) => s.id);diff --git a/frontend/tests/mcp.test.mjs b/frontend/tests/mcp.test.mjsindex e1d18035..fc09238d 100644--- a/frontend/tests/mcp.test.mjs+++ b/frontend/tests/mcp.test.mjs@@ -29,6 +29,8 @@ const {serverStatusKind,isSignedIn,readOAuthMessage,+ kwantUsage,+ defaultKwantServerIds,} = mcp;test('splits command lines like a README shows them', () => {@@ -249,3 +251,29 @@ test('accepts sign-in results only from this origin and in the expected shape',assert.equal(readOAuthMessage({ origin, data: 'kwnt-mcp-oauth' }, origin), null);assert.equal(readOAuthMessage({ origin, data: null }, origin), null);});++test('a server card says which kwants use it', () => {+ const kwants = [+ { id: 'k1', name: 'Architect' },+ { id: 'k2', name: 'SmartDataBeast' },+ ];+ assert.deepEqual(kwantUsage({ disabled_for_kwants: [] }, kwants), { allKwants: true, offFor: [] });+ // Older backends leave the field out: that still means every kwant.+ assert.deepEqual(kwantUsage({}, kwants), { allKwants: true, offFor: [] });+ // Keeps the backend's name order and names only kwants this screen knows.+ assert.deepEqual(kwantUsage({ disabled_for_kwants: ['k1', 'k2', 'gone'] }, kwants), {+ allKwants: false,+ offFor: ['Architect', 'SmartDataBeast'],+ });+});++test('a new kwant starts with every server on, paused ones included', () => {+ assert.deepEqual(defaultKwantServerIds([]), []);+ assert.deepEqual(+ defaultKwantServerIds([+ { id: 'a', enabled: true },+ { id: 'b', enabled: false },+ ]),+ ['a', 'b'],+ );+});