1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! 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(¶ms.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))
}
}