agentmux_srv/server/app_api/
mcp_actor.rs1use crate::backend::rpc::actor::{actor_of, Actor};
15use crate::backend::rpc_types::RpcContext;
16use crate::backend::storage::store::Store;
17
18pub(crate) const REFUSAL: &str = "CONTAINER_AGENT: this would start a program on this computer, which a container agent can't ask for. Ask a host agent, or have the person add it in Connectors.";
20
21pub(crate) const UNKNOWN_REFUSAL: &str = "CONTAINER_AGENT: couldn't tell where this agent runs, so this would not be a program started for it on this computer. Ask a host agent, or have the person add it in Connectors.";
23
24fn runs_in_a_container(store: &Store, id: &str) -> Option<bool> {
26 let def_id = crate::backend::agent_resolve::resolve_agent_id(store, id).ok()?;
27 let def = store.agent_def_get(&def_id).ok()??;
28 Some(def.runtime().is_container())
29}
30
31pub(crate) fn catalog_server_runs_only_in_containers(mstore: &Store, identity_store: &Store, mcp_id: &str) -> bool {
35 let reach = identity_store.mcp_server_reach_all().ok().and_then(|all| all.get(mcp_id).copied()).unwrap_or_default();
36 if reach.all_agents || !reach.in_containers {
37 return false;
38 }
39 let Ok(bound) = mstore.mcp_server_bound_agent_ids(mcp_id) else {
40 return false;
41 };
42 !bound.is_empty() && bound.iter().all(|id| runs_in_a_container(mstore, id) == Some(true))
43}
44
45pub(crate) fn refuse_container_agent(store: &Store, ctx: &RpcContext, command: &str) -> Result<(), String> {
48 let actor = actor_of(ctx);
49 if let Actor::Agent(id) = &actor {
50 let refusal = match runs_in_a_container(store, id) {
51 Some(false) => None,
52 Some(true) => Some(REFUSAL),
53 None => Some(UNKNOWN_REFUSAL),
54 };
55 if let Some(why) = refusal {
56 tracing::warn!(command, actor = %actor.label(), "MCP server command refused: it would start on this computer");
57 return Err(why.to_string());
58 }
59 }
60 tracing::info!(command, actor = %actor.label(), "MCP server command asked for");
61 Ok(())
62}