Request Flow Overview
The Secure MCP Gateway processes requests through a multi-stage pipeline that ensures security, performance, and observability at every step.Complete Request Flow
Detailed Step-by-Step Process
Step 1: Client Connection
Location: Client configuration (Claude Desktop, Cursor) The MCP client connects to the gateway with credentials in the request context: stdio mode:Step 2: Gateway Server Receives Request
Location:src/secure_mcp_gateway/gateway.py:796
The FastMCP server receives the request and extracts credentials:
Step 3: Authentication
Location:src/secure_mcp_gateway/plugins/auth/config_manager.py
The auth manager validates the API key and retrieves the user context:
- Extract
gateway_keyfrom request context - Look up API key in
apikeyssection of config - Retrieve associated
project_idanduser_id - Get
mcp_config_idfrom project configuration - Load full gateway configuration
src/secure_mcp_gateway/client.py:632
Step 4: Request Routing
Location:src/secure_mcp_gateway/gateway.py
The gateway routes the request to the appropriate service:
Route 1: Tool Discovery
Triggered by:enkrypt_discover_all_tools or enkrypt_list_all_servers
Location: src/secure_mcp_gateway/services/discovery/discovery_service.py
Route 2: Tool Execution
Triggered by:enkrypt_secure_call_tools
Location: src/secure_mcp_gateway/services/execution/secure_tool_execution_service.py
Step 5: Gateway Client Forwards Request
Location:src/secure_mcp_gateway/client.py:294
The gateway client connects to the actual MCP server via stdio:
Step 6: MCP Server Processes Request
The actual MCP server (e.g., GitHub, filesystem, custom server) receives and processes the request:Step 7: Response Processing
The response flows back through the gateway:7a. Tool Discovery Response
Location:src/secure_mcp_gateway/services/discovery/discovery_service.py
src/secure_mcp_gateway/client.py:515
7b. Tool Execution Response
Output guardrails processing:Step 8: Telemetry and Logging
Location: Throughout the request flow All operations are logged with structured context:Step 9: Response Return to Client
The final response is returned to the MCP client:OAuth Token Flow
For servers requiring OAuth authentication: Location:src/secure_mcp_gateway/services/oauth/
Token acquisition: src/secure_mcp_gateway/services/oauth/oauth_service.py:71
Cache Strategy
Cache Levels
- Local in-memory cache (single instance)
- External cache (Redis/KeyDB for multi-instance)
Cache Keys
All keys are MD5 hashed for security:Cache Expiration
- Tool cache: 4 hours (default)
- Gateway config cache: 24 hours (default)
- OAuth tokens: Based on
expires_infrom OAuth server (with 5 min buffer)
Cache Registry
The gateway maintains registries for cleanup:Error Handling
Errors are handled at each stage with detailed context: Location:src/secure_mcp_gateway/error_handling.py
Next Steps
Configuration
Learn about all configuration options and settings
Authentication
Understand authentication mechanisms and API keys
Guardrails
Explore input and output protection features
Caching
Optimize performance with intelligent caching