Featured

Deploy OpenClaw in 60 seconds — 20% off logoDeploy OpenClaw in 60 seconds — 20% off

Launch OpenClaw on Hostinger in about 60 seconds and keep your agent live 24/7. Our referral link gives you 20% off, no coupon code needed.

Launch on Hostinger
Run your Hermes agent on Hostinger, fully managed logoRun your Hermes agent on Hostinger, fully managed

Launch Hermes on Hostinger in one click, fully managed, no VPS knowledge needed. Use code ZACAARON10 for 10% off.

Launch on Hostinger
Crawl and scrape any site into clean data, 10% off logoCrawl and scrape any site into clean data, 10% off

Firecrawl crawls and scrapes any site into clean markdown for your agent. Get 1,000 free credits, and new users get 10% off their first purchase.

Try Firecrawl free
Your own AI agent, running 24/7 with QwikClaw logoYour own AI agent, running 24/7 with QwikClaw

QwikClaw sets up and runs an always-on OpenClaw agent for you. One click, no config files, no server setup.

Deploy now
One API to scrape, enrich, and extract the internet. logoOne API to scrape, enrich, and extract the internet.

Context.dev gives your agents a single API to scrape, enrich, and extract live web data — no proxies, no parsers, no maintenance.

Start building free
SetupClaw: done-for-you OpenClaw for founders & exec teams logoSetupClaw: done-for-you OpenClaw for founders & exec teams

White-glove OpenClaw for founders and exec teams (4–50+ employees): we install, harden, integrate your tools, and maintain it — secured from day one.

Get it set up for you
SEO data APIs for your agent, $1 free credit logoSEO data APIs for your agent, $1 free credit

DataForSEO gives your agent live access to SERP results, keyword data, backlinks, and on-page SEO data through one API. New accounts get a $1 credit, good for up to 20,000 keyword or backlink lookups.

Try DataForSEO free
Reach 47,000+ AI builders

A flat monthly placement in front of developers actively installing AI tools. No lock-in, cancel anytime.

Advertise here

Works with

Claude CodeClaude DesktopCursorVS CodeClineCodex CLIOpenClaw+ any MCP client

Install to Claude Code

This server doesn't publish a one-line install command. Follow the setup in the source repository.

Summary

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.md

🧠 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

  1. User input (natural language) is sent via the frontend or CLI.
  2. The MCP Host routes the input to the appropriate tool.
  3. OpenAITool generates SQL from the input using LLM reasoning.
  4. SQLTool executes the query on PostgreSQL, returning raw results.
  5. NaturalLanguageResponseTool translates results into readable form.
  6. 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

  1. Clone the repository
   git clone https://github.com/Ramneek82810/Agentic-AI-MCP-Query-Brain.git
   cd Agentic-AI-MCP-Query-Brain
  1. Install dependencies
   pip install -r requirements.txt
  1. Run the FastAPI service
   uvicorn main:app --reload
  1. 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.

See related servers & alternatives →

Related MCP servers

Browse all →

Related guides

Hand-picked reading to help you choose and use Databases servers.