HMAC Provider Guide

📢 v1.0.0: This guide shows examples for both mark3labs/mcp-go and official modelcontextprotocol/go-sdk. See MIGRATION-V2.mdarrow-up-right for upgrade details.

Overview

HMAC provider uses shared secret JWT validation with HS256 algorithm. Best for testing, development, and service-to-service authentication.

When to Use

Good for:

  • Local development and testing

  • Service-to-service authentication

  • Simple deployments without external OAuth provider

  • Full control over token generation

Not ideal for:

  • User authentication (no SSO)

  • Public-facing applications (secret distribution problem)

  • Multi-tenant applications


Configuration

Using mark3labs/mcp-go

Using Official SDK

Required Fields

  • Provider: "hmac" - Use HMAC validator

  • Audience - Must match the aud claim in tokens

  • JWTSecret - Shared secret for signing/verifying tokens (32+ bytes recommended)


Token Generation

Generate tokens using github.com/golang-jwt/jwt/v5:

Required JWT Claims

  • sub - Subject (user identifier)

  • aud - Audience (must match Config.Audience)

  • exp - Expiration (Unix timestamp)

  • iat - Issued at (Unix timestamp)

Optional Claims (extracted if present)

  • email - User's email

  • preferred_username - Username (falls back to email or sub)


Security Considerations

Secret Management

Secret Strength

  • Minimum: 32 bytes (256 bits)

  • Recommended: Generate with crypto/rand

  • Never: Use passwords, dictionary words, or predictable values

Token Expiration

  • Recommended: 1 hour for user tokens

  • Service tokens: Up to 24 hours

  • Always include exp claim


Testing

1. Start Your MCP Server

2. Generate Test Token

3. Test Authentication


Complete Examples

mark3labs SDK:

Official SDK:

See examples/README.md for setup instructions.


Limitations

  • No built-in user management (you generate tokens)

  • Secret must be shared with all token generators

  • No automatic token refresh

  • Not suitable for public clients (secret exposure risk)

For user authentication with SSO, consider Okta, Google, or Azure providers.

Last updated

Was this helpful?