# π MCP Agentic AI Server - Workflow Diagrams
This document contains comprehensive Mermaid diagrams illustrating all the workflows and processes in the MCP Agentic AI Server project.
## π Table of Contents
1. [Overall System Workflow](#overall-system-workflow)
2. [Custom MCP Server Workflow](#custom-mcp-server-workflow)
3. [Public MCP Server Workflow](#public-mcp-server-workflow)
4. [Streamlit Dashboard Workflow](#streamlit-dashboard-workflow)
5. [Tool Integration Workflow](#tool-integration-workflow)
6. [Statistics Tracking Workflow](#statistics-tracking-workflow)
7. [Error Handling Workflow](#error-handling-workflow)
8. [User Interaction Workflow](#user-interaction-workflow)
9. [AI Processing Workflow](#ai-processing-workflow)
10. [Deployment Workflow](#deployment-workflow)
---
## π Overall System Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
graph TB
A[π€ User] ==> B[π¨ Streamlit Dashboard]
B ==> C{π Server Selection}
C ==> |Custom Tasks| D[π§ Custom MCP Server<br/>Port 8000]
C ==> |Direct Queries| E[π Public MCP Server<br/>Port 8001]
D ==> F[π Task Creation]
F ==> G[π Generate UUID]
G ==> H[πΎ Store Task]
H ==> I[π Task Execution]
I ==> J{π οΈ Tools Required?}
J ==> |Yes| K[π§ Execute Tools]
J ==> |No| L[π€ Direct AI Call]
K ==> L
L ==> M[π§ Google Gemini API]
M ==> N[π Update Statistics]
N ==> O[π€ Return Response]
E ==> P[π€ Direct AI Processing]
P ==> M
O ==> B
P ==> Q[π Update Public Stats]
Q ==> B
classDef sky fill:#e1f5fe,stroke:#039be5,stroke-width:3px,color:#000
classDef purple fill:#f3e5f5,stroke:#8e24aa,stroke-width:3px,color:#000
classDef green fill:#e8f5e8,stroke:#43a047,stroke-width:3px,color:#000
classDef yellow fill:#fff3e0,stroke:#fbc02d,stroke-width:3px,color:#000
classDef rose fill:#ffebee,stroke:#d32f2f,stroke-width:3px,color:#000
class A sky
class B purple
class C yellow
class D,F,G,H,I,J,K green
class E,P,Q yellow
class L,M,N,O rose
```
---
## π§ Custom MCP Server Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
sequenceDiagram
participant U as π€ User
participant D as π¨ Dashboard
participant S as π§ Custom Server
participant C as π Controller
participant T as π οΈ Tools
participant AI as π§ Gemini API
participant DB as πΎ Task Store
U->>D: Enter task input & select tools
D->>S: POST /task {input, tools}
S->>C: create_task(input, tools)
C->>DB: Generate UUID & store task
C->>S: Return task_id
S->>D: {task_id: "uuid"}
D->>S: POST /task/{task_id}/run
S->>C: run(task_id)
C->>DB: Retrieve task data
alt Tools specified
C->>T: Execute specified tools
T->>C: Return processed input
end
C->>AI: Generate content with processed input
AI->>C: AI response
C->>C: Update statistics
C->>S: Return result
S->>D: {task_id, output}
D->>U: Display result
```
---
## π Public MCP Server Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
sequenceDiagram
participant U as π€ User
participant D as π¨ Dashboard
participant S as π Public Server
participant AI as π§ Gemini API
participant ST as π Statistics
U->>D: Enter direct query
D->>S: POST /ask {query}
Note over S: Start timing & session tracking
S->>ST: Increment active sessions
S->>AI: Generate content with query
alt Success
AI->>S: AI response
S->>ST: Update success count
else Failure
AI->>S: Error response
S->>ST: Update failure count
end
S->>ST: Update response time & query count
S->>D: {response} or {error}
D->>U: Display result
Note over S: End timing & session tracking
S->>ST: Decrement active sessions
```
---
## π¨ Streamlit Dashboard Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
flowchart TD
A([π App Start]):::blue
B([π¨ Load CSS Styles]):::purple
C([π Initialize Stats Containers]):::yellow
D([π Main Loop Start]):::green
E{{π‘ Fetch Stats API}}:::yellow
F([π Update Statistics Display]):::green
G([β οΈ Show Default Values]):::rose
H([ποΈ Render UI Components]):::purple
I([π Server Selection Radio]):::blue
J{{π Server Type?}}:::yellow
K([π Task Input Form]):::green
L([π¬ Query Input Form]):::green
M([π οΈ Tool Selection]):::orange
N([βΆοΈ Submit Button]):::green
O{{π€ Form Submitted?}}:::yellow
P([π‘ API Call]):::purple
Q([β³ Wait for Input]):::blue
R{{π API Response?}}:::yellow
S([β
Display Results]):::green
T([β Display Error]):::rose
U([π Auto-refresh Stats]):::blue
V([β±οΈ Wait 2 seconds]):::purple
A --> B
B --> C
C --> D
D --> E
E -- Success --> F
E -- Failure --> G
F --> H
G --> H
H --> I
I --> J
J -- Custom --> K
J -- Public --> L
K --> M
M --> N
L --> N
N --> O
O -- Yes --> P
O -- No --> Q
P --> R
R -- Success --> S
R -- Error --> T
S --> U
T --> U
Q --> U
U --> V
V --> D
classDef blue fill:#e1f5fe,stroke:#039be5,stroke-width:3px,color:#000
classDef purple fill:#f3e5f5,stroke:#8e24aa,stroke-width:3px,color:#000
classDef green fill:#e8f5e8,stroke:#43a047,stroke-width:3px,color:#000
classDef yellow fill:#fff3e0,stroke:#fbc02d,stroke-width:3px,color:#000
classDef rose fill:#ffebee,stroke:#d32f2f,stroke-width:3px,color:#000
classDef orange fill:#ffb74d,stroke:#f57c00,stroke-width:3px,color:#000
```
---
## π οΈ Tool Integration Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
flowchart LR
A[π₯ Task Input] ==> B{π Tools Specified?}
B ==> |No| C[π€ Direct AI Processing]
B ==> |Yes| D[π Parse Tools List]
D ==> E[π For Each Tool]
E ==> F{π οΈ Tool Exists?}
F ==> |Yes| G[βοΈ Execute Tool Function]
F ==> |No| H[β οΈ Log Warning & Skip]
G ==> I[π Process Tool Output]
I ==> J[π Chain to Next Tool]
H ==> J
J ==> K{π More Tools?}
K ==> |Yes| E
K ==> |No| L[π€ Final Processed Input]
L ==> M[π€ AI Processing with Tool Results]
C ==> M
M ==> N[π Update Tool Usage Stats]
N ==> O[π€ Return Final Response]
classDef blue fill:#e1f5fe,stroke:#039be5,stroke-width:3px,color:#000
classDef green fill:#e8f5e8,stroke:#43a047,stroke-width:3px,color:#000
classDef yellow fill:#fff3e0,stroke:#fbc02d,stroke-width:3px,color:#000
classDef rose fill:#ffebee,stroke:#d32f2f,stroke-width:3px,color:#000
class A,B,D,E,F,G,I,J,K,L,M,N,O green
class H rose
class C blue
```
---
## π Statistics Tracking Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
flowchart TD
S1([Idle]):::blue
S2([Processing]):::green
S3{{Need Tools?}}:::yellow
S4([Tool Exec]):::green
S5([AI Call]):::blue
S6{{AI OK?}}:::yellow
S7([Success]):::green
S8([Failure]):::rose
S9([Update Stats]):::purple
S1 --> S2 --> S3
S3 -- Yes --> S4 --> S5
S3 -- No --> S5
S5 --> S6
S6 -- Yes --> S7 --> S9 --> S1
S6 -- No --> S8 --> S9 --> S1
classDef blue fill:#e1f5fe,stroke:#039be5,stroke-width:3px,color:#000
classDef green fill:#e8f5e8,stroke:#43a047,stroke-width:3px,color:#000
classDef yellow fill:#fff3e0,stroke:#fbc02d,stroke-width:3px,color:#000
classDef purple fill:#f3e5f5,stroke:#8e24aa,stroke-width:3px,color:#000
classDef rose fill:#ffebee,stroke:#d32f2f,stroke-width:3px,color:#000
```
---
## β οΈ Error Handling Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
flowchart TD
A[π₯ Request Received] ==> B{π Validation Check}
B ==> |Invalid| C[β Return 400 Error]
B ==> |Valid| D[βοΈ Process Request]
D ==> E{π οΈ Tool Execution}
E ==> |Tool Error| F[β οΈ Log Tool Error]
E ==> |Tool Success| G[π€ AI Processing]
F ==> H[π Continue Without Tool]
H ==> G
G ==> I{π§ AI Response}
I ==> |AI Error| J[β Log AI Error]
I ==> |AI Success| K[β
Success Response]
J ==> L[π Update Failure Stats]
L ==> M[π Return Error Response]
K ==> N[π Update Success Stats]
N ==> O[π€ Return Success Response]
C ==> P[π Log Request Error]
M ==> Q[π Log Processing Error]
P ==> R[π Update Error Metrics]
Q ==> R
classDef blue fill:#e1f5fe,stroke:#039be5,stroke-width:3px,color:#000
classDef green fill:#e8f5e8,stroke:#43a047,stroke-width:3px,color:#000
classDef yellow fill:#fff3e0,stroke:#fbc02d,stroke-width:3px,color:#000
classDef rose fill:#ffebee,stroke:#d32f2f,stroke-width:3px,color:#000
class A,B,D,E,G,I,K,N,O green
class C,F,H,J,L,M,P,Q,R rose
```
---
## π€ User Interaction Workflow
```mermaid
journey
title User Journey Through MCP AI System
section Discovery
Open Dashboard: 5: User
View Interface: 4: User
Read Instructions: 3: User
section Server Selection
Choose Custom MCP: 5: User
Choose Public MCP: 5: User
Understand Difference: 4: User
section Custom MCP Usage
Enter Task Description: 5: User
Select Tools: 4: User
Submit Task: 5: User
Wait for Processing: 3: User
View Results: 5: User
section Public MCP Usage
Enter Direct Query: 5: User
Submit Query: 5: User
Get Instant Response: 5: User
section Monitoring
Check Statistics: 4: User
Monitor Performance: 4: User
Track Usage: 3: User
section Advanced Usage
Test Different Inputs: 4: User
Compare Server Types: 4: User
Optimize Queries: 5: User
```
---
## π§ AI Processing Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
flowchart TD
A([π₯ Input Received]):::blue
B([π§ Preprocessing]):::green
C{{π οΈ Tool Processing?}}:::yellow
D([βοΈ Execute Tools]):::green
E([π Format Prompt]):::purple
F([π€ Gemini API Call]):::rose
G{{π‘ API Response}}:::yellow
H([π Extract Response Text]):::green
I([β οΈ Handle API Error]):::rose
J([π Validate Response]):::blue
K{{β
Valid Response?}}:::yellow
L([π€ Return Success]):::green
M([π Retry Logic]):::purple
N{{π’ Retry Count < Max?}}:::yellow
O([β Return Failure]):::rose
P([π Log Error Details]):::rose
Q([π Update Success Metrics]):::blue
R([π Update Failure Metrics]):::rose
A --> B --> C
C -- Yes --> D --> E
C -- No --> E
E --> F --> G
G -- Success --> H --> J --> K
G -- Error --> I --> P --> O
K -- Yes --> L --> Q
K -- No --> M --> N
N -- Yes --> F
N -- No --> O --> R
classDef blue fill:#e1f5fe,stroke:#039be5,stroke-width:3px,color:#000
classDef green fill:#e8f5e8,stroke:#43a047,stroke-width:3px,color:#000
classDef yellow fill:#fff3e0,stroke:#fbc02d,stroke-width:3px,color:#000
classDef rose fill:#ffebee,stroke:#d32f2f,stroke-width:3px,color:#000
classDef purple fill:#f3e5f5,stroke:#8e24aa,stroke-width:3px,color:#000
```
---
## π Deployment Workflow (Flowchart Version)
```mermaid
%%{init: {'theme': 'neo'}}%%
flowchart TD
S1([Initial Setup]):::blue
S2([Environment Config]):::blue
S3([Development Branch]):::green
S4([Custom MCP Server]):::green
S5([Public MCP Server]):::green
S6([Streamlit Dashboard]):::green
S7([Tool Integration]):::green
S8([Statistics System]):::green
S9([Main Branch]):::yellow
S10([Testing Phase]):::yellow
S11([Production Branch]):::purple
S12([Production Config]):::purple
S13([Security Hardening]):::purple
S14([Performance Optimization]):::purple
S15([Monitoring Setup]):::purple
S16([Merge to Main]):::rose
S17([Release v1.0]):::rose
S1 --> S2 --> S3
S3 --> S4
S3 --> S5
S3 --> S6
S3 --> S7
S3 --> S8
S3 --> S9
S9 --> S10
S10 --> S11
S11 --> S12
S12 --> S13
S13 --> S14
S14 --> S15
S15 --> S16
S16 --> S17
classDef blue fill:#e1f5fe,stroke:#039be5,stroke-width:3px,color:#000
classDef green fill:#e8f5e8,stroke:#43a047,stroke-width:3px,color:#000
classDef yellow fill:#fff3e0,stroke:#fbc02d,stroke-width:3px,color:#000
classDef purple fill:#f3e5f5,stroke:#8e24aa,stroke-width:3px,color:#000
classDef rose fill:#ffebee,stroke:#d32f2f,stroke-width:3px,color:#000
```
---
## π Real-time Data Flow
```mermaid
%%{init: {'theme': 'neo'}}%%
sequenceDiagram
participant Browser as π Browser
participant Streamlit as π¨ Streamlit
participant CustomMCP as π§ Custom MCP
participant PublicMCP as π Public MCP
participant Gemini as π§ Gemini API
participant Stats as π Statistics
loop Every 2 seconds
Browser->>Streamlit: Auto-refresh request
Streamlit->>CustomMCP: GET /stats
Streamlit->>PublicMCP: GET /stats
CustomMCP->>Stats: Fetch current metrics
PublicMCP->>Stats: Fetch current metrics
Stats->>CustomMCP: Return stats data
Stats->>PublicMCP: Return stats data
CustomMCP->>Streamlit: Stats response
PublicMCP->>Streamlit: Stats response
Streamlit->>Browser: Updated dashboard
end
Note over Browser,Stats: Real-time monitoring ensures<br/>users see live system performance
```
---
## π§ System Initialization Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
flowchart TD
A([π System Start]):::blue
B([π Load Environment Variables]):::green
C{{π API Key Present?}}:::yellow
D([β Exit with Error]):::rose
E([π€ Initialize Gemini Client]):::green
F([π§ Start Custom MCP Server]):::green
G([π Start Public MCP Server]):::green
H([π¨ Start Streamlit Dashboard]):::green
I([π Initialize Statistics]):::green
J([π οΈ Load Tool Modules]):::green
K([π Setup Logging]):::green
L([β
System Ready]):::blue
M([π Health Check Loop]):::yellow
N{{π₯ All Services Healthy?}}:::yellow
O([π΄ Wait 30 seconds]):::blue
P([β οΈ Alert & Restart]):::rose
Q([π Restart Failed Services]):::rose
A --> B --> C
C -- No --> D
C -- Yes --> E --> F --> G --> H --> I --> J --> K --> L
L --> M --> N
N -- Yes --> O --> M
N -- No --> P --> Q --> M
classDef blue fill:#e1f5fe,stroke:#039be5,stroke-width:3px,color:#000
classDef green fill:#e8f5e8,stroke:#43a047,stroke-width:3px,color:#000
classDef yellow fill:#fff3e0,stroke:#fbc02d,stroke-width:3px,color:#000
classDef rose fill:#ffebee,stroke:#d32f2f,stroke-width:3px,color:#000
```
---
## π Performance Monitoring Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
flowchart LR
A([π Metrics Collection]):::blue
B([β±οΈ Response Time]):::green
C([β
Success Rate]):::green
D([π Query Count]):::green
E([π Uptime]):::green
F([π Statistics Engine]):::purple
G([π Real-time Updates]):::blue
H([π¨ Dashboard Display]):::green
I([π Logging System]):::green
J([π Log Files]):::blue
K{{β οΈ Threshold Check}}:::yellow
L([β
Continue Monitoring]):::green
M([π¨ Send Notification]):::rose
N([π§ Email Alert]):::rose
O([π± Dashboard Warning]):::rose
A --> B --> F
A --> C --> F
A --> D --> F
A --> E --> F
F --> G --> H
F --> I --> J
F --> K
K -- Normal --> L --> A
K -- Alert --> M --> N --> A
M --> O --> A
classDef blue fill:#e1f5fe,stroke:#039be5,stroke-width:3px,color:#000
classDef green fill:#e8f5e8,stroke:#43a047,stroke-width:3px,color:#000
classDef purple fill:#f3e5f5,stroke:#8e24aa,stroke-width:3px,color:#000
classDef yellow fill:#fff3e0,stroke:#fbc02d,stroke-width:3px,color:#000
classDef rose fill:#ffebee,stroke:#d32f2f,stroke-width:3px,color:#000
```
---
## π Security Workflow
```mermaid
%%{init: {'theme': 'neo'}}%%
sequenceDiagram
participant Client as π€ Client
participant Dashboard as π¨ Dashboard
participant Server as π§ Server
participant Env as π Environment
participant AI as π§ AI Service
Client->>Dashboard: Request with input
Dashboard->>Dashboard: Input validation
alt Invalid Input
Dashboard->>Client: Reject request
else Valid Input
Dashboard->>Server: Forward request
Server->>Server: Sanitize input
Server->>Env: Get API key
alt API Key Missing
Server->>Dashboard: Authentication error
else API Key Valid
Server->>AI: Secure API call
AI->>Server: Response
Server->>Dashboard: Sanitized response
end
Dashboard->>Client: Final response
end
Note over Client,AI: All sensitive data<br/>handled securely
```
---
## π― Summary
These workflow diagrams provide a comprehensive view of how the MCP Agentic AI Server system operates:
- **π Overall System**: Shows the complete user journey and system interactions
- **π§ Custom MCP**: Detailed task-based processing with tool integration
- **π Public MCP**: Simple query-response pattern for direct AI interaction
- **π¨ Dashboard**: Real-time UI updates and user interaction patterns
- **π οΈ Tools**: Extensible tool framework for custom functionality
- **π Statistics**: Thread-safe performance monitoring and metrics
- **β οΈ Error Handling**: Robust error management and recovery
- **π€ User Journey**: Complete user experience mapping
- **π§ AI Processing**: Detailed AI integration and response handling
- **π Deployment**: Development to production workflow
Each diagram uses consistent color coding and emoji symbols to make the workflows easy to understand and follow. These diagrams serve as both documentation and implementation guides for developers working with the system.