@useavalon/caelence-agent 0.2.2-canary.2 → 0.2.2-canary.4

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.
@@ -88,6 +88,7 @@ import {
88
88
  import { FloatNotice } from "./FloatNotice";
89
89
  import { integrationMatches } from "./integration-search";
90
90
  import { LogoMark } from "./LogoMark";
91
+ import { McpPanel } from "./McpPanel";
91
92
  import { pickerKeyAction, pickerStartIndex, stepIndex } from "./picker-nav";
92
93
  import {
93
94
  enqueueMessage,
@@ -1935,6 +1936,45 @@ function IntegrationsPanel(
1935
1936
  bridge: BridgeClient;
1936
1937
  onNotice: (text: string) => void;
1937
1938
  }>,
1939
+ ): React.ReactElement {
1940
+ const [tab, setTab] = useState<"integrations" | "mcp">("integrations");
1941
+
1942
+ return (
1943
+ <div className="desk-integrations">
1944
+ <div className="desk-pane-tabs" role="tablist" aria-label="Integrations and MCP">
1945
+ <button
1946
+ type="button"
1947
+ role="tab"
1948
+ aria-selected={tab === "integrations"}
1949
+ className={tab === "integrations" ? "is-on" : undefined}
1950
+ onClick={() => setTab("integrations")}
1951
+ >
1952
+ Integrations
1953
+ </button>
1954
+ <button
1955
+ type="button"
1956
+ role="tab"
1957
+ aria-selected={tab === "mcp"}
1958
+ className={tab === "mcp" ? "is-on" : undefined}
1959
+ onClick={() => setTab("mcp")}
1960
+ >
1961
+ MCP
1962
+ </button>
1963
+ </div>
1964
+ {tab === "mcp" ? (
1965
+ <McpPanel bridge={props.bridge} onNotice={props.onNotice} />
1966
+ ) : (
1967
+ <HostedIntegrationsList bridge={props.bridge} onNotice={props.onNotice} />
1968
+ )}
1969
+ </div>
1970
+ );
1971
+ }
1972
+
1973
+ function HostedIntegrationsList(
1974
+ props: Readonly<{
1975
+ bridge: BridgeClient;
1976
+ onNotice: (text: string) => void;
1977
+ }>,
1938
1978
  ): React.ReactElement {
1939
1979
  const [items, setItems] = useState<PublicIntegration[] | null>(null);
1940
1980
  const [query, setQuery] = useState("");
@@ -1980,23 +2020,15 @@ function IntegrationsPanel(
1980
2020
  };
1981
2021
 
1982
2022
  if (!items && !loadFailed) {
1983
- return (
1984
- <div className="desk-integrations">
1985
- <p>Loading integrations</p>
1986
- </div>
1987
- );
2023
+ return <p>Loading integrations</p>;
1988
2024
  }
1989
2025
 
1990
2026
  if (!items && loadFailed) {
1991
- return (
1992
- <div className="desk-integrations">
1993
- <p className="desk-side-empty">Integrations could not be loaded</p>
1994
- </div>
1995
- );
2027
+ return <p className="desk-side-empty">Integrations could not be loaded</p>;
1996
2028
  }
1997
2029
 
1998
2030
  return (
1999
- <div className="desk-integrations">
2031
+ <>
2000
2032
  <p className="desk-integrations-lead">
2001
2033
  Hosted MCP servers the agent can call. App connectors for published sites stay in the
2002
2034
  builder.
@@ -2073,7 +2105,7 @@ function IntegrationsPanel(
2073
2105
  ) : null}
2074
2106
  </>
2075
2107
  )}
2076
- </div>
2108
+ </>
2077
2109
  );
2078
2110
  }
2079
2111
 
