Skip to content

Conversation

@Dumbris
Copy link
Contributor

@Dumbris Dumbris commented Nov 30, 2025

Problem

PR #156 attempted to fix OAuth detection in auth status but had an incomplete implementation. While it added the OAuth field to contracts.Server and implemented extraction in ConvertServerConfig(), it missed adding OAuth extraction to ConvertGenericServersToTyped() - the function actually used by the HTTP API.

This caused auth status to still report "No servers with OAuth configuration found" even when servers had "oauth": {} in their config.

Root Cause

The HTTP API endpoint /api/v1/servers uses ConvertGenericServersToTyped() to serialize server data. This function extracted all server fields (name, url, env, headers, timestamps, isolation config) except OAuth configuration, causing it to be silently dropped from API responses.

Changes

Core Fix

  • Added OAuth config extraction in ConvertGenericServersToTyped() (converters.go:238-269)
  • Extracts all OAuth fields: auth_url, token_url, client_id, scopes, extra_params, redirect_port
  • Handles nested maps for scopes ([]interface{}) and extra_params (map[string]interface{})

Testing

  • Added converters_test.go with 3 comprehensive test cases:
    • Full OAuth config with all fields including extra_params
    • Empty OAuth config creates non-nil OAuth struct
    • No OAuth field leaves OAuth as nil

Verification

Before Fix

$ mcpproxy auth status
ℹ️  No servers with OAuth configuration found.
   Configure OAuth in mcp_config.json to enable authentication.

After Fix

$ mcpproxy auth status

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔐 OAuth Authentication Status
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Server: sentry
  Status: ❌ Authentication Failed
  Error: failed to connect: all authentication strategies failed, last error: 
         OAuth authorization required - deferred for background processing

API Response

$ mcpproxy upstream list --output json | jq '.[] | select(.name == "sentry") | {name, oauth}'
{
  "name": "sentry",
  "oauth": {
    "auth_url": "",
    "token_url": "",
    "client_id": ""
  }
}

Testing

# All tests pass
$ go test ./internal/contracts -v
=== RUN   TestConvertGenericServersToTyped_OAuth
--- PASS: TestConvertGenericServersToTyped_OAuth (0.00s)
=== RUN   TestConvertGenericServersToTyped_EmptyOAuth
--- PASS: TestConvertGenericServersToTyped_EmptyOAuth (0.00s)
=== RUN   TestConvertGenericServersToTyped_NoOAuth
--- PASS: TestConvertGenericServersToTyped_NoOAuth (0.00s)
PASS
ok      mcpproxy-go/internal/contracts  0.146s

Impact

This completes the OAuth visibility work started in PR #156, enabling:

  • auth status correctly detects OAuth-configured servers
  • ✅ API responses include OAuth configuration details
  • ✅ Users can diagnose OAuth authentication failures
  • ✅ Foundation for implementing extra_params support (Phase 1+ of Autodetect OAuth without explicit oauth settings #155)

Related


Note: This PR focuses solely on fixing the OAuth config extraction bug. The full extra_params implementation (allowing custom OAuth parameters like RFC 8707 resource) is tracked separately and will follow the plan in docs/plans/2025-11-27-oauth-extra-params.md.

Fixes the regression from PR #156 where `auth status` wasn't detecting
OAuth-configured servers despite the OAuth field being added to contracts.

The bug was in ConvertGenericServersToTyped() which is used by the HTTP
API to serialize servers. It extracted all server fields (env, headers,
timestamps) but completely missed the OAuth configuration.

Changes:
- Added OAuth config extraction in ConvertGenericServersToTyped()
- Extracts all OAuth fields: auth_url, token_url, client_id, scopes,
  extra_params, redirect_port
- Added comprehensive tests for OAuth extraction scenarios

Before fix:
  $ mcpproxy auth status
  ℹ️  No servers with OAuth configuration found.

After fix:
  $ mcpproxy auth status
  Server: sentry
    Status: ❌ Authentication Failed
    Error: OAuth authorization required - deferred for background processing

Resolves: #155
Related: #156
- Remove omitempty from OAuth field to prevent config file overwrites
- Add DetectOAuthAvailability() function for automatic OAuth detection
- Empty OAuth configs now persist through save/load cycles

This ensures that when users add 'oauth: {}' to their config, it won't
be removed when mcpproxy saves the config back to disk (e.g., when
toggling server enable/disable).

The auto-detection function will be used in a follow-up commit to
automatically detect OAuth availability for HTTP/SSE servers.
Updated OpenAPI artifacts to reflect the removal of omitempty from the
OAuth field in config.ServerConfig. This ensures the API documentation
accurately reflects that OAuth configs are always serialized, even when
empty.
@Dumbris Dumbris merged commit 9708bbc into main Nov 30, 2025
21 checks passed
@Dumbris Dumbris deleted the fix/oauth-config-extraction branch November 30, 2025 19:12
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.

Autodetect OAuth without explicit oauth settings

2 participants