MCP Infrastructure Architecture
Overview
The MCP (Model Context Protocol) infrastructure implements a distributed, event-driven architecture for managing MCP server instances. The system supports both containerized and URL-based MCP servers with dynamic configuration and secret management.Architecture Patterns
1. Event-Driven Architecture
Pattern: Domain Events + Redis Pub/Sub Implementation:- Python FastAPI publishes domain events to Redis
- Go MCP Manager subscribes to events and handles container lifecycle
- Async communication ensures loose coupling
MCPServerInstanceCreatedevents trigger container creationMCPServerInstanceDeletedevents trigger container cleanup- Event payload includes complete configuration (
json_spec)
2. Unified Configuration Pattern
Pattern: JSON Specification with Schema Validation Implementation: Inspired by Airbyte Connectors3. Secret Management Pattern
Pattern: Reference-based Secret Storage Implementation:- Environment variables stored as references in
json_spec - Actual values stored in secret manager (Infisical/DB)
- Go service resolves secrets at container runtime
4. Multi-Provider Pattern
Pattern: Type-based Provider Selection Implementation: Support for different MCP deployment typesDocker Provider
URL Provider
5. Repository Pattern
Pattern: Domain-Driven Repository with Event Publishing Implementation:- Separate repositories for
MCPServerandMCPServerInstance - Event publishing integrated into service layer
- Clean separation of persistence and business logic
6. Dependency Injection Pattern
Pattern: FastAPI Dependency Injection Implementation:- Services injected via
Depends() - Secret manager, event broker, repositories all injectable
- Enables testing with mock implementations
Data Models
MCPServer (Schema Definition)
MCPServerInstance (Runtime Configuration)
Environment Schema Structure
Theenv_schema in MCPServer defines the contract for environment variables:
JSON Spec Structure
Thejson_spec in MCPServerInstance contains the complete runtime configuration:
Docker Type
URL Type
Service Architecture
Python FastAPI Services
- MCPServerService: Manages server definitions and schemas
- MCPServerInstanceService: Manages instance lifecycle and configuration
- MCPEnvironmentService: Handles secret storage and retrieval
- EventBroker: Publishes domain events to Redis
Go MCP Manager Services
- EventSubscriber: Listens for Redis events
- ContainerManager: Manages Podman containers
- SecretResolver: Resolves secret references (to be implemented)
- HealthChecker: Monitors container/URL health
Event Flow
-
Instance Creation:
-
Secret Resolution:
-
Health Monitoring:
Network Architecture
Security Patterns
1. Secret Isolation
- Secrets never stored in
json_specdirectly - Reference-based storage with resolution at runtime
- Separate secret manager with encrypted storage
2. Network Isolation
- MCP containers on isolated network
- Reverse proxy (Traefik) for external access
- Internal service communication only
3. Resource Limits
- Container resource constraints (CPU, memory)
- Maximum container limits per instance
- Health check timeouts and retries
Implementation Status
✅ Completed
- Event-driven architecture with Redis
- Basic container management with Podman
- Database models and repositories
- API endpoints for CRUD operations
- Network configuration and service discovery
🚧 In Progress
- Event parsing and data extraction (minor bug fix needed)
- Container creation from
json_spec
📋 TODO
- Secret resolution in Go service
- URL-based MCP provider support
- Health monitoring and status updates
- Resource management and cleanup
- Production deployment configuration
Testing Strategy
Integration Tests
- End-to-end flow from API to container creation
- Event publishing and consumption
- Secret management integration
- Health check validation
Test Containers
agentarea/echo: Simple HTTP echo server for testingmcp/filesystem: Filesystem MCP server- URL endpoint:
localhost:3333/mcpfor URL-based testing