@@ -0,0 +1,268 @@
1
+ import { CheckIcon } from "@phosphor-icons/react/dist/csr/Check";
2
+ import { type ReactElement, useEffect, useState } from "react";
3
+ import { errorMessage } from "../../src/core/errors";
4
+ import { addMcp, type BridgeClient, getMcps, type PublicUserMcp, removeMcp } from "./api";
5
+
6
+ const LOCAL_MCP_PLACEHOLDER = `uvx mcp-server-fetch
7
+ or ------------------------
8
+ {
9
+ "mcpServers": {
10
+ "fetch": {
11
+ "command": "uvx",
12
+ "args": ["mcp-server-fetch"]
13
+ }
14
+ }
15
+ }`;
16
+
17
+ function mcpGlyph(item: PublicUserMcp): string {
18
+ if (item.kind === "http") return "URL";
19
+ const letters = item.label.replace(/[^a-zA-Z0-9]/g, "").slice(0, 2);
20
+ return letters.toUpperCase() || "MCP";
21
+ }
22
+
23
+ function mcpOrigin(item: PublicUserMcp): string {
24
+ if (item.origin === "config") return `${item.detail} · harness.config.ts`;
25
+ return item.detail;
26
+ }
27
+
28
+ function McpActions(
29
+ props: Readonly<{
30
+ item: PublicUserMcp;
31
+ pending: boolean;
32
+ onRemove: () => void;
33
+ }>,
34
+ ): ReactElement {
35
+ if (props.pending) {
36
+ return (
37
+ <span className="desk-integration-ok">
38
+ <span className="cel-chip__spin" aria-hidden="true" />
39
+ <span>Removing</span>
40
+ </span>
41
+ );
42
+ }
43
+ if (props.item.removable) {
44
+ return (
45
+ <button
46
+ type="button"
47
+ className="cel-btn cel-btn--quiet cel-btn--compact"
48
+ onClick={props.onRemove}
49
+ >
50
+ Remove
51
+ </button>
52
+ );
53
+ }
54
+ return (
55
+ <span className="desk-integration-ok">
56
+ <CheckIcon size={16} weight="regular" aria-hidden="true" />
57
+ In config
58
+ </span>
59
+ );
60
+ }
61
+
62
+ function McpRow(
63
+ props: Readonly<{
64
+ item: PublicUserMcp;
65
+ pending: boolean;
66
+ onRemove: () => void;
67
+ }>,
68
+ ): ReactElement {
69
+ const { item } = props;
70
+ return (
71
+ <li>
72
+ <span className="desk-integration-glyph desk-integration-mark" aria-hidden="true">
73
+ {mcpGlyph(item)}
74
+ </span>
75
+ <div>
76
+ <p>{item.label}</p>
77
+ <em>{mcpOrigin(item)}</em>
78
+ </div>
79
+ <div className="desk-integration-actions">
80
+ <McpActions item={item} pending={props.pending} onRemove={props.onRemove} />
81
+ </div>
82
+ </li>
83
+ );
84
+ }
85
+
86
+ export function McpPanel(
87
+ props: Readonly<{
88
+ bridge: BridgeClient;
89
+ onNotice: (text: string) => void;
90
+ }>,
91
+ ): ReactElement {
92
+ const [items, setItems] = useState<PublicUserMcp[] | null>(null);
93
+ const [loadFailed, setLoadFailed] = useState(false);
94
+ const [kind, setKind] = useState<"stdio" | "http">("stdio");
95
+ const [label, setLabel] = useState("");
96
+ const [command, setCommand] = useState("");
97
+ const [url, setUrl] = useState("");
98
+ const [token, setToken] = useState("");
99
+ const [busy, setBusy] = useState(false);
100
+ const [pendingId, setPendingId] = useState<string | null>(null);
101
+
102
+ useEffect(() => {
103
+ let alive = true;
104
+ void getMcps(props.bridge)
105
+ .then((result) => {
106
+ if (alive) setItems(result.items);
107
+ })
108
+ .catch((err: unknown) => {
109
+ if (!alive) return;
110
+ setLoadFailed(true);
111
+ props.onNotice(errorMessage(err));
112
+ });
113
+ return () => {
114
+ alive = false;
115
+ };
116
+ }, [props.bridge, props.onNotice]);
117
+
118
+ const submit = async (): Promise<void> => {
119
+ setBusy(true);
120
+ try {
121
+ const result = await addMcp(
122
+ props.bridge,
123
+ kind === "http"
124
+ ? { kind: "http", label: label.trim() || undefined, url: url.trim(), token: token.trim() }
125
+ : { kind: "stdio", label: label.trim() || undefined, command: command.trim() },
126
+ );
127
+ setItems(result.items);
128
+ setLabel("");
129
+ setCommand("");
130
+ setUrl("");
131
+ setToken("");
132
+ } catch (err) {
133
+ props.onNotice(errorMessage(err));
134
+ } finally {
135
+ setBusy(false);
136
+ }
137
+ };
138
+
139
+ const drop = async (id: string): Promise<void> => {
140
+ setPendingId(id);
141
+ try {
142
+ const result = await removeMcp(props.bridge, id);
143
+ setItems(result.items);
144
+ } catch (err) {
145
+ props.onNotice(errorMessage(err));
146
+ } finally {
147
+ setPendingId(null);
148
+ }
149
+ };
150
+
151
+ if (!items && !loadFailed) {
152
+ return <p>Loading MCP servers</p>;
153
+ }
154
+
155
+ if (!items && loadFailed) {
156
+ return <p className="desk-side-empty">MCP servers could not be loaded</p>;
157
+ }
158
+
159
+ const listed = items ?? [];
160
+ const canAdd = kind === "http" ? url.trim().length > 0 : command.trim().length > 0;
161
+
162
+ return (
163
+ <>
164
+ <p className="desk-integrations-lead">
165
+ Local command or URL MCP servers for this project. Paste a command, or an mcpServers JSON
166
+ block.
167
+ </p>
168
+ <div className="desk-pane-tabs desk-pane-tabs--compact" role="tablist" aria-label="MCP kind">
169
+ <button
170
+ type="button"
171
+ role="tab"
172
+ aria-selected={kind === "stdio"}
173
+ className={kind === "stdio" ? "is-on" : undefined}
174
+ onClick={() => setKind("stdio")}
175
+ >
176
+ Local
177
+ </button>
178
+ <button
179
+ type="button"
180
+ role="tab"
181
+ aria-selected={kind === "http"}
182
+ className={kind === "http" ? "is-on" : undefined}
183
+ onClick={() => setKind("http")}
184
+ >
185
+ URL
186
+ </button>
187
+ </div>
188
+ <form
189
+ className="desk-mcp-form"
190
+ onSubmit={(event) => {
191
+ event.preventDefault();
192
+ if (canAdd && !busy) void submit();
193
+ }}
194
+ >
195
+ <label>
196
+ <span>Name</span>
197
+ <input
198
+ className="cel-input"
199
+ value={label}
200
+ placeholder="Optional"
201
+ onChange={(event) => setLabel(event.target.value)}
202
+ />
203
+ </label>
204
+ {kind === "http" ? (
205
+ <>
206
+ <label>
207
+ <span>Server URL</span>
208
+ <input
209
+ className="cel-input"
210
+ value={url}
211
+ placeholder="http://127.0.0.1:3100/mcp"
212
+ autoComplete="off"
213
+ spellCheck={false}
214
+ onChange={(event) => setUrl(event.target.value)}
215
+ />
216
+ </label>
217
+ <label>
218
+ <span>Bearer token</span>
219
+ <input
220
+ className="cel-input"
221
+ type="password"
222
+ value={token}
223
+ placeholder="Optional"
224
+ autoComplete="off"
225
+ spellCheck={false}
226
+ onChange={(event) => setToken(event.target.value)}
227
+ />
228
+ </label>
229
+ </>
230
+ ) : (
231
+ <label>
232
+ <span>Command</span>
233
+ <textarea
234
+ className="cel-input"
235
+ rows={8}
236
+ value={command}
237
+ placeholder={LOCAL_MCP_PLACEHOLDER}
238
+ autoComplete="off"
239
+ spellCheck={false}
240
+ onChange={(event) => setCommand(event.target.value)}
241
+ />
242
+ </label>
243
+ )}
244
+ <button
245
+ type="submit"
246
+ className="cel-btn cel-btn--secondary cel-btn--compact"
247
+ disabled={!canAdd || busy}
248
+ >
249
+ {busy ? "Adding" : "Add"}
250
+ </button>
251
+ </form>
252
+ {listed.length === 0 ? (
253
+ <p className="desk-side-empty">No MCP servers yet. Add a local command or a URL.</p>
254
+ ) : (
255
+ <ul className="desk-integration-list">
256
+ {listed.map((item) => (
257
+ <McpRow
258
+ key={item.id}
259
+ item={item}
260
+ pending={pendingId === item.id}
261
+ onRemove={() => void drop(item.id)}
262
+ />
263
+ ))}
264
+ </ul>
265
+ )}
266
+ </>
267
+ );
268
+ }
@@ -250,6 +250,48 @@ export function disconnectIntegration(
250
250
  });
