From 58df4ac5c8ece92a768b88a30ed5de6a327afa90 Mon Sep 17 00:00:00 2001 From: Vantz Stockwell Date: Thu, 26 Mar 2026 14:28:13 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20MCP=20sees=20live=20sessions=20=E2=80=94?= =?UTF-8?q?=20wrap=20DashMap=20in=20Arc=20for=20shared=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DashMap::clone() deep-copies all entries into a new map. The MCP server's cloned SshService/SftpService/RdpService/ScrollbackRegistry were snapshots from startup that never saw new sessions. Fix: wrap all DashMap fields in Arc> so clones share the same underlying map. Sessions added after MCP startup are now visible to MCP tools. Affected: SshService, SftpService, RdpService, ScrollbackRegistry. Co-Authored-By: Claude Opus 4.6 (1M context) --- src-tauri/src/mcp/mod.rs | 4 ++-- src-tauri/src/rdp/mod.rs | 4 ++-- src-tauri/src/sftp/mod.rs | 4 ++-- src-tauri/src/ssh/session.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/mcp/mod.rs b/src-tauri/src/mcp/mod.rs index 8147157..faa2a2a 100644 --- a/src-tauri/src/mcp/mod.rs +++ b/src-tauri/src/mcp/mod.rs @@ -19,12 +19,12 @@ use crate::mcp::scrollback::ScrollbackBuffer; /// Shared between SSH/PTY output loops (writers) and MCP tools (readers). #[derive(Clone)] pub struct ScrollbackRegistry { - buffers: DashMap>, + buffers: Arc>>, } impl ScrollbackRegistry { pub fn new() -> Self { - Self { buffers: DashMap::new() } + Self { buffers: Arc::new(DashMap::new()) } } /// Create and register a new scrollback buffer for a session. diff --git a/src-tauri/src/rdp/mod.rs b/src-tauri/src/rdp/mod.rs index e049302..d43f9dd 100644 --- a/src-tauri/src/rdp/mod.rs +++ b/src-tauri/src/rdp/mod.rs @@ -76,13 +76,13 @@ struct RdpSessionHandle { } pub struct RdpService { - sessions: DashMap>, + sessions: Arc>>, } impl RdpService { pub fn new() -> Self { Self { - sessions: DashMap::new(), + sessions: Arc::new(DashMap::new()), } } diff --git a/src-tauri/src/sftp/mod.rs b/src-tauri/src/sftp/mod.rs index e8e39a6..d844668 100644 --- a/src-tauri/src/sftp/mod.rs +++ b/src-tauri/src/sftp/mod.rs @@ -99,13 +99,13 @@ pub struct SftpService { /// One `SftpSession` per SSH session, behind a mutex so async commands can /// take a shared reference to the `SftpService` and still mutably borrow /// individual sessions. - clients: DashMap>>, + clients: Arc>>>, } impl SftpService { pub fn new() -> Self { Self { - clients: DashMap::new(), + clients: Arc::new(DashMap::new()), } } diff --git a/src-tauri/src/ssh/session.rs b/src-tauri/src/ssh/session.rs index 1edff66..4e61d9a 100644 --- a/src-tauri/src/ssh/session.rs +++ b/src-tauri/src/ssh/session.rs @@ -76,13 +76,13 @@ impl client::Handler for SshClient { #[derive(Clone)] pub struct SshService { - sessions: DashMap>, + sessions: Arc>>, db: Database, } impl SshService { pub fn new(db: Database) -> Self { - Self { sessions: DashMap::new(), db } + Self { sessions: Arc::new(DashMap::new()), db } } pub async fn connect(&self, app_handle: AppHandle, hostname: &str, port: u16, username: &str, auth: AuthMethod, cols: u32, rows: u32, sftp_service: &SftpService, scrollback: &ScrollbackRegistry, error_watcher: &ErrorWatcher) -> Result {