# ποΈ MCP Agentic AI Server - Architecture Designs
This document contains comprehensive Mermaid diagrams illustrating the system architecture, component designs, and technical infrastructure of the MCP Agentic AI Server project.
## π Table of Contents
1. [High-Level System Architecture](#high-level-system-architecture)
2. [Component Architecture](#component-architecture)
3. [Data Architecture](#data-architecture)
4. [Network Architecture](#network-architecture)
5. [Security Architecture](#security-architecture)
6. [Deployment Architecture](#deployment-architecture)
7. [Microservices Architecture](#microservices-architecture)
8. [Database Design](#database-design)
9. [API Architecture](#api-architecture)
10. [Monitoring Architecture](#monitoring-architecture)
---
## π High-Level System Architecture
```mermaid
C4Context
title System Context Diagram - MCP Agentic AI Server
Person(user, "End User", "Interacts with AI agents through web interface")
System_Boundary(mcp_system, "MCP Agentic AI System") {
System(dashboard, "Streamlit Dashboard", "Interactive web interface for AI interactions")
System(custom_mcp, "Custom MCP Server", "Task-based AI processing with tool integration")
System(public_mcp, "Public MCP Server", "Direct AI query processing")
}
System_Ext(gemini, "Google Gemini API", "AI language model service")
System_Ext(browser, "Web Browser", "User interface client")
Rel(user, browser, "Uses")
Rel(browser, dashboard, "HTTP/WebSocket")
Rel(dashboard, custom_mcp, "REST API")
Rel(dashboard, public_mcp, "REST API")
Rel(custom_mcp, gemini, "HTTPS API")
Rel(public_mcp, gemini, "HTTPS API")
```
---
## π§ Component Architecture
```mermaid
graph TB
subgraph "π¨ Presentation Layer"
A[Streamlit Dashboard]
A1[Real-time Stats Display]
A2[Interactive Forms]
A3[Response Visualization]
A --> A1
A --> A2
A --> A3
end
subgraph "π Application Layer"
B[Custom MCP Server]
C[Public MCP Server]
subgraph "π§ Custom MCP Components"
B1[Flask Web Server]
B2[MCP Controller]
B3[Task Manager]
B4[Tool Framework]
B --> B1
B --> B2
B --> B3
B --> B4
end
subgraph "π Public MCP Components"
C1[Flask Web Server]
C2[Direct AI Handler]
C3[Statistics Tracker]
C --> C1
C --> C2
C --> C3
end
end
subgraph "π οΈ Service Layer"
D[Gemini AI Client]
E[Configuration Manager]
F[Logging Service]
G[Statistics Engine]
end
subgraph "πΎ Data Layer"
H[In-Memory Task Store]
I[Statistics Cache]
J[Configuration Files]
K[Log Files]
end
A1 --> G
A2 --> B1
A2 --> C1
B2 --> D
B3 --> H
B4 --> D
C2 --> D
C3 --> I
B2 --> G
C2 --> G
D --> E
G --> F
F --> K
E --> J
style A fill:#e1f5fe
style B fill:#e8f5e8
style C fill:#fff3e0
style D fill:#ffebee
```
---
## π Data Architecture
```mermaid
erDiagram
TASK {
string task_id PK
string input
array tools
timestamp created_at
string status
}
STATISTICS {
int queries_processed
float total_response_time
int successful_queries
int failed_queries
timestamp session_start_time
int active_sessions
}
TOOL_EXECUTION {
string execution_id PK
string task_id FK
string tool_name
string input_data
string output_data
float execution_time
string status
}
AI_RESPONSE {
string response_id PK
string task_id FK
string prompt
string response
float response_time
string model_used
timestamp created_at
}
USER_SESSION {
string session_id PK
timestamp start_time
timestamp last_activity
int query_count
string user_agent
}
TASK ||--o{ TOOL_EXECUTION : "has"
TASK ||--|| AI_RESPONSE : "generates"
USER_SESSION ||--o{ TASK : "creates"
STATISTICS ||--o{ TASK : "tracks"
```
---
## π Network Architecture
```mermaid
graph TB
subgraph "π Internet"
U[π€ Users]
end
subgraph "π DMZ Zone"
LB[βοΈ Load Balancer<br/>nginx/HAProxy]
FW[π‘οΈ Firewall<br/>iptables/UFW]
end
subgraph "π’ Application Zone"
subgraph "π¨ Frontend Tier"
ST[π¨ Streamlit<br/>Port 8501]
end
subgraph "βοΈ Backend Tier"
CM[π§ Custom MCP<br/>Port 8000]
PM[π Public MCP<br/>Port 8001]
end
subgraph "π Monitoring Tier"
MON[π Monitoring<br/>Prometheus/Grafana]
LOG[π Logging<br/>ELK Stack]
end
end
subgraph "π External Services"
GM[π§ Google Gemini API<br/>HTTPS/443]
end
U --> FW
FW --> LB
LB --> ST
ST --> CM
ST --> PM
CM --> GM
PM --> GM
CM --> MON
PM --> MON
ST --> MON
CM --> LOG
PM --> LOG
ST --> LOG
style U fill:#e1f5fe
style LB fill:#fff3e0
style FW fill:#ffebee
style GM fill:#f3e5f5
```
---
## π Security Architecture
```mermaid
graph TB
subgraph "π‘οΈ Security Layers"
subgraph "π Network Security"
A[π₯ Firewall Rules]
B[π HTTPS/TLS]
C[π« Rate Limiting]
end
subgraph "π Authentication & Authorization"
D[π API Key Management]
E[π« Session Management]
F[π€ User Validation]
end
subgraph "π Data Security"
G[π Input Sanitization]
H[π‘οΈ Output Filtering]
I[π Audit Logging]
end
subgraph "ποΈ Application Security"
J[β οΈ Error Handling]
K[π Input Validation]
L[π¨ Security Headers]
end
end
subgraph "π― Attack Vectors & Mitigations"
M[π« SQL Injection β Input Validation]
N[π« XSS β Output Encoding]
O[π« CSRF β Token Validation]
P[π« DDoS β Rate Limiting]
Q[π« Data Breach β Encryption]
end
A --> D
B --> E
C --> F
D --> G
E --> H
F --> I
G --> J
H --> K
I --> L
style A fill:#ffebee
style D fill:#fff3e0
style G fill:#e8f5e8
style J fill:#e1f5fe
```
---
## π Deployment Architecture
```mermaid
graph TB
subgraph "βοΈ Cloud Infrastructure"
subgraph "π Production Environment"
subgraph "π Load Balancer Tier"
LB1[βοΈ Primary LB]
LB2[βοΈ Secondary LB]
end
subgraph "π¨ Frontend Tier"
ST1[π¨ Streamlit Instance 1]
ST2[π¨ Streamlit Instance 2]
ST3[π¨ Streamlit Instance 3]
end
subgraph "βοΈ Backend Tier"
CM1[π§ Custom MCP 1]
CM2[π§ Custom MCP 2]
PM1[π Public MCP 1]
PM2[π Public MCP 2]
end
subgraph "πΎ Data Tier"
RD[π Redis Cache]
DB[ποΈ PostgreSQL]
FS[π File Storage]
end
end
subgraph "π§ͺ Staging Environment"
ST_STG[π¨ Streamlit Staging]
CM_STG[π§ Custom MCP Staging]
PM_STG[π Public MCP Staging]
end
subgraph "π§ Development Environment"
ST_DEV[π¨ Streamlit Dev]
CM_DEV[π§ Custom MCP Dev]
PM_DEV[π Public MCP Dev]
end
end
subgraph "π CI/CD Pipeline"
GIT[π Git Repository]
BUILD[π¨ Build Process]
TEST[π§ͺ Automated Tests]
DEPLOY[π Deployment]
end
LB1 --> ST1
LB1 --> ST2
LB2 --> ST3
ST1 --> CM1
ST2 --> CM2
ST3 --> PM1
ST1 --> PM2
CM1 --> RD
CM2 --> RD
PM1 --> DB
PM2 --> DB
GIT --> BUILD
BUILD --> TEST
TEST --> DEPLOY
DEPLOY --> ST_STG
DEPLOY --> CM_STG
DEPLOY --> PM_STG
style LB1 fill:#fff3e0
style ST1 fill:#e1f5fe
style CM1 fill:#e8f5e8
style RD fill:#f3e5f5
```
---
## π Microservices Architecture
```mermaid
graph TB
subgraph "π― API Gateway"
GW[πͺ API Gateway<br/>Kong/Zuul]
end
subgraph "π§ Core Services"
subgraph "π¨ UI Service"
UI[π¨ Streamlit Service<br/>Port 8501]
end
subgraph "π€ AI Services"
CM[π§ Custom MCP Service<br/>Port 8000]
PM[π Public MCP Service<br/>Port 8001]
end
subgraph "π οΈ Support Services"
TS[π Task Service]
SS[π Statistics Service]
LS[π Logging Service]
CS[βοΈ Config Service]
end
end
subgraph "πΎ Data Services"
CACHE[π Redis Cache]
DB[ποΈ Database]
QUEUE[π¬ Message Queue]
end
subgraph "π External Services"
GEMINI[π§ Gemini API]
MONITOR[π Monitoring]
end
GW --> UI
GW --> CM
GW --> PM
UI --> CM
UI --> PM
UI --> SS
CM --> TS
CM --> SS
CM --> GEMINI
PM --> SS
PM --> GEMINI
TS --> CACHE
SS --> CACHE
LS --> DB
CS --> DB
CM --> QUEUE
PM --> QUEUE
SS --> MONITOR
LS --> MONITOR
style GW fill:#fff3e0
style UI fill:#e1f5fe
style CM fill:#e8f5e8
style GEMINI fill:#ffebee
```
---
## ποΈ Database Design
```mermaid
graph TB
subgraph "πΎ Data Storage Architecture"
subgraph "π Operational Data"
CACHE[π Redis Cache<br/>β’ Session Data<br/>β’ Statistics<br/>β’ Temporary Results]
MEMORY[π In-Memory Store<br/>β’ Active Tasks<br/>β’ Real-time Metrics<br/>β’ User Sessions]
end
subgraph "π Persistent Data"
LOGS[π Log Files<br/>β’ Application Logs<br/>β’ Error Logs<br/>β’ Access Logs]
CONFIG[βοΈ Configuration<br/>β’ YAML Files<br/>β’ Environment Variables<br/>β’ API Keys]
end
subgraph "π Analytics Data"
METRICS[π Time Series DB<br/>β’ Performance Metrics<br/>β’ Usage Statistics<br/>β’ Historical Data]
AUDIT[π Audit Trail<br/>β’ User Actions<br/>β’ System Events<br/>β’ Security Logs]
end
end
subgraph "π Data Flow"
APP[π― Application Layer]
APP --> CACHE
APP --> MEMORY
APP --> LOGS
APP --> CONFIG
CACHE --> METRICS
MEMORY --> METRICS
LOGS --> AUDIT
end
style CACHE fill:#e1f5fe
style MEMORY fill:#fff3e0
style LOGS fill:#e8f5e8
style METRICS fill:#f3e5f5
```
---
## π API Architecture
```mermaid
graph TB
subgraph "π API Layer Architecture"
subgraph "πͺ API Gateway"
GW[πͺ Gateway Router<br/>β’ Authentication<br/>β’ Rate Limiting<br/>β’ Load Balancing]
end
subgraph "π§ Custom MCP API"
CM_API[π§ Custom MCP Endpoints]
CM_TASK[π POST /task<br/>Create Task]
CM_RUN[βΆοΈ POST /task/{id}/run<br/>Execute Task]
CM_STATS[π GET /stats<br/>Get Statistics]
CM_API --> CM_TASK
CM_API --> CM_RUN
CM_API --> CM_STATS
end
subgraph "π Public MCP API"
PM_API[π Public MCP Endpoints]
PM_ASK[π¬ POST /ask<br/>Direct Query]
PM_STATS[π GET /stats<br/>Get Statistics]
PM_API --> PM_ASK
PM_API --> PM_STATS
end
subgraph "π¨ Dashboard API"
UI_API[π¨ Streamlit Interface]
UI_FORM[π Form Handlers]
UI_DISPLAY[π Data Display]
UI_API --> UI_FORM
UI_API --> UI_DISPLAY
end
end
subgraph "π API Documentation"
SWAGGER[π OpenAPI/Swagger<br/>β’ Endpoint Documentation<br/>β’ Request/Response Schemas<br/>β’ Interactive Testing]
end
subgraph "π API Monitoring"
MONITOR[π API Analytics<br/>β’ Response Times<br/>β’ Error Rates<br/>β’ Usage Patterns]
end
GW --> CM_API
GW --> PM_API
GW --> UI_API
CM_API --> SWAGGER
PM_API --> SWAGGER
CM_API --> MONITOR
PM_API --> MONITOR
UI_API --> MONITOR
style GW fill:#fff3e0
style CM_API fill:#e8f5e8
style PM_API fill:#e1f5fe
style SWAGGER fill:#f3e5f5
```
---
## π Monitoring Architecture
```mermaid
graph TB
subgraph "π Monitoring Stack"
subgraph "π Metrics Collection"
PROM[π Prometheus<br/>β’ System Metrics<br/>β’ Application Metrics<br/>β’ Custom Metrics]
NODE[π₯οΈ Node Exporter<br/>β’ CPU, Memory<br/>β’ Disk, Network<br/>β’ System Health]
APP_METRICS[π± Application Metrics<br/>β’ Response Times<br/>β’ Error Rates<br/>β’ Business Metrics]
end
subgraph "π Visualization"
GRAFANA[π Grafana<br/>β’ Dashboards<br/>β’ Alerts<br/>β’ Reports]
DASH[π Custom Dashboards<br/>β’ Real-time Stats<br/>β’ Performance Trends<br/>β’ Usage Analytics]
end
subgraph "π¨ Alerting"
ALERT[π¨ Alert Manager<br/>β’ Threshold Alerts<br/>β’ Escalation Rules<br/>β’ Notification Routing]
NOTIFY[π§ Notifications<br/>β’ Email Alerts<br/>β’ Slack Integration<br/>β’ SMS Alerts]
end
subgraph "π Logging"
ELK[π ELK Stack<br/>β’ Elasticsearch<br/>β’ Logstash<br/>β’ Kibana]
LOGS[π Log Aggregation<br/>β’ Application Logs<br/>β’ Error Logs<br/>β’ Access Logs]
end
end
subgraph "π― Monitored Services"
ST[π¨ Streamlit]
CM[π§ Custom MCP]
PM[π Public MCP]
SYS[π₯οΈ System Resources]
end
ST --> APP_METRICS
CM --> APP_METRICS
PM --> APP_METRICS
SYS --> NODE
APP_METRICS --> PROM
NODE --> PROM
PROM --> GRAFANA
PROM --> ALERT
GRAFANA --> DASH
ALERT --> NOTIFY
ST --> LOGS
CM --> LOGS
PM --> LOGS
LOGS --> ELK
style PROM fill:#e1f5fe
style GRAFANA fill:#e8f5e8
style ALERT fill:#fff3e0
style ELK fill:#f3e5f5
```
---
## π Event-Driven Architecture
```mermaid
graph TB
subgraph "π¬ Event Bus"
EB[π¬ Message Queue<br/>Redis Pub/Sub]
end
subgraph "π€ Event Publishers"
CM_PUB[π§ Custom MCP<br/>β’ Task Created<br/>β’ Task Completed<br/>β’ Tool Executed]
PM_PUB[π Public MCP<br/>β’ Query Received<br/>β’ Response Generated<br/>β’ Error Occurred]
UI_PUB[π¨ Dashboard<br/>β’ User Action<br/>β’ Page View<br/>β’ Form Submit]
end
subgraph "π₯ Event Subscribers"
STATS_SUB[π Statistics Service<br/>β’ Update Metrics<br/>β’ Calculate Rates<br/>β’ Store History]
LOG_SUB[π Logging Service<br/>β’ Write Logs<br/>β’ Index Events<br/>β’ Archive Data]
MONITOR_SUB[π Monitoring Service<br/>β’ Track Performance<br/>β’ Generate Alerts<br/>β’ Update Dashboards]
NOTIFY_SUB[π§ Notification Service<br/>β’ Send Alerts<br/>β’ User Notifications<br/>β’ System Messages]
end
CM_PUB --> EB
PM_PUB --> EB
UI_PUB --> EB
EB --> STATS_SUB
EB --> LOG_SUB
EB --> MONITOR_SUB
EB --> NOTIFY_SUB
style EB fill:#fff3e0
style CM_PUB fill:#e8f5e8
style STATS_SUB fill:#e1f5fe
```
---
## ποΈ Infrastructure as Code
```mermaid
graph TB
subgraph "π§ Infrastructure Management"
subgraph "π Configuration Management"
TERRAFORM[ποΈ Terraform<br/>β’ Infrastructure Provisioning<br/>β’ Resource Management<br/>β’ State Management]
ANSIBLE[βοΈ Ansible<br/>β’ Configuration Management<br/>β’ Application Deployment<br/>β’ Service Orchestration]
end
subgraph "π³ Containerization"
DOCKER[π³ Docker<br/>β’ Application Containers<br/>β’ Multi-stage Builds<br/>β’ Image Management]
K8S[βΈοΈ Kubernetes<br/>β’ Container Orchestration<br/>β’ Service Discovery<br/>β’ Auto-scaling]
end
subgraph "π CI/CD Pipeline"
GITHUB[π GitHub Actions<br/>β’ Source Control<br/>β’ Automated Testing<br/>β’ Deployment Pipeline]
JENKINS[π Jenkins<br/>β’ Build Automation<br/>β’ Testing Pipeline<br/>β’ Deployment Orchestration]
end
end
subgraph "βοΈ Cloud Providers"
AWS[βοΈ AWS<br/>β’ EC2 Instances<br/>β’ Load Balancers<br/>β’ RDS Database]
GCP[βοΈ Google Cloud<br/>β’ Compute Engine<br/>β’ Cloud SQL<br/>β’ Cloud Storage]
AZURE[βοΈ Azure<br/>β’ Virtual Machines<br/>β’ App Services<br/>β’ Cosmos DB]
end
TERRAFORM --> AWS
TERRAFORM --> GCP
TERRAFORM --> AZURE
ANSIBLE --> DOCKER
DOCKER --> K8S
GITHUB --> JENKINS
JENKINS --> K8S
style TERRAFORM fill:#e1f5fe
style DOCKER fill:#e8f5e8
style K8S fill:#fff3e0
style AWS fill:#f3e5f5
```
---
## π― Summary
These architecture diagrams provide a comprehensive view of the MCP Agentic AI Server system design:
### ποΈ **Key Architectural Patterns**
- **Microservices Architecture**: Loosely coupled, independently deployable services
- **Event-Driven Design**: Asynchronous communication through message queues
- **Layered Architecture**: Clear separation of concerns across presentation, application, and data layers
- **API-First Design**: Well-defined interfaces for all service interactions
### π§ **Technology Stack**
- **Frontend**: Streamlit with modern CSS and responsive design
- **Backend**: Flask-based microservices with Python
- **AI Integration**: Google Gemini API with robust error handling
- **Data Storage**: Redis for caching, in-memory for real-time data
- **Monitoring**: Prometheus, Grafana, and ELK stack
- **Deployment**: Docker containers with Kubernetes orchestration
### π **Scalability Features**
- **Horizontal Scaling**: Multiple instances of each service
- **Load Balancing**: Traffic distribution across service instances
- **Caching Strategy**: Redis for performance optimization
- **Monitoring**: Comprehensive observability and alerting
### π **Security Considerations**
- **API Security**: Authentication, authorization, and rate limiting
- **Data Protection**: Input validation, output sanitization, and encryption
- **Network Security**: Firewall rules, HTTPS/TLS, and secure communication
- **Audit Trail**: Comprehensive logging and monitoring for security events
These designs serve as blueprints for implementing, scaling, and maintaining the MCP Agentic AI Server system in production environments.