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-proxy

2. Choose Your SDK

chevron-rightmark3labs/mcp-go SDKhashtag

Import Packages

Configure OAuth

Create MCP Server with OAuth

Setup Endpoint with Automatic 401 Handling

Start Server

chevron-rightOfficial modelcontextprotocol/go-sdkhashtag

Import Packages

Create MCP Server

Add OAuth Protection

Start Server


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 Unauthorized if Bearer token is missing

  • ✅ Returns RFC 6750 compliant WWW-Authenticate headers

  • ✅ Includes OAuth discovery URL in response (resource_metadata)

  • ✅ Passes through OPTIONS requests (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:

  1. Extracts token from Authorization: Bearer <token> header

  2. Checks cache - tokens cached for 5 minutes (keyed by SHA-256 hash)

  3. Validates if not cached:

    • HMAC: Verifies signature with shared secret

    • OIDC: Validates JWT against provider's JWKS

  4. 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:

Field
Description
Example

Subject

Stable user identifier (OIDC sub)

"00u1abc2def3ghi4jkl"

Username

Username or preferred_username

"john.doe"

Email

User's email address

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:

  1. How to authenticate - OAuth provider details

  2. Where to get tokens - Authorization endpoints

  3. How to send tokens - Authorization header format

This library provides automatic discovery via OAuth 2.0 metadata endpoints.


How It Works

spinner

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:

  1. Fetch https://your-server.com/.well-known/oauth-authorization-server

  2. Discover OAuth issuer and endpoints

  3. Guide user through OAuth flow

  4. 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

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:

  1. Token's iss matches Config.Issuer

  2. Token's aud matches Config.Audience

  3. Token not expired (exp claim)

  4. For HMAC: correct JWTSecret

  5. For 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:

  1. Client is sending Authorization: Bearer <token> header

  2. Token is valid (not expired)

  3. Token's iss and aud match 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.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

  • Linux: ~/.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

Last updated

Was this helpful?