Skip to content

feat(connect): add ZCode as a supported Connect client - #1339

Merged
Dumbris merged 2 commits into
mainfrom
claude/zcode-mcpproxy-client-882742
Sep 22, 2026
Merged

Dumbris merged 2 commits into
mainfrom
claude/zcode-mcpproxy-client-882742

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 22, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds ZCode (a Claude-Code-style coding agent CLI/desktop app) as a supported client in the "Connect MCPProxy" wizard, joining Claude Code, Claude Desktop, Cursor, Windsurf, VS Code, Codex, Gemini, and OpenCode.
  • ZCode's config file (~/.zcode/cli/config.json) nests server entries under mcp.servers, unlike every other supported client, which stores entries under a single flat top-level key. Rather than special-casing this at each read/write call site, internal/connect gains serversMapPath/getServersMap/setServersMap helpers that fall back to the existing flat-key behavior for every other client and only nest for zcode. The next client with a nested schema should extend serversMapPath rather than adding another one-off.
  • Frontend icon maps (ConnectModal.vue, Dashboard.vue), session labeling (sessionLabel.ts), REST docs, CLI help text, and the generated OpenAPI spec are updated to include ZCode.

Why

ZCode is installed locally and exposes an MCP-client config surface compatible with mcpproxy's existing Connect wizard pattern — adding it lets users wire mcpproxy into ZCode the same one-click way as the other supported clients.

Verification

  • go test -race ./internal/connect/... ./internal/httpapi/... — all pass, including 5 new ZCode-specific tests (config path, nested-key write, sibling-key preservation at both the top level and under mcp, credential header, disconnect round-trip).
  • go vet ./..., golangci-lint run --config .github/.golangci.yml ./..., go build ./..., gofmt — all clean.
  • Verified against a real local ZCode install, not just unit tests: ran the built mcpproxy binary's connect zcode command against the actual ~/.zcode/cli/config.json, confirmed the written JSON matches ZCode's documented schema, then queried ZCode's own CLI (zcode --prompt "/mcp list") — it reported mcpproxy connected with its real tool list (retrieve_tools, call_tool_read/write/destructive, code_execution, etc.), confirming an actual working end-to-end connection.
  • Frontend type-check (vue-tsc --noEmit) passes.

Notes for reviewers

  • oas/swagger.yaml / oas/docs.go are regenerated via make swagger from the updated @Param Swagger annotations in internal/httpapi/connect.go — diff is scoped to the new zcode entry in the 5 client-ID enumerations, no other drift.
  • ClientDef.ServerKey for zcode ("mcp.servers") is a display-only label; the actual nested read/write path is serversMapPath.

🤖 Generated with Claude Code

ZCode's config schema (~/.zcode/cli/config.json) nests server entries
under mcp.servers, unlike every other client's flat top-level key, so
the client registry gains serversMapPath/getServersMap/setServersMap
helpers to support nested paths without touching the other 8 clients'
behavior. Verified end-to-end against a real local ZCode install: a
live connect wrote a schema-correct entry and the ZCode CLI itself
reported mcpproxy connected with its tool list.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

@codecov-commenter

codecov-commenter commented Sep 22, 2026 •

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 93.10345% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/connect/connect.go 88.88% 1 Missing and 1 partial ⚠️
cmd/mcpproxy/connect_cmd.go 0.00% 1 Missing ⚠️
internal/connect/clients.go 97.22% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

…json shadowing

Cross-model review (codex gpt-5.6-sol, zcode GLM) of PR #1339 found two
real issues:

- A config file whose content is literally the JSON `null` (4 bytes)
  unmarshals without error into a nil map, and every write path in this
  package assumed a non-nil map — data[serversKey] = ... and the new
  nested setServersMap both panic with "assignment to entry in nil map".
  This predates this PR (reproduces on main with cursor too, confirmed
  by stashing the fix and re-running the new regression test); the fix
  normalizes a nil map result once, in unmarshalLenientJSON, covering
  every caller including undo's replayConnectWrite.
