HMAC Provider Guide
📢 v1.0.0: This guide shows examples for both
mark3labs/mcp-goand officialmodelcontextprotocol/go-sdk. See MIGRATION-V2.md 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 validatorAudience- Must match theaudclaim in tokensJWTSecret- 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 matchConfig.Audience)exp- Expiration (Unix timestamp)iat- Issued at (Unix timestamp)
Optional Claims (extracted if present)
email- User's emailpreferred_username- Username (falls back toemailorsub)
Security Considerations
Secret Management
Secret Strength
Minimum: 32 bytes (256 bits)
Recommended: Generate with
crypto/randNever: Use passwords, dictionary words, or predictable values
Token Expiration
Recommended: 1 hour for user tokens
Service tokens: Up to 24 hours
Always include
expclaim
Testing
1. Start Your MCP Server
2. Generate Test Token
3. Test Authentication
Complete Examples
mark3labs SDK:
examples/mark3labs/simple/ - Minimal HMAC setup
examples/mark3labs/advanced/ - Full featured
Official SDK:
examples/official/simple/ - Minimal HMAC setup
examples/official/advanced/ - Full featured
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?