Lines begin with "- " instead of an indent: one to a line in a terminal and where the reply is drawn as markdown (the web UI). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
4 files changed
+24
-22
No files matched your search
+9
-8
@@ -1,6 +1,8 @@
|
||||
// What is said about the MCP servers in words: the states, where a server comes from, and the
|
||||
// plain table `/mcp` prints where there is no menu (`lembas run`, a prompt sent over the link —
|
||||
// the web UI shows it as a reply). The TUI's menu (tui/mcpmenu.ts) reads the same words.
|
||||
// plain list `/mcp` prints where there is no menu (`lembas run`, a prompt sent over the link —
|
||||
// the web UI shows it as a reply). Lines of a list begin with "- ": they read as they are in a
|
||||
// terminal and stay one to a line where the reply is drawn as markdown (indented lines would run
|
||||
// together there). The TUI's menu (tui/mcpmenu.ts) reads the same words.
|
||||
import type { McpManager, ServerState } from "./index.ts"
|
||||
import { LIBRARY_SERVER } from "./index.ts"
|
||||
|
||||
@@ -47,23 +49,22 @@ export function mcpText(mcp: McpManager, name = "", rule: (tool: string) => stri
|
||||
if (name) {
|
||||
const s = mcp.servers.get(name)
|
||||
if (!s) return `No MCP server "${name}" — the servers: ${servers.map((x) => x.name).join(", ")}.`
|
||||
const lines = [`${s.name} — ${stateLine(s)}`, ` from ${SOURCE_WORDS[sourceOf(s)]} · ${whereOf(s)}`]
|
||||
if (s.error && s.error.includes("\n")) lines.push("", ...s.error.split("\n").map((l) => ` ${l}`))
|
||||
const lines = [`${s.name} — ${stateLine(s)}`, "", `From ${SOURCE_WORDS[sourceOf(s)]} · ${whereOf(s)}`]
|
||||
if (s.error && s.error.includes("\n")) lines.push("", "The error in full:", "", ...s.error.split("\n").map((l) => ` ${l}`))
|
||||
if (s.status === "connected") {
|
||||
if (s.tools.length) lines.push("", "Tools:")
|
||||
for (const t of s.tools) {
|
||||
const called = mcp.nameOf(s.name, t.name)
|
||||
const said = { allow: "always allowed", deny: "denied", ask: "asks" }[rule(called) ?? "ask"] ?? "asks"
|
||||
lines.push(` ${called} — ${said}${t.annotations?.readOnlyHint ? ", read-only" : ""}${t.description ? ` — ${t.description.trim().split("\n")[0]}` : ""}`)
|
||||
lines.push(`- ${called} — ${said}${t.annotations?.readOnlyHint ? ", read-only" : ""}${t.description ? ` — ${t.description.trim().split("\n")[0]}` : ""}`)
|
||||
}
|
||||
if (s.prompts.length) lines.push("", "Prompts:", ...s.prompts.map((p) => ` /${s.name}:${p.name}${p.description ? ` — ${p.description.split("\n")[0]}` : ""}`))
|
||||
if (s.prompts.length) lines.push("", "Prompts:", ...s.prompts.map((p) => `- /${s.name}:${p.name}${p.description ? ` — ${p.description.split("\n")[0]}` : ""}`))
|
||||
}
|
||||
return lines.join("\n")
|
||||
}
|
||||
const width = Math.max(...servers.map((s) => s.name.length))
|
||||
return [
|
||||
"MCP servers:",
|
||||
...servers.map((s) => ` ${s.name.padEnd(width)} ${stateLine(s)} (${SOURCE_WORDS[sourceOf(s)]})`),
|
||||
...servers.map((s) => `- ${s.name} — ${stateLine(s)} (${SOURCE_WORDS[sourceOf(s)]})`),
|
||||
"",
|
||||
"/mcp <name> lists one server's tools. A tool asks before it runs unless a permission rule allows it.",
|
||||
].join("\n")
|
||||
|
||||
@@ -41,7 +41,7 @@ export function permissionsText(app: App): string {
|
||||
for (const { rule, from: f } of rules) {
|
||||
if (f !== from) lines.push("", `${RULE_FROM[f]}:`)
|
||||
from = f
|
||||
lines.push(` ${rule.action.padEnd(5)} ${ruleLine(rule)}`)
|
||||
lines.push(`- ${rule.action}: ${ruleLine(rule)}`)
|
||||
}
|
||||
return lines.join("\n")
|
||||
}
|
||||
@@ -89,13 +89,12 @@ export function statusRows(app: App): StatusRow[] {
|
||||
|
||||
export function statusText(app: App): string {
|
||||
const rows = statusRows(app)
|
||||
const width = Math.max(...rows.map((r) => r.label.length))
|
||||
const out: string[] = []
|
||||
let section = ""
|
||||
for (const r of rows) {
|
||||
if (r.section !== section) out.push(...(out.length ? [""] : []), `${r.section}:`)
|
||||
section = r.section
|
||||
out.push(` ${r.label.padEnd(width)} ${r.value}${r.attention ? " (needs attention)" : ""}`)
|
||||
out.push(`- ${r.label}: ${r.value}${r.attention ? " (needs attention)" : ""}`)
|
||||
}
|
||||
return out.join("\n")
|
||||
}
|
||||
@@ -231,16 +231,18 @@ test("without a menu — over the link, in lembas run — /mcp is a plain table,
|
||||
const text = (all as { text: string }).text
|
||||
expect(text.split("\n")).toEqual([
|
||||
"MCP servers:",
|
||||
" alpha connected — 2 tools (your config)",
|
||||
" beta failed: connect ECONNREFUSED (your config)",
|
||||
" lembas-library connected — 1 tool (the LLeMbas server's library)",
|
||||
"- alpha — connected — 2 tools (your config)",
|
||||
"- beta — failed: connect ECONNREFUSED (your config)",
|
||||
"- lembas-library — connected — 1 tool (the LLeMbas server's library)",
|
||||
"",
|
||||
"/mcp <name> lists one server's tools. A tool asks before it runs unless a permission rule allows it.",
|
||||
])
|
||||
const one = (expandSlash(t.app, "/mcp alpha") as { text: string }).text
|
||||
expect(one).toContain("alpha — connected — 2 tools")
|
||||
expect(one).toContain(" mcp__alpha__tool_0 — asks — Does thing 0.")
|
||||
expect(one).toContain(" mcp__alpha__tool_1 — always allowed — Does thing 1.")
|
||||
expect(one).toContain("\n- mcp__alpha__tool_0 — asks — Does thing 0.")
|
||||
expect(one).toContain("\n- mcp__alpha__tool_1 — always allowed — Does thing 1.")
|
||||
// One to a line in a terminal and where a reply is drawn as markdown: list lines, none indented.
|
||||
expect(text.split("\n").some((l) => /^ {1,3}\S/.test(l))).toBe(false)
|
||||
expect((expandSlash(t.app, "/mcp beta") as { text: string }).text).toContain("at the second line")
|
||||
expect((expandSlash(t.app, "/mcp off alpha") as { text: string }).text).toContain("done at the terminal")
|
||||
expect(mcpText(t.app.mcp, "nosuch")).toContain('No MCP server "nosuch"')
|
||||
|
||||
@@ -161,12 +161,12 @@ test("without a menu the same commands are plain text: /permissions and /status
|
||||
t.app.engine.setRule({ permission: "edit", pattern: "docs/*", action: "allow" })
|
||||
const p = text("/permissions")
|
||||
expect(p).toStartWith("Mode: manual.")
|
||||
expect(p).toContain("This session:\n allow edit docs/*")
|
||||
expect(p).toContain("Your config:\n deny bash git push *")
|
||||
expect(p).toContain("This session:\n- allow: edit docs/*")
|
||||
expect(p).toContain("Your config:\n- deny: bash git push *")
|
||||
expect(p).toContain("Built in:")
|
||||
const s = text("/status")
|
||||
expect(s).toContain("This program:\n version")
|
||||
expect(s).toMatch(/model +fake\/coder/)
|
||||
expect(s).toMatch(/trusted +no: .*\(needs attention\)/)
|
||||
expect(s).toMatch(/servers +none configured/)
|
||||
expect(s).toContain("This program:\n- version: ")
|
||||
expect(s).toContain("- model: fake/coder")
|
||||
expect(s).toMatch(/- trusted: no: .*\(needs attention\)/)
|
||||
expect(s).toContain("- servers: none configured")
|
||||
})
|
||||
Reference in new issue
Block a user