251
251
  }
252
252
 
253
+ export interface PublicUserMcp {
254
+ id: string;
255
+ label: string;
256
+ kind: "stdio" | "http";
257
+ detail: string;
258
+ origin: "user" | "config";
259
+ removable: boolean;
260
+ }
261
+
262
+ export interface AddMcpInput {
263
+ label?: string;
264
+ kind: "stdio" | "http";
265
+ command?: string;
266
+ args?: string;
267
+ url?: string;
268
+ token?: string;
269
+ }
270
+
271
+ export function getMcps(bridge: BridgeClient): Promise<{ items: PublicUserMcp[] }> {
272
+ return request(bridge, "/mcp");
273
+ }
274
+
275
+ export function addMcp(
276
+ bridge: BridgeClient,
277
+ input: AddMcpInput,
278
+ ): Promise<{ ok: boolean; items: PublicUserMcp[] }> {
279
+ return request(bridge, "/mcp/add", {
280
+ method: "POST",
281
+ body: JSON.stringify(input),
282
+ });
283
+ }
284
+
285
+ export function removeMcp(
286
+ bridge: BridgeClient,
287
+ id: string,
288
+ ): Promise<{ ok: boolean; items: PublicUserMcp[] }> {
289
+ return request(bridge, "/mcp/remove", {
290
+ method: "POST",
291
+ body: JSON.stringify({ id }),
292
+ });
293
+ }
294
+
253
295
  export function openUrl(bridge: BridgeClient, url: string): Promise<{ ok: boolean }> {
254
296
  return request(bridge, "/open", {
255
297
  method: "POST",
@@ -1630,6 +1630,75 @@ p.desk-line__caption {
1630
1630
  gap: 12px;
1631
1631
  }
1632
1632
 
1633
+ .desk-pane-tabs {
1634
+ display: flex;
1635
+ align-self: start;
1636
+ gap: 2px;
1637
+ padding: 3px;
1638
+ border-radius: var(--r-lg);
1639
+ background: var(--bg-inset);
1640
+ }
1641
+
1642
+ .desk-pane-tabs button {
1643
+ margin: 0;
1644
+ padding: 6px 12px;
1645
+ border: 0;
1646
+ border-radius: var(--r-md);
1647
+ background: transparent;
1648
+ color: var(--text-secondary);
1649
+ font: inherit;
1650
+ font-size: 13px;
1651
+ font-weight: 600;
1652
+ line-height: 1.2;
1653
+ cursor: pointer;
1654
+ }
1655
+
1656
+ .desk-pane-tabs button.is-on {
1657
+ background: var(--card);
1658
+ color: var(--text);
1659
+ box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 14%, transparent);
1660
+ }
1661
+
1662
+ .desk-pane-tabs button:focus-visible {
1663
+ outline: 1.5px solid var(--measure);
1664
+ outline-offset: 1px;
1665
+ }
1666
+
1667
+ .desk-pane-tabs--compact button {
1668
+ padding: 5px 10px;
1669
+ font-weight: 500;
1670
+ }
1671
+
1672
+ .desk-mcp-form {
1673
+ display: flex;
1674
+ flex-direction: column;
1675
+ gap: 10px;
1676
+ }
1677
+
1678
+ .desk-mcp-form label {
1679
+ display: flex;
1680
+ flex-direction: column;
1681
+ gap: 6px;
1682
+ }
1683
+
1684
+ .desk-mcp-form label > span:first-child {
1685
+ font-weight: 600;
1686
+ }
1687
+
1688
+ .desk-mcp-form .cel-btn {
1689
+ align-self: flex-start;
1690
+ }
1691
+
1692
+ .desk-mcp-form textarea.cel-input {
1693
+ height: auto;
1694
+ min-height: 148px;
1695
+ padding-top: 8px;
1696
+ padding-bottom: 8px;
1697
+ resize: vertical;
1698
+ line-height: 1.45;
1699
+ font-family: var(--mono);
1700
+ }
1701
+
1633
1702
  .desk-integrations-lead {
1634
1703
  margin: 0;
1635
1704
  color: var(--text-secondary);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/caelence-agent",
3
- "version": "0.2.2-canary.2",
3
+ "version": "0.2.2-canary.4",
4
4
  "description": "Caelence agent: Strands turn loop, local tools, skills, evals, and a themable terminal UI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,6 +58,7 @@ function fakeHarness(overrides: Partial<HarnessRuntime> = {}): HarnessRuntime {
58
58
  disabledSkills: () => [],
59
59
  enableSkill: () => ({ ok: true }),
60
60
  reloadIntegrations: async () => {},
61
+ reloadExtraMcp: async () => {},
61
62
  chat: async () => "",
62
63
  observability: {} as HarnessRuntime["observability"],
63
64
  close() {},
@@ -57,4 +57,46 @@ describe("exec approval", () => {
57
57
  await gate.request({ callId: "1", toolName: "exec", input: { command: "sudo ls" } }),
58
58
  ).toBe(false);
59
59
  });
60
+
61
+ test("prompt policy asks before ordinary file writes", async () => {
62
+ const asked: string[] = [];
63
+ const alwaysAllow = new Set<string>();
64
+ const gate = createExecApprovalGate({
65
+ policy: "prompt",
66
+ alwaysAllow,
67
+ ask: async (req) => {
68
+ asked.push(`${req.toolName}:${String(req.input.path)}`);
69
+ return true;
70
+ },
71
+ });
72
+ expect(
73
+ await gate.request({
74
+ callId: "1",
75
+ toolName: "write_file",
76
+ input: { path: "README.md", content: "x" },
77
+ }),
78
+ ).toBe(true);
79
+ expect(asked).toEqual(["write_file:README.md"]);
80
+ alwaysAllow.add("write_file");
81
+ alwaysAllow.add("edit_file");
82
+ expect(
83
+ await gate.request({
84
+ callId: "2",
85
+ toolName: "edit_file",
86
+ input: { path: "README.md", old: "x", new: "y" },
87
+ }),
88
+ ).toBe(true);
89
+ expect(asked).toEqual(["write_file:README.md"]);
90
+ });
91
+
92
+ test("deny and auto still allow file writes", async () => {
93
+ const deny = createExecApprovalGate({ policy: "deny" });
94
+ const auto = createExecApprovalGate({ policy: "auto" });
95
+ expect(
96
+ await deny.request({ callId: "1", toolName: "write_file", input: { path: "a.ts" } }),
97
+ ).toBe(true);
98
+ expect(
99
+ await auto.request({ callId: "2", toolName: "edit_file", input: { path: "a.ts" } }),
100
+ ).toBe(true);
101
+ });
60
102
  });
