Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(mcp): allow clearing a server timeout override
vastsa445e48860d08
diff --git a/apps/desktop/src/components/extensions/McpEditorSheet.tsx b/apps/desktop/src/components/extensions/McpEditorSheet.tsxindex 12e513766..295166516 100644--- a/apps/desktop/src/components/extensions/McpEditorSheet.tsx+++ b/apps/desktop/src/components/extensions/McpEditorSheet.tsx@@ -138,15 +138,18 @@ export function draftToInput(const parsedTimeout = draft.timeoutSeconds.trim()? Number.parseInt(draft.timeoutSeconds.trim(), 10): undefined;+ const timeoutInput: { timeoutSeconds?: number | null } = {};+ if (!draft.timeoutSeconds.trim()) timeoutInput.timeoutSeconds = null;+ else if (typeof parsedTimeout === "number" && !Number.isNaN(parsedTimeout)) {+ timeoutInput.timeoutSeconds = parsedTimeout;+ }const base = {id: draft.id.trim(),...(context?.level ? { level: context.level } : {}),...(context?.projectPath ? { projectPath: context.projectPath } : {}),label: draft.label.trim() || draft.id.trim(),description: draft.description.trim() || undefined,- ...(typeof parsedTimeout === "number" && !Number.isNaN(parsedTimeout)- ? { timeoutSeconds: parsedTimeout }- : {}),+ ...timeoutInput,enabled: draft.enabled,scope: draft.scope,};diff --git a/apps/desktop/test/mcp-editor-timeout.test.mjs b/apps/desktop/test/mcp-editor-timeout.test.mjsnew file mode 100644index 000000000..29516f9e6--- /dev/null+++ b/apps/desktop/test/mcp-editor-timeout.test.mjs@@ -0,0 +1,41 @@+import assert from "node:assert/strict";+import test from "node:test";+import { fileURLToPath } from "node:url";+import { createServer } from "vite";++test("editing an MCP server can set or clear its timeout override", async () => {+ const server = await createServer({+ root: fileURLToPath(new URL("..", import.meta.url)),+ configFile: false,+ server: { middlewareMode: true, hmr: false, ws: false },+ esbuild: { jsx: "automatic" },+ appType: "custom",+ optimizeDeps: { noDiscovery: true, include: [] },+ });+ try {+ const { draftFromRecord, draftToInput, mcpDraftError } = await server.ssrLoadModule(+ "/src/components/extensions/McpEditorSheet.tsx",+ );+ const record = {+ id: "slow-server",+ label: "Slow server",+ transport: "stdio",+ command: "npx",+ enabled: true,+ timeoutSeconds: 45,+ };++ const edited = draftFromRecord(record);+ assert.equal(edited.timeoutSeconds, "45");+ edited.timeoutSeconds = "";+ assert.equal(mcpDraftError(edited), null);+ assert.equal(draftToInput(edited).timeoutSeconds, null);++ edited.timeoutSeconds = "90";+ assert.equal(draftToInput(edited).timeoutSeconds, 90);+ edited.timeoutSeconds = "601";+ assert.equal(mcpDraftError(edited), "extensions.mcp.errorTimeoutRange");+ } finally {+ await server.close();+ }+});diff --git a/crates/host-core/src/mcp_servers.rs b/crates/host-core/src/mcp_servers.rsindex 2b17006ac..6b4a289fa 100644--- a/crates/host-core/src/mcp_servers.rs+++ b/crates/host-core/src/mcp_servers.rs@@ -5,7 +5,7 @@ use crate::agent_capabilities::{CapabilityLevel, CapabilityState, CapabilityTarget,};use anyhow::{bail, Context, Result};-use serde::{Deserialize, Serialize};+use serde::{Deserialize, Deserializer, Serialize};use std::collections::{BTreeMap, HashSet};use std::fs;use std::path::Path;@@ -88,13 +88,23 @@ pub struct McpServerInput {pub env: Option<BTreeMap<String, String>>,pub url: Option<String>,pub headers: Option<BTreeMap<String, String>>,- pub timeout_seconds: Option<u64>,+ #[serde(default, deserialize_with = "deserialize_timeout_override")]+ pub timeout_seconds: Option<Option<u64>>,pub enabled: Option<bool>,/// Kept for protocol compatibility; capability state is app-local instead.#[allow(dead_code)]pub scope: Option<ActivationScope>,}+fn deserialize_timeout_override<'de, D>(+ deserializer: D,+) -> std::result::Result<Option<Option<u64>>, D::Error>+where+ D: Deserializer<'de>,+{+ Option::<u64>::deserialize(deserializer).map(Some)+}+pub struct McpServerRegistry {state: CapabilityState,}@@ -424,7 +434,7 @@ impl McpServerRegistry {transport,timeout_seconds: input.timeout_seconds- .or_else(|| current.and_then(|record| record.timeout_seconds)),+ .unwrap_or_else(|| current.and_then(|record| record.timeout_seconds)),..Default::default()};if config.transport == "stdio" {diff --git a/crates/host-core/src/mcp_servers/tests.rs b/crates/host-core/src/mcp_servers/tests.rsindex 164c14bb1..cc85b01b2 100644--- a/crates/host-core/src/mcp_servers/tests.rs+++ b/crates/host-core/src/mcp_servers/tests.rs@@ -56,6 +56,29 @@ fn config_round_trips_without_activation_fields() {assert_eq!(serde_json::from_str::<McpConfig>(&raw).unwrap().id, "files");}+#[test]+fn clearing_a_custom_timeout_restores_the_default() {+ let dir = tempdir().unwrap();+ let mut registry = McpServerRegistry::new(dir.path());+ let mut initial = stdio("slow-server");+ initial.timeout_seconds = Some(Some(45));+ let saved = registry.upsert(initial).unwrap();+ assert_eq!(saved.timeout_seconds, Some(45));++ let preserve = serde_json::from_value(serde_json::json!({ "id": "slow-server" })).unwrap();+ let preserved = registry.upsert(preserve).unwrap();+ assert_eq!(preserved.timeout_seconds, Some(45));++ let clear = serde_json::from_value(serde_json::json!({+ "id": "slow-server",+ "timeoutSeconds": null+ }))+ .unwrap();+ let updated = registry.upsert(clear).unwrap();++ assert_eq!(updated.timeout_seconds, None);+}+#[test]fn disabled_project_server_shadows_global_server() {let global = McpServerRecord {diff --git a/docs/spec/03-runtime/01-ipc-protocol.md b/docs/spec/03-runtime/01-ipc-protocol.mdindex 6e23b3177..84ec09552 100644--- a/docs/spec/03-runtime/01-ipc-protocol.md+++ b/docs/spec/03-runtime/01-ipc-protocol.md@@ -1470,6 +1470,9 @@ application-local `<data>/agent-capabilities/mcp.json` state file.- `mcp.list({ level, projectPath? })` → `{ servers: McpServerRecord[]; statuses: McpServerStatus[] }`- `mcp.active({ projectPath? })` → the effective runtime list- `mcp.upsert(server)` — creates or replaces the file at the requested level+- `McpServerInput.timeoutSeconds` accepts an integer from 1 through 600.+ Omitting it preserves the current value during an edit; sending `null` clears+ the override and restores the runtime default.- `mcp.remove({ id, level, projectPath? })`- `mcp.setEnabled({ id, enabled, level, projectPath? })`- `mcp.setScope` remains a compatibility-shaped call; the Settings page usesdiff --git a/docs/spec/04-ux/06-settings-ia.md b/docs/spec/04-ux/06-settings-ia.mdindex 3807a7a96..85cdba3af 100644--- a/docs/spec/04-ux/06-settings-ia.md+++ b/docs/spec/04-ux/06-settings-ia.md@@ -593,6 +593,9 @@ system while preserving their different data ownership:Move to Global. With no project selected the Move into <project> item is notoffered and the project group asks for a project selection instead, so acapability is never sent to an unnamed project.+- The MCP editor's optional connection timeout accepts 1–600 seconds. A blank+ value clears the server override and restores the default; saving a changed+ timeout refreshes that server's live connection.- Skeleton rows appear on first paint only. A later refresh keeps the rows italready has and dims the list instead, announcing the refresh to assistivetechnology, so toggling a switch never replaces the list with skeletons.diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 33ed8e590..01bb96f6a 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -7589,7 +7589,9 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.5. Ask again in each project.6. In the already-open `~/personal/site` session — assembled while the serverwas global — ask the agent to call one of the server's tools by name.- 7. Edit the server's `env` and save; ask in `~/work/api` again.+ 7. Edit the server's `env`, set a 45-second connection timeout, and save.+ Reopen it to confirm the value persisted, then clear the timeout and save.+ Ask in `~/work/api` again.8. Rename the server and re-scope it; ask once more.9. Point the server's command at a binary that does not exist, save, and opena new session.@@ -7621,6 +7623,8 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.- The `env` edit drops the connection: the next assembly or call re-handshakes, andthe tool's behaviour reflects the new value. The rename in step 8 does notreconnect anything.+ - The editor restores a saved timeout when reopened. Clearing it removes the+ override so the next connection uses the default handshake timeout.- The broken command records `failed` with a message, contributes no tools,and is not re-dialled on the following session assembly; pressing Testretries it.diff --git a/packages/shared/src/types/capabilities.ts b/packages/shared/src/types/capabilities.tsindex 358c771fc..506f73870 100644--- a/packages/shared/src/types/capabilities.ts+++ b/packages/shared/src/types/capabilities.ts@@ -83,7 +83,8 @@ export type McpServerInput = {env?: Record<string, string>;url?: string;headers?: Record<string, string>;- timeoutSeconds?: number;+ /** Set to null to clear an existing server-specific timeout override. */+ timeoutSeconds?: number | null;enabled?: boolean;scope?: ActivationScope;};