DEV Community

RajeevaChandra
RajeevaChandra

Posted on

Introducing Postgres MCP Server: Query Your Database in Plain English with AI

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  
Enter fullscreen mode Exit fullscreen mode

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? ๐Ÿš€

Top comments (0)