# hsx-9506/mcp_test architecture

> Architecture diagram of the GitHub repository hsx-9506/mcp_test, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hsx-9506/mcp_test
- Repository: https://github.com/hsx-9506/mcp_test

## Overview

##### Project type and purpose
- This is an intelligent manufacturing data-preprocessing and multi-tool orchestration system built in Python.
- It uses a microservices (MCP) architecture to:
- Ingest raw Excel batch data at the edge (ETL)
- Cache structured JSON
- Expose multiple domain-specific APIs (KPI, SPC, anomaly, downtime, yield, etc.)
- Drive an LLM Agent that calls these services based on user intent and aggregates results.

##### File structure
- Top-level directories:
- agent_client/      ← Orchestrates calls to multiple MCP servers and feeds the LLM
- edge_etl/          ← ETL pipeline: Excel → JSON into json_cache/
- mcp_server/        ← One Python “server” per summary type reading from json_cache/
- intent_config/     ← Defines LLM intents and tool metadata (intents.json)
- config/            ← Global settings (setting.py, settings.json)
- mock_data/         ← Sample Excel data sets for testing
- Key patterns:
- Edge-processing → Cache → Microservices → Orchestration
- Each “*.py” under mcp_server is a standalone API endpoint
- Separation of concerns: ETL layer, storage layer, API layer, orchestration layer

##### Extract insights from README
- Workflow:
1. edge_etl/etl_to_json.py processes Excel → JSON cache
2. mcp_server/*_server.py each exposes a REST API for a different summary
3. agent_client/llm_agent.py uses intent_config/intents.json to break down questions, call servers, synthesize answers via LLM
- Dependencies: Python 3.9+, virtual environment, standard libs plus LLM SDK

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Ingestion Layer
    subgraph "Data Ingestion" 
        RawData["Raw Excel Data\n(mock_data/)"]:::dataStore
        EdgeETL["Edge ETL Service\n(edge_etl/etl_to_json.py)"]:::processing
        RawData -->|"reads Excel"| EdgeETL
    end

    %% Cache Layer
    subgraph "Cache Layer"
        JSONCache["JSON Cache\n(json_cache/)"]:::dataStore
        EdgeETL -->|"writes JSON"| JSONCache
    end

    %% Microservices Layer
    subgraph "MCP Microservices" 
        KPI["KPI Summary\n(KPI_summary_server.py)"]:::processing
        AnomalyTrend["Anomaly Trend\n(anomaly_trend_server.py)"]:::processing
        BatchAnomaly["Batch Anomaly\n(batch_anomaly_server.py)"]:::processing
        DowntimeSummary["Downtime Summary\n(downtime_summary_server.py)"]:::processing
        IssueTracker["Issue Tracker\n(issue_tracker_server.py)"]:::processing
        ProductionSummary["Production Summary\n(production_summary_server.py)"]:::processing
        SPCSummary["SPC Summary\n(spc_summary_server.py)"]:::processing
        YieldSummary["Yield Summary\n(yield_summary_server.py)"]:::processing

        JSONCache -->|"HTTP/JSON"| KPI
        JSONCache -->|"HTTP/JSON"| AnomalyTrend
        JSONCache -->|"HTTP/JSON"| BatchAnomaly
        JSONCache -->|"HTTP/JSON"| DowntimeSummary
        JSONCache -->|"HTTP/JSON"| IssueTracker
        JSONCache -->|"HTTP/JSON"| ProductionSummary
        JSONCache -->|"HTTP/JSON"| SPCSummary
        JSONCache -->|"HTTP/JSON"| YieldSummary
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        IntentConfig["Intent Configuration\n(intent_config/intents.json)"]:::orchestration
        LLMAgent["Agent Client (LLM Agent)\n(agent_client/llm_agent.py)"]:::orchestration
        IntentConfig -->|reads config| LLMAgent
        LLMAgent -.->|HTTP/JSON| KPI
        LLMAgent -.->|HTTP/JSON| AnomalyTrend
        LLMAgent -.->|HTTP/JSON| BatchAnomaly
        LLMAgent -.->|HTTP/JSON| DowntimeSummary
        LLMAgent -.->|HTTP/JSON| IssueTracker
        LLMAgent -.->|HTTP/JSON| ProductionSummary
        LLMAgent -.->|HTTP/JSON| SPCSummary
        LLMAgent -.->|HTTP/JSON| YieldSummary
    end

    %% External Systems
    subgraph "External Systems"
        LLMProvider["External LLM Provider\n(OpenAI, etc.)"]:::external
        LLMAgent -->|"LLM SDK"| LLMProvider
        LLMProvider -->|"response"| LLMAgent
    end

    %% Configuration Module
    ConfigModule["Global Configuration\n(config/setting.py)"]:::orchestration
    ConfigModule -.-> EdgeETL
    ConfigModule -.-> KPI
    ConfigModule -.-> AnomalyTrend
    ConfigModule -.-> BatchAnomaly
    ConfigModule -.-> DowntimeSummary
    ConfigModule -.-> IssueTracker
    ConfigModule -.-> ProductionSummary
    ConfigModule -.-> SPCSummary
    ConfigModule -.-> YieldSummary
    ConfigModule -.-> LLMAgent

    %% Click Events
    click EdgeETL "https://github.com/hsx-9506/mcp_test/blob/main/edge_etl/etl_to_json.py"
    click LLMAgent "https://github.com/hsx-9506/mcp_test/blob/main/agent_client/llm_agent.py"
    click IntentConfig "https://github.com/hsx-9506/mcp_test/blob/main/intent_config/intents.json"
    click ConfigModule "https://github.com/hsx-9506/mcp_test/blob/main/config/setting.py"
    click KPI "https://github.com/hsx-9506/mcp_test/blob/main/mcp_server/KPI_summary_server.py"
    click AnomalyTrend "https://github.com/hsx-9506/mcp_test/blob/main/mcp_server/anomaly_trend_server.py"
    click BatchAnomaly "https://github.com/hsx-9506/mcp_test/blob/main/mcp_server/batch_anomaly_server.py"
    click DowntimeSummary "https://github.com/hsx-9506/mcp_test/blob/main/mcp_server/downtime_summary_server.py"
    click IssueTracker "https://github.com/hsx-9506/mcp_test/blob/main/mcp_server/issue_tracker_server.py"
    click ProductionSummary "https://github.com/hsx-9506/mcp_test/blob/main/mcp_server/production_summary_server.py"
    click SPCSummary "https://github.com/hsx-9506/mcp_test/blob/main/mcp_server/spc_summary_server.py"
    click YieldSummary "https://github.com/hsx-9506/mcp_test/blob/main/mcp_server/yield_summary_server.py"

    %% Styles
    classDef dataStore fill:#9f6,stroke:#333,stroke-width:1px;
    classDef processing fill:#f96,stroke:#333,stroke-width:1px;
    classDef orchestration fill:#6cf,stroke:#333,stroke-width:1px;
    classDef external fill:#c9f,stroke:#333,stroke-width:1px;
```
