Skip to content

fix(cli): carry oauth through add-json and import, warn on unknown keys - #1972

Open
felipecrs wants to merge 6 commits into
smart-mcp-proxy:mainfrom
felipecrs:fix/add-json-oauth
Open

felipecrs wants to merge 6 commits into
smart-mcp-proxy:mainfrom
felipecrs:fix/add-json-oauth

Conversation

@felipecrs

@felipecrs felipecrs commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

Description

mcpproxy upstream add-json silently dropped the oauth block. The parser only knew url, command, args, env, headers, working_dir, protocol and trust_mode, and json.Unmarshal discards anything else, so the command reported success while the server was saved with "oauth": null. It then failed sign-in with OAUTH_NO_CLIENT_ID. POST /api/v1/servers had no oauth field either, so no client could set OAuth on create through REST.

I hit this adding a Home Assistant MCP server. Home Assistant has no Dynamic Client Registration and uses IndieAuth: the client_id is a URL and the redirect must share its host and port. The server only works with a pinned client_id and redirect_uri, and the only ways to set those were editing mcp_config.json or the upstream_servers MCP tool.

The same drop existed in upstream import. The daemon-mode path rebuilt each server as an AddServerRequest without oauth, so servers imported from Cursor or Gemini files lost their OAuth settings the same way. Claude Code files will follow in a separate PR, since their oauth block needs its own parser.

Changes:

  • REST create: POST /api/v1/servers accepts oauth and validates it with the existing OAuthConfig.Validate(). A bad block gets a 400 before anything is saved. The existing mask check already walks the whole ServerConfig, so it covers oauth too.
  • REST PATCH: PATCH shares AddServerRequest but has no oauth merge, so it now refuses oauth with a 400 instead of decoding and ignoring it. I checked that the Web UI, the macOS app and upstream patch never send oauth on PATCH.
  • add-json:
  • upstream import: the daemon-mode path now carries the parsed oauth block, matching what the config-file path already did.
  • Docs: docs/cli-management-commands.md lists the accepted keys and adds an OAuth example. oas/ was regenerated with make swagger (swag v2.0.0-rc4).

Behavior change: an add-json payload with keys the command never applied (for example enabled or isolation) used to succeed and silently drop them. It now fails with an error that names those keys.

Testing

  • I have tested these changes locally
  • I have added/updated tests that prove my fix is effective or my feature works
  • All existing tests pass

New tests:

  • TestParseAddJSONOAuthAndUnknownKeys
  • TestUpstreamAddConfigModeKeepsOAuth
  • TestApplyImportedServersDaemonModeCarriesOauth
  • TestHandleAddServer_OAuth
  • TestHandlePatchServer_RefusesOAuth

internal/httpapi, internal/cliclient and internal/config pass. In cmd/mcpproxy, the TestUpstreamImport* tests and TestApplyNewBinary_* fail on Windows. The TestUpstreamImport* failures also happen on unchanged main. I didn't rerun TestApplyNewBinary_* on main, but they test the self-update binary swap, which this PR doesn't touch.

I also ran a built binary end to end against a throwaway config and core:

  • add-json with oauth saves the block, both with and without a daemon.
  • An invalid redirect_uri is refused on both paths.
  • Unknown keys are refused, top-level and inside oauth.
  • PATCH with oauth returns 400.

golangci-lint was not run locally; CI will run it.

felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 20, 2026
`mcpproxy upstream add-json` decoded the payload into a struct that only
named url/command/args/env/headers/working_dir/protocol/trust_mode, so an
`oauth` block (and every other key) was dropped while the command reported
success. POST /api/v1/servers had no oauth field either, so the block could
not reach the daemon by any client.

- POST /api/v1/servers accepts `oauth`, validated with OAuthConfig.Validate
  (400 on a bad block); PATCH, which shares the request type but has no
  oauth merge, refuses it with 400 instead of decoding and ignoring it.
- add-json carries `oauth` on both the daemon and config-file paths,
  refuses any unknown top-level key (listing them all) and any unknown key
  inside `oauth`, and accepts `type` as an alias for `protocol` so configs
  pasted from Claude Desktop / VS Code keep working.
- Docs and OpenAPI updated.
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 21, 2026
@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

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

`upstream import` in daemon mode built the AddServerRequest without the
oauth block, so servers imported from claude-code, cursor or gemini files
silently lost their oauth settings while the import reported success.
Pass s.Server.OAuth through, as the config-file path already did.
@felipecrs felipecrs changed the title fix(cli): carry oauth through upstream add-json and refuse unknown keys fix(cli): carry oauth through add-json and import, refuse unknown keys Nov 23, 2026
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 23, 2026
…on create

