[Bug]: serve ignores <data-dir>/mcp_config.json (management commands read it), and MCPPROXY_DATA_DIR is documented but not implemented
What happened?
mcpproxy serve --data-dir <dir> does not read <dir>/mcp_config.json. Without --config, serve still discovers its config only in the working directory and $HOME/.mcpproxy, and applies the data dir afterwards as a process-only override. Every management command (token, upstream, status, …) does read <dir>/mcp_config.json (#854, #897, #908), so serve and the CLI disagree about which config is "the" config for the same --data-dir.
Observed with v0.71.1 (and current main): a config with "listen":"127.0.0.1:18495" and a fixed api_key sat in the data dir. serve --data-dir <dir> ignored it, created $HOME/.mcpproxy/mcp_config.json with 127.0.0.1:8080 and a freshly generated API key, and ran with that. In a container where the data dir is the only mounted location, the config on the volume is never used and the API key changes on every re-create. docs/getting-started/installation.md currently documents this as a trap ("Don't use MCPPROXY_DATA or a bare --data-dir…") and specs/111-personal-docker-image/research.md (R1) lists it as a known limitation and calls fixing it "right long-term".
Related doc/code mismatch: docs/configuration/environment-variables.md lists MCPPROXY_DATA_DIR ("Override data directory", and MCPPROXY_DATA as the backward-compat spelling), but the code only reads MCPPROXY_DATA; installation.md itself says MCPPROXY_DATA_DIR "is not implemented at all".
Expected behavior
serve --data-dir XreadsX/mcp_config.jsonwhen it exists (same file the management commands read), and on a first run with no config anywhere seeds the default there instead of under$HOME. An explicit--configstill wins; the legacy discovery stays the fallback whenXholds no config but one exists in the legacy locations.MCPPROXY_DATA_DIRworks as documented, as the environment spelling of--data-dir. LegacyMCPPROXY_DATAkeeps its current meaning (relocates the data directory only), and loses when both are set.
Steps to reproduce
mkdir /tmp/d && echo '{"listen":"127.0.0.1:18495","api_key":"my-fixed-key-123","enable_socket":false,"mcpServers":[]}' > /tmp/d/mcp_config.jsonHOME=/tmp/h mcpproxy serve --data-dir /tmp/d(with a clean/tmp/h)curl -H 'X-API-Key: my-fixed-key-123' http://127.0.0.1:18495/api/v1/statusfails; the proxy is on127.0.0.1:8080,/tmp/h/.mcpproxy/mcp_config.jsonwas created with a different key.MCPPROXY_DATA_DIR=/tmp/d mcpproxy servebehaves the same (the variable is not read at all).
MCPProxy version
v0.71.1 (personal) linux/amd64, and main at 1b5c0d17
Operating system
Linux
Relevant logs
None needed.
Notes
I have a fix with tests and doc updates ready and will open a PR that closes this issue. It is a behaviour change for one case: an instance started with --data-dir X that relied on the legacy config while a stale X/mcp_config.json also exists (SaveConfig can leave one there) would now read the one in X; I noted it in the CHANGELOG entry. Happy to narrow it (for example, only when the file exists and --config is absent, which is what it does now) if you prefer.
- [x] I searched existing issues and did not find a duplicate (related and closed: #854, #897, #908, #1396)