Repository navigation
fix(serve): read <data-dir>/mcp_config.json and implement MCPPROXY_DATA_DIR - #1694
Conversation
serve looked for mcp_config.json only in the working directory and $HOME/.mcpproxy and applied --data-dir afterwards, while every management command already read <data-dir>/mcp_config.json. serve now resolves the config the same way: --config, then <data-dir>/mcp_config.json when it exists, and on a first run the default is seeded in the data dir. MCPPROXY_DATA_DIR, documented but never read, now seeds --data-dir; the legacy MCPPROXY_DATA still only relocates the data directory and loses when both are set. Fixes smart-mcp-proxy#1693
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
… legacy-config fallback A whitespace-only MCPPROXY_DATA_DIR set cfg.DataDir to the blank value and shadowed MCPPROXY_DATA, because the env override read the raw variable while DataDirFromEnv trims it. Both now go through the trimmed value. Docs: the installation guide says what happens when the data dir has no config but a legacy one exists, and the CHANGELOG notes that an already exported MCPPROXY_DATA_DIR takes effect for the first time. Related smart-mcp-proxy#1693
|
Thanks @james-crowley, this is a clean fix and the live checks (data-dir config, env-only, the packaged --config + --data-dir layout, and a first run) all behaved as described. I pushed one small commit on top of your branch: the env override now reads the trimmed MCPPROXY_DATA_DIR (a whitespace-only value used to set the data dir to blanks and shadow MCPPROXY_DATA), plus a clause in the installation guide about the legacy-config fallback and a CHANGELOG note that an already exported MCPPROXY_DATA_DIR now takes effect. Auto-merge is armed; it lands as soon as CI is green. |
|
CI on the current head (0a1fea5) is red, and I think none of it is a product problem, but I can't rerun jobs (no admin rights here), so flagging what I found:
Could you rerun the failed jobs when convenient? |
|
Pushed a merge of main onto your branch (the only conflict was the CHANGELOG, resolved as a union). No change to your code. That also gives CI a fresh run in place of the proxy and Windows temp-dir failures you flagged; merging once it is green. |
Seeding a first-run config probes Docker with a docker info subprocess under a 2 s timeout. On Windows a probe killed at the deadline can still hold the test's working directory and fail t.TempDir cleanup, which is the unlinkat failure CI showed on TestServeFirstRunSeedsConfigInDataDir.
|
One more small commit on your branch (5e182db): the serve data-dir tests now put an empty directory on PATH. Seeding a first-run config probes Docker with a |
Dumbris
left a comment
There was a problem hiding this comment.
Verified on a merge with main: build, CI lint config, race tests for cmd/mcpproxy and internal/config; cross-reviewed; live checks done earlier. The env-dir-must-exist behaviour matches the existing MCPPROXY_DATA semantics.
|
Merged, and #1693 is closed with it. Thank you, @james-crowley! Contributions like this are what keep MCPProxy moving, and they matter a lot to the project. One small ask, only if you feel like it: a short public note about your change (a tweet, a LinkedIn post, a line in a community you are part of) helps more people discover MCPProxy. No pressure at all, and I would be glad to repost it. |
Description
Fixes #1693.
servenow resolves its config the way the management commands already do (#854, #897, #908): an explicit--configwins, then<data-dir>/mcp_config.jsonwhen it exists, otherwise the legacy discovery (cwd,$HOME/.mcpproxy). On a first run with no config anywhere, the default (and its generated API key) is seeded inside the named data dir instead of under$HOME.MCPPROXY_DATA_DIR, which the docs list but the code never read, now seeds--data-dirfor every command (an explicit flag still wins). The legacyMCPPROXY_DATAkeeps its meaning (relocates the data directory only) and loses when both are set.--helpis unchanged when the variable is set.Changes:
cmd/mcpproxy/main.go(implicitDataDirConfigPath, used byloadConfig),cmd/mcpproxy/path_flag.go,internal/config/loader.go(EnvDataDir,EnvDataDirLegacy,DataDirFromEnv), docs (installation.mdtrap rewritten, env var tables, command reference) and a CHANGELOG entry.Behaviour change, one case: an instance started with
--data-dir Xthat relied on the legacy config while a staleX/mcp_config.jsonalso exists now reads the one inX(noted in the CHANGELOG as a migration).Verified with a built binary: a config with a fixed port and API key in the data dir is used through both
--data-dirandMCPPROXY_DATA_DIR, nothing is created under a clean$HOME, and a first run seeds<data-dir>/mcp_config.json.Testing
cmd/mcpproxy/serve_data_dir_config_test.go: data-dir and env read the config, flag beats env,--configbeats data dir, first run seeds in the data dir, legacy config kept when the data dir has none, env name precedence)go test ./cmd/mcpproxy ./internal/config ./cmd/release-gate)