# plaban1981/rag-mcp architecture

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

- Interactive diagram: https://gitdiagram.com/plaban1981/rag-mcp
- Repository: https://github.com/plaban1981/rag-mcp

## Overview

##### Project type and purpose
- This is a full-stack Python application combining:
- A local “MCP” (Managed Composition Pattern) server (FastAPI/Uvicorn)
- A LangChain-based client library for orchestrating queries via SSE
- A retrieval-augmented‐generation (RAG) pipeline using web search + vector store
- A Streamlit frontend for interactive querying and display
- Purpose: accept a user query in a browser UI, invoke web search & RAG over search results, generate an LLM answer via an agent pattern, and stream results back to the UI.

##### File structure analysis
- mcp_server.py – FastAPI app exposing:
– SSE endpoint (/sse) to register sessions
– HTTP POST (/messages) to receive user messages and drive agent tooling
- langchain_client.py – Python client that:
– Connects to the MCP server via HTTP & SSE
– Discovers available tools and posts user queries
– Receives streamed LLM responses
- search.py – Module for web search (Exa API) and parsing results
- rag.py – Constructs RAG pipeline:
– Embeddings via HTTP embedding service (localhost:11434)
– FAISS vector store for retrieval
– LLM summarization/generation
- streamlit_app.py – Frontend:
– Uses LangChainMCPClient under the hood
– Displays streamed output and logs
- requirements.txt, README.md, LICENSE – metadata & dependencies

##### Insights from README
- Shows MCP server startup and log traces (Uvicorn + FastAPI + SSE + agent “tools” calls)
- Illustrates Streamlit logs demonstrating client connecting to server, SSE registration, message posting, tool initialization, and RAG processing

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Streamlit["Streamlit Frontend"]:::frontend
    end

    %% Client Layer
    subgraph "Client Library"
        LangClient["LangChainMCPClient"]:::client
    end

    %% Server Layer
    subgraph "MCP Server"
        MCPServer["MCP Server (FastAPI/Uvicorn)"]:::server
    end

    %% RAG Layer
    subgraph "RAG Pipeline"
        RAG["RAG Pipeline"]:::service
        FAISS["Vector Store\n(FAISS)"]:::storage
    end

    %% External Services
    subgraph "External Services"
        SearchService["Web Search Service\n(Exa API)"]:::external
        EmbeddingService["Embedding Service\n(localhost:11434)"]:::external
        OpenAI["OpenAI LLM"]:::external
    end

    %% Metadata
    subgraph "Project Metadata"
        Requirements["requirements.txt"]
        Readme["README.md"]
        License["LICENSE"]
    end

    %% Connections
    Streamlit -->|"User Query"| LangClient
    LangClient -->|"GET /sse"| MCPServer
    LangClient -->|"POST /messages"| MCPServer
    MCPServer -->|"invoke search tool"| SearchService
    MCPServer -->|"invoke RAG tool"| RAG
    RAG -->|"Search API call"| SearchService
    RAG -->|"Embedding API call"| EmbeddingService
    EmbeddingService -->|"vectors"| RAG
    RAG -->|"store & retrieve"| FAISS
    RAG -->|"generate answer"| OpenAI
    MCPServer -->|"SSE stream"| LangClient
    LangClient -->|"streamed answer"| Streamlit

    %% Click Events
    click Streamlit "https://github.com/plaban1981/rag-mcp/blob/main/streamlit_app.py"
    click LangClient "https://github.com/plaban1981/rag-mcp/blob/main/langchain_client.py"
    click MCPServer "https://github.com/plaban1981/rag-mcp/blob/main/mcp_server.py"
    click RAG "https://github.com/plaban1981/rag-mcp/blob/main/rag.py"
    click SearchService "https://github.com/plaban1981/rag-mcp/blob/main/search.py"
    click Requirements "https://github.com/plaban1981/rag-mcp/blob/main/requirements.txt"
    click Readme "https://github.com/plaban1981/rag-mcp/blob/main/README.md"
    click License "https://github.com/plaban1981/rag-mcp/tree/main/LICENSE"

    %% Styles
    classDef frontend fill:#DCEEFB,stroke:#0366D6,color:#0366D6
    classDef client fill:#E6F4EA,stroke:#28A745,color:#28A745
    classDef server fill:#FFF4E5,stroke:#D69E2E,color:#D69E2E
    classDef service fill:#F0F4FF,stroke:#6F42C1,color:#6F42C1
    classDef storage fill:#FFF0F6,stroke:#E83E8C,color:#E83E8C
    classDef external stroke-dasharray: 5 5,fill:#F8F9FA,stroke:#6C757D,color:#6C757D
    classDef default fill:#FFFFFF,stroke:#CCCCCC;color:#333333
```
