rho-coding-agent 3.9.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! Reconciles a loaded session's MCP servers with `config.toml` between its
//! turns (`rho/session/mcp/reload`), as the TUI's `/mcp reload` asks, so a
//! server added, changed, or given a stored secret since the session opened
//! reaches it without opening it again.

use rho_protocol::{
    RpcError, SessionMcpReloadOutcome, SessionMcpReloadParams, SessionMcpReloadResponse,
};

use super::{inspect::not_loaded, Sessions};

impl Sessions {
    /// Reloads the session's MCP servers from the config as it is now. A
    /// config that does not load, or a session that cannot reload, leaves
    /// them as they were, which the answer says, rather than failing the
    /// request.
    pub(in crate::app::daemon_host) async fn reload_mcp(
        &self,
        params: SessionMcpReloadParams,
    ) -> Result<SessionMcpReloadResponse, RpcError> {
        let session = self.between_turns(&params.session).await?;
        let global = self.settings.config_to_open().await;
        let mut runtime = session.runtime.lock().await;
        let runtime = runtime.as_mut().ok_or_else(not_loaded)?;
        let outcome = match global {
            Err(error) => SessionMcpReloadOutcome::Refused {
                reason: error.to_string(),
            },
            Ok(global) => match runtime.reload_mcp(&global.mcp, &session.config()).await {
                Ok(changes) => SessionMcpReloadOutcome::Reloaded {
                    kept: changes.kept,
                    started: changes.started,
                    stopped: changes.stopped,
                },
                Err(error) => SessionMcpReloadOutcome::Refused {
                    reason: error.to_string(),
                },
            },
        };
        // Clients see where the servers ended up, the tools they brought
        // included, even when the runtime kept its old list.
        session.tool_sources_attached(runtime).await;
        let inventory = session
            .mcp
            .lock()
            .unwrap_or_else(std::sync::PoisonError::into_inner)
            .snapshot();
        Ok(SessionMcpReloadResponse::new(outcome, inventory))
    }
}