Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(host): give Codex a server name nothing else uses, and know it by it

leepokaie12363f34500
diff --git a/docs/features/marketplace.md b/docs/features/marketplace.md
index 6da10cad..87aab2f3 100644
--- a/docs/features/marketplace.md
+++ b/docs/features/marketplace.md
@@ -32,7 +32,7 @@ Registry package installs use pinned package references: npm, PyPI and NuGet req
A custom connector is a command line (split like a shell), a URL, or a pasted MCP config (`importConnectors {config}`: the `mcpServers` / `servers` JSON from READMEs, Claude, Cursor or VS Code, or one server's entry); every server in a config is added.
-A connector installed on the computer (or an app connected through Composio) is turned on for every existing bot, and a new bot starts with all of them on; each bot can turn one off in its settings. An enabled connector is passed to the agent as an MCP server when its session starts or resumes. Local connectors are spawned by the agent; remote ones always go through the host's stdio proxy (`codync-host mcp remote`, `host/src/mcp.rs`), so they work with agents that only speak stdio and always carry a fresh token. The proxy speaks streamable HTTP and falls back to the older HTTP+SSE transport when the first POST fails with 400/404/405, as the MCP spec suggests. Each server is named after its connector id. codex-acp leaves out a requested server whose name Codex's own config already uses (its `[mcp_servers.<name>]`, disabled ones too, in `~/.codex`, `/etc/codex` or a `.codex` folder from the bot's folder up) and says so only in a startup notice, so for a Codex bot such a server is named `codync-<name>` instead (`agent/bot/codex_names.rs`, #217).
+A connector installed on the computer (or an app connected through Composio) is turned on for every existing bot, and a new bot starts with all of them on; each bot can turn one off in its settings. An enabled connector is passed to the agent as an MCP server when its session starts or resumes. Local connectors are spawned by the agent; remote ones always go through the host's stdio proxy (`codync-host mcp remote`, `host/src/mcp.rs`), so they work with agents that only speak stdio and always carry a fresh token. The proxy speaks streamable HTTP and falls back to the older HTTP+SSE transport when the first POST fails with 400/404/405, as the MCP spec suggests. Each server is named after its connector id. codex-acp leaves out a requested server whose name Codex's own config already uses (its `[mcp_servers.<name>]`, disabled ones too, in `$CODEX_HOME` (a saved one first, else `~/.codex`), `/etc/codex` or a `.codex` folder from the bot's folder up) and says so only in a startup notice, so for a Codex bot such a server is named `codync-<name>` instead, or `codync-<name>-2`… when that is taken too (`agent/bot/codex_names.rs`, #217). The calls of Codync's own `chat` and `memory` servers are recognized by the name the agent got, so a user's own `memory` server stays in the working steps.
Every `codync-host mcp` server Codync gives an agent, connectors and built-in tools alike, carries the host's data directory as `CODYNC_HOME` in its ACP `env` (`mcp::acp_server`): some agents start MCP servers with only a few environment variables (Hermes keeps PATH, HOME and the like), and without it a host with a custom `CODYNC_HOME` (a sandbox, a server) would leave those tools reading the wrong token.
diff --git a/host/src/agent/bot/codex_names.rs b/host/src/agent/bot/codex_names.rs
index 072a67b8..8223df7e 100644
--- a/host/src/agent/bot/codex_names.rs
+++ b/host/src/agent/bot/codex_names.rs
@@ -3,32 +3,60 @@
//! named like one of the user's Codex servers (`notion`) then never reaches the bot (#217), so it gets a free name.
use serde_json::Value;
-use std::collections::HashSet;
+use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use toml_edit::{DocumentMut, Item};
-/// Renames each of `servers` whose name a Codex config for `cwd` already defines.
-pub(super) async fn avoid_clashes(servers: &mut Value, cwd: &str) {
- let files = config_files(Path::new(cwd));
+/// Codync's servers that got another name for this agent: requested name -> the name the agent knows.
+pub(super) type Renamed = HashMap<String, String>;
+
+/// What the agent calls Codync's server `name`.
+pub(super) fn name_of<'a>(renamed: &'a Renamed, name: &'a str) -> &'a str {
+ renamed.get(name).map_or(name, String::as_str)
+}
+
+/// Renames each of `servers` whose name a Codex config for `cwd` already defines. `codex_home` is the agent's
+/// own `CODEX_HOME` when it has one.
+pub(super) async fn avoid_clashes(servers: &mut Value, cwd: &str, codex_home: Option<PathBuf>) -> Renamed {
+ let files = config_files(Path::new(cwd), codex_home);
match tokio::task::spawn_blocking(move || taken(&files)).await {
Ok(taken) => rename(servers, &taken),
- Err(e) => tracing::warn!(error = format!("{e:#}"), "couldn't read Codex's MCP server names"),
+ Err(e) => {
+ tracing::warn!(error = format!("{e:#}"), "couldn't read Codex's MCP server names");
+ Renamed::new()
+ }
}
}
-fn rename(servers: &mut Value, taken: &HashSet<String>) {
- for server in servers.as_array_mut().into_iter().flatten() {
- if let Some(name) = server["name"].as_str().filter(|name| taken.contains(*name)) {
- server["name"] = format!("codync-{name}").into();
- }
+/// A clashing server becomes `codync-<name>`, or `codync-<name>-2`… when that is taken too: by Codex's config
+/// or by another requested server.
+fn rename(servers: &mut Value, taken: &HashSet<String>) -> Renamed {
+ let list = servers.as_array_mut().map(Vec::as_mut_slice).unwrap_or_default();
+ let mut used: HashSet<String> = taken.clone();
+ used.extend(list.iter().filter_map(|s| s["name"].as_str().map(str::to_owned)));
+ let mut renamed = Renamed::new();
+ for server in list {
+ let Some(name) = server["name"].as_str().filter(|name| taken.contains(*name)).map(str::to_owned) else {
+ continue;
+ };
+ let free = (1..=used.len() + 1)
+ .map(|n| if n == 1 { format!("codync-{name}") } else { format!("codync-{name}-{n}") })
+ .find(|candidate| !used.contains(candidate))
+ .expect("one of more names than are used is free");
+ used.insert(free.clone());
+ server["name"] = free.clone().into();
+ renamed.insert(name, free);
}
+ renamed
}
/// The files Codex layers its config from: the user's and the system's, and `.codex/config.toml` in the folders
/// from `cwd` up (projects).
// ponytail: `[profiles.<name>.mcp_servers]` isn't read; add it if a profile's server ever clashes.
-fn config_files(cwd: &Path) -> Vec<PathBuf> {
- let user = std::env::var_os("CODEX_HOME").map(PathBuf::from).or_else(|| dirs::home_dir().map(|h| h.join(".codex")));
+fn config_files(cwd: &Path, codex_home: Option<PathBuf>) -> Vec<PathBuf> {
+ let user = codex_home
+ .or_else(|| std::env::var_os("CODEX_HOME").map(PathBuf::from))
+ .or_else(|| dirs::home_dir().map(|h| h.join(".codex")));
let mut files: Vec<PathBuf> = user.into_iter().map(|dir| dir.join("config.toml")).collect();
if cfg!(unix) {
files.push("/etc/codex/config.toml".into());
@@ -67,8 +95,18 @@ mod tests {
.expect("config");
let files: Vec<PathBuf> = project.ancestors().map(|d| d.join(".codex/config.toml")).collect();
let mut servers = json!([{"name": "notion"}, {"name": "memory"}, {"name": "chat"}]);
- rename(&mut servers, &taken(&files));
+ let renamed = rename(&mut servers, &taken(&files));
assert_eq!(servers, json!([{"name": "codync-notion"}, {"name": "codync-memory"}, {"name": "chat"}]));
+ assert_eq!(name_of(&renamed, "memory"), "codync-memory");
+ assert_eq!(name_of(&renamed, "chat"), "chat");
std::fs::remove_dir_all(dir).expect("cleanup");
}
+
+ #[test]
+ fn a_replacement_name_that_is_taken_too_moves_on() {
+ let taken: HashSet<String> = ["notion", "codync-notion"].map(str::to_owned).into();
+ let mut servers = json!([{"name": "notion"}, {"name": "codync-notion-2"}]);
+ rename(&mut servers, &taken);
+ assert_eq!(servers, json!([{"name": "codync-notion-3"}, {"name": "codync-notion-2"}]));
+ }
}
diff --git a/host/src/agent/bot/mod.rs b/host/src/agent/bot/mod.rs
index be18f6b8..729ae9e2 100644
--- a/host/src/agent/bot/mod.rs
+++ b/host/src/agent/bot/mod.rs
@@ -125,6 +125,7 @@ pub fn spawn(hub: Arc<Hub>, base: BotConfig) -> BotHandle {
cancel_deadline: None,
exit_tail: None,
tools_changed: false,
+ renamed: codex_names::Renamed::new(),
restart_after_turn: false,
fast_support,
idle_checked: Instant::now(),
@@ -302,6 +303,8 @@ struct Actor {
/// Connectors changed: restart the agent before the next turn so the
/// session is resumed with the new MCP servers.
tools_changed: bool,
+ /// Codync's MCP servers the agent knows by another name (`codex_names`), so their calls are still recognized.
+ renamed: codex_names::Renamed,
/// A change that restarts the agent (`restart_agent`) came during a turn: it restarts once the turn ends.
restart_after_turn: bool,
/// What the agent says about Fast mode; clients see it in the bot's runtime.
diff --git a/host/src/agent/bot/session.rs b/host/src/agent/bot/session.rs
index 19bbafc4..85da4dc8 100644
--- a/host/src/agent/bot/session.rs
+++ b/host/src/agent/bot/session.rs
@@ -183,9 +183,17 @@ impl Actor {
}
}
let mut servers = self.mcp_servers()?;
- if self.conn.as_ref().is_some_and(|c| c.adapter == Adapter::Codex) {
- codex_names::avoid_clashes(&mut servers, &self.cfg.cwd).await;
- }
+ self.renamed = if self.conn.as_ref().is_some_and(|c| c.adapter == Adapter::Codex) {
+ // A `CODEX_HOME` saved for Codex (`setAgentEnv`) is where its own config is.
+ let saved = crate::agent::auth::env(&self.hub.store, &self.cfg.backend).unwrap_or_else(|e| {
+ tracing::warn!(error = format!("{e:#}"), "couldn't read Codex's saved environment");
+ Vec::new()
+ });
+ let home = saved.into_iter().find(|(k, _)| k == "CODEX_HOME").map(|(_, v)| v.into());
+ codex_names::avoid_clashes(&mut servers, &self.cfg.cwd, home).await
+ } else {
+ codex_names::Renamed::new()
+ };
let instructions = self.conn.as_ref().map_or(Instructions::FirstMessage, Conn::instructions);
// Claude gets the frozen instructions as its system prompt. When a compaction
// re-rendered them, loading the session again swaps the prompt in (the adapter
diff --git a/host/src/agent/bot/tool_entry.rs b/host/src/agent/bot/tool_entry.rs
index 835ce52e..0690f37b 100644
--- a/host/src/agent/bot/tool_entry.rs
+++ b/host/src/agent/bot/tool_entry.rs
@@ -1,6 +1,7 @@
//! Tool-call entries: ACP content folded into output and diffs, the working line a call shows,
//! and which calls are the bot's own bookkeeping.
+use super::codex_names::{Renamed, name_of};
use crate::agent::acp;
use crate::chat::memory::files;
use crate::store::BotConfig;
@@ -66,23 +67,24 @@ fn diff_summary(path: &str, old: &str, new: &str) -> Value {
})
}
-/// A Codex call's `server.tool`: codex-acp titles it `mcp.chat.send_message` (older ones `chat.send_message`),
-/// and the server is `codync-chat` where the user's Codex config already has a `chat` (see `codex_names`).
-fn codex_call(title: &str) -> &str {
- let call = title.strip_prefix("mcp.").unwrap_or(title);
- call.strip_prefix("codync-").unwrap_or(call)
+/// A call of Codync's MCP server `server` (a tool starting with `tool`), by the name the agent titles it with:
+/// Claude's `mcp__chat__send_message`, codex-acp's `mcp.chat.send_message` (older ones `chat.send_message`), the
+/// server under the name Codex knows it by (`codync-chat` when the user's Codex config has its own `chat`).
+fn calls(title: &str, renamed: &Renamed, server: &str, tool: &str) -> bool {
+ let codex = title.strip_prefix("mcp.").unwrap_or(title);
+ title.starts_with(&format!("mcp__{server}__{tool}"))
+ || codex.starts_with(&format!("{}.{tool}", name_of(renamed, server)))
}
-/// Composing the bot's message: the `chat` MCP server's `send_message`, by the name the agent titles the call with.
-fn sends_message(title: &str) -> bool {
- title.starts_with("mcp__chat__send_message") || codex_call(title).starts_with("chat.send_message")
+/// Composing the bot's message: the `chat` MCP server's `send_message`.
+fn sends_message(title: &str, renamed: &Renamed) -> bool {
+ calls(title, renamed, "chat", "send_message")
}
/// Keeping the bot's memory: a call of the `memory` MCP server, or one that names a file in a memory folder the
/// bot sees (in its `locations` or diffs, as `chat::memory::turns::touched` reads them).
-fn keeps_memory(cfg: &BotConfig, data: &Value) -> bool {
- let title = data["title"].as_str().unwrap_or_default();
- if title.starts_with("mcp__memory__") || codex_call(title).starts_with("memory.") {
+fn keeps_memory(cfg: &BotConfig, renamed: &Renamed, data: &Value) -> bool {
+ if calls(data["title"].as_str().unwrap_or_default(), renamed, "memory", "") {
return true;
}
let folders: Vec<PathBuf> = files::layers(cfg).iter().map(|layer| files::folder(layer.as_deref())).collect();
@@ -98,16 +100,16 @@ fn keeps_memory(cfg: &BotConfig, data: &Value) -> bool {
/// Flags whether a call is the bot's own bookkeeping (composing its message, keeping its memory), which the
/// working steps a chat unfolds leave out. An update can change the title or paths, so the flag follows them.
/// Always written, so clients tell an older host's unflagged call from one that isn't bookkeeping.
-pub(super) fn mark_bookkeeping(cfg: &BotConfig, data: &mut Value) {
- let flag = sends_message(data["title"].as_str().unwrap_or_default()) || keeps_memory(cfg, data);
+pub(super) fn mark_bookkeeping(cfg: &BotConfig, renamed: &Renamed, data: &mut Value) {
+ let flag = sends_message(data["title"].as_str().unwrap_or_default(), renamed) || keeps_memory(cfg, renamed, data);
data["bookkeeping"] = flag.into();
}
/// The working line for a flagged tool call: composing a message reads as typing, and memory stays out of the
/// chat, its working line included (the memory settings show it).
-pub(super) fn activity(data: &Value) -> &str {
+pub(super) fn activity<'a>(data: &'a Value, renamed: &Renamed) -> &'a str {
let title = data["title"].as_str().unwrap_or("Tool");
- if sends_message(title) {
+ if sends_message(title, renamed) {
"Typing…"
} else if data["bookkeeping"] == true {
"Thinking…"
@@ -123,7 +125,16 @@ mod tests {
fn marked(mut data: Value) -> Value {
let cfg = serde_json::from_value(json!({"id": "b", "name": "Bot", "backend": "claude", "cwd": "/tmp"}))
.expect("a bot config");
- mark_bookkeeping(&cfg, &mut data);
+ mark_bookkeeping(&cfg, &Renamed::new(), &mut data);
+ data
+ }
+
+ /// Marked for a Codex bot whose Codex config has its own `memory` server.
+ fn marked_renamed(mut data: Value) -> Value {
+ let cfg = serde_json::from_value(json!({"id": "b", "name": "Bot", "backend": "codex", "cwd": "/tmp"}))
+ .expect("a bot config");
+ let renamed = Renamed::from([("memory".to_owned(), "codync-memory".to_owned())]);
+ mark_bookkeeping(&cfg, &renamed, &mut data);
data
}
@@ -136,7 +147,7 @@ mod tests {
json!({"title": "mcp__memory__edit_memory"}),
json!({"title": "memory.search_memory"}),
json!({"title": "mcp.chat.send_message"}),
- json!({"title": "mcp.codync-memory.edit_memory"}),
+ json!({"title": "mcp.memory.edit_memory"}),
json!({"title": "Write", "locations": [{"path": note}]}),
json!({"title": "Edit", "diffs": [{"path": note}]}),
] {
@@ -156,6 +167,13 @@ mod tests {
}
}
+ #[test]
+ fn a_renamed_server_is_ours_and_the_users_own_is_not() {
+ assert_eq!(marked_renamed(json!({"title": "mcp.codync-memory.edit_memory"}))["bookkeeping"], true);
+ assert_eq!(marked_renamed(json!({"title": "mcp.memory.create_entities"}))["bookkeeping"], false);
+ assert_eq!(marked_renamed(json!({"title": "mcp.chat.send_message"}))["bookkeeping"], true);
+ }
+
#[test]
fn bookkeeping_follows_the_title() {
let mut data = marked(json!({"title": "Tool"}));
@@ -166,10 +184,10 @@ mod tests {
#[test]
fn memory_work_reads_as_thinking() {
- assert_eq!(activity(&marked(json!({"title": "mcp__chat__send_message"}))), "Typing…");
- assert_eq!(activity(&marked(json!({"title": "mcp__memory__edit_memory"}))), "Thinking…");
- assert_eq!(activity(&marked(json!({"title": "Read src/memory.rs"}))), "Read src/memory.rs");
- assert_eq!(activity(&marked(json!({"title": "Terminal"}))), "Terminal");
+ assert_eq!(activity(&marked(json!({"title": "mcp__chat__send_message"})), &Renamed::new()), "Typing…");
+ assert_eq!(activity(&marked(json!({"title": "mcp__memory__edit_memory"})), &Renamed::new()), "Thinking…");
+ assert_eq!(activity(&marked(json!({"title": "Read src/memory.rs"})), &Renamed::new()), "Read src/memory.rs");
+ assert_eq!(activity(&marked(json!({"title": "Terminal"})), &Renamed::new()), "Terminal");
}
#[test]
diff --git a/host/src/agent/bot/updates.rs b/host/src/agent/bot/updates.rs
index 14d046de..9e8180ed 100644
--- a/host/src/agent/bot/updates.rs
+++ b/host/src/agent/bot/updates.rs
@@ -83,9 +83,9 @@ impl Actor {
"locations": u["locations"].clone(),
});
merge_tool_content(&mut data, &u["content"]);
- mark_bookkeeping(&self.cfg, &mut data);
+ mark_bookkeeping(&self.cfg, &self.renamed, &mut data);
crate::chat::memory::turns::touched(&self.hub, &self.cfg, &data);
- let working = activity(&data).to_owned();
+ let working = activity(&data, &self.renamed).to_owned();
if let Some(e) = self.add(EntryKind::Tool, turn, data) {
self.tools.insert(tool_id, e.id);
}
@@ -104,9 +104,9 @@ impl Actor {
e.data["locations"] = u["locations"].clone();
}
merge_tool_content(&mut e.data, &u["content"]);
- mark_bookkeeping(&self.cfg, &mut e.data);
+ mark_bookkeeping(&self.cfg, &self.renamed, &mut e.data);
crate::chat::memory::turns::touched(&self.hub, &self.cfg, &e.data);
- let working = (e.data["status"] == "in_progress").then(|| activity(&e.data).to_owned());
+ let working = (e.data["status"] == "in_progress").then(|| activity(&e.data, &self.renamed).to_owned());
self.hub.set_entry(&entry_id, &e.data);
if let Some(working) = working {
self.set_activity(&working);