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
Add
github.com/tuannvm/[email protected]to go.modRun
go mod tidyto fetch 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 URLOIDC_ISSUER- OAuth issuer URLOIDC_CLIENT_ID- OAuth client ID (proxy mode only)OIDC_CLIENT_SECRET- OAuth client secret (proxy mode only)OIDC_AUDIENCE- OAuth audienceOAUTH_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 timeMux 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
internal/config/config.go- Add OAuth and HTTP port configuration fields and parsinginternal/mcp/server.go- Implement HTTP transport with OAuth middlewareCLAUDE.md- Document OAuth configuration and usagego.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
STDIO mode without OAuth (backwards compatibility)
HTTP mode without OAuth
HTTP mode with native OAuth (Okta)
HTTP mode with proxy OAuth (Google)
Invalid token rejection
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
Add OAuth configuration (disabled)
Test HTTP transport without OAuth
Configure OAuth provider
Enable OAuth in staging
Test client integration
Roll out to production
Dependencies
Direct Dependencies
github.com/tuannvm/[email protected]- OAuth middlewaregithub.com/mark3labs/[email protected]- MCP framework (already present)
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?