Skip to main content
Glama

SQL Query MCP Server

πŸš€ MCP-Powered Streamlit Dashboard with Ollama + PostgreSQL

A modern data analysis tool that lets you:

  • Query your PostgreSQL database with natural language

  • Run SQL manually or generate it using LLMs (Ollama)

  • Analyze data with charts, statistics, and export to CSV


🧠 Prompt-to-SQL Flow

graph TD A[πŸ§‘ User types a data question] --> B[Streamlit sends prompt to Ollama API] B --> C[Ollama generates SQL query as text] C --> D[Streamlit extracts the SQL] D --> E[Streamlit sends SQL to MCP server] E --> F[MCP executes query on PostgreSQL] F --> G[Results returned to Streamlit] G --> H[πŸ“Š Results shown + Chart + CSV Export]

πŸ“¦ Architecture

  • Streamlit – UI + charting

  • MCP (FastMCP) – Tools/resources for SQL query and table listing

  • PostgreSQL – Stores your company data

  • Ollama – LLM that translates natural language prompts to SQL


πŸ“Œ Features

βœ… Natural language β†’ SQL
βœ… Charting (bar/line/time series)
βœ… CSV download
βœ… Statistical summary
βœ… Prompt explainability with raw output
βœ… Auto-detect date/time fields
βœ… LLM integration with llama3 (configurable)


πŸ› οΈ Getting Started

git clone <this-repo> cd postgres-mcp-server docker-compose up --build

βš™οΈ Env Configuration

MCP_API_URL=http://mcp-server:3333/mcp OLLAMA_URL=http://ollama:11434/api/generate

πŸ“€ Prompt Example

β€œList departments with average salary > 50000”

πŸ‘‰ Translated to SQL:

SELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) > 50000;

Why is this a good use case for MCP?

πŸ”— MCP makes it dead simple to expose structured tools like SQL queries to LLMs. 🎯 Agents can discover and call your tools without hardcoding logic. πŸ’¬ You get the best of both worlds β€” interpretability, flexibility, and control.

Whether you're building internal tools, research dashboards, or intelligent agents β€” this pattern is reusable, secure, and 100% local.

πŸ“„ License

MIT

-
security - not tested
F
license - not found
-
quality - not tested

Related MCP Servers

  • -
    security
    -
    license
    -
    quality
    An MCP server that enables natural language querying of Supabase PostgreSQL databases using Claude 3.7, allowing users to inspect schemas, execute SQL, manage migrations, and convert natural language to SQL queries.
  • -
    security
    F
    license
    -
    quality
    A FastMCP server that provides natural language interaction with MS SQL databases, enabling users to query data, list tables, describe structures, and execute database operations through a conversational AI interface.
    Last updated -
  • -
    security
    A
    license
    -
    quality
    MCP-Server from your Database optimized for LLMs and AI-Agents. Supports PostgreSQL, MySQL, ClickHouse, Snowflake, MSSQL, BigQuery, Oracle Database, SQLite, ElasticSearch, DuckDB
    Last updated -
    503
    Apache 2.0
    • Linux
  • -
    security
    A
    license
    -
    quality
    A FastMCP-based server that enables executing Microsoft SQL Server data queries and table structure queries through a standardized MCP protocol interface.
    Last updated -
    5
    MIT License

View all related MCP servers

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/rajeevchandra/mcp-ollama-postgres'

If you have feedback or need assistance with the MCP directory API, please join our Discord server