Agentic-AI-MCP-Query-Brain
Uses OpenAI's LLM to convert natural language queries into SQL statements for database execution.
Executes SQL queries generated from natural language against a PostgreSQL database, returning results for further processing.
Stores conversational context in Redis memory to enable follow-up queries with retained context.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Agentic-AI-MCP-Query-BrainShow me the top 5 products by sales this year"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
π§ 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
Related MCP server: nl2sql-mcp
π§ 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-BrainInstall dependencies
pip install -r requirements.txtRun the FastAPI service
uvicorn main:app --reloadOr 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.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Ramneek82810/Agentic-AI-MCP-Query-Brain'
If you have feedback or need assistance with the MCP directory API, please join our Discord server