Agentic-AI-MCP-Query-Brain
An MCP server that transforms natural language questions into SQL, executes queries on PostgreSQL, and returns human-friendly responses, with Redis memory for context.
README
🧠 Agentic-AI-MCP-Query-Brain
An intelligent, agentic system built with Model Context Protocol (MCP) that transforms natural language queries into SQL, executes them against a database, and returns human-friendly results. Powered by modular microservices, Redis memory, and PostgreSQL for robust, context-aware querying.
📌 Overview
This project enables you to ask questions in plain English and receive structured data answers. It does so using:
- A modular MCP architecture for agent-to-tool communication
- FastAPI microservices hosting API endpoints
- Redis memory for storing conversational context
- OpenAI / LLM integration for generating SQL
- PostgreSQL backend for executing queries
- Docker + NGINX setup for production scalability
🧠 Tech Stack
| Component | Technology |
|---|---|
| Language | Python 3.12 |
| Web Framework | FastAPI |
| AI / LLM Integration | OpenAI (via LLM) |
| Memory Store | Redis |
| Database | PostgreSQL |
| Containerization | Docker & Docker Compose |
| Reverse Proxy / Load Balancer | NGINX |
| Communication | JSON over standard I/O / HTTP |
📁 Project Structure
Agentic-AI-MCP-Query-Brain/
├── agent/ # Core MCP agent logic
├── api_client/ # Client side communication logic
├── api_service/ # FastAPI based endpoints
├── docker/ # Dockerfiles & container setup
├── memory/ # Redis memory and context logic
├── models/ # Data models & schema definitions
├── sdk/ # MCP SDK & router utilities
├── services/ # Tool registry and helper services
├── sql_tool/ # SQL execution, explanation & validation
│
├── main.py # FastAPI entry point
├── main_stdio.py # MCP host via stdio runner
├── requirements.txt # Python dependencies
├── docker-compose.yml # Multi-container orchestration
├── nginx.conf # NGINX configuration
└── README.md # This documentation
🧩 Key Tools & Modules
- OpenAITool — Converts natural language queries to SQL
- SQLTool — Executes SQL on PostgreSQL securely
- ExplainSQLTool — Converts SQL into readable descriptions
- QueryCacheTool — Caches commonly run queries
- FeedbackLoggingTool — Logs user feedback for model tuning
- NaturalLanguageResponseTool — Turns SQL results into textual responses
- RateLimiterTool — Controls request throughput
- TableSchemaTool — Retrieves schema metadata for better query accuracy
🧠 How It Works
- User input (natural language) is sent via the frontend or CLI.
- The MCP Host routes the input to the appropriate tool.
- OpenAITool generates SQL from the input using LLM reasoning.
- SQLTool executes the query on PostgreSQL, returning raw results.
- NaturalLanguageResponseTool translates results into readable form.
- Redis memory retains conversation context for follow-up queries.
⚙️ Example Configuration Snippet (VS Code / MCP)
Use this example in your MCP setup (sensitive keys masked for security):
{
"mcpServers": {
"vartopia-sql-agent": {
"command": "D:/vartopia/.venv/Scripts/python.exe",
"args": [
"-u",
"D:/vartopia/main_stdio.py"
],
"env": {
"OPENAI_API_KEY": "sk-proj-********-REDACTED",
"DB_URL": "postgresql://mcp_postgres_user:********@render.com/mcp_postgres",
"REDIS_URL": "redis://localhost:6379"
},
"transport": "stdio",
"workingDirectory": "D:/vartopia"
}
}
}
▶️ Getting Started
✅ Prerequisites
- Python 3.12+
- PostgreSQL database
- Redis server
- Docker & Docker Compose (optional, but recommended)
🛠 Setup Steps
-
Clone the repository
git clone https://github.com/Ramneek82810/Agentic-AI-MCP-Query-Brain.git cd Agentic-AI-MCP-Query-Brain -
Install dependencies
pip install -r requirements.txt -
Run the FastAPI service
uvicorn main:app --reload -
Or start with Docker (multi-container setup)
docker-compose up --build
🧠 Architecture Flow
User Input
↓
MCP Client → MCP Host (FastAPI)
↓
Tool Router → [OpenAITool ⇄ SQLTool ⇄ MemoryTool]
↓
Redis Memory ↔ PostgreSQL
↓
Formatted JSON or Natural Language Response
🧩 Example Use Case
Input:
“Show the top 5 sales by department for the last quarter.”
Pipeline:
- OpenAITool → Generates SQL
- SQLTool → Executes query
- NaturalLanguageResponseTool → Formats the results
Output:
“Here are the top 5 departments by sales last quarter: Electronics, Home, Fashion, Sports, and Toys.”
📈 Future Enhancements
- 🗄 Multi-database support (MySQL, MongoDB)
- 🧠 Custom fine-tuned LLMs for SQL generation
- 🛡 Role-based authentication & access control
- 🤖 Multi-agent orchestration for complex workflows
📄 License
This project is licensed under the MIT License — free to use, modify, and distribute with attribution.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。