Skip to main content

Overview

Secure MCP Gateway provides comprehensive guardrail protection for both input requests and output responses. Guardrails validate content before it reaches MCP servers and after responses are received, protecting against various security threats and policy violations. Guardrails Architecture

Architecture

The guardrail system follows a plugin-based architecture with three main components:
  • GuardrailProvider: Abstract base class for all guardrail implementations
  • InputGuardrail: Validates requests before sending to MCP servers
  • OutputGuardrail: Validates responses after receiving from MCP servers
  • PIIHandler: Specialized interface for PII detection and redaction

Violation Types

The gateway detects and blocks various violation types:

Input Violations

PII Detection

Detects personally identifiable information in requests

Injection Attacks

Prevents prompt injection, SQL injection, and command injection

Toxic Content

Filters hate speech, abuse, and harmful language

NSFW Content

Blocks inappropriate or explicit content

Policy Violations

Enforces custom organizational policies

Bias Detection

Identifies biased or discriminatory content

Output Violations

All input violations plus:

Relevancy

Validates response relevance to the original request

Adherence

Ensures response follows instructions and policies

Hallucination

Detects AI-generated false information

GuardrailProvider Interface

All guardrail providers implement the GuardrailProvider abstract base class:
src/secure_mcp_gateway/plugins/guardrails/base.py

Built-in Providers

Enkrypt Provider

Production-grade guardrails powered by Enkrypt AI’s API:
src/secure_mcp_gateway/plugins/guardrails/enkrypt_provider.py

OpenAI Moderation Provider

Using OpenAI’s Moderation API:
src/secure_mcp_gateway/plugins/guardrails/example_providers.py

Custom Keyword Provider

Simple keyword-based blocking:
src/secure_mcp_gateway/plugins/guardrails/example_providers.py

Configuration

Enable Guardrails for a Server

Configure Plugin Provider

enkrypt_mcp_config.json

PII Handling

The gateway provides automatic PII redaction and de-anonymization:
1

Detect PII

Input guardrails detect PII in requests (emails, phone numbers, SSNs, etc.)
2

Redact PII

PII is replaced with placeholders before sending to MCP server
3

Store Mapping

Original PII values are stored in a secure mapping with correlation IDs
4

De-anonymize Response

Output guardrails restore original PII values in responses using the mapping
Example Flow

Guardrail Actions

When a violation is detected, the gateway can take different actions:

Usage Examples

Test Guardrails with MCP Client

Create Custom Guardrail Provider

my_custom_provider.py

Best Practices

Performance Considerations: Guardrails add latency to requests. Use asynchronous guardrails (enkrypt_async_input_guardrails_enabled: true) for high-throughput scenarios.
Policy Management: Create guardrail policies in the Enkrypt Dashboard for easier management and updates.
Testing: Use the included test servers in bad_mcps/ to test your guardrail configurations against various attack vectors.

Metrics and Monitoring

Guardrails emit telemetry for monitoring:
  • guardrail.input.validation.count - Number of input validations
  • guardrail.output.validation.count - Number of output validations
  • guardrail.violations.count - Violations detected by type
  • guardrail.blocks.count - Requests blocked
  • guardrail.latency.ms - Validation latency
View metrics in Grafana dashboard or query via Prometheus.