fix(mcp): sync live server bound port

This commit is contained in:
Kayshen-X 2026-06-02 09:41:53 +08:00
parent 61f50999e2
commit 776a06bcbc
2 changed files with 23 additions and 1 deletions

View file

@ -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"
);
}

View file

@ -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}");