For the complete documentation index, see llms.txt. This page is also available as Markdown.

OAuth MCP Proxy Examples

This directory contains example MCP servers demonstrating OAuth integration with both supported SDKs.

Directory Structure

examples/
├── mark3labs/              (mark3labs/mcp-go SDK examples)
│   ├── simple/            - Basic OAuth integration
│   └── advanced/          - ConfigBuilder, env vars, multiple tools

└── official/               (modelcontextprotocol/go-sdk examples)
    ├── simple/            - Basic OAuth integration
    └── advanced/          - Multiple tools, env vars, logging

Examples Overview

SDK
Example
Tools
Provider
Features

mark3labs

simple

1 (greet)

Okta

Basic OAuth, env vars

mark3labs

advanced

1 (get_user_info)

Okta

ConfigBuilder, env vars, logging, status endpoint

official

simple

1 (greet)

Okta

Basic OAuth, env vars

official

advanced

1 (get_user_info)

Okta

ConfigBuilder, env vars, logging, status endpoint


Quick Start

mark3labs SDK

Simple:

Advanced:

Official SDK

Simple:

Advanced:

All examples start a server on http://localhost:8080 with OAuth protection.


Okta Setup

All examples use Okta as the OAuth provider. Before running, you need to set up Okta:

1. Create Okta Account

Sign up at https://developer.okta.com (free developer account)

2. Create API in Okta

  1. Go to Security > API in Okta Admin Console

  2. Click Add Authorization Server or use the default

  3. Note your Issuer URI (e.g., https://dev-12345.okta.com)

  4. Create an Audience identifier (e.g., api://my-mcp-server)

3. Set Environment Variables

4. Get a Test Token

Option A: Using Okta CLI

Option B: Using Okta Dashboard

  1. Go to Security > API > Authorization Servers

  2. Click your authorization server

  3. Go to Token Preview tab

  4. Generate a token with your audience

5. Test the Server


Configuration Options

Environment Variables

All examples support these environment variables:

Using Other Providers

To use Google or Azure AD instead of Okta, modify the config:

Google:

Azure AD:


Example Comparison

mark3labs/simple

What it shows:

  • Basic OAuth integration with mark3labs.WithOAuth()

  • Single tool with user context access

  • Okta provider configuration

  • Environment variable support

Use when: You want the simplest possible OAuth setup with mark3labs SDK.

mark3labs/advanced

What it shows:

  • ConfigBuilder for flexible configuration

  • Environment variable support (Okta domain, audience, server URL)

  • Multiple tools with different functionality

  • Custom logging

  • OAuth endpoint discovery logging

  • Production-ready patterns

Use when: You need production-ready configuration with mark3labs SDK.

official/simple

What it shows:

  • Basic OAuth integration with mcpoauth.WithOAuth()

  • Single tool with user context access

  • Official SDK tool definition patterns

  • Okta provider configuration

  • Environment variable support

Use when: You want the simplest possible OAuth setup with official SDK.

official/advanced

What it shows:

  • ConfigBuilder for flexible configuration

  • Multiple tools (greet, whoami, server_time)

  • Environment variable support (Okta domain, audience)

  • OAuth endpoint discovery logging

  • Production-ready patterns

  • Official SDK patterns

Use when: You need production-ready configuration with official SDK.


Code Patterns Comparison

mark3labs SDK

Setup:

Adding Tools:

Official SDK

Setup:

Adding Tools:

Key Difference: mark3labs uses ServerOption before server creation, official SDK wraps the server with http.Handler after creation.


Accessing User Information

All examples show how to access authenticated user information:

For the official SDK, you can also access user info via the go-sdk's auth context:


Common Issues

"authentication required: missing OAuth token"

Cause: No Authorization header or invalid format.

Solution:

"authentication failed: token validation failed"

Cause: Invalid token or wrong secret.

Solution:

  • For HMAC: Ensure HMAC_SECRET matches the secret used to sign the token

  • For OIDC: Verify issuer, audience, and that the token is from the correct provider

"Accept must contain both 'application/json' and 'text/event-stream'"

Cause: Missing Accept header (official SDK only).

Solution:


Building for Production

Dockerfile Example

Production Checklist


Further Reading


Need Help?

  • Issues: https://github.com/tuannvm/oauth-mcp-proxy/issues

  • Discussions: https://github.com/tuannvm/oauth-mcp-proxy/discussions

  • Documentation: See files in /docs directory

Last updated

Was this helpful?