Skip to content

fix(serve): make --listen "" reach native stdio transport - #1301

Merged
Dumbris merged 2 commits into
mainfrom
claude/great-gagarin-423949
Sep 18, 2026
Merged

Dumbris merged 2 commits into
mainfrom
claude/great-gagarin-423949

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 18, 2026

Copy link
Copy Markdown
Member

What

mcpproxy serve --listen "" now boots in native stdio transport, as the flag was documented to do. Previously only --listen :0 worked.

Why

loadConfig applied the --listen override and then called cfg.Validate(), which resets an empty Listen to 127.0.0.1:8080. Validate() cannot distinguish "no listen key in the config file" (which must default to HTTP) from "cleared on purpose", so the process silently started in HTTP mode. Found during real-instance verification for Spec 107 PR-D.

How

  • cmd/mcpproxy/main.go loadConfig: an explicit empty --listen is mapped to the ":0" sentinel that internal/server/server.go already treats as stdio. This is the only seam where "explicitly cleared" is knowable, so Validate()'s default for config files is untouched.
  • Flag help text documents both "" and ":0".
  • New cmd/mcpproxy/listen_flag_test.go covers unset flag → 8080 default, explicit address, :0, and "". The "" case failed before the fix (got "127.0.0.1:8080").

Verification

  • go test ./cmd/mcpproxy ok; go vet + gofmt clean.
  • Real instance: serve --listen "" --enable-socket=false answered initialize over stdin and logged transport: stdio with zero streamable-http lines.
  • Cross-model review (opencode github-copilot/gpt-5.6-sol): seam choice confirmed, :0 never reaches net.Listen/SplitHostPort on the serve path. One finding, verified as pre-existing and out of scope: any CLI --listen value (including :0, which already worked) is persisted into mcp_config.json by the API-key / startup-outcome saves on a fresh boot. Tracked separately.

`serve --listen ""` was documented as a stdio trigger, but loadConfig
applied the flag and then called cfg.Validate(), which resets an empty
Listen to 127.0.0.1:8080 — it cannot tell "no listen key in the file"
(must default to HTTP) from "cleared on purpose". The process silently
booted in HTTP mode; only `--listen :0` actually reached stdio.

Map an explicit empty flag onto the ":0" sentinel that the server already
recognises after validation. loadConfig is the only seam where the intent
is knowable, so Validate()'s default stays intact for config files.

Update the flag help text to document both spellings and add
TestLoadConfig_ListenFlag (unset / explicit addr / :0 / "").
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0582e96
Status: ✅  Deploy successful!
Preview URL: https://c1999ae1.mcpproxy-docs.pages.dev
Branch Preview URL: https://claude-great-gagarin-423949.mcpproxy-docs.pages.dev

View logs

loader.go applies MCPPROXY_LISTEN even with an explicit config file, so an
ambient value in the developer shell failed the "unset flag" case. Pin the
env per case and add the two env interplay cases (unset flag keeps the env
override; explicit --listen "" beats it).
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: claude/great-gagarin-423949

