Skip to content

feat(import): parse claude code oauth blocks - #2018

Draft
felipecrs wants to merge 4 commits into
smart-mcp-proxy:mainfrom
felipecrs:feat/claude-code-oauth-import
Draft

felipecrs wants to merge 4 commits into
smart-mcp-proxy:mainfrom
felipecrs:feat/claude-code-oauth-import

Conversation

@felipecrs

@felipecrs felipecrs commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

Description

upstream import can read Claude Code config files, but it silently dropped the oauth block. The parser struct had no oauth field, so a server exported or pasted from Claude Code arrived without OAuth and needed manual setup in config or the web UI before sign-in worked.

Claude Code documents the block in its MCP config reference: clientId, scopes (a space-separated string there, not a list), callbackPort and authServerMetadataUrl. The client secret is kept in the keychain, not in the config, so a block with a clientId warns that the secret has to be set again.

Changes:

  • Parse the oauth block per server and pass it through the mapper as OAuthConfig.
  • clientId and authServerMetadataUrl map 1:1. An authServerMetadataUrl mcpproxy would not accept is dropped with a warning.
  • scopes becomes a list via strings.Fields.
  • An empty clientId stays empty: mcpproxy falls back to DCR or public-client PKCE, which is what a server without a static client needs anyway.
  • callbackPort has no mcpproxy equivalent. redirect_uri pins the whole callback URL, so a port-only pin can't be half-applied; it's dropped with a warning that names the field, also when it is the only key. Claude Code also allocates that port for its own callback rather than expecting a fixed one at the IdP.
  • Unknown keys inside oauth warn and are ignored instead of refusing the import. This is a foreign file format; when Claude Code grows a field mcpproxy doesn't know, the import should say "ignored", not fail. A malformed oauth value is also a warning for that server only; the other servers still import.
  • An oauth object counts as a Claude Code indicator in format detection (Gemini's has enabled).

In daemon mode the parsed block reaches the daemon through the AddServerRequest oauth field from #1972. The parser, mapper and config-file mode work without it.

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:

  • TestClaudeCodeParser_Parse/oauth_block
  • TestClaudeCodeParser_Parse/oauth_unknown_keys_warned
  • TestClaudeCodeParser_Parse/oauth_malformed_keeps_servers
  • TestMapToServerConfig/claude_code_oauth
  • TestMapToServerConfig/claude_code_oauth_without_client_id
  • TestMapToServerConfig/claude_code_oauth_callback_port_only
  • TestMapToServerConfig/claude_code_oauth_invalid_metadata_url_dropped
  • TestDetectFormat/claude_code_sse_with_oauth and gemini_oauth_is_not_claude_code

go test ./internal/configimport/ and the related cmd/mcpproxy tests pass.

golangci-lint is clean on internal/configimport.

Claude Code configs can carry an oauth block per server (clientId,
clientSecret, scopes, callbackPort, authServerMetadataUrl), but the
import parser ignored it, so those servers arrived without OAuth and
needed manual setup. Parse the block, map it to OAuthConfig and warn
on the parts that do not translate.

Field mapping:
- clientId, clientSecret and authServerMetadataUrl map 1:1.
- scopes arrives as a space-separated string and becomes a list.
- callbackPort pins only a port; mcpproxy pins the whole redirect URL,
  so the port is dropped with a warning instead of half-applied.
- An empty clientId stays empty: mcpproxy falls back to DCR or
  public-client PKCE, which is what a server without a static client
  needs.
- Unknown keys in the block warn and are ignored rather than refused:
  this is a foreign file format, and new Claude Code fields should
  surface as ignored, not break the import.

Daemon-mode apply needs the AddServerRequest oauth field from smart-mcp-proxy#1972;
config-file mode and the parse and map pipeline are complete here.
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 23, 2026
@Dumbris

Dumbris commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thanks for this, Felipe — the direction is right and the mapping of scopes / authServerMetadataUrl / empty clientId looks good. Early notes since it's a draft:

  1. clientSecret isn't an oauth key in Claude Code. The MCP docs (code.claude.com/docs/en/mcp, "pre-configured OAuth credentials") say the secret is passed once with --client-secret / MCP_CLIENT_SECRET and stored in the keychain, not in the config. So exports never carry it. I'd drop the field from the parser (or keep it but not advertise it) and instead warn that the secret has to be re-entered when clientId is set.
  2. callbackPort-only blocks are dropped silently — the warning in mapper.go sits inside if oauth != nil, but a port-only block maps to nil. That's a documented Claude Code setup.
  3. A malformed oauth value fails the whole file (scopes as array, callbackPort as string, oauth: false) because the custom UnmarshalJSON errors out of Parse. Decoding oauth as json.RawMessage and warning per server would keep the other servers importable.
  4. Detection: an SSE-only .mcp.json falls to the Cursor format and loses the block unless --format claude-code is passed; an oauth object could count as a Claude Code indicator.
  5. Consider validating authServerMetadataUrl in the mapper (https, no userinfo/query, see config.OAuthConfig.Validate) like the Gemini redirect_uri path, so an invalid URL is warned about at import rather than dropped at load. Minor: unknown-key matching is case-sensitive while Go's decoder isn't (ClientID is applied but reported as ignored).
  6. Daemon mode needs fix(cli): carry oauth through add-json and import, warn on unknown keys #1972 first (it adds the oauth field to the add-server request); on main the CLI would say "OAuth credentials imported" while the daemon drops it. Worth rebasing on fix(cli): carry oauth through add-json and import, warn on unknown keys #1972 once it lands, and a test for that path.

Also: CI hasn't run (fork workflows await approval); please run golangci-lint and the full go test ./... for the last checkbox. I'll approve the CI runs once you mark it ready.

@Dumbris Dumbris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes per the review above (#2018 (comment)). The direction is good; the daemon-mode part depends on #1972, which is close to merging. Thanks!

@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 86.11111% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/configimport/claude_code.go 78.94% 2 Missing and 2 partials ⚠️
internal/configimport/mapper.go 94.11% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@felipecrs

Copy link
Copy Markdown
Contributor Author

Thanks for the review! 1–5 are fixed via 5e57420, and main is merged in. For 6, I'll merge again and add the daemon mode test once #1972 lands.

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