CLIENT-SETUP
Setup Guide
Complete guide for integrating oauth-mcp-proxy into your MCP server and configuring clients.
Table of Contents
Server Integration
Step-by-step guide for adding OAuth to your MCP server.
Quick Start
1. Install Library
go get github.com/tuannvm/oauth-mcp-proxy2. Choose Your SDK
What Happens Automatically
1. OAuth Discovery Endpoints
When you call WithOAuth(), the library automatically registers these endpoints:
MCP clients (like Claude Desktop) use these to auto-discover your OAuth configuration.
2. Automatic 401 Handling (v1.0.1+)
For mark3labs SDK: Use WrapMCPEndpoint() to wrap your /mcp endpoint:
For official SDK: Automatic - the handler returned by WithOAuth() includes 401 handling.
What it does:
✅ Returns
401 Unauthorizedif Bearer token is missing✅ Returns RFC 6750 compliant
WWW-Authenticateheaders✅ Includes OAuth discovery URL in response (
resource_metadata)✅ Passes through
OPTIONSrequests (CORS pre-flight)✅ Rejects non-Bearer auth schemes (only OAuth is supported)
Example 401 response:
3. Token Validation with Caching
Every request with a Bearer token:
Extracts token from
Authorization: Bearer <token>headerChecks cache - tokens cached for 5 minutes (keyed by SHA-256 hash)
Validates if not cached:
HMAC: Verifies signature with shared secret
OIDC: Validates JWT against provider's JWKS
Adds user to context - available via
oauth.GetUserFromContext(ctx)
4. Tool Protection
All tools registered on your MCP server are automatically protected:
No per-tool configuration needed. If authentication fails, the request never reaches your tool handler.
Accessing Authenticated User
In any tool handler, access the authenticated user from context:
User struct fields:
Subject
Stable user identifier (OIDC sub)
"00u1abc2def3ghi4jkl"
Username
Username or preferred_username
"john.doe"
Email
User's email address
"john.doe@company.com"
Name
Full name (if available)
"John Doe"
Configuration Options
Required Fields
Optional Fields
Provider-Specific Configuration
See provider-specific guides:
Client Configuration
How MCP clients discover and connect to OAuth-protected servers.
Overview
When you enable OAuth on your MCP server, clients need to know:
How to authenticate - OAuth provider details
Where to get tokens - Authorization endpoints
How to send tokens - Authorization header format
This library provides automatic discovery via OAuth 2.0 metadata endpoints.
Client Auto-Discovery (Recommended)
How It Works
Clients that support auto-discovery:
Claude Desktop (native OAuth)
Claude Code (native OAuth)
MCP Inspector (browser OAuth)
Client Configuration
Claude Desktop (claude_desktop_config.json):
That's it! Claude Desktop will:
Fetch
https://your-server.com/.well-known/oauth-authorization-serverDiscover OAuth issuer and endpoints
Guide user through OAuth flow
Store and manage tokens automatically
Manual Client Configuration
For clients without auto-discovery:
With Bearer Token (Pre-obtained)
How to get token:
HMAC: Generate using
jwt.NewWithClaims()(see HMAC Guide)OIDC: Use OAuth provider's token endpoint or admin tools
Proxy Mode (Server Handles OAuth)
For simple clients that can't do OAuth:
Client can now use your server's OAuth endpoints instead of going directly to the provider.
Configuration By Mode
Native Mode
Server config (mark3labs SDK):
Server config (official SDK):
Client discovers:
Metadata endpoints return Okta URLs
Client authenticates directly with Okta
Client sends Okta token to your server
Your server validates token against Okta
Client config (auto-discovery):
Client fetches metadata, sees Okta issuer, handles OAuth with Okta directly.
Proxy Mode
Server config (mark3labs SDK):
Server config (official SDK):
Client discovers:
Metadata endpoints return YOUR server URLs (not Okta)
Client authenticates through your server
Your server proxies to Okta
Client sends token from your server
Client config (auto-discovery):
Client fetches metadata, sees your server as issuer, does OAuth flow through your server.
Deployment Configuration
Environment Variables (Recommended)
Kubernetes (Helm)
Docker Compose
Testing Your Setup
1. Verify OAuth Endpoints
2. Test 401 Handling
3. Test with Valid Token
4. Test with MCP Client
Add to Claude Desktop config (claude_desktop_config.json):
Claude Desktop will auto-discover OAuth and guide you through authentication.
Troubleshooting
Server-Side Issues
"Authentication required: missing OAuth token"
Problem: Tool handler receives request without user in context.
Solution: Ensure you're using CreateHTTPContextFunc():
"Token validation fails"
Problem: Valid-looking token rejected.
Check:
Token's
issmatchesConfig.IssuerToken's
audmatchesConfig.AudienceToken not expired (
expclaim)For HMAC: correct
JWTSecretFor OIDC: provider JWKS reachable
Enable debug logging:
Client-Side Issues
Client Can't Discover OAuth
Check:
If 404, verify WithOAuth() was called and server is running.
Client Shows "Authentication Required"
Check:
Client is sending
Authorization: Bearer <token>headerToken is valid (not expired)
Token's
issandaudmatch server config
Debug: Enable verbose logging in client if available.
OAuth Flow Fails
Native mode:
Check client can reach OAuth provider directly
Verify provider's redirect URIs include client's callback
Proxy mode:
Check client can reach your server's /oauth endpoints
Verify your server's redirect URIs configured in provider
Client Configuration Examples
Claude Desktop
Location:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Config:
Claude Desktop auto-discovers OAuth via metadata endpoints.
Cursor / Other MCP Clients
With auto-discovery:
With manual token:
See Also
Configuration Guide - Server-side OAuth configuration
Provider Guides - OAuth provider setup (Okta, Google, Azure, HMAC)
Security Guide - Production best practices
Troubleshooting - Common issues
Examples - Working code examples for both SDKs
Last updated
Was this helpful?