diff --git a/crates/op-host-desktop/src/main_tests.rs b/crates/op-host-desktop/src/main_tests.rs index a9b8464d4..8451c1906 100644 --- a/crates/op-host-desktop/src/main_tests.rs +++ b/crates/op-host-desktop/src/main_tests.rs @@ -155,4 +155,14 @@ fn startup_mcp_bootstrap_starts_live_server_for_enabled_cli() { 0, "ephemeral port should be reported after binding" ); + assert_eq!( + app.host + .editor_state() + .editor_ui + .agent_settings + .mcp_server + .port, + app.mcp_server.as_ref().expect("server").port(), + "settings should reflect the bound port so the server is not restarted on every reconcile" + ); } diff --git a/crates/op-host-desktop/src/mcp_runtime.rs b/crates/op-host-desktop/src/mcp_runtime.rs index 8fff34b7f..80ab96ea7 100644 --- a/crates/op-host-desktop/src/mcp_runtime.rs +++ b/crates/op-host-desktop/src/mcp_runtime.rs @@ -65,8 +65,20 @@ impl DesktopApp { } match mcp_live::McpLiveServer::start(port) { Ok(server) => { + let bound_port = server.port(); self.mcp_server = Some(server); - false + if bound_port != port { + self.host + .editor_state_mut() + .editor_ui + .agent_settings + .mcp_server + .port = bound_port; + self.host.mark_editor_state_dirty(); + true + } else { + false + } } Err(err) => { eprintln!("openpencil-desktop mcp: failed to start: {err}");