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<DashMap<...>> 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) <noreply@anthropic.com>
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
//! MCP (Model Context Protocol) infrastructure for Wraith.
|
|
//!
|
|
//! Provides programmatic access to active sessions so AI tools running in the
|
|
//! copilot panel can read terminal output, execute commands, and enumerate
|
|
//! sessions.
|
|
|
|
pub mod scrollback;
|
|
pub mod server;
|
|
pub mod error_watcher;
|
|
pub mod bridge_manager;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use dashmap::DashMap;
|
|
|
|
use crate::mcp::scrollback::ScrollbackBuffer;
|
|
|
|
/// Registry of scrollback buffers keyed by session ID.
|
|
/// Shared between SSH/PTY output loops (writers) and MCP tools (readers).
|
|
#[derive(Clone)]
|
|
pub struct ScrollbackRegistry {
|
|
buffers: Arc<DashMap<String, Arc<ScrollbackBuffer>>>,
|
|
}
|
|
|
|
impl ScrollbackRegistry {
|
|
pub fn new() -> Self {
|
|
Self { buffers: Arc::new(DashMap::new()) }
|
|
}
|
|
|
|
/// Create and register a new scrollback buffer for a session.
|
|
pub fn create(&self, session_id: &str) -> Arc<ScrollbackBuffer> {
|
|
let buf = Arc::new(ScrollbackBuffer::new());
|
|
self.buffers.insert(session_id.to_string(), buf.clone());
|
|
buf
|
|
}
|
|
|
|
/// Get the scrollback buffer for a session.
|
|
pub fn get(&self, session_id: &str) -> Option<Arc<ScrollbackBuffer>> {
|
|
self.buffers.get(session_id).map(|entry| entry.clone())
|
|
}
|
|
|
|
/// Remove a session's scrollback buffer.
|
|
pub fn remove(&self, session_id: &str) {
|
|
self.buffers.remove(session_id);
|
|
}
|
|
}
|