mcpproxy-go icon indicating copy to clipboard operation
mcpproxy-go copied to clipboard

[Bug]: serve ignores <data-dir>/mcp_config.json (management commands read it), and MCPPROXY_DATA_DIR is documented but not implemented

Open james-crowley opened this issue 1 month ago • 0 comments

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 X reads X/mcp_config.json when 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 --config still wins; the legacy discovery stays the fallback when X holds no config but one exists in the legacy locations.
  • MCPPROXY_DATA_DIR works as documented, as the environment spelling of --data-dir. Legacy MCPPROXY_DATA keeps its current meaning (relocates the data directory only), and loses when both are set.

Steps to reproduce

  1. mkdir /tmp/d && echo '{"listen":"127.0.0.1:18495","api_key":"my-fixed-key-123","enable_socket":false,"mcpServers":[]}' > /tmp/d/mcp_config.json
  2. HOME=/tmp/h mcpproxy serve --data-dir /tmp/d (with a clean /tmp/h)
  3. curl -H 'X-API-Key: my-fixed-key-123' http://127.0.0.1:18495/api/v1/status fails; the proxy is on 127.0.0.1:8080, /tmp/h/.mcpproxy/mcp_config.json was created with a different key.
  4. MCPPROXY_DATA_DIR=/tmp/d mcpproxy serve behaves 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)

james-crowley avatar Oct 20 '26 12:10 james-crowley