Retail Analytics Agent
БесплатноНе проверенAn MCP server that combines SQL and RAG tools into a reasoning agent for answering retail analytics questions using natural language.
Описание
An MCP server that combines SQL and RAG tools into a reasoning agent for answering retail analytics questions using natural language.
README
A from-scratch MCP (Model Context Protocol) server combining SQL query tools and RAG (Retrieval-Augmented Generation) into a single ReAct agent. Built without LangChain, LlamaIndex, or any agentic framework — just Python, Flask, FAISS, and the OpenAI API.
What This Is
Most agentic AI tutorials either wrap everything in LangChain and hide what's actually happening, or demo a single tool (SQL or RAG) in isolation.
This project does neither. It builds a multi-tool MCP server where a reasoning agent decides in real time whether a question requires structured data retrieval (SQL), unstructured knowledge lookup (RAG), or both in sequence.
Example:
"What is the return rate for each customer segment? Use the correct metric definition."
The agent:
- Calls search_metrics — retrieves the Return Rate definition, learns cancelled orders must be excluded from both numerator and denominator
- Calls get_schema — discovers actual table and column names
- Calls run_sql with wrong case — gets zeros, self-corrects by checking distinct status values
- Calls run_sql again with correct values — returns accurate rates per segment
No framework orchestrated that. The agent reasoned through it.
Tools
| Tool | Type | Description |
|---|---|---|
| get_schema | SQL | Returns all table names, column names, and data types |
| run_sql | SQL | Executes a SELECT query, returns rows as JSON |
| list_metrics | RAG | Returns all metric names and one-line descriptions |
| search_metrics | RAG | Semantic search over the metrics glossary PDF |
The Metrics Glossary
The RAG knowledge base is a PDF containing precise business metric definitions with inclusion/exclusion rules. These are the distinctions a naive agent would get wrong without it:
- Return Rate: cancelled orders excluded from both numerator and denominator
- LTV Gross: returned orders included — this is a demand-side metric
- LTV Net: returned orders netted to zero — this is the revenue-side metric
- Category Affinity: returned items excluded — a return signals category rejection
- Recent Purchase Activity: returned orders included — engagement, not revenue
Dataset
Synthetic Indian retail database:
- 15 customers across 6 cities, segmented into Premium / Standard / Budget
- 15 products across 8 categories with rupee-denominated pricing
- 90 orders across 2024 with statuses: Completed / Returned / Pending
- 222 line items with quantity and discount percentage
Seeded deterministically (random.seed(42)) — results are reproducible.
Quickstart
1. Clone and install
git clone https://github.com/sourabhsurana06/retail-analytics-agent cd retail-analytics-agent pip install -r requirements.txt
2. Set up environment
cp .env.example .env
Add your OPENAI_API_KEY
3. Build the database and vector index
python3 core/CreateDB.py python3 build_index.py
4. Start the MCP server
python3 server.py
5. Run the agent (second terminal)
python3 agent.py
Project Structure
retail-analytics-agent/ ├── core/ │ ├── init.py │ ├── database.py │ ├── CreateDB.py │ ├── sql_tools.py │ ├── rag_tools.py │ └── retail_analytics_metric_list.pdf ├── data/ (gitignored — generated files) ├── agent.py ├── server.py ├── build_index.py ├── requirements.txt ├── .env.example └── .gitignore
What This Is Not
- Not production-ready (SQLite, no auth, single-threaded Flask dev server)
- Not a framework demo — no LangChain, no LlamaIndex, no AutoGen
- Not complete (no streaming, no async, no retry logic)
It is a learning system that shows exactly what is happening at each step.
License
MIT
Установка Retail Analytics Agent
У этого сервера нет опубликованного пакета — он собирается из исходников. Открой репозиторий и следуй инструкции в README.
▸ github.com/sourabhsurana06/retail-analytics-agentFAQ
Retail Analytics Agent MCP бесплатный?
Да, Retail Analytics Agent MCP бесплатный — установка в пару кликов через Unyly без оплаты.
Нужен ли API-ключ для Retail Analytics Agent?
Нет, Retail Analytics Agent работает без API-ключей и переменных окружения.
Retail Analytics Agent — hosted или self-hosted?
Self-hosted: сервер запускается локально на твоей машине командой из раздела установки.
Как установить Retail Analytics Agent в Claude Desktop, Claude Code или Cursor?
Открой Retail Analytics Agent на unyly.org, выбери вкладку своего клиента (Claude Desktop, Claude Code, Cursor) и нажми Install — конфиг сгенерируется автоматически, без правки JSON.
Похожие MCP
wenb1n-dev/SmartDB_MCP
A universal database MCP server supporting simultaneous connections to multiple databases. It provides tools for database operations, health analysis, SQL optim
автор: wenb1n-devPostgres Server
This server enables interaction with PostgreSQL databases through the Model Context Protocol, optimized for the AWS Bedrock AgentCore Runtime. It provides tools
автор: madhurprashPostgres
Query your database in natural language
автор: AnthropicPostgreSQL
Read-only database access with schema inspection.
автор: modelcontextprotocolCompare Retail Analytics Agent with
Не уверен что выбрать?
Найди свой стек за 60 секунд
Автор?
Embed-бейдж для README
Похожее
Все в категории data
