Compare commits

...

1 Commits

Author SHA1 Message Date
Kit Langton 3fa7105fe3 fix(tui): summarize MCP sidebar errors 2026-08-04 19:53:06 +00:00
4 changed files with 76 additions and 9 deletions
+2 -2
View File
@@ -799,8 +799,8 @@ function App(props: { pair?: DialogPairCredentials }) {
title: "MCP servers",
category: "Agent",
slash: { name: "mcps" },
run: () => {
dialog.replace(() => <DialogMcp />)
run: (server?: string) => {
dialog.replace(() => <DialogMcp server={server} />)
},
},
{
+12 -1
View File
@@ -28,7 +28,7 @@ function Status(props: { enabled: boolean; loading: boolean }) {
return <span style={{ fg: theme.text.subdued }}> Disabled</span>
}
export function DialogMcp() {
export function DialogMcp(props: { server?: string }) {
const data = useData()
const dialog = useDialog()
const client = useClient()
@@ -37,6 +37,7 @@ export function DialogMcp() {
const [focused, setFocused] = createSignal<string>()
const [detail, setDetail] = createSignal<McpServer>()
const [loading, setLoading] = createSignal<string | null>(null)
const [initial, setInitial] = createSignal(props.server)
const servers = createMemo(() =>
pipe(
@@ -45,6 +46,16 @@ export function DialogMcp() {
),
)
createEffect(() => {
const name = initial()
if (!name) return
const server = servers().find((entry) => entry.name === name)
if (!server) return
setInitial()
setFocused(name)
if (statusError(server.status)) setDetail(server)
})
createEffect(() => {
if (focused()) return
const first = servers()[0]
@@ -1,7 +1,7 @@
import { Plugin } from "@opencode-ai/plugin/tui"
import { createMemo, For, Match, Show, Switch, createSignal } from "solid-js"
function View(props: { context: Plugin.Context; sessionID: string }) {
export function McpSidebar(props: { context: Plugin.Context; sessionID: string }) {
const [open, setOpen] = createSignal(true)
const theme = props.context.theme
const session = createMemo(() => props.context.data.session.get(props.sessionID))
@@ -46,7 +46,14 @@ function View(props: { context: Plugin.Context; sessionID: string }) {
<Show when={list().length <= 2 || open()}>
<For each={list()}>
{(item) => (
<box flexDirection="row" gap={1}>
<box
flexDirection="row"
gap={1}
onMouseUp={() => {
if (item.status.status !== "failed" && item.status.status !== "needs_client_registration") return
props.context.keymap.dispatch("mcp.list", item.name)
}}
>
<text
flexShrink={0}
style={{
@@ -60,9 +67,7 @@ function View(props: { context: Plugin.Context; sessionID: string }) {
<span style={{ fg: theme.text.subdued }}>
<Switch fallback={item.status.status}>
<Match when={item.status.status === "connected"}>Connected</Match>
<Match when={item.status.status === "failed"}>
<i>{item.status.status === "failed" ? item.status.error : undefined}</i>
</Match>
<Match when={item.status.status === "failed"}>Failed</Match>
<Match when={item.status.status === "disabled"}>Disabled</Match>
<Match when={item.status.status === "needs_auth"}>Needs auth</Match>
<Match when={item.status.status === "needs_client_registration"}>Needs client ID</Match>
@@ -81,6 +86,6 @@ function View(props: { context: Plugin.Context; sessionID: string }) {
export default Plugin.define({
id: "internal:sidebar-mcp",
setup(context) {
context.ui.slot("sidebar.content", (props) => <View context={context} sessionID={props.sessionID} />)
context.ui.slot("sidebar.content", (props) => <McpSidebar context={context} sessionID={props.sessionID} />)
},
})
@@ -0,0 +1,51 @@
/** @jsxImportSource @opentui/solid */
import { expect, test } from "bun:test"
import { RGBA } from "@opentui/core"
import { testRender } from "@opentui/solid"
import type { Context } from "@opencode-ai/plugin/tui/context"
import { McpSidebar } from "../../src/feature-plugins/sidebar/mcp"
function context() {
const color = RGBA.fromInts(200, 200, 200)
return {
theme: {
text: {
default: color,
subdued: color,
feedback: { success: { default: color }, error: { default: color }, warning: { default: color } },
},
},
data: {
session: { get: () => ({ location: { directory: "/workspace" } }) },
location: {
mcp: {
server: {
list: () => [
{
name: "broken",
status: { status: "failed", error: "<!DOCTYPE html><html><body>raw response</body></html>" },
},
],
},
},
},
},
} as unknown as Context
}
test("sidebar summarizes MCP failures without rendering error details", async () => {
const app = await testRender(() => <McpSidebar context={context()} sessionID="session" />, {
width: 42,
height: 8,
})
try {
await app.renderOnce()
const frame = app.captureCharFrame()
expect(frame).toContain("broken Failed")
expect(frame).not.toContain("DOCTYPE")
expect(frame).not.toContain("raw response")
} finally {
app.renderer.destroy()
}
})