Skip to main content

Authentication Overview

The Secure MCP Gateway uses a multi-layered authentication system that maps API keys to projects and users, ensuring secure access control and proper request routing.

Authentication Architecture

Core Concepts

1. API Keys (Gateway Keys)

Purpose: Authenticate clients and identify their project and user context. Location in config:
API Key Format:
  • 34+ characters
  • URL-safe characters (alphanumeric, _, -)
  • Generated by secure_mcp_gateway.utils.generate_custom_id()
  • Example: 2W8UupCkazk4SsOcSu_1hAbiOgPdv0g-nN9NtfZyg-rvYGat
Generation:
API keys are automatically generated when you run secure-mcp-gateway generate-config.

2. Users

Purpose: Represent individual users of the gateway. Location in config:
User Management:
User Properties:

3. Projects

Purpose: Group users with a shared MCP configuration. Multiple users can belong to the same project and share access to the same set of MCP servers. Location in config:
Project Management:
Project Properties:

4. MCP Configs

Purpose: Define the set of MCP servers, their configurations, and guardrail policies. Location in config:
See Configuration for complete MCP config structure.

Authentication Flow

Step 1: Client Provides API Key

stdio mode (Claude Desktop, Cursor):
HTTP mode:

Step 2: Gateway Extracts Credentials

Location: src/secure_mcp_gateway/gateway.py:253
Extraction sources:
  1. Environment variables (stdio mode):
    • ENKRYPT_GATEWAY_KEY
    • ENKRYPT_PROJECT_ID (optional)
    • ENKRYPT_USER_ID (optional)
  2. HTTP headers (HTTP mode):
    • Authorization: Bearer <API_KEY>
    • X-Project-Id: <PROJECT_UUID> (optional)
    • X-User-Id: <USER_UUID> (optional)
  3. Request context (FastMCP):
    • ctx.request_context.request.headers

Step 3: Validate API Key

Location: src/secure_mcp_gateway/plugins/auth/config_manager.py
Validation process:
  1. Extract gateway_key from context
  2. Check if key exists in apikeys section
  3. If not found, return authentication error
  4. If found, retrieve project_id and user_id

Step 4: Resolve Project and User

Step 5: Load MCP Configuration

Step 6: Cache Configuration

Location: src/secure_mcp_gateway/client.py:667

Admin API Authentication

Purpose: Secure REST API endpoints for administrative operations. Admin API Key:
Usage:
Protected endpoints:
  • /api/v1/configs/* - Configuration management
  • /api/v1/projects/* - Project management
  • /api/v1/users/* - User management
  • /api/v1/api-keys/* - API key management
  • /api/v1/system/* - System operations
Public endpoints:
  • /health - Health check (no auth required)
  • /docs - Swagger documentation (no auth required)

Security Best Practices

Rotate API keys regularly to minimize exposure:
Create separate projects for different access levels:
Enable telemetry to track all authentication attempts:
Review logs regularly:
Never hardcode API keys in code or commit them to version control:Good:
Bad:
For production environments, consider implementing additional authentication layers:
  1. Network-level: Use VPN or IP whitelisting
  2. TLS certificates: Enable mutual TLS (mTLS)
  3. OAuth integration: Use Enkrypt’s OAuth provider for centralized auth
Example with OAuth:

Common Scenarios

Scenario 1: Single User, Single Project

Use case: Personal development environment

Scenario 2: Team Project, Multiple Users

Use case: Shared production environment
All three users share the same MCP config but have individual API keys for tracking.

Scenario 3: Multi-Environment, Same User

Use case: One user accessing dev, staging, and production
The user has different API keys for each environment.

Scenario 4: Service Accounts

Use case: Automated tools/CI/CD accessing the gateway

Troubleshooting

Error: “Invalid API key”

Cause: API key not found in apikeys section. Solution:

Error: “Project not found”

Cause: project_id referenced by API key doesn’t exist. Solution:

Error: “User not authorized for project”

Cause: User exists but is not in project’s user list. Solution:

Error: “MCP configuration not found”

Cause: mcp_config_id referenced by project doesn’t exist. Solution:

Next Steps

Configuration

Learn about MCP configs and server settings

API Keys Management

CLI commands for managing API keys

Projects

CLI commands for managing projects

Users

CLI commands for managing users