xonecas.io
64875
Mc

mini-coder / commit 326697c

fix: persist mcp server enabled state

xonecas2026-04-19 326697ca457c9b1f27c7625a6d2fce265dfe33e4 parent aa4298f

8 files changed

TODO.md+5−2
@@ -7,6 +7,11 @@ The spec and code are the sources of truth; this file is just the verified backl
77
88 ## Open issues:
99
10+- [ ] `/skill:name` is not in help text. It also doesn't appear in the `/` auto complete. It should appear and when selected or userd without `:name` it opens an select overlay with the skills list for the user to select it. Populates the input with the selected skill command: User selects `ui-design` skill, hits enter, the prompt reads `/skill:ui-design` and doesn't submit.
11+- [ ] Preserve the current slash-command draft when opening command autocomplete instead of clearing the input (`src/ui.ts`, `src/ui/commands.ts`)
12+
13+# Defered issues:
14+
1015 ## Theme config plan
1116
1217 - [ ] Extend the existing `settings.json` schema/loader with `theme` overrides and merge them into the active UI theme (`src/settings.ts`, `src/theme.ts`, `src/index.ts`, `spec.md`)
@@ -15,8 +20,6 @@ The spec and code are the sources of truth; this file is just the verified backl
1520 ## Verified UX / behavior debt
1621
1722 - [ ] Prevent `/session` from switching sessions mid-run (`src/ui/commands.ts`, `src/ui/agent.ts`)
18-- [ ] Preserve the current slash-command draft when opening command autocomplete instead of clearing the input (`src/ui.ts`, `src/ui/commands.ts`)
19-- [ ] Persist `/mcp` enabled/disabled state across app restarts (`src/settings.ts`, `src/index.ts`, `src/ui/commands.ts`, `spec.md`)
2023
2124 ## Product backlog
2225
spec.md+7−6
@@ -152,6 +152,8 @@ When `settings.json` includes `mcp.servers`, mini-coder connects to each configu
152152 Implementation details:
153153
154154 - Only MCP **tools** are imported. MCP prompts and resources are not surfaced in the UI yet.
155+- Each configured server entry stores a `name`, `url`, and `enabled` flag. When `enabled` is omitted while loading older configs, it defaults to `true`.
156+- Disabled servers are still discovered at startup so `/mcp` can re-enable them without reconnecting; the flag only controls whether their imported tools are exposed to new turns.
155157 - Imported tool names are prefixed as `<serverName>__<toolName>` so they stay stable and avoid collisions with built-ins and other servers.
156158 - Tool input schemas are forwarded from MCP JSON Schema into pi-ai tool definitions.
157159 - Tool calls execute through the MCP client and preserve text/image output directly. Unsupported MCP content kinds are summarized as text.
@@ -786,7 +788,7 @@ add tests for undo_
786788 | `/undo` | Remove the last conversational turn from history: the most recent user message and all assistant/tool messages that followed in that turn. Persisted UI messages are not part of turns and are not removed by `/undo`. Context-only — does not revert filesystem changes. …
787789 | `/reasoning` | Toggle display of model thinking/reasoning content in the log. The new on/off state is persisted immediately and restored on launch. When no setting exists yet, reasoning defaults to shown. …
788790 | `/verbose` | Toggle [verbose tool rendering](#verbose-tool-rendering) for shell previews/results, read previews/results, grep previews/results, edit previews, and edit errors. Successful edit results stay compact regardless of this setting. Todo tool results always render in full. …
789-| `/mcp` | Interactive MCP server selector. Lists discovered MCP servers with their current on/off state. Selecting a server toggles it for future turns and appends a UI-only notice with the exact tool delta, for example `Disabled MCP server "docs" (-3 tools).` Discovery and connection still happen only at startup; `/mcp` does not add, remove, or reload servers. …
791+| `/mcp` | Interactive MCP server selector. Lists discovered MCP servers with their current on/off state. Selecting a server toggles it for future turns, persists the new on/off state immediately, and appends a UI-only notice with the exact tool delta, for example `Disabled MCP server "docs" (-3 tools).` Discovery and connection still happen only at startup; `/mcp` does not add, remove, or reload servers. …
790792 | `/todo` | Append the current session todo list to the conversation pane as a UI-only checklist block. The message is persisted with the session, excluded from model context, and does not create a session by itself when no session exists yet. …
791793 | `/login` | Interactive OAuth login. Shows a selector with available OAuth providers and their login status (logged in / not logged in). Selecting a provider starts the browser-based OAuth flow. Uses pi-ai's OAuth registry. Credentials are persisted to the app data directory and used for provider discovery on subsequent launches. …
792794 | `/logout` | Interactive OAuth logout. Shows a selector with logged-in OAuth providers. Selecting one clears its saved credentials. …
@@ -860,9 +862,9 @@ On launch, mini-coder:
860862 - Invalid entries are dropped while loading settings. Duplicate custom provider names keep the first entry.
861863 - If an endpoint is unreachable, returns a non-2xx response, or the custom provider name conflicts with an already-available built-in provider, startup continues and a warning is added to the UI log.
862864 4. Connects user-configured MCP servers from `settings.json`.
863- - Each entry must provide a `name` and Streamable HTTP endpoint `url`.
865+ - Each entry must provide a `name` and Streamable HTTP endpoint `url`. It also stores an `enabled` flag; older entries that omit it default to enabled.
864866 - Invalid entries are dropped while loading settings. Duplicate MCP server names keep the first entry.
865- - Startup imports only MCP tools. Imported names are exposed to the model as `<serverName>__<toolName>`.
867+ - Startup imports only MCP tools. Imported names are exposed to the model as `<serverName>__<toolName>`, and only servers whose `enabled` flag is on are exposed to new turns.
866868 - If a server URL is invalid, the endpoint is unreachable, or the server exposes no tools, startup continues and a warning is added to the UI log.
867869 5. Selects the startup model, effort, reasoning visibility, and verbose mode from those settings when available.
868870 - `defaultModel`: if the saved provider/model is currently available, use it; otherwise fall back to the first available model for this launch.
@@ -920,10 +922,9 @@ mini-coder persists global user defaults in `~/.config/mini-coder/settings.json`
920922 - Unreachable or invalid custom providers do not block startup; mini-coder skips them and shows a warning in the interactive log.
921923 - Custom providers are discovered only at startup. There is currently no interactive slash command to add or remove them.
922924 - `mcp.servers` is an optional array of user-configured Streamable HTTP MCP endpoints.
923-- Each `mcp.servers` entry has a `name` and `url`. `name` must be a simple identifier (`A-Z`, `a-z`, `0-9`, `_`, `-`) because it becomes the imported tool prefix, for example `docs__search`.
925+- Each `mcp.servers` entry has a `name`, `url`, and `enabled` flag. `name` must be a simple identifier (`A-Z`, `a-z`, `0-9`, `_`, `-`) because it becomes the imported tool prefix, for example `docs__search`. Older entries that omit `enabled` default to `true` when loaded.
924926 - Invalid MCP entries are dropped while loading settings. Unreachable, invalid-URL, or tool-less MCP servers do not block startup; mini-coder skips them and shows a warning in the interactive log.
925-- MCP server discovery is startup-only. `/mcp` can toggle already-discovered servers on or off for future turns during the current app run, but there is still no interactive slash command to add, remove, or reload servers.
926-- `/mcp` changes only the current in-memory runtime state. It does not persist a setting change.
927+- MCP server discovery is startup-only. `/mcp` can toggle already-discovered servers on or off for future turns during the current app run, and that on/off state is persisted back to `settings.json`, but there is still no interactive slash command to add, remove, or reload servers.
927928 - Only MCP tools are imported today; MCP prompts and resources are not surfaced yet.
928929
929930 ## Session persistence
src/mcp.test.ts+9−5
@@ -140,7 +140,7 @@ test("discoverMcpServers_reachableServer_importsPrefixedToolsAndExecutesCalls",
140140
141141 const result = await discoverMcpServers(
142142 {
143- servers: [{ name: "docs", url: "http://docs.test/mcp" }],
143+ servers: [{ name: "docs", url: "http://docs.test/mcp", enabled: true }],
144144 },
145145 createFakeRuntime({ "http://docs.test/mcp": behavior }),
146146 );
@@ -200,11 +200,15 @@ test("discoverMcpServers_structuredFallbackResult_formatsStructuredContent", asy
200200
201201 const result = await discoverMcpServers(
202202 {
203- servers: [{ name: "state", url: "http://state.test/mcp" }],
203+ servers: [
204+ { name: "state", url: "http://state.test/mcp", enabled: false },
205+ ],
204206 },
205207 createFakeRuntime({ "http://state.test/mcp": behavior }),
206208 );
207209
210+ expect(result.servers[0]?.enabled).toBe(false);
211+
208212 const handler = result.servers[0]?.toolHandlers.get("state__inspect");
209213 const toolResult = await handler!({}, "/tmp");
210214
@@ -235,9 +239,9 @@ test("discoverMcpServers_invalidOrUnusableServers_skipsThemWithWarningsAndCleanu
235239 const result = await discoverMcpServers(
236240 {
237241 servers: [
238- { name: "bad-url", url: "not-a-url" },
239- { name: "empty", url: "http://empty.test/mcp" },
240- { name: "down", url: "http://down.test/mcp" },
242+ { name: "bad-url", url: "not-a-url", enabled: true },
243+ { name: "empty", url: "http://empty.test/mcp", enabled: true },
244+ { name: "down", url: "http://down.test/mcp", enabled: true },
241245 ],
242246 },
243247 createFakeRuntime({
src/mcp.ts+1−1
@@ -234,7 +234,7 @@ export async function discoverMcpServers(
234234 servers.push({
235235 name: entry.name,
236236 url: entry.url,
237- enabled: true,
237+ enabled: entry.enabled,
238238 tools,
239239 toolHandlers,
240240 close: () => transport.close(),
src/settings.test.ts+29−7
@@ -299,7 +299,11 @@ describe("settings", () => {
299299 mcp: {
300300 servers: [
301301 { name: "docs", url: "http://127.0.0.1:8787/mcp" },
302- { name: "github_tools", url: "https://example.com/mcp" },
302+ {
303+ name: "github_tools",
304+ url: "https://example.com/mcp",
305+ enabled: false,
306+ },
303307 ],
304308 },
305309 }),
@@ -309,8 +313,12 @@ describe("settings", () => {
309313 const settings = loadSettings(path);
310314 expect(settings.mcp).toEqual({
311315 servers: [
312- { name: "docs", url: "http://127.0.0.1:8787/mcp" },
313- { name: "github_tools", url: "https://example.com/mcp" },
316+ { name: "docs", url: "http://127.0.0.1:8787/mcp", enabled: true },
317+ {
318+ name: "github_tools",
319+ url: "https://example.com/mcp",
320+ enabled: false,
321+ },
314322 ],
315323 });
316324 });
@@ -324,7 +332,7 @@ describe("settings", () => {
324332 mcp: {
325333 servers: [
326334 { name: "docs", url: "http://127.0.0.1:8787/mcp" },
327- { name: "docs", url: "http://127.0.0.1:8788/mcp" },
335+ { name: "docs", url: "http://127.0.0.1:8788/mcp", enabled: false },
328336 { name: "bad name", url: "http://127.0.0.1:8789/mcp" },
329337 { name: "", url: "http://127.0.0.1:8790/mcp" },
330338 { name: "missing-url" },
@@ -338,7 +346,9 @@ describe("settings", () => {
338346
339347 const settings = loadSettings(path);
340348 expect(settings.mcp).toEqual({
341- servers: [{ name: "docs", url: "http://127.0.0.1:8787/mcp" }],
349+ servers: [
350+ { name: "docs", url: "http://127.0.0.1:8787/mcp", enabled: true },
351+ ],
342352 });
343353 });
344354
@@ -350,7 +360,13 @@ describe("settings", () => {
350360 JSON.stringify({
351361 verbose: false,
352362 mcp: {
353- servers: [{ name: "docs", url: "http://127.0.0.1:8787/mcp" }],
363+ servers: [
364+ {
365+ name: "docs",
366+ url: "http://127.0.0.1:8787/mcp",
367+ enabled: false,
368+ },
369+ ],
354370 },
355371 }),
356372 "utf-8",
@@ -361,7 +377,13 @@ describe("settings", () => {
361377 expect(updated).toEqual({
362378 verbose: true,
363379 mcp: {
364- servers: [{ name: "docs", url: "http://127.0.0.1:8787/mcp" }],
380+ servers: [
381+ {
382+ name: "docs",
383+ url: "http://127.0.0.1:8787/mcp",
384+ enabled: false,
385+ },
386+ ],
365387 },
366388 });
367389 });
src/settings.ts+5−2
@@ -2,7 +2,7 @@
22 * User settings persistence and startup resolution.
33 *
44 * Stores global defaults such as model, effort, reasoning visibility,
5- * verbose tool output, custom providers, and MCP server endpoints in a JSON
5+ * verbose tool output, custom providers, and MCP server settings in a JSON
66 * file under the app data directory.
77 *
88 * @module
@@ -30,6 +30,8 @@ export interface McpServerConfig {
3030 name: string;
3131 /** Absolute Streamable HTTP MCP endpoint URL. */
3232 url: string;
33+ /** Whether the server should start enabled. */
34+ enabled: boolean;
3335 }
3436
3537 /** MCP-related user settings. */
@@ -324,12 +326,13 @@ function parseMcpServer(item: unknown): McpServerConfig | null {
324326
325327 const name = readString(candidate, "name")?.trim() ?? "";
326328 const url = readString(candidate, "url")?.trim() ?? "";
329+ const enabled = readBoolean(candidate, "enabled") ?? true;
327330
328331 if (!name || !url || !MCP_SERVER_NAME_PATTERN.test(name)) {
329332 return null;
330333 }
331334
332- return { name, url };
335+ return { name, url, enabled };
333336 }
334337
335338 /**
src/ui/commands.test.ts+63−1
@@ -11,7 +11,7 @@ import {
1111 loadMessages,
1212 openDatabase,
1313 } from "../session.ts";
14-import { loadSettings } from "../settings.ts";
14+import { loadSettings, saveSettings } from "../settings.ts";
1515 import { DEFAULT_THEME } from "../theme.ts";
1616 import { createCommandController } from "./commands.ts";
1717 import type { ActiveOverlay } from "./overlay.ts";
@@ -397,6 +397,22 @@ describe("ui/commands", () => {
397397 close: async () => {},
398398 },
399399 ];
400+ state.settings = saveSettings(state.settingsPath, {
401+ mcp: {
402+ servers: [
403+ {
404+ name: "docs",
405+ url: "http://docs.test/mcp",
406+ enabled: true,
407+ },
408+ {
409+ name: "down",
410+ url: "http://down.test/mcp",
411+ enabled: false,
412+ },
413+ ],
414+ },
415+ });
400416 const runtimeState = { overlay: null as ActiveOverlay | null };
401417 const appended: Array<{
402418 text: string;
@@ -431,6 +447,36 @@ describe("ui/commands", () => {
431447
432448 expect(runtimeState.overlay).toBeNull();
433449 expect(state.mcpServers[0]?.enabled).toBe(false);
450+ expect(state.settings.mcp).toEqual({
451+ servers: [
452+ {
453+ name: "docs",
454+ url: "http://docs.test/mcp",
455+ enabled: false,
456+ },
457+ {
458+ name: "down",
459+ url: "http://down.test/mcp",
460+ enabled: false,
461+ },
462+ ],
463+ });
464+ expect(loadSettings(state.settingsPath)).toEqual({
465+ mcp: {
466+ servers: [
467+ {
468+ name: "docs",
469+ url: "http://docs.test/mcp",
470+ enabled: false,
471+ },
472+ {
473+ name: "down",
474+ url: "http://down.test/mcp",
475+ enabled: false,
476+ },
477+ ],
478+ },
479+ });
434480 expect(appended).toEqual([
435481 {
436482 text: 'Disabled MCP server "docs" (-2 tools).',
@@ -446,6 +492,22 @@ describe("ui/commands", () => {
446492 renderSelect(secondOverlay).props.onKeyPress?.("enter");
447493
448494 expect(state.mcpServers[0]?.enabled).toBe(true);
495+ expect(loadSettings(state.settingsPath)).toEqual({
496+ mcp: {
497+ servers: [
498+ {
499+ name: "docs",
500+ url: "http://docs.test/mcp",
501+ enabled: true,
502+ },
503+ {
504+ name: "down",
505+ url: "http://down.test/mcp",
506+ enabled: false,
507+ },
508+ ],
509+ },
510+ });
449511 expect(appended[1]).toEqual({
450512 text: 'Enabled MCP server "docs" (+2 tools).',
451513 sessionId: null,
src/ui/commands.ts+28−0
@@ -230,6 +230,33 @@ function formatMcpToggleMessage(
230230 return `${action} MCP server "${server.name}" (${delta} ${toolSuffix}).`;
231231 }
232232
233+function persistMcpServerSettings(
234+ state: AppState,
235+ server: AppState["mcpServers"][number],
236+): void {
237+ const currentServers = state.settings.mcp?.servers ?? [];
238+ let found = false;
239+ const servers = currentServers.map((entry) => {
240+ if (entry.name !== server.name) {
241+ return entry;
242+ }
243+ found = true;
244+ return { ...entry, enabled: server.enabled };
245+ });
246+
247+ if (!found) {
248+ servers.push({
249+ name: server.name,
250+ url: server.url,
251+ enabled: server.enabled,
252+ });
253+ }
254+
255+ state.settings = updateSettings(state.settingsPath, {
256+ mcp: { servers },
257+ });
258+}
259+
233260 /**
234261 * Create the UI command controller bound to the current UI runtime hooks.
235262 *
@@ -497,6 +524,7 @@ export function createCommandController(
497524 runtime.dismissOverlay();
498525 if (server) {
499526 server.enabled = !server.enabled;
527+ persistMcpServerSettings(state, server);
500528 runtime.appendInfoMessage(formatMcpToggleMessage(server), state);
501529 }
502530 },