Have you ever wished you could just ask your database a question, without writing SQL?

"Show me the average salary by department."
"List employees in New York earning over $80K."
"Plot monthly sales trends."

What if you could get these answers instantly, without writing a single SQL query?

That’s exactly why I built Postgres MCP Server—an open-source AI SQL dashboard that translates natural language into safe, optimized PostgreSQL queries.

✅ What Postgres MCP Server Can Do

  • 🧠 Natural Language to SQL: Converts human questions into valid SQL queries using LLaMA 3 via Ollama.
  • 📊 Statistical Data Analysis: Computes summary stats, correlation matrices, and aggregates on your data automatically.
  • 📅 Time Series & Charts: Detects date fields and visualizes trends using line/bar charts.
  • 💬 Prompt-Based Filtering: Understands queries like “employees in NY earning over 80K” and applies them as SQL filters.
  • 📎 MCP-Compliant API Server: Exposes sql://query and table://list tools via the Model Context Protocol for LLM and agent compatibility.
  • 📦 Streamlit Dashboard: Clean, reactive UI to browse data, input prompts, see SQL, and export CSV.
  • 🔐 Safe Read-Only Queries: Executes only non-destructive SQL with validation; protects your source database.
  • 🧱 Dockerized Setup: Entire app runs locally using Docker Compose — PostgreSQL, Streamlit, MCP server, Ollama.
  • 💬 LLM Agent-Ready: Compatible with Claude, GPT, LangChain, or AutoGen frameworks via MCP schema.

Why MCP? (Model Context Protocol)
Most AI agents rely on hardcoded APIs or brittle prompts—but MCP changes that. It’s an open protocol that lets LLMs discover and use tools dynamically.

MCP enables:
✅ Self-documenting APIs (LLMs understand what your server can do)
✅ Agent-friendly tool discovery (no rigid integrations)
✅ Flexible schema definitions (describe tables, queries, and operations in a model-readable way)

Instead of writing custom prompts for every agent, MCP lets your LLM automatically understand how to query your database.

🧪 Sample Prompts

  • "Show total number of employees"
  • "List departments with avg salary > 80K"
  • "Number of employees in each location"
  • "Plot salary trends over time"

The server translates these into SQL, executes them securely, and returns results in the UI.

🚀 Run It Locally in 3 Steps

git clone https://github.com/rajeevchandra/mcp-ollama-postgres  
cd mcp-ollama-postgres  
docker-compose up --build

Note: Requires Ollama with llama3 pulled (ollama pull llama3).

Try it out, star the repo, and let me know what you think!
GitHub - https://github.com/rajeevchandra/mcp-ollama-postgres

Would love your feedback—what features would make this even more useful for you? 🚀