Skip to main content

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
Key Components:
  • MCPServerInstanceCreated events trigger container creation
  • MCPServerInstanceDeleted events trigger container cleanup
  • Event payload includes complete configuration (json_spec)

2. Unified Configuration Pattern

Pattern: JSON Specification with Schema Validation Implementation: Industry-standard connector design

3. 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 types

Docker Provider

URL Provider

5. Repository Pattern

Pattern: Domain-Driven Repository with Event Publishing Implementation:
  • Separate repositories for MCPServer and MCPServerInstance
  • 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

The env_schema in MCPServer defines the contract for environment variables:

JSON Spec Structure

The json_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

  1. Instance Creation:
  2. Secret Resolution:
  3. Health Monitoring:

Network Architecture

Security Patterns

1. Secret Isolation

  • Secrets never stored in json_spec directly
  • 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

📋 Future Enhancements

  • 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 testing
  • mcp/filesystem: Filesystem MCP server
  • URL endpoint: localhost:3333/mcp for URL-based testing

Configuration Examples

Example 1: Docker-based MCP Server

Example 2: URL-based MCP Server

This architecture provides a flexible, scalable foundation for managing MCP servers with strong separation of concerns, event-driven communication, and secure secret management.