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): read Codex config as TOML and keep more credentials out of connector summaries

leepokaia337fd1f833d
diff --git a/host/Cargo.lock b/host/Cargo.lock
index 4bcc38f4..c7b8f25e 100644
--- a/host/Cargo.lock
+++ b/host/Cargo.lock
@@ -750,6 +750,7 @@ dependencies = [
"tokio",
"tokio-stream",
"tokio-tungstenite",
+ "toml_edit",
"tracing",
"tracing-subscriber",
"unicode-width",
diff --git a/host/Cargo.toml b/host/Cargo.toml
index 2ea9516e..c7091083 100644
--- a/host/Cargo.toml
+++ b/host/Cargo.toml
@@ -53,6 +53,7 @@ tar = "0.4.46"
tokio = { version = "1.53.1", features = ["full"] }
tokio-stream = { version = "0.1.19", features = ["sync"] }
tokio-tungstenite = { version = "0.29", features = ["rustls-tls-webpki-roots"] }
+toml_edit = { version = "0.25.15", default-features = false, features = ["parse"] }
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
unicode-width = "0.2"
diff --git a/host/src/agent/gear/connectors.rs b/host/src/agent/gear/connectors.rs
index e1f141b6..4af094d8 100644
--- a/host/src/agent/gear/connectors.rs
+++ b/host/src/agent/gear/connectors.rs
@@ -3,6 +3,7 @@
use serde_json::{Map, Value};
use std::path::Path;
+use toml_edit::{DocumentMut, Item};
use super::{MAX_ITEMS, MCP_BYTES, NAME_CHARS, TEXT_CHARS, clip, homes, read_limited};
@@ -86,35 +87,47 @@ fn command_text(server: &Map<String, Value>) -> String {
keep_public(&parts)
}
-/// Drops a flag or `NAME=value` named like a credential (and the value after such a flag) and a
-/// long letter-and-digit run; a URL keeps only its origin, since a path can carry a key.
+/// A command without its credentials. Each argument is split into words, so a `sh -c "…"` script
+/// is filtered too. Dropped: a header (`Authorization: Bearer …`), a flag or `NAME=value` named like
+/// a credential and the value after such a flag (`-H`, `-u` too), and a long letter-and-digit run.
+/// A URL keeps only its origin, since a path can carry a key.
fn keep_public(parts: &[String]) -> String {
let mut kept = Vec::new();
let mut skip_value = false;
for part in parts {
- if std::mem::take(&mut skip_value) {
+ if header(part) {
+ skip_value = false;
continue;
}
- let raw = part.trim().trim_matches(['"', '\'']);
- let (name, value) = raw.split_once('=').map_or((raw, None), |(name, value)| (name, Some(value)));
- // `--token=…`, `API_KEY=…`, a header (`-H`, `Authorization: Bearer …`).
- let key = raw.split(['=', ':']).next().unwrap_or(raw);
- if credential_name(key) || raw == "-H" || raw.to_ascii_lowercase().contains("bearer ") {
- skip_value = raw.starts_with('-') && value.is_none();
- continue;
- }
- if let Some(url) = value.filter(|v| v.contains("://")) {
- kept.push(format!("{name}={}", visible_url(url)));
- } else if raw.contains("://") {
- kept.push(visible_url(raw));
- } else if !token_run(raw) {
- kept.push(part.clone());
+ for word in part.split_whitespace() {
+ if std::mem::take(&mut skip_value) {
+ continue;
+ }
+ let raw = word.trim_matches(['"', '\'']);
+ let (name, value) = raw.split_once('=').map_or((raw, None), |(name, value)| (name, Some(value)));
+ if credential_name(name) || matches!(raw, "-H" | "-u") {
+ skip_value = raw.starts_with('-') && value.is_none();
+ } else if let Some(url) = value.filter(|v| v.contains("://")) {
+ kept.push(format!("{name}={}", visible_url(url)));
+ } else if raw.contains("://") {
+ kept.push(visible_url(raw));
+ } else if !token_run(raw) {
+ kept.push(raw.to_owned());
+ }
}
}
- kept.retain(|part| !part.is_empty());
+ kept.retain(|word| !word.is_empty());
kept.join(" ")
}
+/// `Authorization: Bearer …`, `X-Api-Key: …`: a whole header, dropped before it splits into words.
+fn header(part: &str) -> bool {
+ let lower = part.to_ascii_lowercase();
+ lower.contains("bearer ")
+ || lower.contains("basic ")
+ || part.split_once(':').is_some_and(|(name, _)| !name.contains(char::is_whitespace) && credential_name(name))
+}
+
fn credential_name(name: &str) -> bool {
let name = name.trim_start_matches('-').to_ascii_lowercase().replace('-', "_");
name.contains("api_key")
@@ -122,15 +135,26 @@ fn credential_name(name: &str) -> bool {
matches!(
seg,
"token"
+ | "tokens"
| "secret"
+ | "secrets"
| "password"
+ | "passwd"
+ | "pass"
+ | "pwd"
| "authorization"
| "apikey"
| "auth"
| "key"
+ | "keys"
| "header"
| "headers"
| "cookie"
+ | "cookies"
+ | "credential"
+ | "credentials"
+ | "user"
+ | "bearer"
)
})
}
@@ -155,117 +179,33 @@ fn visible_url(raw: &str) -> String {
}
}
-/// `[mcp_servers.name]` tables. `enabled = false` leaves the server out. Nested tables are skipped.
+/// `[mcp_servers.<name>]` tables in Codex's `config.toml`. `enabled = false` leaves the server out.
fn mcp_toml(text: &str) -> Vec<Named> {
- let mut out = Vec::new();
- let mut name: Option<String> = None;
- let mut server = TomlServer::default();
- let flush = |name: &mut Option<String>, server: &mut TomlServer, out: &mut Vec<Named>| {
- if let Some(name) = name.take()
- && !server.disabled
- {
- let name = clip(&name, NAME_CHARS);
- if !name.is_empty() {
- out.push(Named { name, description: String::new(), detail: clip(&server.detail(), TEXT_CHARS) });
- }
- }
- *server = TomlServer::default();
- };
- for line in text.lines() {
- let trimmed = line.trim();
- if trimmed.is_empty() || trimmed.starts_with('#') {
- continue;
- }
- if let Some(next) = toml_header(trimmed) {
- flush(&mut name, &mut server, &mut out);
- name = match next {
- TomlTable::Server(server) => Some(server),
- TomlTable::Other => None,
- };
- continue;
- }
- if name.is_none() {
- continue;
- }
- if super::toml_scalar(trimmed, "enabled").as_deref() == Some("false") {
- server.disabled = true;
- } else if let Some(url) = super::toml_scalar(trimmed, "url") {
- server.url = Some(url);
- } else if let Some(command) = super::toml_scalar(trimmed, "command") {
- server.command = split_command(&command);
- } else if let Some(args) = super::toml_scalar(trimmed, "args") {
- server.args = toml_strings(&args);
- }
- }
- flush(&mut name, &mut server, &mut out);
- out
-}
-
-/// One `[mcp_servers.name]` table as it is read, line by line.
-#[derive(Default)]
-struct TomlServer {
- disabled: bool,
- url: Option<String>,
- command: Vec<String>,
- args: Vec<String>,
-}
-
-impl TomlServer {
- fn detail(&self) -> String {
- if let Some(url) = &self.url {
- return visible_url(url);
- }
- keep_public(&[self.command.as_slice(), self.args.as_slice()].concat())
- }
+ let Ok(doc) = text.parse::<DocumentMut>() else { return Vec::new() };
+ let Some(servers) = doc.get("mcp_servers").and_then(Item::as_table_like) else { return Vec::new() };
+ servers
+ .iter()
+ .filter(|(_, server)| server.get("enabled").and_then(Item::as_bool) != Some(false))
+ .filter_map(|(name, server)| {
+ let name = clip(name, NAME_CHARS);
+ (!name.is_empty()).then(|| Named {
+ name,
+ description: String::new(),
+ detail: clip(&toml_detail(server), TEXT_CHARS),
+ })
+ })
+ .collect()
}
-/// The strings in a one-line TOML array (`["-y", 'pkg']`). An array split over several
-/// lines reads as empty, so the detail is the command alone.
-fn toml_strings(value: &str) -> Vec<String> {
- let Some(inner) = value.trim().strip_prefix('[').and_then(|v| v.strip_suffix(']')) else { return Vec::new() };
- let mut out = Vec::new();
- let mut current: Option<(char, String)> = None;
- let mut escaped = false;
- for c in inner.chars() {
- match &mut current {
- Some((quote, text)) => {
- if escaped {
- text.push(c);
- escaped = false;
- } else if c == '\\' && *quote == '"' {
- escaped = true;
- } else if c == *quote {
- out.push(std::mem::take(text));
- current = None;
- } else {
- text.push(c);
- }
- }
- None if c == '"' || c == '\'' => current = Some((c, String::new())),
- None => {}
- }
+fn toml_detail(server: &Item) -> String {
+ if let Some(url) = server.get("url").and_then(Item::as_str) {
+ return visible_url(url);
}
- out
-}
-
-fn split_command(command: &str) -> Vec<String> {
- command.split_whitespace().map(str::to_owned).collect()
-}
-
-enum TomlTable {
- Server(String),
- Other,
-}
-
-fn toml_header(line: &str) -> Option<TomlTable> {
- let inner = line.strip_prefix('[')?.strip_suffix(']')?.trim().trim_matches('"');
- let Some(rest) = inner.strip_prefix("mcp_servers.") else {
- return Some(TomlTable::Other);
- };
- if rest.is_empty() || rest.contains('.') {
- return Some(TomlTable::Other);
+ let mut parts: Vec<String> = server.get("command").and_then(Item::as_str).map(str::to_owned).into_iter().collect();
+ if let Some(args) = server.get("args").and_then(Item::as_array) {
+ parts.extend(args.iter().filter_map(|arg| arg.as_str().map(str::to_owned)));
}
- Some(TomlTable::Server(rest.to_owned()))
+ keep_public(&parts)
}
#[cfg(test)]
@@ -285,30 +225,55 @@ mod tests {
std::fs::create_dir_all(home.join(".claude")).expect("claude");
let pad = "x".repeat(300 * 1024);
let body = format!(
- r#"{{"history":"{pad}","mcpServers":{{"github":{{"command":"npx","args":["--api-key","abc123","-y","server","sk-abc123def456ghij78","--token=abc123","API_KEY=abc123","--header","Authorization: Bearer abc123","https://hooks.zapier.com/api/mcp/s/abc123/mcp"]}},"off":{{"command":"nope","enabled":false}},"zap":{{"url":"https://user:[email protected]/api/mcp/s/secret-token/mcp?token=1"}}}}}}"#
+ r#"{{"history":"{pad}","mcpServers":{{"github":{{"command":"npx","args":["--api-key","abc123","-y","server","sk-abc123def456ghij78","--token=abc123","API_KEY=abc123","--header","Authorization: Bearer abc123","https://hooks.zapier.com/api/mcp/s/abc123/mcp"]}},"off":{{"command":"nope","enabled":false}},"shell":{{"command":"sh","args":["-c","mcp-server --token abc123 --port 3000"]}},"basic":{{"command":"curl","args":["-u","alice:abc123","https://example.test/mcp","--user=alice:abc123"]}},"zap":{{"url":"https://user:[email protected]/api/mcp/s/secret-token/mcp?token=1"}}}}}}"#
);
std::fs::write(home.join(".claude.json"), body).expect("claude.json");
let connectors = list("claude", &home);
- assert_eq!(connectors.iter().map(|c| c.name.as_str()).collect::<Vec<_>>(), ["github", "zap"]);
- assert_eq!(connectors[0].detail, "npx -y server https://hooks.zapier.com");
- assert_eq!(connectors[1].detail, "https://hooks.zapier.com");
- let dumped = format!("{} {}", connectors[0].detail, connectors[1].detail);
- assert!(!dumped.contains("abc123") && !dumped.contains("secret"), "{dumped}");
+ let mut names = connectors.iter().map(|c| c.name.as_str()).collect::<Vec<_>>();
+ names.sort_unstable();
+ assert_eq!(names, ["basic", "github", "shell", "zap"]);
+ assert_eq!(detail(&connectors, "github"), "npx -y server https://hooks.zapier.com");
+ assert_eq!(detail(&connectors, "shell"), "sh -c mcp-server --port 3000");
+ assert_eq!(detail(&connectors, "basic"), "curl https://example.test");
+ assert_eq!(detail(&connectors, "zap"), "https://hooks.zapier.com");
+ let dumped = connectors.iter().map(|c| c.detail.as_str()).collect::<Vec<_>>().join(" ");
+ assert!(!dumped.contains("abc123") && !dumped.contains("secret") && !dumped.contains("alice"), "{dumped}");
let _ = std::fs::remove_dir_all(root);
}
+ fn detail<'a>(connectors: &'a [Named], name: &str) -> &'a str {
+ connectors.iter().find(|c| c.name == name).map_or("<missing>", |c| c.detail.as_str())
+ }
+
#[test]
- fn a_disabled_codex_server_is_left_out() {
+ fn codex_servers_read_as_toml() {
let root = scratch();
let home = root.join("home");
std::fs::create_dir_all(home.join(".codex")).expect("codex");
std::fs::write(
home.join(".codex/config.toml"),
- "[mcp_servers.github]\ncommand = \"github-mcp\"\nenabled = false # temporarily off\n\n[mcp_servers.play]\ncommand = \"npx\"\nargs = [\"-y\", '@playwright/mcp', \"--api-key\", \"abc123\", \"-H\", \"X-Api-Key: abc123\"]\n\n[mcp_servers.docs]\nurl = \"https://alice:[email protected]/mcp?key=xyz\" # kept\n\n[mcp_servers.docs.env]\nTOKEN = \"secret-token\"\n",
+ r#"[mcp_servers.github]
+command = "github-mcp"
+enabled = false # temporarily off
+
+[mcp_servers.play] # personal
+command = "npx"
+args = [
+ "-y", '@playwright/mcp',
+ "--api-key", "abc123",
+ "-H", "X-Api-Key: abc123",
+]
+
+[mcp_servers."docs.v2"]
+url = "https://alice:[email protected]/mcp?key=xyz" # kept
+
+[mcp_servers."docs.v2".env]
+TOKEN = "secret-token"
+"#,
)
.expect("toml");
let connectors = list("codex", &home);
- assert_eq!(connectors.iter().map(|c| c.name.as_str()).collect::<Vec<_>>(), ["play", "docs"]);
+ assert_eq!(connectors.iter().map(|c| c.name.as_str()).collect::<Vec<_>>(), ["play", "docs.v2"]);
assert_eq!(connectors[0].detail, "npx -y @playwright/mcp");
assert_eq!(connectors[1].detail, "https://example.test");
let dumped = format!("{} {}", connectors[0].detail, connectors[1].detail);
diff --git a/host/src/agent/gear/mod.rs b/host/src/agent/gear/mod.rs
index c3468b45..1fb67b79 100644
--- a/host/src/agent/gear/mod.rs
+++ b/host/src/agent/gear/mod.rs
@@ -99,40 +99,3 @@ pub(super) fn skipped_name(name: &str) -> bool {
pub(super) fn is_dir(path: &Path) -> bool {
std::fs::metadata(path).is_ok_and(|meta| meta.is_dir())
}
-
-/// `key = value` on one TOML line. A `#` comment after the value is not part of it.
-pub(super) fn toml_scalar(line: &str, key: &str) -> Option<String> {
- let code = strip_toml_comment(line.trim());
- let rest = code.strip_prefix(key)?.trim_start();
- let rest = rest.strip_prefix('=')?.trim();
- let value = rest.trim().trim_matches(['"', '\'']).trim();
- (!value.is_empty()).then(|| value.to_owned())
-}
-
-/// Drops a trailing `#` comment. A `#` inside quotes stays.
-fn strip_toml_comment(line: &str) -> &str {
- let mut quote = None;
- let mut escaped = false;
- for (i, c) in line.char_indices() {
- if escaped {
- escaped = false;
- continue;
- }
- if c == '\\' && quote == Some('"') {
- escaped = true;
- continue;
- }
- if c == '"' || c == '\'' {
- quote = match quote {
- Some(open) if open == c => None,
- None => Some(c),
- other => other,
- };
- continue;
- }
- if c == '#' && quote.is_none() {
- return line[..i].trim_end();
- }
- }
- line
-}
diff --git a/host/src/agent/gear/plugins.rs b/host/src/agent/gear/plugins.rs
index 2bdf40d5..263b9539 100644
--- a/host/src/agent/gear/plugins.rs
+++ b/host/src/agent/gear/plugins.rs
@@ -5,6 +5,7 @@
use serde_json::Value;
use std::collections::HashSet;
use std::path::Path;
+use toml_edit::{DocumentMut, Item};
use super::{MAX_DEPTH, MAX_ITEMS, MCP_BYTES, NAME_CHARS, TEXT_CHARS, clip, homes, is_dir, read_limited, skipped_name};
@@ -112,50 +113,33 @@ fn read_copilot(home: &Path, out: &mut Vec<Named>) {
walk_plugins(&path, 0, out);
}
+/// `[plugins."<name>@<marketplace>"]` tables in Codex's `config.toml`, each named by its cached
+/// manifest. `enabled = false` leaves the plugin out.
fn read_codex(home: &Path, out: &mut Vec<Named>) {
let Some(text) = read_limited(&home.join(".codex/config.toml"), MCP_BYTES) else { return };
+ let Ok(doc) = text.parse::<DocumentMut>() else { return };
+ let Some(plugins) = doc.get("plugins").and_then(Item::as_table_like) else { return };
let cache = home.join(".codex/plugins/cache");
- let mut current: Option<(String, String)> = None;
- let mut disabled = false;
- let flush = |current: &mut Option<(String, String)>, disabled: &mut bool, out: &mut Vec<Named>| {
- if let Some((name, market)) = current.take()
- && !*disabled
- && out.len() < MAX_ITEMS
- {
- let dir = cache.join(&market).join(&name);
- let item = manifest_under(&dir).unwrap_or(Named {
- name: clip(&name, NAME_CHARS),
- description: String::new(),
- detail: String::new(),
- });
- if !item.name.is_empty() {
- out.push(item);
- }
+ for (key, plugin) in plugins.iter() {
+ if out.len() >= MAX_ITEMS {
+ return;
}
- *disabled = false;
- };
- for line in text.lines() {
- let trimmed = line.trim();
- if let Some((name, market)) = codex_header(trimmed) {
- flush(&mut current, &mut disabled, out);
- current = Some((name, market));
+ if plugin.get("enabled").and_then(Item::as_bool) == Some(false) {
continue;
}
- if current.is_some() && super::toml_scalar(trimmed, "enabled").as_deref() == Some("false") {
- disabled = true;
+ let Some((name, market)) = key.split_once('@').filter(|(name, market)| !name.is_empty() && !market.is_empty())
+ else {
+ continue;
+ };
+ let item = manifest_under(&cache.join(market).join(name)).unwrap_or(Named {
+ name: clip(name, NAME_CHARS),
+ description: String::new(),
+ detail: String::new(),
+ });
+ if !item.name.is_empty() {
+ out.push(item);
}
}
- flush(&mut current, &mut disabled, out);
-}
-
-fn codex_header(line: &str) -> Option<(String, String)> {
- let inner = line.strip_prefix('[')?.strip_suffix(']')?.trim();
- let rest = inner.strip_prefix("plugins.")?.trim_matches('"');
- if rest.is_empty() || rest.contains('.') {
- return None;
- }
- let (name, market) = rest.split_once('@')?;
- (!name.is_empty() && !market.is_empty()).then(|| (name.to_owned(), market.to_owned()))
}
fn walk_plugins(dir: &Path, depth: usize, out: &mut Vec<Named>) {
@@ -267,7 +251,7 @@ mod tests {
std::fs::write(plug.join("plugin.json"), r#"{"name":"docs","description":"Write docs"}"#).expect("manifest");
std::fs::write(
home.join(".codex/config.toml"),
- "[plugins.\"docs@openai-bundled\"]\n\n[plugins.\"browser@openai-bundled\"]\nenabled = false # temporarily off\n\n[plugins.\"docs@openai-bundled\".env]\nTOKEN = \"secret-token\"\n",
+ "[plugins.\"docs@openai-bundled\"] # pinned\n\n[mcp_servers.off]\nenabled = false\n\n[plugins.\"browser@openai-bundled\"]\nenabled = false # temporarily off\n\n[plugins.\"docs@openai-bundled\".env]\nTOKEN = \"secret-token\"\n",
)
.expect("config");
let plugins = list("codex", &home);