Skip to main content

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 the PluginLoader class. The loader:
  1. Reads plugin configuration from plugins section in config file
  2. Instantiates the specified provider class
  3. Registers the provider with the appropriate manager
  4. 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 in plugin_loader.py:55:

Design Patterns

Registry Pattern

Each plugin type uses a registry to manage provider instances:

Factory Pattern

The GuardrailFactory creates guardrail instances from registered providers:

Protocol/Interface Segregation

Guardrail providers use multiple protocols for different capabilities:
  • InputGuardrail - Validates requests before execution
  • OutputGuardrail - Validates responses after execution
  • PIIHandler - Handles PII detection and redaction
This allows providers to implement only the features they support.

Plugin Lifecycle

Initialization

  1. Gateway Startup - gateway.py loads common config
  2. Plugin Loading - PluginLoader.load_plugin_providers() discovers providers
  3. Registration - Providers registered with manager instances
  4. Validation - Provider config validated with validate_config()

Request Processing

  1. Credential Extraction - Auth manager extracts credentials from request
  2. Authentication - Auth provider validates credentials
  3. Tool Discovery - Gateway discovers available tools
  4. Input Guardrails - Request validated before execution (optional)
  5. Tool Execution - MCP tool executed via client
  6. Output Guardrails - Response validated after execution (optional)
  7. Telemetry - Events logged/traced throughout

Shutdown

Telemetry providers can implement shutdown() for cleanup:

Best Practices

Always wrap provider operations in try/except blocks and return appropriate status codes:
Never log sensitive credentials. Use masking utilities:
Implement validate_config() to check required fields:
Use async/await for I/O operations:

Default Providers

The gateway includes these default providers:
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