Skip to main content

install_codex_mcp_config

Function install_codex_mcp_config 

Source
pub fn install_codex_mcp_config() -> Result<bool>
Expand description

Merge sqz’s MCP server entry into Codex’s user-level config.toml.

Codex reads MCP servers from ~/.codex/config.toml (or $CODEX_HOME/config.toml when set). The relevant TOML shape is:

[mcp_servers.sqz]
command = "sqz-mcp"
args = ["--transport", "stdio"]

Notes:

  • Key is mcp_servers (snake_case). JSON-tool users who write mcpServers will be quietly ignored by Codex.
  • We go through toml_edit so the user’s existing comments, key order, and formatting are preserved across the round-trip. Plain toml::from_str → toml::to_string wipes comments.

Idempotent: if [mcp_servers.sqz] is already present with a command field, we do not overwrite — the user may have tuned it. Returns Ok(false) in that case.

If the config file doesn’t exist yet, it is created with only sqz’s entry (and its parent ~/.codex/ directory is created on demand).