Skip to main content
GolfMCP provides flexible authentication mechanisms to secure your MCP servers:
  1. JWT Authentication - Enterprise-grade authentication with JWKS support for production
  2. Development Authentication - Simple token-based authentication for development and testing
  3. OAuth Server - Full OAuth 2.0 authorization server functionality
  4. Remote Authentication - Distributed authentication across multiple resource servers
  5. API Key Authentication - Pass-through authentication to upstream APIs
Authentication is configured using a dedicated auth.py file in your project root, providing clean separation from other build logic.

JWT authentication

Overview

JWT authentication provides enterprise-grade security with JWKS (JSON Web Key Set) support. This is the recommended approach for production environments where you need standards-compliant token validation.

Configuration

Configure JWT authentication in your project’s auth.py:

Environment variables

Set these environment variables in your .env file:

How it works

  1. Token Validation: Golf validates JWTs against the JWKS endpoint
  2. Standards Compliance: Full RFC 7519 JWT validation
  3. Scope Verification: Ensures tokens have required scopes

Development authentication

Overview

Development authentication provides a simple token-based system perfect for development and testing environments. You can define custom tokens with specific client IDs and scopes.

Configuration

Configure development authentication in your project’s auth.py:

Using development tokens

Pass tokens via the Authorization header:

OAuth server configuration

Overview

Golf v0.2.0 can act as a complete OAuth 2.0 authorization server, not just validate tokens. This mode allows your MCP server to issue JWT tokens to clients and provide full OAuth 2.0 endpoints for authorization, token issuance, and revocation.

Configuration

Configure OAuth server mode in your project’s auth.py:

Environment variables

Configure runtime URL overrides in your .env file:

Remote authentication configuration

Overview

Remote authentication allows you to distribute authentication across multiple resource servers while maintaining centralized token validation. This is useful for microservices architectures where multiple services need to validate tokens from the same authorization servers.

Configuration

Environment variables

API key authentication

Overview

Golf provides a simple API key pass-through authentication mechanism that allows MCP servers to extract API keys from request headers and forward them to upstream services. The actual authentication happens at the destination API level, not within the MCP server.

Configuration

Configure API key extraction in your project’s auth.py:

Using API keys in tools

Tools access the API key with a simple import:

Using authentication tokens in tools

Overview

Golf provides a utility function for extracting authentication tokens from reqest context within your MCP tools: get_auth_token().

Token extraction functions

get_auth_token()

Enhanced environment variable support

Overview

Golf v0.2.0 significantly expanded environment variable support across all auth providers.

JWT authentication environment variables

All JWT fields now support environment variable resolution:

Migration from v0.1.x

Breaking changes from previous versions: