Skip to content

Architecture

2. Architecture OverviewΒΆ

2.1 High-Level ArchitectureΒΆ

flowchart TB
    subgraph "MCP Client"
        Client["πŸ§‘β€πŸ’» MCP Client Application"]
    end

    subgraph "MCP Gateway"
        Gateway["🌐 Gateway Core"]
        PM["πŸ”Œ Plugin Manager"]
        Executor["⚑ Plugin Executor"]
    end

    subgraph "Plugin Ecosystem"
        Native["πŸ“¦ Native Plugins"]
        External["🌍 External MCP <br> Plugin Servers"]
    end

    subgraph "External Services"
        AI["πŸ€– AI Safety Services<br>(LlamaGuard, OpenAI)"]
        Security["πŸ” Security Services<br>(Vault, OPA)"]
    end

    Client --> Gateway
    Gateway --> PM
    PM --> Executor
    Executor --> Native
    Executor --> External
    External --> AI
    External --> Security

    style Gateway fill:#e3f2fd
    style PM fill:#fff3e0
    style Native fill:#e8f5e8
    style External fill:#fff8e1

2.2 Framework StructureΒΆ

mcpgateway/plugins/framework/
β”œβ”€β”€ base.py              # Plugin base classes
β”œβ”€β”€ models.py            # Pydantic models for all plugin types
β”œβ”€β”€ manager.py           # PluginManager singleton with lifecycle management
β”œβ”€β”€ registry.py          # Plugin instance registry and discovery
β”œβ”€β”€ constants.py         # Framework constants and enums
β”œβ”€β”€ errors.py            # Plugin-specific exception types
β”œβ”€β”€ utils.py             # Utility functions for plugin operations
β”œβ”€β”€ loader/
β”‚   β”œβ”€β”€ config.py        # Configuration loading and validation
β”‚   └── plugin.py        # Dynamic plugin loading and instantiation
└── external/
    └── mcp/             # MCP external service integration
        β”œβ”€β”€ client.py    # MCP client for external plugin communication
        └── server/      # MCP server runtime for plugin hosting

2.3 Plugin Deployment PatternsΒΆ

2.3.1 Native Plugins (In-Process)ΒΆ

  • Execute within the main gateway process
  • Extends the base Plugin class
  • Sub-millisecond latency (<1ms)
  • Direct memory access to gateway state
  • Examples: PII filtering, regex transforms, validation

2.3.2 External Plugins (Remote MCP Servers)ΒΆ

  • Standalone MCP servers implementing plugin logic
  • Language-agnostic (Python, TypeScript, Go, Rust, etc.)
  • Communicate via MCP protocol over various transports
  • 10-100ms latency depending on service and network
  • Examples: LlamaGuard, OpenAI Moderation, custom AI services