How faiz2/llm-mcp-rag-demo works
Project type and purpose
• This is a backend‐only, TypeScript‐based demo application illustrating an end‐to‐end Retrieval‑Augmented Generation (RAG) pipeline that combines:
• a FileReader (local document ingestion)
• EmbeddingRetriever + VectorStore (semantic search over embeddings)
• ChatOpenAI (calls to the OpenAI LLM API)
• MCPClient (publishes or consumes messages via an external messaging channel)
• Agent (orchestration)
• It is not a full web‐frontend; it runs as an npm/CLI process that loads data, builds a vector store, and performs LLM queries on demand.
File structure
• src/index.ts – application entrypoint; wires together all components
• src/FileReader.ts – reads markdown files (file/news.md, file/news2.md, knowledge/…)
• src/EmbeddingRetriever.ts – generates or retrieves embeddings for document chunks
• src/VectorStore.ts – in‐memory or persisted vector database interface
• src/ChatOpenAI.ts – wraps OpenAI REST calls (chat completion + embedding endpoints)
• src/MCPClient.ts – interfaces with an external message channel (publish/subscribe)
• src/Agent.ts – orchestrator: takes user input, calls retriever, invokes LLM, emits via MCP
• src/utils.ts, src/types – shared helpers and type definitions
Key insights from the README
• Uses ESM, TypeScript, npm, ESLint, Prettier, Vitest
• Environment variable OPENAI_API_KEY for external API access
• No built‐in HTTP server—implies CLI or message‐based invocation
Essential elements to capture
• EntryPoint (index.ts)
• Document ingestion pipeline (FileReader → EmbeddingRetriever → VectorStore)
• Query pipeline (MCPClient inbound → Agent → VectorStore search → ChatOpenAI → MCPClient outbound)
• External dependencies (OpenAI API, Messaging Service)
• Environment/config layer for API keys