@@ -16,6 +16,10 @@ export function isRiskyToolCall(toolName: string): boolean {
16
16
  return toolName === "exec" || toolName === "git_commit";
17
17
  }
18
18
 
19
+ export function isFileWriteTool(toolName: string): boolean {
20
+ return toolName === "edit_file" || toolName === "write_file";
21
+ }
22
+
19
23
  /** Host-side denylist — local exec is the machine, not a sandbox. */
20
24
  export const DESTRUCTIVE_COMMAND_PATTERNS: readonly RegExp[] = [
21
25
  /\bsudo\b/,
@@ -55,10 +59,28 @@ export interface ExecApprovalGateDeps {
55
59
  alwaysAllow?: Set<string>;
56
60
  }
57
61
 
62
+ async function promptAsk(deps: ExecApprovalGateDeps, req: ApprovalRequest): Promise<boolean> {
63
+ deps.emit?.({
64
+ kind: "approval_request",
65
+ callId: req.callId,
66
+ toolName: req.toolName,
67
+ input: req.input,
68
+ });
69
+ if (!deps.ask) return false;
70
+ return deps.ask(req);
71
+ }
72
+
58
73
  export function createExecApprovalGate(deps: ExecApprovalGateDeps): ApprovalGate {
59
74
  const always = deps.alwaysAllow ?? new Set<string>();
60
75
  return {
61
76
  async request(req) {
77
+ if (isFileWriteTool(req.toolName)) {
78
+ if (always.has("write_file") || always.has("edit_file") || always.has(req.toolName)) {
79
+ return true;
80
+ }
81
+ if (deps.policy === "prompt" && deps.ask) return promptAsk(deps, req);
82
+ return true;
83
+ }
62
84
  if (!isRiskyToolCall(req.toolName)) return true;
63
85
  if (always.has(req.toolName)) return true;
64
86
  if (deps.policy === "deny") return false;
@@ -66,14 +88,7 @@ export function createExecApprovalGate(deps: ExecApprovalGateDeps): ApprovalGate
66
88
  if (deps.policy === "auto") {
67
89
  return !isLikelyDestructive(command);
68
90
  }
69
- deps.emit?.({
70
- kind: "approval_request",
71
- callId: req.callId,
72
- toolName: req.toolName,
73
- input: req.input,
74
- });
75
- if (!deps.ask) return false;
76
- return deps.ask(req);
91
+ return promptAsk(deps, req);
77
92
  },
78
93
  };
79
94
  }
package/src/core/mode.ts CHANGED
@@ -55,6 +55,7 @@ export function modePrompt(mode: AgentMode): string {
55
55
  return [
56
56
  "## Mode: agent",
57
57
  "You may edit files, run approved exec, and commit when the user asked for the change.",
58
+ "If they asked to change a file, call write_file or edit_file. Do not claim the write until the tool succeeds.",
58
59
  "Use todo_write for multi-step work. Prefer git_status / git_diff / git_log over exec for git.",
59
60
  ].join("\n");
60
61
  }
@@ -2,7 +2,7 @@ import { noopObservability } from "../observability/noop.ts";
2
2
  import { sanitize } from "../observability/sanitize.ts";
3
3
  import type { Observability } from "../observability/types.ts";
4
4
  import type { ApprovalGate } from "./approval.ts";
5
- import { isRiskyToolCall } from "./approval.ts";
5
+ import { isFileWriteTool, isRiskyToolCall } from "./approval.ts";
6
6
  import { errorMessage, isAbortError } from "./errors.ts";
7
7
  import type { AgentEventEmitter, MainModelProvider } from "./events.ts";
8
8
  import type { HookRunner } from "./hooks.ts";
@@ -359,7 +359,7 @@ async function invokeGuardedBody(
359
359
  result = errorResult(errorText);
360
360
  }
361
361
  let approved = true;
362
- if (!result && isRiskyToolCall(def.name)) {
362
+ if (!result && (isRiskyToolCall(def.name) || isFileWriteTool(def.name))) {
363
363
  approved = await approval.request({ callId, toolName: def.name, input });
364
364
  }
365
365
  if (result) {
@@ -439,6 +439,7 @@ export function buildSystemPrompt(input: {
439
439
  "You are a coding agent in this project.",
440
440
  `Project root: ${input.cwd}.`,
441
441
  "Prefer small, targeted edits. Use edit_file for snippets, write_file for new files.",
442
+ "If the user asked to change a file, call write_file or edit_file before you reply. Do not say you wrote, edited, or saved a file unless that tool returned success.",
442
443
  "Use read_file, glob, and grep to inspect the repo. Do not use exec to read or search files.",
443
444
  "Use git_status, git_diff, and git_log for git. git_commit requires approval and does not push.",
444
445
  "Read skills with read_skill when a task matches a skill name. Spawn a subagent with task for a focused job.",
@@ -21,6 +21,12 @@ import {
21
21
  } from "../integrations/connect.ts";
22
22
  import { readProviderOAuth, writeProviderOAuth } from "../integrations/oauth-clients.ts";
23
23
  import { listPublicIntegrations, removeConnection } from "../integrations/store.ts";
24
+ import {
25
+ type AddUserMcpInput,
26
+ addUserMcpServer,
27
+ listPublicMcps,
28
+ removeUserMcpServer,
29
+ } from "../mcp/user-servers.ts";
24
30
  import { transcribeAudio } from "../media/openrouter-generate.ts";
25
31
  import { readMediaPrefs } from "../media/prefs.ts";
26
32
  import { PRODUCT_NAME } from "../product.ts";
@@ -385,6 +391,31 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
385
391
  return json({ ok: true, items: listPublicIntegrations() });
386
392
  };
387
393
 
394
+ const mcpPage = () => ({ items: listPublicMcps(harness.cwd, harness.config.mcp) });
395
+
396
+ const route_get_mcp = async (_req: Request, _url: URL): Promise<Response> => {
397
+ return json(mcpPage());
398
+ };
399
+
400
+ const route_post_mcp_add = async (req: Request, _url: URL): Promise<Response> => {
401
+ const body = (await readJson(req)) as AddUserMcpInput;
402
+ const added = addUserMcpServer(harness.cwd, body, harness.config.mcp);
403
+ if ("error" in added) return json({ error: added.error }, 400);
404
+ await harness.reloadExtraMcp();
405
+ return json({ ok: true, ...mcpPage() });
406
+ };
407
+
408
+ const route_post_mcp_remove = async (req: Request, _url: URL): Promise<Response> => {
409
+ const body = await readJson(req);
410
+ const id = typeof body.id === "string" ? body.id.trim() : "";
411
+ if (!id) return json({ error: "id is required." }, 400);
412
+ if (!removeUserMcpServer(harness.cwd, id)) {
413
+ return json({ error: "MCP not found." }, 400);
414
+ }
415
+ await harness.reloadExtraMcp();
416
+ return json({ ok: true, ...mcpPage() });
417
+ };
418
+
388
419
  const skillsPage = (popular = cachedPopularSkills()) =>
389
420
  buildSkillsPage(
390
421
  withDisabledCatalogSkills(harness.skills, harness.disabledSkills()),
@@ -780,6 +811,9 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
780
811
  "GET /integrations": route_get_integrations,
781
812
  "POST /integrations/connect": route_post_integrations_connect,
782
813
  "POST /integrations/disconnect": route_post_integrations_disconnect,
814
+ "GET /mcp": route_get_mcp,
815
+ "POST /mcp/add": route_post_mcp_add,
816
+ "POST /mcp/remove": route_post_mcp_remove,
783
817
  "GET /skills": route_get_skills,
784
818
  "GET /skills/popular": route_get_skills_popular,
785
819
  "GET /skills/search": route_get_skills_search,