The MCP upstream_servers door runs OAuthConfig.ValidateRefreshReplay on an
oauth block; POST /api/v1/servers and upstream add-json only ran Validate, so
a refresh_replay_enabled block without an explicit token_endpoint was accepted
and then failed config validation on the next load. Run the same check on both
doors, and cover a masked client_secret being refused (and not echoed) on
create.
@Dumbris

Dumbris commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thanks @felipecrs — the diagnosis is right and the fix is well scoped. I read the diff end to end, ran the touched packages and the API e2e script, and had it cross-reviewed. Summary:

What I verified

  • oauth survives add-json (daemon and config-file paths) and upstream import (daemon path); client_secret is not logged or echoed, and a masked client_secret is refused on POST /api/v1/servers by the existing mask walk.
  • PATCH refusing oauth is safe: the Web UI (patchServer), the macOS app and upstream patch never send it.
  • internal/httpapi, cliclient, config, oauth, the cmd/mcpproxy add/import tests and scripts/test-api-e2e.sh pass.

What I pushed to your branch (06adc3c, one small commit, normal push): the MCP upstream_servers door runs OAuthConfig.ValidateRefreshReplay() on an oauth block, but the new REST/CLI paths only ran Validate(). A block with refresh_replay_enabled: true and no token_endpoint was accepted and then failed config validation on the next load. I added the same check to handleAddServer and parseAddJSONRequest, plus tests for it and for a masked client_secret being refused and not echoed.

One decision for the maintainer: unknown top-level keys in add-json
Refusing them is a behaviour change for a patch release. Our own specs/023-smart-config-patch/quickstart.md shows add-json with an isolation block that was always silently dropped, and snippets pasted from other clients (enabled, disabled, cwd, timeout, autoApprove) now fail. We would rather warn first: print the dropped keys to stderr, still add the server, and refuse in the next minor. Refusing unknown keys inside oauth can stay as is, since oauth was never carried before. Could you make the top-level check a warning (keep the sorted list of keys and the accepted set in the message)? The maintainer will confirm.

Non-blocking nits from the cross-review

  • Inside oauth, DisallowUnknownFields is case-insensitive, so {"client_secret":"a","CLIENT_SECRET":"b"} silently takes the last value; the top-level check is exact. Consider one policy.
  • type: "htp" is not validated by the parser (same as protocol today); protocol: "streamable-http" plus type: "http" is reported as a conflict though they mean the same thing.
  • null / [] payloads give a misleading error; "add-json expects a JSON object" would be clearer.
  • PATCH {"oauth": null, "enabled": false} is treated as no oauth, so it applies enabled and ignores the null.

Open items

  • CI is approved and running on the current head (main merged in, f00bd2c); the previous run's only failure was in internal/storage and passes locally.
  • The unticked "All existing tests pass" box: please tick it once CI is green, and say so if TestApplyNewBinary_* should be re-run on main on Windows.

Refusing keys the command never applied is a behaviour change for payloads
that used to succeed (for example the documented isolation block). Report the
sorted dropped keys and the accepted set on stderr and still add the server;
an unknown key inside oauth stays refused, since oauth was never carried
before. Refusal can follow in the next minor.
@Dumbris Dumbris changed the title fix(cli): carry oauth through add-json and import, refuse unknown keys fix(cli): carry oauth through add-json and import, warn on unknown keys Nov 24, 2026
@Dumbris

Dumbris commented Nov 24, 2026

Copy link
Copy Markdown
Member

Pushed two small commits on top of yours (authorship of your commits untouched, no rebase):

  • 06adc3c50 — refresh_replay_enabled without token_endpoint is now refused on REST create and add-json, like the MCP upstream_servers door; plus tests for it and for a masked client_secret being refused and not echoed.
  • 8db4ed127 — maintainer confirmed warn-first: unknown top-level keys in add-json now print a warning on stderr (sorted dropped keys plus the accepted set) and the server is still added; unknown keys inside oauth stay refused. Refusing top-level keys can follow in the next minor. Docs, help text and tests updated.

Merged main in as well (only oas/docs.go conflicted; regenerated with make swagger). Touched packages and scripts/test-api-e2e.sh pass locally; cross-reviewed with gpt-6.2-sol, no blocking findings. Merging once CI is green.

@Dumbris
Dumbris enabled auto-merge (squash) November 24, 2026 13:07
auto-merge was automatically disabled November 24, 2026 16:07

Head branch was pushed to by a user without write access

@felipecrs

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the fixes! I merged main via 970e9b1, as oas/docs.go was conflicting. The push turned auto-merge off, could you please re-enable it?

felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 24, 2026

This branch has not been deployed

No deployments
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.

3 participants