- ZCode reads ~/.agents/mcp.json as a fallback only while its own
  ~/.zcode/cli/config.json defines no MCP servers; the moment mcpproxy
  connects there, that fallback is silently ignored for the whole scope
  (ZCode's own diagnosing-mcp skill doc). Added a Note surfaced by the
  existing ConnectModal.vue note UI, same pattern as Claude Desktop's
  bridge caveat.

A third finding (a non-object mcp.servers/mcpServers section is silently
replaced rather than refused, weakening precondition-token drift
detection) is real but pre-existing across all 9 clients and touches
security-sensitive token derivation — flagged separately rather than
bolted onto this PR.

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

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: claude/zcode-mcpproxy-client-882742

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 (22 MB)
  • smart-mcp-proxymcpproxy-goNK36T4.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 35739208401 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit 674a05e into main Sep 22, 2026
43 checks passed
Dumbris added a commit that referenced this pull request Sep 22, 2026
…ift fix

main gained PR #1339 (ZCode client, nested mcp.servers schema via
serversMapPath/getServersMap/setServersMap) after this branch's round-6
CLEAN review verdict, touching the same call sites this PR's fix does —
exactly the coordination trap flagged in project memory when both PRs were
open simultaneously.

Reconciled by extracting resolveServersMapState (internal/connect/clients.go)
alongside the existing getServersMap/setServersMap: it distinguishes "key
absent" (legitimate create) from "key present but not an object" (malformed
— must refuse) along serversMapPath, generalizing this PR's flat-key-only
distinction to ZCode's nested path too. getServersMap is now defined in
terms of it (behavior-preserving — it already collapsed both non-found cases
into one `bool`).

Updated to use resolveServersMapState: resolveExistingEntry (preview.go),
connectJSON/connectTOML's top-of-function check, and findEntryJSONBytes
(GetStatus consistency). refuseIfServersSectionRaced (the 3-checks-deep
race guard from rounds 3-5) now takes *ClientDef instead of a flat
(serversKey, format) pair, so all three of its checks are nested-path-aware
too — ZCode gets the full defense-in-depth protection, not just the
top-of-function one.

Removed now-redundant nil-map guards in readOrCreateJSON and undo.go's
replayConnectWrite: #1339 added a more centralized fix
(normalizeNilConfigMap inside unmarshalLenientJSON itself) that covers the
same cases more thoroughly than this PR's original per-call-site guards.

