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.jsonitself); 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 contentas a host agent’s config is written forwork_dir: as it is, except in a folder the rule holds for, where theagentmuxcommand 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_dirwhen it is kept outside the folder:relocated_pathfor a user’s project. For any folder the rule ofcrate::backend::mcp_folder_ruleholds 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.Nonewhen the file belongs in the folder. Reads the disk and the store. - is_
agent_ owned_ workdir - Whether
work_diris AgentMux’s own folder, where a launch may keep the agent’s.mcp.jsonas 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.jsonservers (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.Nonewhen neither file exists or is usable. - relocated_
dir - The folder holding
work_dir’s relocated config, orNonewhen 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, orNonewhen the folder is AgentMux’s own and the file belongs in it (<work_dir>/.mcp.json). - write_
relocated - Write the relocated config
contentatpath: parent folders created, the file0600on Unix, through a temporary file and a rename so it is never briefly readable.