Skip to content

fix(restart): re-read mcp_config.json before restarting upstream (#467)#471

Open
Dumbris wants to merge 1 commit into
mainfrom
fix/467-file-watcher-env-headers
Open

fix(restart): re-read mcp_config.json before restarting upstream (#467)#471
Dumbris wants to merge 1 commit into
mainfrom
fix/467-file-watcher-env-headers

Conversation

@Dumbris
Copy link
Copy Markdown
Member

@Dumbris Dumbris commented May 15, 2026

Closes #467.

Summary

Runtime.RestartServer pulled the server's config from BoltDB only. There is no fsnotify-style auto file-watcher anywhere in the codebase (despite the issue title — the user's mental model was that one existed). So a user who edited mcp_config.json (changing env, headers, args, or isolation_json) and then ran mcpproxy upstream restart from the CLI / tray silently replayed the stale config — only the live REST PATCH path used to update those maps.

The repro from #467 (env wiped + restored on obsidian-pilot) confirmed this: editing the file changed nothing on the running container; only mcpproxy upstream patch made the change visible.

Approach

Pull the latest server config from disk first, fall back to BoltDB on read / parse failure, and persist the disk-loaded config back to BoltDB so subsequent restarts (and any other read-from-storage code path) see consistent state. The new lookupServerConfigForRestart() keeps RestartServer itself readable.

RestartAll inherits the fix automatically because it loops through RestartServer.

Why this and not a real fsnotify watcher

Adding a real file watcher is a separate spec — it has correctness concerns around debouncing, atomic-rename-vs-truncate, partial writes, and what to do with the existing r.cfg snapshot during reload. The fix here addresses the user-observable gap with a much smaller surface.

What about other restart-time staleness?

AddServerConfig (internal/upstream/manager.go:269-276) already diffs Env, Headers, Args etc. against the running client's config. So once the disk-loaded config reaches AddServer, the existing reconnect path picks it up correctly. No change needed there.

Test plan

  • go test ./internal/runtime/ -run TestRestartServer -race -v — three new cases:
    • TestRestartServer_PicksUpDiskEnvChanges — reproduces the original repro, asserts BoltDB reflects the disk env after restart
    • TestRestartServer_PicksUpDiskHeaderChanges — same shape for HTTP Headers
    • TestRestartServer_FallsBackToStorageWhenDiskMissing — guarantees a malformed disk file doesn't break restart
  • go build ./... clean

🤖 Generated with Claude Code

Runtime.RestartServer pulled the server's config from BoltDB, never from
disk. There is no fsnotify-style auto file-watcher, so a user who edited
mcp_config.json (changing env, headers, args, or isolation_json) and then
ran `mcpproxy upstream restart` from the CLI / tray would silently
replay the stale config — only the live REST PATCH path used to update
those maps.

The repro from #467 (env wiped + restored on obsidian-pilot) confirmed
this: editing the file changed nothing on the running container; only
`mcpproxy upstream patch` made the change visible.

Fix: pull the latest server config from disk first, fall back to BoltDB
on read / parse failure, and persist the disk-loaded config back to
BoltDB so subsequent restarts see consistent state. Added
lookupServerConfigForRestart() to keep the restart path readable.

RestartAll inherits the fix automatically because it loops through
RestartServer.

Tests cover env, headers, and the storage fallback path. The latter
proves a malformed disk file doesn't break restart.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 253a921
Status: ✅  Deploy successful!
Preview URL: https://050a3d35.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-467-file-watcher-env-hea.mcpproxy-docs.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: mcp_config.json file-watcher hot-reload doesn't propagate env (and likely headers) changes to running upstreams

2 participants