Architecture
The Secure MCP Gateway uses a flexible plugin-based architecture to support custom authentication, guardrails, and telemetry providers. This design allows you to extend the gateway’s functionality without modifying core code.Plugin Types
The gateway supports three types of plugins:Auth Providers
Validate API keys, OAuth tokens, JWT, and custom credentials
Guardrail Providers
Detect PII, toxicity, policy violations, and security threats
Telemetry Providers
Export logs, traces, and metrics to observability platforms
Plugin Discovery
Plugins are loaded dynamically using thePluginLoader class. The loader:
- Reads plugin configuration from
pluginssection in config file - Instantiates the specified provider class
- Registers the provider with the appropriate manager
- Falls back to default Enkrypt providers if custom providers fail
Configuration Structure
Creating a Custom Plugin
Step 1: Implement the Provider Interface
Create a new Python file with your provider class implementing the appropriate abstract base class:Step 2: Register Your Plugin
Update your configuration to use the custom provider:Step 3: Make Your Provider Discoverable
Add your provider to the plugin loader mapping inplugin_loader.py:55:
Design Patterns
Registry Pattern
Each plugin type uses a registry to manage provider instances:Factory Pattern
TheGuardrailFactory creates guardrail instances from registered providers:
Protocol/Interface Segregation
Guardrail providers use multiple protocols for different capabilities:InputGuardrail- Validates requests before executionOutputGuardrail- Validates responses after executionPIIHandler- Handles PII detection and redaction
Plugin Lifecycle
Initialization
- Gateway Startup -
gateway.pyloads common config - Plugin Loading -
PluginLoader.load_plugin_providers()discovers providers - Registration - Providers registered with manager instances
- Validation - Provider config validated with
validate_config()
Request Processing
- Credential Extraction - Auth manager extracts credentials from request
- Authentication - Auth provider validates credentials
- Tool Discovery - Gateway discovers available tools
- Input Guardrails - Request validated before execution (optional)
- Tool Execution - MCP tool executed via client
- Output Guardrails - Response validated after execution (optional)
- Telemetry - Events logged/traced throughout
Shutdown
Telemetry providers can implementshutdown() for cleanup:
Best Practices
Error Handling
Error Handling
Always wrap provider operations in try/except blocks and return appropriate status codes:
Sensitive Data Masking
Sensitive Data Masking
Never log sensitive credentials. Use masking utilities:
Configuration Validation
Configuration Validation
Implement
validate_config() to check required fields:Async Operations
Async Operations
Use async/await for I/O operations:
Default Providers
The gateway includes these default providers:| Plugin Type | Provider | Description |
|---|---|---|
| Auth | local_apikey | Validates API keys from local config file |
| Auth | enkrypt | Remote authentication via Enkrypt API |
| Guardrails | enkrypt | Production guardrail service with 10+ detectors |
| Telemetry | opentelemetry | Full OpenTelemetry with OTLP export |
The
PluginLoader automatically falls back to default Enkrypt providers if custom providers fail to load.Next Steps
Auth Providers
Learn about the AuthProvider interface
Guardrail Providers
Build custom security guardrails
Telemetry Providers
Integrate custom observability backends