OAuth 2.1 Implementation Plan

Overview

Integrate OAuth 2.1 authentication for kafka-mcp-server using the oauth-mcp-proxy library. This implementation follows the pattern established in mcp-trino.

Architecture

OAuth Modes

Native Mode (Zero server-side secrets)

  • Clients handle OAuth flow directly

  • Server validates Bearer tokens via OAuth provider

  • No client secrets stored on server

  • Most secure option

Proxy Mode (Centralized management)

  • Server manages OAuth flow and token exchange

  • Requires client ID, client secret, and JWT secret

  • Supports redirect URI configuration

  • Useful for centralized control

Transport Requirement

OAuth authentication requires HTTP transport (Bearer tokens in headers). STDIO transport will remain available for local/trusted environments without authentication.

Implementation Phases

Phase 1: Dependencies

Phase 2: Configuration

Update internal/config/config.go:

Environment variables:

  • MCP_HTTP_PORT - HTTP server port (default: 8080)

  • OAUTH_ENABLED - Enable OAuth (default: false)

  • OAUTH_MODE - "native" or "proxy" (default: native)

  • OAUTH_PROVIDER - Provider type (default: okta)

  • OAUTH_SERVER_URL - Server base URL

  • OIDC_ISSUER - OAuth issuer URL

  • OIDC_CLIENT_ID - OAuth client ID (proxy mode only)

  • OIDC_CLIENT_SECRET - OAuth client secret (proxy mode only)

  • OIDC_AUDIENCE - OAuth audience

  • OAUTH_REDIRECT_URIS - Comma-separated redirect URIs (proxy mode only)

  • JWT_SECRET - JWT signing secret (proxy mode only)

Phase 3: Add OAuth Helper Function

Add to internal/mcp/server.go:

Phase 4: Update Main Entry Point

Update cmd/main.go to create OAuth option BEFORE server creation:

Phase 5: Update Server Start Function

Update internal/mcp/server.go Start function:

Critical Notes:

  • OAuth option MUST be passed to NewMCPServer() at creation time

  • Mux must be created BEFORE calling CreateOAuthOption (WithOAuth registers routes on it)

  • CreateHTTPContextFunc() extracts Bearer tokens from Authorization header

  • OAuth endpoints automatically registered when CreateOAuthOption is called

Phase 6: Documentation Updates

Update CLAUDE.md:

  • Add OAuth configuration section

  • Document environment variables

  • Provide examples for both modes

  • Add troubleshooting guide

Code Changes Summary

Files to Modify

  1. internal/config/config.go - Add OAuth and HTTP port configuration fields and parsing

  2. internal/mcp/server.go - Implement HTTP transport with OAuth middleware

  3. CLAUDE.md - Document OAuth configuration and usage

  4. go.mod - Add oauth-mcp-proxy dependency

Files to Create

  • None (optional: example configs for different providers)

Configuration Examples

Native Mode (Okta)

Proxy Mode (Google)

Testing Strategy

Unit Tests

  • Config parsing for all OAuth parameters

  • OAuth middleware initialization

  • Error handling for invalid configurations

Integration Tests

  • HTTP server startup with OAuth enabled/disabled

  • Token validation (using test tokens)

  • Both native and proxy mode flows

Manual Testing

  1. STDIO mode without OAuth (backwards compatibility)

  2. HTTP mode without OAuth

  3. HTTP mode with native OAuth (Okta)

  4. HTTP mode with proxy OAuth (Google)

  5. Invalid token rejection

  6. User context extraction from valid tokens

Deployment Considerations

Backwards Compatibility

  • STDIO transport remains default

  • OAuth disabled by default

  • Existing configurations continue to work

Security Notes

  • Never log OAuth secrets or tokens

  • Use TLS in production (HTTPS)

  • Rotate JWT secrets regularly in proxy mode

  • Validate issuer URLs match expected providers

Migration Path

  1. Add OAuth configuration (disabled)

  2. Test HTTP transport without OAuth

  3. Configure OAuth provider

  4. Enable OAuth in staging

  5. Test client integration

  6. Roll out to production

Dependencies

Direct Dependencies

OAuth Provider Requirements

  • Okta: Okta account, OAuth application configured

  • Google: Google Cloud project, OAuth 2.0 credentials

  • Azure AD: Azure AD tenant, app registration

  • HMAC: Shared secret for development/testing

Success Criteria

Last updated

Was this helpful?