import { Component, createMemo, Show } from "solid-js" import { useSync } from "@/context/sync" import { Dialog } from "@opencode-ai/ui/dialog" import { List } from "@opencode-ai/ui/list" import { Switch } from "@opencode-ai/ui/switch" import { useLanguage } from "@/context/language" import { useMcpToggle } from "@/context/mcp" const statusLabels = { connected: "mcp.status.connected", failed: "mcp.status.failed", needs_auth: "mcp.status.needs_auth", needs_client_registration: "mcp.status.needs_client_registration", disabled: "mcp.status.disabled", } as const export const DialogSelectMcp: Component = () => { const sync = useSync() const language = useLanguage() const items = createMemo(() => Object.entries(sync.data.mcp ?? {}) .map(([name, status]) => ({ name, status: status.status })) .sort((a, b) => a.name.localeCompare(b.name)), ) const toggle = useMcpToggle() const enabledCount = createMemo(() => items().filter((i) => i.status === "connected").length) const totalCount = createMemo(() => items().length) return ( x?.name ?? ""} items={items} filterKeys={["name", "status"]} sortBy={(a, b) => a.name.localeCompare(b.name)} onSelect={(x) => { if (!x || toggle.isPending) return toggle.mutate(x.name) }} > {(i) => { const mcpStatus = () => sync.data.mcp[i.name] const status = () => mcpStatus()?.status const statusLabel = () => { const key = status() ? statusLabels[status() as keyof typeof statusLabels] : undefined if (!key) return return language.t(key) } const error = () => { const s = mcpStatus() if (s?.status === "failed" || s?.status === "needs_client_registration") return s.error } const enabled = () => status() === "connected" return (
{i.name} {statusLabel()}
{error()}
e.stopPropagation()}> { if (toggle.isPending) return toggle.mutate(i.name) }} />
) }}
) }