This repo contains:
- RAG pipeline:
documents/→ FAISS index (faiss_index/) → LLM answers viarag.py - Dataset utilities:
data_analysis.py(CSV/Excel via pandas + charts) - MCP server:
server.pyexposes tools for an MCP client - Web app:
webapp/— a FastAPI backend + simple HTML/JS frontend over the same dataset/RAG functions, for use in a browser instead of an MCP client
- Python 3.10+
- A Groq API key (used by
langchain_groq)
From the project root:
pip install -r requirements.txtCreate .env in the project root.
copy .env.example .envEdit .env and set your Groq API key (variable name must match what langchain_groq expects).
Place .txt or .pdf files in:
documents/
Place .csv, .xlsx, .xls files in:
datasets/
python ingest.pyGenerates:
faiss_index/index.faissfaiss_index/index.pkl
python server.pyThe server exposes tools including:
answer_question(query)(RAG overdocuments/)list_datasets()dataset_info(filename)preview_dataset(filename, n)summary_statistics(filename)filter_dataset(filename, query, limit)group_by_aggregate(filename, group_by, agg_column, agg_func)correlation_matrix(filename)plot_chart(filename, chart_type, x, y=None)
Charts are saved to:
outputs/
Supported chart_type: bar, line, scatter, hist
An alternative to using an MCP client: a small FastAPI backend (webapp/main.py) exposes the same dataset tools (and RAG) as HTTP endpoints, with a plain HTML/JS frontend (webapp/static/) to drive them from a browser.
python -m uvicorn webapp.main:app --reloadThen open http://127.0.0.1:8000/ in a browser.
GET /api/datasetsGET /api/datasets/{filename}/infoGET /api/datasets/{filename}/preview?n=5GET /api/datasets/{filename}/summaryGET /api/datasets/{filename}/filter?query=...&limit=20GET /api/datasets/{filename}/group_by?group_by=...&agg_column=...&agg_func=meanGET /api/datasets/{filename}/correlationGET /api/datasets/{filename}/plot?chart_type=bar&x=...&y=...— returns{"url": "/outputs/..."}, an image path served staticallyGET /api/documents/sources,GET /api/ask?query=...— RAG endpoints;rag.pyis imported lazily on first use, so the app still starts fine even without a Groq key or FAISS index configured
The frontend has two tabs: Datasets (dropdown + buttons for info/preview/summary/correlation, forms for filter/group-by/chart) and Ask Documents (RAG Q&A).
Note: this web app doesn't go through the MCP protocol — it calls data_analysis.py/rag.py directly. Use it for browser-based / human interaction; use server.py for MCP clients (Claude Desktop, Cursor, etc.).
Build and run the server in a container instead of a local venv.
docker build -t data-analyst-mcp .This bakes in all dependencies (CPU-only PyTorch, to avoid pulling ~1.3GB of unneeded CUDA packages) and pre-downloads the all-MiniLM-L6-v2 embedding model at build time, since rag.py forces HF_HUB_OFFLINE=1 at runtime.
The server speaks MCP over stdio, so it's meant to be launched by an MCP client (not left running as a background service). Point your client's command at:
docker run --rm -i --env-file .env ^
-v "%cd%\documents:/app/documents" ^
-v "%cd%\datasets:/app/datasets" ^
-v "%cd%\outputs:/app/outputs" ^
-v "%cd%\faiss_index:/app/faiss_index" ^
data-analyst-mcpOr with Docker Compose (docker-compose.yml already wires up the same volumes and .env):
docker compose run --rm data-analyst-mcpOn first run, if faiss_index/index.faiss isn't present, the container runs ingest.py automatically before starting server.py (requires files already in documents/).
Git Bash on Windows users: MSYS path conversion mangles container paths like /app/datasets in -v flags. Prefix the command with MSYS_NO_PATHCONV=1 if invoking docker run from Git Bash instead of cmd/PowerShell.
Re-run docker build whenever requirements.txt changes. Document/dataset changes don't require a rebuild since those folders are volume-mounted — just re-run ingest.py inside the container (or delete faiss_index/index.faiss so the entrypoint rebuilds it) after editing documents/.
If you changed documents, re-run:
python ingest.pyEnsure .env exists and contains a valid Groq API key.
- Run:
python ingest.py python server.py
- Call MCP tool
list_datasets()from your MCP client. - Call MCP tool
answer_question("...your question...").