Skip to content
45 changes: 42 additions & 3 deletions cmux-tui/crates/acpmux/src/agent_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,26 @@ fn resolve_with_cua_helper(
env: vec![],
});
}
if crate::cloud_repo_mcp::is_cloud_machine() {
if let Some(acpmux) = &inputs.acpmux {
// Cloud repository tools run on Cloud machines only. They forward
// the session caller token to the daemon action bridge.
servers.push(McpServer {
name: crate::cloud_repo_mcp::SERVER_NAME.into(),
command: acpmux.exe.clone(),
args: acpmux.args_lossy(&["repo-mcp"]),
env: executable("cmux")
.map(|path| ("CMUX_BIN".into(), path.to_string_lossy().into_owned()))
.into_iter()
.chain(
std::env::var("CMUX_SOCKET_PATH")
.ok()
.map(|path| ("CMUX_SOCKET_PATH".into(), path)),
)
.collect(),
});
}
}
if let Some(acpmux) = &inputs.acpmux {
// announce, rules and ack (`forum_mcp.rs`, hq#2570): acts as the
// session with its caller token, like the sub-session server.
Expand Down Expand Up @@ -706,19 +726,33 @@ impl AgentTools {
/// an allowlisted env to a stdio MCP server (Codex does).
pub fn for_session(mut self, session_id: &str) -> Self {
for server in &mut self.servers {
let repo_route: Vec<_> = if server.name == crate::cloud_repo_mcp::SERVER_NAME {
server
.env
.iter()
.filter(|(k, _)| matches!(k.as_str(), "CMUX_BIN" | "CMUX_SOCKET_PATH"))
.cloned()
.collect()
} else {
Vec::new()
};
server.env.retain(|(k, _)| k != AGENT_SESSION_ENV);
if server.name == "cmux" || server.name == MEMORY_SERVER_NAME {
server.env.push((AGENT_SESSION_ENV.to_owned(), session_id.to_owned()));
}
let session_env = match server.name.as_str() {
crate::secret_mcp::SERVER_NAME => Some(crate::secret_mcp::SESSION_ENV),
crate::offer_mcp::SERVER_NAME => Some(crate::offer_mcp::SESSION_ENV),
crate::cloud_repo_mcp::SERVER_NAME => Some(crate::cloud_repo_mcp::SESSION_ENV),
_ => None,
};
if let Some(key) = session_env {
if session_env.is_some() {
let socket = crate::config::socket_path().to_string_lossy().into_owned();
server.env = vec![
(key.to_owned(), session_id.to_owned()),
(
session_env.unwrap_or(crate::subsession_mcp::SESSION_ENV).to_owned(),
session_id.to_owned(),
),
("ACPMUX_SOCKET".to_owned(), socket),
("ACPMUX_HOME".to_owned(), home_env()),
];
Expand All @@ -730,10 +764,14 @@ impl AgentTools {
if server.name == crate::subsession_mcp::SERVER_NAME
|| server.name == crate::forum_mcp::SERVER_NAME
|| server.name == crate::acpmux_mcp::SERVER_NAME
|| server.name == crate::cloud_repo_mcp::SERVER_NAME
{
let socket = crate::config::socket_path().to_string_lossy().into_owned();
server.env = vec![
(crate::subsession_mcp::SESSION_ENV.to_owned(), session_id.to_owned()),
(
session_env.unwrap_or(crate::subsession_mcp::SESSION_ENV).to_owned(),
session_id.to_owned(),
),
("ACPMUX_SOCKET".to_owned(), socket),
("ACPMUX_HOME".to_owned(), home_env()),
];
Expand All @@ -743,6 +781,7 @@ impl AgentTools {
.map(|(k, v)| (k.to_owned(), v)),
);
}
server.env.extend(repo_route);
}
self
}
Expand Down
3 changes: 3 additions & 0 deletions cmux-tui/crates/acpmux/src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ pub enum Command {
/// for one agent session (agent_tools.rs registers it; not for people).
#[command(hide = true)]
ForumMcp,
/// The agent's Cloud repository tools (list_repos and add_repo), only on Cloud machines.
#[command(hide = true)]
RepoMcp,
/// The agent's tools to message other sessions and read them (send, ls, last, info): an
/// MCP stdio server for one agent session (agent_tools.rs registers it; not for people).
#[command(hide = true)]
Expand Down
17 changes: 12 additions & 5 deletions cmux-tui/crates/acpmux/src/cli/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ pub fn main(args: Vec<OsString>, invocation: Invocation) -> Result<()> {
/// subagent gets its own set, kept until the app-server exits), so a tokio
/// worker per core in each one adds up: about 100 tasks a set on a 32-core
/// machine, which filled the sessions slice's task cap on a fleet host.
const STDIO_MCP_SERVERS: [&str; 6] =
["acpmux-mcp", "subsession-mcp", "forum-mcp", "offer-mcp", "secret-mcp", "cua-mcp"];
const STDIO_MCP_SERVERS: [&str; 7] =
["acpmux-mcp", "subsession-mcp", "forum-mcp", "offer-mcp", "secret-mcp", "cua-mcp", "repo-mcp"];

/// Worker threads of a stdio MCP server: it answers one client's requests
/// on one pipe. Still a multi-thread runtime, so `block_in_place` works.
Expand Down Expand Up @@ -352,6 +352,7 @@ async fn async_main(args: Vec<OsString>, invocation: Invocation) -> Result<()> {
Some(Command::OfferMcp) => crate::offer_mcp::run().await,
Some(Command::SubsessionMcp) => crate::subsession_mcp::run().await,
Some(Command::ForumMcp) => crate::forum_mcp::run().await,
Some(Command::RepoMcp) => crate::cloud_repo_mcp::run().await,
Some(Command::AcpmuxMcp) => crate::acpmux_mcp::run().await,
Some(Command::Skill) => {
use std::io::Write;
Expand Down Expand Up @@ -394,9 +395,15 @@ mod tests {

#[test]
fn a_stdio_mcp_server_runs_on_a_small_runtime() {
for name in
["acpmux-mcp", "subsession-mcp", "forum-mcp", "offer-mcp", "secret-mcp", "cua-mcp"]
{
for name in [
"acpmux-mcp",
"subsession-mcp",
"forum-mcp",
"offer-mcp",
"secret-mcp",
"cua-mcp",
"repo-mcp",
] {
assert_eq!(runtime_workers(&os(&[name])), Some(MCP_WORKERS), "{name}");
assert_eq!(runtime_workers(&os(&["--json", name])), Some(MCP_WORKERS), "{name}");
}
Expand Down
Loading