Added zcode coverage to fulfill the original task's request for "at least
one flat-key client and zcode" test coverage, which wasn't possible when
this PR was first written (zcode didn't exist in this codebase yet):
non-object-section detection at both the leaf (mcp.servers) and intermediate
(mcp) nesting levels, in both Preview and the tokenless Connect() write path.

All pre-merge tests (6 rounds of cross-model review) and all of #1339's own
zcode tests pass unchanged. go build/vet/test -race/golangci-lint (both bare
and --build-tags server) all clean.

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

* fix(connect): refuse writes when a client's servers section is not an object

resolveExistingEntry type-asserted data[client.ServerKey] to a map and, on
failure, reported "no servers section" — indistinguishable from the key being
absent entirely. A hand-edited config whose servers section holds a string,
number, array, or bool (e.g. {"mcpServers":"old"}) therefore classified as a
clean "create" case in both preview and write.

Since the precondition token only ever hashes the resolved ENTRY (never the
section's own raw value/type), two different non-object section values minted
identical tokens, so drift in that value between preview and write went
undetected (Spec 091 FR-005 gap, confirmed by a codex gpt-5.6-sol cross-model
review of #1339 and reproduced independently against main). On write,
connectJSON/connectTOML then silently replaced the section with a fresh map,
destroying whatever was there.

Treat "key present but not an object" as a distinct, refusable accessMalformed
state instead of falling through to "create": resolveExistingEntry now
separates key-absent (still a legitimate create) from key-present-wrong-type,
and ConnectWithPrecondition refuses the write outright whenever the resolved
access state is malformed, independent of whether a precondition token was
even supplied. This closes the gap without touching the token's hash inputs.

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

* fix(connect): close TOCTOU and nil-map panic found by review round 1

Cross-model review (codex gpt-5.6-sol, round 1 of the PR #1340 gate) found
three real issues in the first cut of the non-object-servers-section fix:

1. must-fix: the upstream accessMalformed check in ConnectWithPrecondition
   read the file once via preWriteState, but connectJSON/connectTOML each
   perform their OWN independent read a few lines later. A file mutated
   between those two reads (object-shaped at check time, non-object at write
   time) bypassed the guard entirely and reached the original destructive
   fallthrough. Fix: drop the upstream check and make the type-assertion
   sites inside connectJSON/connectTOML themselves the authoritative,
   last-read guard — they now distinguish "key absent" from "key present,
   wrong type" and refuse before backup/mutation, immune to the race because
   there is no later read to race against.

2. should-fix: the removed upstream check's blanket error message covered
   every accessMalformed cause (stat/read I/O errors like EIO, not just a
   non-object section), masking genuine I/O failures behind a misleading
   "not an object" message. Moot now that the section-shape check only lives
   at the writer's own type assertion, which only runs after a successful
   parse — a real read/stat error still propagates through its original,
   accurate wrapped-error path unchanged.

3. should-fix: GetStatus (via findEntryJSONBytes/findEntryTOMLBytes) had the
   same "key present, wrong type" blind spot as the write path, reporting a
   plain "not connected" for a config Preview/Connect now refuse to touch.
   Both now classify consistently as accessMalformed.

Also fixed a genuine, PRE-EXISTING crash the review surfaced while checking
this diff: a config file containing exactly the JSON literal `null` decodes
successfully with a nil top-level map (encoding/json leaves the target
untouched for a JSON null), and connectJSON's final `data[serversKey] =
serversMap` assignment panicked with "assignment to entry in nil map" —
reachable through the plain tokenless Connect() path, no precondition token
involved. readOrCreateJSON/readOrCreateTOML now normalize a nil top-level
document to an empty map.

New tests: a TOCTOU race test using the readFile seam to prove the fix isn't
just a single upstream check, a GetStatus consistency test, a null-document
regression test, and an I/O-error-not-masked test. Tightened the round-1
tests to assert the exact (nil result, non-nil error) contract instead of
loosely checking res.Success.

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

* fix(connect): undo nil-map panic + test tightening from review round 2

Round 2 of the codex gpt-5.6-sol cross-model review of PR #1340 verified
round 1's fixes and found one more genuine, in-scope bug plus two test nits:

- must-fix: internal/connect/undo.go's replayConnectWrite has its own,
  independent JSON parse of the backup bytes (separate from
  readOrCreateJSON, which round 1 already fixed). A backup file containing
  exactly the JSON literal `null` hits the exact same nil-map reset
  encoding/json performs on a pre-initialized map target, but this path
  panicked at `data[client.ServerKey] = serversMap` instead — reachable via
  Connect (against a null-content config, which backs up the null bytes
  verbatim) followed by Undo. Same one-line guard as round 1's fix, applied
  here too.

- nit: tightened the TOCTOU race test and the I/O-error test to assert the
  exact read count (2, not merely >=2) and require errors.Is() rather than
  an OR with a loose string match, pinning that they exercise the paths they
  claim to rather than passing for an unrelated reason.

Two further must-fix findings from this round — a broader precondition-token
TOCTOU (the token is checked against preWriteState's read but never
re-validated against connectJSON/connectTOML's own later, independent read,
so a same-shape entry that drifts in VALUE between the two reads can still
be overwritten under force=true) and a sibling race in guardJsoncComments
(OpenCode JSONC comments can be stripped by the same read/read gap) — were
verified as genuine but PRE-EXISTING on main, unrelated to the non-object-
section gap this PR set out to fix, and present since Spec 091 shipped.
Given this PR's own scope was deliberately narrow specifically to avoid
introducing a NEW drift-detection bug in this security-sensitive code, both
are documented in place (see the comment block in ConnectWithPrecondition)
and tracked as separate follow-up work rather than folded into this PR.

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

* fix(connect): close the remaining read-to-write race from review round 3

Round 3 (codex gpt-5.6-sol) confirmed round 2's fixes (undo.go nil-map panic;
tightened test assertions) and judged the two deferred pre-existing gaps
(broader precondition-token TOCTOU; guardJsoncComments race) as genuinely
orthogonal to this PR's guarantee, so deferring those was correct.

But it found one more must-fix, and it's real: the "authoritative, last-read"
comment on the servers-section type check in connectJSON/connectTOML
overclaimed. That check runs right after readOrCreateJSON/readOrCreateTOML,
but the actual disk write (atomicWriteFile) happens several lines later,
after backupFile performs its own real file I/O. An external process could
still replace the servers section with a non-object value in that gap and
have it silently destroyed by the pending write — the exact harm this PR
exists to prevent, just with a narrower window than before round 1.

Fix: a second, minimal re-check (refuseIfServersSectionRaced) immediately
before backupFile in both connectJSON and connectTOML, using a fresh read
right at the point of committing. This shrinks the exploitable window to the
residual gap between that check and atomicWriteFile's rename — eliminating
it entirely would need an OS-level file lock held across the whole
read-modify-write sequence, which is a larger change appropriately left to
the same follow-up track as round 2's deferred findings, not bundled here.

New test: TestConnectWithPrecondition_NonObjectServersSection_RaceIsClosedAtTheFinalPreWriteCheck,
using the read-file seam to make both the top-of-function check's reads
observe an object-shaped section (so it passes) and only the new, later
check observe the raced-in non-object value — proving the fix closes
specifically the window round 3 identified, not just the one round 1 closed.

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

* fix(connect): add post-backup pre-write check per review round 4

Round 4 (codex gpt-5.6-sol) confirmed round 3's pre-backup check runs at the
right point in both connectJSON/connectTOML with no intervening reads, and
found no TOML-path bug — but flagged that the check alone still left a
practically (not just theoretically) exploitable window: backupFile performs
real Stat/Open/copy I/O, so a change landing DURING that backup — AFTER the
pre-backup check already passed — could still slip through to
atomicWriteFile undetected.

Fix: a third refuseIfServersSectionRaced call, positioned after backupFile
and marshaling, immediately before atomicWriteFile — as close to the actual
write as this codebase's non-locking design allows. The residual gap between
this final check and atomicWriteFile's own temp-write-then-rename is
unavoidable without an OS-level file lock across the whole read-modify-write
sequence (the same larger architectural change already correctly deferred
for round 2's other findings), and is now the ONLY remaining, syscall-width
window — no longer one wide enough to contain a real I/O operation.

Also fixed an overclaiming comment in ConnectWithPrecondition ("fully
protected without racing") that round 4 flagged as inconsistent with the
acknowledged residual gap.

Renamed the round-3 test to RaceIsClosedAtThePreBackupCheck for clarity
against the new RaceIsClosedAfterBackup test, which simulates the race
landing specifically during backupFile's I/O (reads #1-#3 see the
object-shaped section, so a backup IS legitimately created; only the 4th,
post-backup read sees the raced-in non-object value) and asserts the config
file itself stays untouched despite the backup existing.

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

* fix(connect): move final race check inside atomicWriteFile's rename step

Round 5 (codex gpt-5.6-sol) found round 4's "immediately before
atomicWriteFile" placement for the third refuseIfServersSectionRaced call
still left a real, I/O-bearing window: atomicWriteFile itself stages a temp
file (MkdirAll, CreateTemp, Write, Close, Chmod — all real filesystem
operations) before the rename that actually replaces the target file, and
none of that staging was covered by the check.

Fix: atomicWriteFile now accepts an optional preRename func() error,
invoked after all staging completes and immediately before os.Rename — the
true last point at which the write can still be aborted. connectJSON and
connectTOML pass their section-race check as this hook instead of calling it
themselves before atomicWriteFile. The other three call sites
(disconnectJSON, disconnectTOML, undo.go's restore, and the direct unit
test) pass nil, unaffected.

This closes the residual down to a handful of fast local syscalls between
the hook and the rename itself — the practical floor without an OS-level
file lock across the whole read-modify-write sequence, which remains
tracked as a separate, larger architectural change per the round-2 deferral.

Also fixed two stale "first of TWO checks" comments round 5 flagged (now
three: the top-of-function type assertion, the pre-backup fast-fail, and
this new preRename hook), and updated refuseIfServersSectionRaced's and the
round-4 test's doc comments to describe the corrected placement — the
existing read-counting test's assertions were unaffected (none of
atomicWriteFile's temp-file staging touches the s.read seam it mocks), but
its comment previously implied a placement precision the black-box test
can't itself prove.

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

* docs(connect): soften overclaimed "not a real I/O operation" comment

Round 6 review nit: os.Rename on Unix performs an Lstat before the actual
rename/replace syscall, so the residual pre-rename window isn't literally
zero I/O. Corrected the comment to say what's actually true — one fast local
metadata lookup, not a copy or anything an external writer could practically
race against — without changing any behavior.

Round 6 (codex gpt-5.6-sol) verdict: CLEAN, merge-ready. Six rounds
progressively closed a real TOCTOU from "no protection" down to this
documented, irreducible platform-rename window, with two genuinely
pre-existing/orthogonal architectural gaps deferred to follow-up tasks.

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