Available Artifacts

  • archive-darwin-amd64 (30 MB)
  • archive-darwin-arm64 (27 MB)
  • archive-linux-amd64 (18 MB)
  • archive-linux-arm64 (16 MB)
  • archive-windows-amd64 (30 MB)
  • archive-windows-arm64 (26 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (24 MB)
  • installer-dmg-darwin-arm64 (21 MB)
  • smart-mcp-proxymcpproxy-goV9DAPE.dockerbuild (0 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 35324351915 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/mcpproxy/main.go 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris merged commit a6564a0 into main Sep 18, 2026
41 checks passed
Dumbris added a commit that referenced this pull request Sep 18, 2026
…gnature

CI on PR #1300 failed to build cmd/mcpproxy on every platform: "assignment
mismatch: 2 variables but loadConfig returns 3 values". Unrelated to this
PR's instance-ID changes -- main itself is currently broken this way (#1299
changed loadConfig to also return a *serveConfigSaver, and the
listen_flag_test.go added by #1301 wasn't updated for it). Discard the
unused saver return to match the real signature.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Dumbris added a commit that referenced this pull request Sep 18, 2026
…p file (#1300)

* fix(docker): scope instance ID to data dir instead of a host-wide temp file

GetInstanceID() persisted to a single filepath.Join(os.TempDir(), ...) file
shared by every process a user runs on a host, so any two concurrent
mcpproxy processes (a scratch dev instance next to the main app, two
separate installs) silently got the SAME instance ID. That defeats
com.mcpproxy.instance container-ownership labels used by
manager.go's cleanup and by the ownership filter added in PR #1298 for
same-host instances (cross-host-shared-daemon cases still work).

Scope the ID to the process's data dir instead (cfg.DataDir, set once via
core.SetInstanceDataDir from upstream.NewManager, the common construction
point for every entry point) since concurrent instances on one host already
require distinct data dirs -- BBolt locks config.db. Fall back to a fresh
per-process UUID when no data dir is known yet. On first run under a data
dir, adopt-then-retire the legacy shared file so pre-upgrade containers
stay cleanable by whichever instance starts first, without letting every
future data dir keep re-adopting the same shared ID.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(docker): close legacy-instance-id adoption race found by cross-review

codex gpt-5.6-sol review of the instance-ID fix (PR #1300) found that
adoptLegacyInstanceID's read-then-remove let two concurrent processes both
read the same legacy id before either deleted the file, recreating the very
host-wide-shared-id bug the fix targets. Claim the legacy file via
os.Rename to a process-unique path instead: rename atomically fails once
another process has already claimed the source, so exactly one process
adopts a given legacy id.

Also fixes a test bug the same review caught: the subprocess helper tests
never overrode legacyInstanceIDPath in the child process, so they could
have adopted-and-deleted a real machine's actual pre-upgrade legacy file.
Threads a scratch path through an env var instead. Adds a goroutine-race
test (50x under -race) proving the claim is exclusive.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(test): make legacy-id claim path unique per call, not just per PID

Windows CI failed TestAdoptLegacyInstanceIDConcurrentClaimIsExclusive
(#1300 windows-amd64
build): all 8 concurrent goroutines got 0 adopters instead of exactly 1.
The test spawns racers as goroutines in one OS process, so they all share
one os.Getpid() and therefore compute the identical claim destination --
a collision that can't happen in real usage (real racers are always
separate processes with distinct PIDs). On Windows that collision made
every racer's rename fail.

Add an atomic per-call sequence number alongside the PID in the claim
path, so it can never collide even when called concurrently within one
process. No behavior change for the real (cross-process) case.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(docker): use a random claim path and preserve claims on save failure

Second codex gpt-5.6-sol review round on PR #1300. opencode's Copilot quota
was still exhausted, so codex gpt-5.6-sol (the documented fallback) reviewed
again. Findings:

1. adoptLegacyInstanceID removed the claimed legacy file unconditionally,
   even when the subsequent save to the new per-data-dir location failed --
   silently losing the id on the next restart. Now the claim file is only
   removed after a successful save; on failure it's left in place so it
   isn't silently destroyed.

2. The PID+sequence claim-path suffix (from the previous round's Windows
   fix) doesn't guarantee cross-restart uniqueness -- PIDs get reused, and
   the review argued a stale claim file from a crash could collide with a
   later process's first claim. Go's os.Rename on Windows actually uses
   MOVEFILE_REPLACE_EXISTING (verified against the Go 1.26 stdlib source),
   so this wouldn't have caused a failure the way the review described, but
   using a random UUID instead of PID+sequence removes any theoretical
   collision outright and is simpler.

3. Test coverage: TestGetInstanceIDDistinctAcrossConcurrentProcesses ran its
   two subprocesses sequentially despite its name; and there was no test of
   the ACTUAL cross-process legacy-claim race (only an in-process
   goroutine simulation, which artificially shares one PID across racers).
   Added TestGetInstanceIDCrossProcessLegacyClaimIsExclusive (two real
   subprocesses racing over one seeded legacy file) and
   TestAdoptLegacyInstanceIDPreservesClaimWhenSaveFails, and made the
   existing "concurrent processes" test actually start both processes
   concurrently.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(test): match TestLoadConfig_ListenFlag to loadConfig's 3-value signature

CI on PR #1300 failed to build cmd/mcpproxy on every platform: "assignment
mismatch: 2 variables but loadConfig returns 3 values". Unrelated to this
PR's instance-ID changes -- main itself is currently broken this way (#1299
changed loadConfig to also return a *serveConfigSaver, and the
listen_flag_test.go added by #1301 wasn't updated for it). Discard the
unused saver return to match the real signature.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
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.

2 participants