Skip to main content

Module mcp_config_file

Module mcp_config_file 

Source
Expand description

Where an agent’s MCP config lives (#3680).

An agent’s working_directory may be the user’s own project. A launch used to write .mcp.json there, which overwrote the project’s own file and put the agent’s signing keys where a routine git add -A could publish them. This module is the one answer to “where is this agent’s MCP config”:

  • In a folder AgentMux owns (under its data directory) the file stays where it has always been, <working directory>/.mcp.json, which Claude Code reads on its own.
  • In a user’s project the file moves to AgentMux’s data directory, outside the project, in a folder keyed by the project path: <data dir>/mcp/<hash>/mcp.json. Claude is pointed at it with --mcp-config (it still reads the project’s own .mcp.json itself); every other harness is given the servers from it by srv. A launch never writes into the project.

The config has its own folder rather than a bare file because a container gets it as a bind mount. A single-file bind keeps the inode it was made with, so an atomic rewrite (a new inode) would leave a running container reading the old config; a directory bind follows the replacement.

The relocated file is written 0600 and lives under the data root AgentMux keeps owner-only. The path itself is derived by agentmux_common::mcp_config_path, so srv (which writes it) and agentmux-mcp doctor (which diagnoses it) cannot disagree.

Constants§

MCP_JSON
The file name every provider’s workspace MCP config uses.

Functions§

config_path
Where this agent’s MCP config is: in its working directory when AgentMux owns the folder, else under AgentMux’s data root.
host_config_path
Where a host agent’s MCP config is: config_path, except that it is outside a folder a container agent can write (host_relocated_path).
host_content
content as a host agent’s config is written for work_dir: as it is, except in a folder the rule holds for, where the agentmux command is named by its path (mcp_folder_rule::with_the_command_by_path). Every writer of a host agent’s config outside its folder passes the text through here.
host_relocated_path
The config of a host agent in work_dir when it is kept outside the folder: relocated_path for a user’s project. For any folder the rule of crate::backend::mcp_folder_rule holds for (a container agent can write it), AgentMux’s own included, it is in the folder kept for host agents alone (mcp_config_path::HOST_ONLY_DIR), which no container has in its mounts. None when the file belongs in the folder. Reads the disk and the store.
is_agent_owned_workdir
Whether work_dir is AgentMux’s own folder, where a launch may keep the agent’s .mcp.json as it always has.
read_for_turn
The MCP config a host turn reads: for a user’s project, AgentMux’s relocated config merged with the project’s own .mcp.json servers (read-only — the project file is never written), so a user’s servers keep reaching every harness, as they did when the launch merged them. None when neither file exists or is usable.
relocated_dir
The folder holding work_dir’s relocated config, or None when the folder is AgentMux’s own and the file belongs in it (<work_dir>/.mcp.json). This is what a container binds (a directory, not the file: see the module doc).
relocated_path
The relocated config for work_dir, or None when the folder is AgentMux’s own and the file belongs in it (<work_dir>/.mcp.json).
write_relocated
Write the relocated config content at path: parent folders created, the file 0600 on Unix, through a temporary file and a rename so it is never briefly readable.