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
51
52
53
54
55
56
//! 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, SessionCapability, SessionMcpReloadAnswer, SessionMcpReloadOutcome,
SessionMcpReloadParams,
};
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<SessionMcpReloadAnswer, RpcError> {
let session = self
.between_turns(¶ms.session, SessionCapability::McpReload)
.await?;
let global = self.settings.config_to_open().await;
let mut runtime = session.engine.lock().await;
let runtime = runtime
.as_mut()
.ok_or_else(not_loaded)?
.rho_for_mut(SessionCapability::McpReload)?;
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(SessionMcpReloadAnswer::new(outcome, inventory))
}
}