@blackbelt-technology/pi-dashboard-mcp-client-plugin 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @blackbelt-technology/pi-dashboard-mcp-client-plugin
2
+
3
+ Dashboard plugin owning pi's MCP server configuration — the generic MCP server
4
+ manager (create / edit / enable / disable, `exposure` / `toolExposure`, global +
5
+ folder scope), live state from `pi mcp list --json`, and the effective config
6
+ view. Uses pi's BUILT-IN MCP (pi ≥ 1.0.0); no `pi-mcp-adapter`.
7
+
8
+ ## Entries
9
+
10
+ | Export | Purpose |
11
+ |---|---|
12
+ | `.` / `./client` | Settings claim + sidebar/worktree folder MCP section + `/folder/:cwd/mcp` page |
13
+ | `./server` | `registerPlugin` — provides `mcp-client.config`, mounts the REST surface |
14
+ | `./core` | Host-free logic (also consumed by the hostless `apple-tools` installer CLI) |
15
+
16
+ ## Two layers
17
+
18
+ Pi global `$PI_CODING_AGENT_DIR/mcp.json` (else `~/.pi/agent/mcp.json`) and
19
+ trusted `<cwd>/.pi/mcp.json`. A project entry replaces the global entry of the
20
+ same name — whole entry, matching pi. Both layers parse as strict `JSON.parse`;
21
+ a file with comments or trailing commas is skipped whole by pi and shown as
22
+ unparseable. Trust comes from the injected `isProjectTrusted(cwd)` predicate
23
+ (the server supplies `host.isProjectTrusted`).
24
+
25
+ ## `mcp-client.config` service
26
+
27
+ In-process service consumed by other plugins via
28
+ `ctx.consume("mcp-client.config")` (declare `dependsOn: ["mcp-client"]`).
29
+ Backed by merge-only Pi-owned writes: strict JSON parse, whole-entry replace,
30
+ atomic `0o600` write, prototype-key refusal, and a closed refusal union
31
+ (`unparseable | entry-not-object | invalid-name | name-collision |
32
+ transport-conflict | invalid-entry | write-failed`).
33
+
34
+ | Method | Purpose |
35
+ |---|---|
36
+ | `readServerEntry(name, scope)` | Raw file entry from the scope's Pi-owned layer |
37
+ | `ensureServerEntry(name, fields, scope)` | Merge a `command`/`url` transport + fields |
38
+ | `saveServer(name, entry, scope, previousName?)` | Write a whole entry (optional rename) |
39
+ | `setEnabled(name, enabled, scope)` | `enabled: false`, or remove the key |
40
+ | `removeServer(name, scope)` | Delete one entry (returns the removed raw entry) |
41
+ | `convertAdapterLeftovers(name, scope)` | Convert adapter `disabled` → `enabled: false`, drop other adapter keys |
42
+ | `previewEnsure(name, fields, scope)` | Write-suppressed check parity with the writers |
43
+ | `readParseStatus(scope)` | Per-layer strict-JSON parse status |
44
+ | `getLiveState(scope, { fresh? })` | `pi mcp list --json` rows (30 s timeout + cache) |
45
+
46
+ ## REST surface (`networkGuard` on every route)
47
+
48
+ | Route | Purpose |
49
+ |---|---|
50
+ | `GET /api/mcp-client/effective?cwd=` | Effective servers with provenance + live state (global secrets redacted) |
51
+ | `GET /api/mcp-client/live?cwd=&fresh=1` | Live state from `pi mcp list --json` |
52
+ | `GET /api/mcp-client/schema` | Published config schema |
53
+ | `PUT /api/mcp-client/servers/:name` | `{ scope, cwd?, entry, previousName? }` |
54
+ | `DELETE /api/mcp-client/servers/:name?scope=&cwd=` | Remove one server → `{ ok, removed }` |
55
+ | `PUT /api/mcp-client/servers/:name/enabled` | `{ scope, cwd?, enabled }` |
56
+ | `POST /api/mcp-client/servers/:name/convert` | `{ scope, cwd? }` — convert adapter leftovers |
57
+
58
+ Project `cwd`s must be in the known-folder set (`host.knownFolderCwds`) and
59
+ trusted; otherwise the route answers `403 not-allowed` with a `reason`/`hint`
60
+ before any IO. Path names are decoded + validated first.
61
+
62
+ See change: `extract-mcp-client-plugin`, `migrate-mcp-to-pi-builtin`.
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@blackbelt-technology/pi-dashboard-mcp-client-plugin",
3
+ "version": "0.8.0",
4
+ "description": "First-party dashboard plugin managing pi's built-in MCP configuration: Pi-global + trusted-folder mcp.json view with live state from `pi mcp list`, validated atomic writes, and global + folder MCP management surfaces.",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "type": "module",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/BlackBeltTechnology/pi-agent-dashboard",
13
+ "directory": "packages/mcp-client-plugin"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./src/client/index.tsx",
18
+ "default": "./src/client/index.tsx"
19
+ },
20
+ "./client": {
21
+ "types": "./src/client/index.tsx",
22
+ "default": "./src/client/index.tsx"
23
+ },
24
+ "./server": {
25
+ "types": "./src/server/index.ts",
26
+ "default": "./src/server/index.ts"
27
+ },
28
+ "./core": {
29
+ "types": "./src/core/index.ts",
30
+ "default": "./src/core/index.ts"
31
+ }
32
+ },
33
+ "files": [
34
+ "src/",
35
+ "schema/",
36
+ "!**/AGENTS.md",
37
+ "!**/*.AGENTS.md",
38
+ "!**/__tests__",
39
+ "!**/*.test.ts",
40
+ "!**/*.test.tsx"
41
+ ],
42
+ "peerDependencies": {
43
+ "fastify": "^5.0.0",
44
+ "react": ">=18.0.0",
45
+ "react-dom": ">=18.0.0",
46
+ "wouter": ">=3.0.0"
47
+ },
48
+ "dependencies": {
49
+ "@blackbelt-technology/dashboard-plugin-runtime": "^0.8.0",
50
+ "@blackbelt-technology/pi-dashboard-shared": "^0.8.0",
51
+ "@mdi/js": "^7.4.47",
52
+ "@mdi/react": "^1.6.1",
53
+ "ajv": "^8.17.1"
54
+ },
55
+ "devDependencies": {
56
+ "@testing-library/react": "^16.1.0",
57
+ "@types/react": "^19.0.0",
58
+ "@types/react-dom": "^19.0.0",
59
+ "fastify": "^5.0.0",
60
+ "react": "^19.0.0",
61
+ "react-dom": "^19.0.0",
62
+ "vitest": "^4.0.0",
63
+ "wouter": "^3.9.0"
64
+ },
65
+ "pi-dashboard-plugin": {
66
+ "id": "mcp-client",
67
+ "displayName": "MCP Client",
68
+ "priority": 100,
69
+ "client": "./src/client/index.tsx",
70
+ "server": "./src/server/index.ts",
71
+ "claims": [
72
+ {
73
+ "slot": "settings-section",
74
+ "component": "McpSettingsClaim",
75
+ "tab": "general"
76
+ },
77
+ {
78
+ "slot": "sidebar-folder-section",
79
+ "component": "FolderMcpSection"
80
+ },
81
+ {
82
+ "slot": "worktree-card-section",
83
+ "component": "FolderMcpSection"
84
+ },
85
+ {
86
+ "slot": "shell-overlay-route",
87
+ "component": "FolderMcpPage",
88
+ "path": "/folder/:encodedCwd/mcp",
89
+ "depth": 2,
90
+ "parentPath": "/folder/:encodedCwd"
91
+ }
92
+ ]
93
+ }
94
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://pi-dashboard.local/schemas/mcp-config.schema.json",
4
+ "title": "pi built-in MCP server entry",
5
+ "description": "Hand-authored from pi 1.0.0 dist/core/mcp-servers.d.ts (McpServerConfig). Describes one `mcpServers.<name>` entry of ~/.pi/agent/mcp.json or <cwd>/.pi/mcp.json so the dashboard client can render editors without hard-coding field lists. Annotations: x-transport marks the two mutually exclusive transports (command xor url); x-secret marks credential-bearing fields (masked in the editor, redacted when inherited, omitted from folder copies); x-global-only marks fields pi reads only from the global file. The writer additionally mirrors pi's validateMcpServerConfig rules (pi-rules.ts).",
6
+ "$defs": {
7
+ "Exposure": {
8
+ "enum": ["codemode", "deferred", "direct", "hidden", "codemode-deferred"],
9
+ "description": "How the server's tools reach the model. Default codemode. codemode-deferred is pi's legacy alias of codemode, accepted on read and preserved."
10
+ },
11
+ "OAuthConfig": {
12
+ "type": "object",
13
+ "additionalProperties": true,
14
+ "properties": {
15
+ "clientId": { "type": "string" },
16
+ "clientSecret": { "type": "string", "x-secret": true },
17
+ "callbackPort": { "type": "integer", "minimum": 1, "maximum": 65535 },
18
+ "callbackUrl": { "type": "string" },
19
+ "scope": { "type": "string" },
20
+ "clientName": { "type": "string", "minLength": 1 },
21
+ "authServerMetadataUrl": { "type": "string" }
22
+ }
23
+ },
24
+ "AuthConfig": {
25
+ "type": "object",
26
+ "additionalProperties": true,
27
+ "required": ["provider"],
28
+ "properties": {
29
+ "provider": { "type": "string", "minLength": 1 }
30
+ }
31
+ },
32
+ "ServerEntry": {
33
+ "type": "object",
34
+ "additionalProperties": true,
35
+ "description": "One pi MCP server entry: stdio (command) or streamable HTTP (url).",
36
+ "properties": {
37
+ "type": { "enum": ["stdio", "http", "streamable-http"] },
38
+ "description": { "type": "string" },
39
+ "command": { "type": "string", "x-transport": "command" },
40
+ "args": { "type": "array", "items": { "type": "string" } },
41
+ "env": { "type": "object", "additionalProperties": { "type": "string" }, "x-secret": true },
42
+ "cwd": { "type": "string" },
43
+ "url": { "type": "string", "x-transport": "url" },
44
+ "headers": { "type": "object", "additionalProperties": { "type": "string" }, "x-secret": true },
45
+ "oauth": { "$ref": "#/$defs/OAuthConfig" },
46
+ "auth": { "$ref": "#/$defs/AuthConfig", "x-global-only": true },
47
+ "exposure": { "$ref": "#/$defs/Exposure" },
48
+ "toolExposure": { "type": "object", "additionalProperties": { "$ref": "#/$defs/Exposure" } },
49
+ "timeout": { "type": "number", "exclusiveMinimum": 0 },
50
+ "enabled": { "type": "boolean" }
51
+ }
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,417 @@
1
+ /**
2
+ * FolderMcpPage — `shell-overlay-route` claim at `/folder/:encodedCwd/mcp`.
3
+ *
4
+ * The effective MCP configuration for one folder cwd with pi's two layers.
5
+ * Admission is server-side only: the route decodes the cwd and the
6
+ * effective-view request is refused (403) for a folder the host does not
7
+ * track, so the page renders a not-allowed empty state with NO retry and no
8
+ * data. Rows carry provenance badges (Pi global / Pi folder) and the
9
+ * whole-entry override marker; a global row's "Override…" opens the editor
10
+ * pre-filled with the complete global entry minus secrets + `auth`, each
11
+ * omission flagged. An untrusted folder shows a notice (dashboard-spawned
12
+ * headless sessions trust the folder per run) while editing stays allowed.
13
+ * Folder writes are project-scope only; a folder enable that needs re-entered
14
+ * secrets offers remove-or-reenter; a removal keeps an undo toast that re-PUTs
15
+ * the removed raw entry.
16
+ *
17
+ * See change: migrate-mcp-to-pi-builtin.
18
+ */
19
+ import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
20
+ import type React from "react";
21
+ import { useMemo, useState } from "react";
22
+ import type { EffectiveView, Provenance, Scope } from "../core/types.js";
23
+ import { ApiError, removeServer, saveServer, scopeToWire } from "./api.js";
24
+ import { folderOverrideDraftOf, isFolderOwned } from "./folder-view.js";
25
+ import { invalidateEffective, useEffectiveConfig } from "./hooks.js";
26
+ import { ServerEditor } from "./ServerEditor.js";
27
+ import type { RowRef } from "./ServerList.js";
28
+ import { ServerList } from "./ServerList.js";
29
+ import { useIsNarrow } from "./useIsNarrow.js";
30
+
31
+ export interface FolderMcpPageProps {
32
+ params: Record<string, string>;
33
+ session?: unknown;
34
+ onBack: () => void;
35
+ }
36
+
37
+ /** Decode the route's `encodedCwd`; a malformed encode is not a valid cwd. */
38
+ function decodeFolderCwd(encoded: string | undefined): string | null {
39
+ if (!encoded) return null;
40
+ try {
41
+ const cwd = decodeURIComponent(encoded);
42
+ return cwd.length > 0 ? cwd : null;
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+
48
+ function PageHeader({ onBack }: { onBack: () => void }): React.ReactElement {
49
+ const t = useT();
50
+ return (
51
+ <div className="flex items-center gap-2">
52
+ <button
53
+ type="button"
54
+ onClick={onBack}
55
+ data-testid="mcp-folder-back"
56
+ className="text-[11px] px-2 py-1 min-h-11 min-w-11 sm:min-h-0 sm:min-w-0 rounded border border-[var(--border-secondary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]"
57
+ >
58
+ {t("mcpFolderBack", undefined, "Back")}
59
+ </button>
60
+ <h3 className="text-sm font-semibold m-0 text-[var(--text-primary)]">
61
+ {t("mcpFolderHeading", undefined, "MCP servers · this folder")}
62
+ </h3>
63
+ </div>
64
+ );
65
+ }
66
+
67
+ function NotAllowed(): React.ReactElement {
68
+ const t = useT();
69
+ return (
70
+ <p
71
+ data-testid="mcp-folder-not-allowed"
72
+ role="alert"
73
+ className="text-[11px] text-[var(--text-secondary)] m-0"
74
+ >
75
+ {t("mcpFolderNotAllowed", undefined, "This folder is not tracked by the dashboard.")}
76
+ </p>
77
+ );
78
+ }
79
+
80
+ function UntrustedNotice(): React.ReactElement {
81
+ const t = useT();
82
+ return (
83
+ <div
84
+ data-testid="mcp-folder-untrusted"
85
+ role="status"
86
+ className="text-[11px] px-2 py-1.5 rounded border border-[var(--border-secondary)] text-[var(--text-secondary)]"
87
+ >
88
+ {t(
89
+ "mcpFolderUntrusted",
90
+ undefined,
91
+ "pi does not trust this project yet: folder servers stay inactive until the project is trusted. Headless sessions the dashboard starts in this folder trust it per run. Editing <cwd>/.pi/mcp.json stays allowed.",
92
+ )}
93
+ </div>
94
+ );
95
+ }
96
+
97
+ interface EditingState {
98
+ /** The row name; "" = add. */
99
+ name: string;
100
+ entry: Record<string, unknown>;
101
+ /** Dotted fields the override pre-fill dropped (warnings in the editor). */
102
+ omitted?: string[];
103
+ }
104
+
105
+ interface UndoState {
106
+ name: string;
107
+ removed: Record<string, unknown>;
108
+ }
109
+
110
+ interface ChoiceState {
111
+ row: RowRef;
112
+ omitted: string[];
113
+ }
114
+
115
+ interface OmittedNoteState {
116
+ key: string;
117
+ name: string;
118
+ omitted: string[];
119
+ }
120
+
121
+ /** The editor pre-fill for a row: the folder's own entry, or the override copy. */
122
+ function prefillFor(server: { name: string; provenance: Provenance; entry: Record<string, unknown> } | null): EditingState {
123
+ if (server === null) return { name: "", entry: {} };
124
+ if (isFolderOwned(server.provenance)) return { name: server.name, entry: server.entry };
125
+ // A global row: the override pre-fill drops secrets + auth and flags them.
126
+ const { draft, omitted } = folderOverrideDraftOf(server.entry);
127
+ return { name: server.name, entry: draft, omitted };
128
+ }
129
+
130
+ interface FolderActions {
131
+ editing: EditingState | null;
132
+ undo: UndoState | null;
133
+ choice: ChoiceState | null;
134
+ omittedNote: OmittedNoteState | null;
135
+ actionError: string | null;
136
+ scope: Scope;
137
+ open: (name: string, provenance: Provenance) => void;
138
+ openAdd: () => void;
139
+ closeEditor: () => void;
140
+ removeOverride: (name: string) => void;
141
+ undoRemove: () => void;
142
+ resolveChoiceRemove: () => void;
143
+ resolveChoiceReenter: () => void;
144
+ onNeedsChoice: (row: RowRef, omitted: string[]) => void;
145
+ onOmitted: (row: RowRef, omitted: string[]) => void;
146
+ refreshed: () => void;
147
+ }
148
+
149
+ /** Editing / choice / undo state for one folder page. */
150
+ function useFolderActions(
151
+ cwd: string,
152
+ view: EffectiveView | null,
153
+ reload: () => void,
154
+ ): FolderActions {
155
+ const [editing, setEditing] = useState<EditingState | null>(null);
156
+ const [undo, setUndo] = useState<UndoState | null>(null);
157
+ const [choice, setChoice] = useState<ChoiceState | null>(null);
158
+ const [omittedNote, setOmittedNote] = useState<OmittedNoteState | null>(null);
159
+ const [actionError, setActionError] = useState<string | null>(null);
160
+ const scope = useMemo<Scope>(() => ({ kind: "project", cwd }), [cwd]);
161
+ const refreshed = (): void => {
162
+ invalidateEffective(cwd);
163
+ reload();
164
+ };
165
+
166
+ async function removeOverride(name: string): Promise<void> {
167
+ setActionError(null);
168
+ try {
169
+ const res = await removeServer(name, scopeToWire(scope));
170
+ setEditing(null);
171
+ setChoice(null);
172
+ setUndo({ name, removed: res.removed ?? {} });
173
+ refreshed();
174
+ } catch (e) {
175
+ setActionError(e instanceof ApiError ? e.message : String(e));
176
+ }
177
+ }
178
+
179
+ async function undoRemove(): Promise<void> {
180
+ if (!undo) return;
181
+ try {
182
+ await saveServer(undo.name, { ...scopeToWire(scope), entry: undo.removed });
183
+ setUndo(null);
184
+ refreshed();
185
+ } catch (e) {
186
+ setActionError(e instanceof ApiError ? e.message : String(e));
187
+ }
188
+ }
189
+
190
+ return {
191
+ editing,
192
+ undo,
193
+ choice,
194
+ omittedNote,
195
+ actionError,
196
+ scope,
197
+ open: (name, provenance) => {
198
+ // Same-name rows (untrusted folder + global) are distinct: act on the
199
+ // row the operator clicked.
200
+ const server = view?.servers.find((s) => s.name === name && s.provenance === provenance) ?? null;
201
+ setEditing(prefillFor(server));
202
+ },
203
+ openAdd: () => setEditing({ name: "", entry: {} }),
204
+ closeEditor: () => setEditing(null),
205
+ removeOverride: (name) => void removeOverride(name),
206
+ undoRemove: () => void undoRemove(),
207
+ resolveChoiceRemove: () => {
208
+ if (choice) void removeOverride(choice.row.name);
209
+ },
210
+ resolveChoiceReenter: () => {
211
+ if (!choice) return;
212
+ // Re-enter on the FOLDER row (its own stored entry, verbatim).
213
+ const server =
214
+ view?.servers.find((s) => s.name === choice.row.name && s.provenance === "pi-folder") ??
215
+ view?.servers.find((s) => s.name === choice.row.name) ??
216
+ null;
217
+ setChoice(null);
218
+ setEditing(prefillFor(server));
219
+ },
220
+ onNeedsChoice: (row, omitted) => setChoice({ row, omitted }),
221
+ onOmitted: (row, omitted) => setOmittedNote({ key: row.key, name: row.name, omitted }),
222
+ refreshed,
223
+ };
224
+ }
225
+
226
+ function UndoToast({ name, onUndo }: { name: string; onUndo: () => void }): React.ReactElement {
227
+ const t = useT();
228
+ return (
229
+ <div
230
+ data-testid="mcp-folder-undo-toast"
231
+ role="status"
232
+ className="flex items-center gap-2 text-[11px] px-2 py-1.5 rounded border border-[var(--border-secondary)] text-[var(--text-secondary)]"
233
+ >
234
+ <span>{t("mcpFolderOverrideRemoved", { name }, `Removed folder override for ${name}.`)}</span>
235
+ <button
236
+ type="button"
237
+ onClick={onUndo}
238
+ data-testid="mcp-folder-undo"
239
+ className="px-2 py-1 min-h-11 min-w-11 sm:min-h-0 sm:min-w-0 rounded border border-[var(--border-secondary)]"
240
+ >
241
+ {t("mcpFolderUndo", undefined, "Undo")}
242
+ </button>
243
+ </div>
244
+ );
245
+ }
246
+
247
+ /** A folder enable that cannot inherit the global entry's secrets. */
248
+ function NeedsChoicePanel({
249
+ name,
250
+ omitted,
251
+ onRemove,
252
+ onReenter,
253
+ }: {
254
+ name: string;
255
+ omitted: string[];
256
+ onRemove: () => void;
257
+ onReenter: () => void;
258
+ }): React.ReactElement {
259
+ const t = useT();
260
+ return (
261
+ <div
262
+ data-testid="mcp-folder-needs-choice"
263
+ role="alert"
264
+ className="text-[11px] px-2 py-1.5 rounded border border-amber-500 text-[var(--text-secondary)] space-y-1"
265
+ >
266
+ <p className="m-0">
267
+ {t(
268
+ "mcpFolderNeedsChoice",
269
+ { name, omitted: omitted.join(", ") },
270
+ `Enabling ${name} at folder scope cannot inherit the global entry's secrets (${omitted.join(", ")}).`,
271
+ )}
272
+ </p>
273
+ <div className="flex items-center gap-2">
274
+ <button
275
+ type="button"
276
+ onClick={onRemove}
277
+ data-testid="mcp-choice-remove"
278
+ className="px-2 py-1 min-h-11 min-w-11 sm:min-h-0 sm:min-w-0 rounded border border-[var(--border-secondary)]"
279
+ >
280
+ {t("mcpChoiceRemove", undefined, "Remove folder entry (global applies again)")}
281
+ </button>
282
+ <button
283
+ type="button"
284
+ onClick={onReenter}
285
+ data-testid="mcp-choice-reenter"
286
+ className="px-2 py-1 min-h-11 min-w-11 sm:min-h-0 sm:min-w-0 rounded border border-[var(--accent-primary,#60a5fa)] text-[var(--accent-primary,#60a5fa)]"
287
+ >
288
+ {t("mcpChoiceReenter", undefined, "Re-enter omitted values")}
289
+ </button>
290
+ </div>
291
+ </div>
292
+ );
293
+ }
294
+
295
+ /** The provenance legend under the list. */
296
+ function FolderSummary({ view }: { view: EffectiveView }): React.ReactElement {
297
+ const t = useT();
298
+ const overrides = view.servers.filter((s) => s.overridesGlobal).length;
299
+ return (
300
+ <p data-testid="mcp-folder-summary" className="text-[10px] text-[var(--text-tertiary)] m-0">
301
+ {t(
302
+ "mcpFolderSummary",
303
+ { count: overrides },
304
+ `A folder entry replaces the global entry of the same name as a whole · ${overrides} override(s)`,
305
+ )}
306
+ </p>
307
+ );
308
+ }
309
+
310
+ function FolderMcpPageBody({ cwd }: { cwd: string }): React.ReactElement {
311
+ const t = useT();
312
+ const { view, loading, error, reload } = useEffectiveConfig(cwd);
313
+ const actions = useFolderActions(cwd, view, reload);
314
+ const narrow = useIsNarrow();
315
+
316
+ if (error instanceof ApiError && error.isNotAllowed) return <NotAllowed />;
317
+ if (error) {
318
+ const message = (error as Error).message;
319
+ return (
320
+ <p
321
+ data-testid="mcp-folder-error"
322
+ role="alert"
323
+ className="text-[11px] text-[var(--status-error,#f87171)] m-0"
324
+ >
325
+ {t("mcpFolderError", { message }, `Could not load the folder's MCP configuration: ${message}`)}{" "}
326
+ <button
327
+ type="button"
328
+ onClick={reload}
329
+ data-testid="mcp-folder-error-retry"
330
+ className="px-1.5 py-0.5 min-h-11 min-w-11 sm:min-h-0 sm:min-w-0 rounded border border-[var(--border-secondary)]"
331
+ >
332
+ {t("mcpFolderRetry", undefined, "Retry")}
333
+ </button>
334
+ </p>
335
+ );
336
+ }
337
+
338
+ const servers = view?.servers ?? [];
339
+
340
+ return (
341
+ <div className="space-y-2">
342
+ {view?.trusted === false && <UntrustedNotice />}
343
+ {actions.actionError && (
344
+ <p
345
+ data-testid="mcp-folder-action-error"
346
+ role="alert"
347
+ className="text-[11px] text-[var(--status-error,#f87171)] m-0"
348
+ >
349
+ {actions.actionError}
350
+ </p>
351
+ )}
352
+ {actions.omittedNote && (
353
+ <p
354
+ data-testid={`mcp-folder-omitted-${actions.omittedNote.key}`}
355
+ role="status"
356
+ className="text-[11px] text-[var(--text-secondary)] m-0"
357
+ >
358
+ {t(
359
+ "mcpFolderOmitted",
360
+ { name: actions.omittedNote.name, omitted: actions.omittedNote.omitted.join(", ") },
361
+ `The folder copy of ${actions.omittedNote.name} omits: ${actions.omittedNote.omitted.join(", ")}. Re-enter them via Edit.`,
362
+ )}
363
+ </p>
364
+ )}
365
+
366
+ <ServerList
367
+ servers={servers}
368
+ layers={view?.layers ?? []}
369
+ loading={loading}
370
+ scope={actions.scope}
371
+ onOpen={actions.open}
372
+ onAdd={actions.openAdd}
373
+ onChanged={actions.refreshed}
374
+ onNeedsChoice={actions.onNeedsChoice}
375
+ onOmitted={actions.onOmitted}
376
+ onRemoveOverride={actions.removeOverride}
377
+ chipsRemovable={!narrow}
378
+ />
379
+
380
+ {actions.choice && (
381
+ <NeedsChoicePanel
382
+ name={actions.choice.row.name}
383
+ omitted={actions.choice.omitted}
384
+ onRemove={actions.resolveChoiceRemove}
385
+ onReenter={actions.resolveChoiceReenter}
386
+ />
387
+ )}
388
+
389
+ {actions.undo && <UndoToast name={actions.undo.name} onUndo={actions.undoRemove} />}
390
+
391
+ {actions.editing && (
392
+ <ServerEditor
393
+ key={actions.editing.name}
394
+ name={actions.editing.name === "" ? null : actions.editing.name}
395
+ entry={actions.editing.entry}
396
+ omitted={actions.editing.omitted}
397
+ scope={actions.scope}
398
+ dialogTestId="mcp-folder-editor"
399
+ onClose={actions.closeEditor}
400
+ onChanged={actions.refreshed}
401
+ />
402
+ )}
403
+
404
+ {view && <FolderSummary view={view} />}
405
+ </div>
406
+ );
407
+ }
408
+
409
+ export function FolderMcpPage({ params, onBack }: FolderMcpPageProps): React.ReactElement {
410
+ const cwd = decodeFolderCwd(params.encodedCwd);
411
+ return (
412
+ <section data-testid="mcp-folder-page" className="p-3 space-y-2">
413
+ <PageHeader onBack={onBack} />
414
+ {cwd === null ? <NotAllowed /> : <FolderMcpPageBody cwd={cwd} />}
415
+ </section>
416
+ );
417
+ }