Commit 6702e62
feat(connect): preview the exact change before writing + stop leaking the API key into client configs (Spec 078 US1) (#802)
* feat(connect): preview endpoint sharing buildServerEntry with the write path
First slice of specs/078-connect-trust-preview US1 (see spec FR-001..004,
012, 013). Adds GET /api/v1/connect/{client}/preview returning the exact
change a subsequent connect would make — target config_path, server_key,
entry name, and the exact entry contents — WITHOUT modifying the file or
creating a backup.
Preview==write guarantee: buildServerEntry is now the single construction
path for every client, including Codex/TOML (connectTOML previously built
its {url} entry inline). Preview derives its entry from the same function
the write uses, so what is previewed equals what is written (FR-002); a
table-driven test connects each supported client and asserts the written
file entry deep-equals the shared constructor output across JSON and TOML.
API-key honesty (FR-004): the embedded apikey is masked in the payload
(entry, entry_text) while contains_api_key flags that a credential is
written; the real key never appears in the preview (verified by test that
marshals the whole payload and asserts the secret is absent).
Spec 075 access states (FR-012): the on-demand read used to classify
create-vs-overwrite degrades to access_state=absent|malformed and a denial
returns the same typed AccessError (403 + remediation) as connect/disconnect.
- internal/connect/preview.go: Service.Preview, maskURLAPIKey, entry render
- internal/connect/clients.go: buildServerEntry gains the codex case
- internal/connect/connect.go: connectTOML uses buildServerEntry
- internal/httpapi: handler + route + tests (masked, no side effects, 403)
- oas: regenerated for the new endpoint (make swagger)
Tests: preview-equals-write (JSON+TOML), masking, entry_exists (create vs
overwrite), no-side-effects (no write, no backup, mtime unchanged), absent/
malformed/denied degradation. go test -race ./internal/connect/... and
./internal/httpapi/... pass; golangci-lint v2 clean.
Related #793
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* feat(web): preview the exact change before writing in wizard + Connect modal
Second slice of specs/078-connect-trust-preview US1 (FR-001,003,004): the
Connect action in BOTH the standalone Connect modal and the onboarding
wizard's ClientRow now fetches the preview first and shows an inline panel
before any file is written:
- target config path and, in a monospace additive ("+ will be added")
block, the exact entry that will be written (pretty JSON, or TOML for
Codex) with the API key masked;
- plain-language trust copy ("Only this entry is added — everything else in
the file stays untouched. A timestamped backup is created first.");
- a masked-key line when contains_api_key so the user knows a credential is
written;
- an overwrite warning when an entry with the same name already exists, in
which case confirming implies force=true;
- graceful copy for the bridge/no-prior-file (access_state=absent) and
unparseable (malformed) cases.
Confirm proceeds with the connect (reusing the existing #799 post-connect
backup-path line, untouched); Cancel dismisses the panel and writes nothing.
A non-denial preview fetch error is surfaced inline; in the modal a denied
read still resolves the Spec 075 access banner via checkAccess. Wizard
connect-step telemetry (markConnectCompleted/Skipped) is unchanged.
- types/api.ts: ConnectPreview; services/api.ts: getConnectPreview
- ConnectModal.vue + OnboardingWizard.vue ClientRow: preview panel + flow
- The existing #799 connect specs are updated to drive click → preview →
confirm (Connect no longer writes on the first click); new
connect-preview.spec.ts covers preview render, cancel-writes-nothing,
confirm-proceeds, masked key, and overwrite→force for both surfaces.
Full frontend suite: 33 files, 244 tests pass; vue-tsc clean; make build
embeds the updated dist. npm-ci lockfile churn reverted (as in #799).
Related #793
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(connect): stop leaking the API key into client configs; auth-aware carrier
Security fix folded into Spec 078. Connect (and the new preview) previously
appended ?apikey=<REST-admin key> to EVERY client entry via mcpURL(), but
/mcp does not require auth by default (config.RequireMCPAuth defaults false;
the admin context is granted unauthenticated). So connect leaked the
REST-admin API key in plaintext into other apps' config files where it
served no purpose.
New behavior, threaded from config.RequireMCPAuth into connect.Service the
same way listenAddr/apiKey are (server wiring + both CLI sites), via
WithRequireMCPAuth:
- require_mcp_auth=false (default): the entry carries NO credential — a clean
http://host:port/mcp URL, no query, no headers. Existing configs keep
working because /mcp accepts unauthenticated requests when protection is off.
- require_mcp_auth=true: the credential is written via the carrier each
client's real config schema supports (verified against vendor docs):
* X-API-Key header — claude-code, vscode, cursor, windsurf, gemini,
opencode (all support a "headers" object on their remote entry);
* mcp-remote --header "X-API-Key:<key>" bridge arg — claude-desktop
(no space after the colon: Claude Desktop/Cursor don't escape spaces in
args and mangle the header — geelen/mcp-remote README; our keys are
space-free);
* ?apikey= query fallback — codex only, whose TOML HTTP transport takes
header values indirectly via env-var names (http_headers /
bearer_token_env_var) and cannot express a literal header value.
Server-side ExtractToken accepts X-API-Key, Authorization: Bearer, and
?apikey= (in that order), so header and query authenticate identically.
buildServerEntry now takes serverEntryParams{baseURL, credential}; mcpURL()
is replaced by the credential-free baseURL() anchor. Entry MATCHING
(findEntry*/findEquivalentJSONServerName/entryPointsToBridge) already keys on
baseURL with an optional ?query, so it recognizes BOTH legacy ?apikey=
entries and new clean entries — reconnect adopts/updates in place (no
duplicate) and disconnect still finds legacy entries; a force-reconnect over a
legacy entry upgrades it and drops the leaked key.
Preview reflects reality: contains_api_key is true only when require_mcp_auth
is on; the credential is masked in whichever carrier it uses (header value,
bridge arg, or query) and the real key never appears in the preview payload.
Tests: matrix over require_mcp_auth on/off × all 8 clients for both write and
preview (preview==write shape, auth-off writes contain NO apikey/headers at
all); per-client carrier assertions; legacy ?apikey= migration (recognized,
upgraded in place, no duplicate, disconnect still works). go test -race
./internal/connect/... ./internal/httpapi/... pass; server/config/management
pass; golangci-lint v2 clean.
Related #793
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* feat(web): carrier-agnostic credential copy in the connect preview
Follows the connect security fix: the preview panel's masked-credential line
now reads "This entry includes your API key (shown masked)…" instead of "The
URL includes…", since with require_mcp_auth on the credential is carried in an
X-API-Key header (or the mcp-remote --header bridge arg) for most clients and
only falls back to the ?apikey= URL query for Codex. The line already renders
only when contains_api_key is true, which the backend now sets only when
require_mcp_auth is on — so the default (keyless) connect shows no credential
line at all.
Adds a frontend test for the default keyless case: contains_api_key=false ⇒
no credential line, and the previewed entry shows neither an apikey query nor
a mask. Full frontend suite: 33 files, 245 tests pass; vue-tsc clean.
Related #793
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(connect): live-config carrier + honest preview for edge cases
Codex review of the Spec 078 US1 connect-preview branch surfaced one blocker
and three preview/write-divergence gaps; this addresses them:
- blocker: the HTTP connect service snapshotted require_mcp_auth (and
listen/api_key) once at startup and was never rebuilt, while the /mcp auth
middleware honors require_mcp_auth live per-request. Toggling auth off at
runtime (wizard toggle or hot-reload) left the service embedding the real
API key into client configs — the exact leak this branch closes. Add a
live config-provider seam (WithConfigProvider) wired to runtime.Config() so
preview and write always match the currently-enforced auth state.
- OpenCode preview divergence: previewEntryExists checked only the exact
server name, but OpenCode's write path adopts/normalizes an equivalent entry
(incl. the legacy ?apikey= shape) under a different key. Preview now mirrors
that via findEquivalentJSONServerName so entry_exists reflects the overwrite.
- preview endpoint ignored server_name and always previewed "mcpproxy" while
POST connect accepts a custom name. Honor an optional ?server_name= query so
a caller previewing then connecting under a custom name does not diverge.
- malformed config: the write parses the same bytes and would fail, but the
preview copy promised it "still writes only the entry" and left Connect
enabled. Make the copy honest and disable Connect for malformed configs.
Tests: live-toggle credential (auth off->on without rebuild), OpenCode
equivalent-entry preview, server_name honoring, and malformed confirm-disabled.
go test -race ./internal/connect/... ./internal/httpapi/... green; frontend
246 tests + vue-tsc clean; golangci-lint v2 ./... 0 issues; swagger regenerated.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(web): make the first connect click explicitly commitment-free
The preview only appeared AFTER clicking "Connect" — the exact button
hesitant users avoid, fearing the click immediately modifies their
config. Rename the row action to "Review & connect" and say up front
in the modal subtitle and wizard intro that nothing is written until
the confirm step, so the safety of the first click is visible before
it happens (Spec 078 US1 trust copy).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* docs(web): align setup.md and test prose with the Review & connect flow
Codex review follow-up: docs/setup.md described the Claude Desktop
bridge registration as one-click "Connect"; it is now review-then-
confirm. Test comments updated to match the renamed row action.
Spec 046/075 texts intentionally left untouched — they are point-in-
time records (046 FR-005 already required the diff preview this
branch implements).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent b2003ba commit 6702e62
21 files changed
Lines changed: 2000 additions & 158 deletions
File tree
- cmd/mcpproxy
- docs
- frontend
- src
- components
- services
- types
- tests/unit
- internal
- connect
- httpapi
- server
- oas
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
| 73 | + | |
73 | 74 | | |
74 | | - | |
| 75 | + | |
75 | 76 | | |
76 | | - | |
77 | | - | |
| 77 | + | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
120 | 203 | | |
121 | 204 | | |
122 | 205 | | |
| |||
210 | 293 | | |
211 | 294 | | |
212 | 295 | | |
213 | | - | |
| 296 | + | |
214 | 297 | | |
215 | 298 | | |
216 | 299 | | |
| |||
251 | 334 | | |
252 | 335 | | |
253 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
254 | 344 | | |
255 | 345 | | |
256 | 346 | | |
| |||
326 | 416 | | |
327 | 417 | | |
328 | 418 | | |
329 | | - | |
330 | | - | |
331 | | - | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
332 | 461 | | |
333 | 462 | | |
334 | | - | |
| 463 | + | |
| 464 | + | |
335 | 465 | | |
336 | 466 | | |
337 | 467 | | |
338 | 468 | | |
339 | | - | |
| 469 | + | |
340 | 470 | | |
341 | 471 | | |
342 | 472 | | |
343 | 473 | | |
344 | 474 | | |
345 | 475 | | |
346 | | - | |
| 476 | + | |
347 | 477 | | |
348 | 478 | | |
349 | 479 | | |
| |||
525 | 655 | | |
526 | 656 | | |
527 | 657 | | |
| 658 | + | |
| 659 | + | |
528 | 660 | | |
529 | 661 | | |
530 | 662 | | |
| |||
540 | 672 | | |
541 | 673 | | |
542 | 674 | | |
| 675 | + | |
| 676 | + | |
543 | 677 | | |
544 | 678 | | |
545 | 679 | | |
0 commit comments