MCP Text-to-SQL Agent
Provides MCP tools to inspect schema, validate SQL syntax, and execute SQL queries against Apache Hive analytics databases.
Provides MCP tools to inspect schema, validate SQL syntax, and execute SQL queries against PostgreSQL analytics databases.
Click on "Deploy 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., "@MCP Text-to-SQL Agentshow me last quarter's sales by region in PostgreSQL"
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.
MCP Text-to-SQL Agent (UAT Staging) π
An enterprise-grade Multi-Agent Management Intelligence System designed for automated Text-to-SQL query generation, multi-stage User Acceptance Testing (UAT) safety validation, and synthesized executive narrative reporting.
Built on LangGraph, Anthropic Claude Opus 4.1, Model Context Protocol (MCP), PostgreSQL/Hive, and containerized for cloud staging environments with Docker & Kubernetes.
π Key Highlights & Capabilities
Multi-Agent Orchestration Engine: Features specialized autonomous agents (Orchestrator, Text-to-SQL, UAT Validation, and Executive Narrative) operating on a centralized
StateGraph.Model Context Protocol (MCP) DB Interface: Standardized MCP server exposing secure tools (
get_db_schema,validate_sql_syntax,execute_sql_query) for PostgreSQL and Apache Hive analytics databases.Contextual State Memory & Self-Repair Loops: Automatic syntax and policy error feedback cycles. If a query fails UAT validation, the UAT Agent sends detailed tracebacks back to the Text-to-SQL Agent for automatic query re-synthesis.
Production Staging & Cloud Infra Ready: Pre-configured with multi-stage
Dockerfile,docker-compose.ymllocal analytics stack, and Kubernetes staging manifests (deployment.yaml,service.yaml,configmap.yaml).Significant ROI: Designed to reduce manual SQL reporting and business intelligence turnaround time by over 80%.
Related MCP server: PostgreSQL Advanced MCP Server
ποΈ System Architecture
flowchart TD
User([User Natural Language Query]) --> Orchestrator[Orchestrator Agent]
Orchestrator --> Text2SQL[Text-to-SQL Agent]
subgraph MCP ["Model Context Protocol (MCP) Server"]
MCPServer[MCP Postgres / Hive Tools]
DBSchema[get_db_schema]
DBExec[execute_sql_query]
DBVal[validate_sql_syntax]
end
subgraph Infrastructure ["Database Layer"]
DB[(PostgreSQL / Hive Analytics DB)]
end
Text2SQL <-->|Tool Calls| MCPServer
MCPServer <--> Infrastructure
Text2SQL --> UAT[UAT / User Validation Agent]
UAT -->|Syntax Error / Policy Violation| Text2SQL
UAT -->|APPROVED & Validated| Narrative[Executive Narrative Agent]
Narrative --> Output([Executive Business Report & Tabular Data])π€ Multi-Agent Workflow
Agent Node | Responsibility | Output Artifact |
Orchestrator Agent | Dispatches requests, tracks workflow state, handles initial state allocation. |
|
Text-to-SQL Agent | Inspects schema via MCP tools, constructs dialect-aware SQL (PostgreSQL/Hive). |
|
UAT Validation Agent | Enforces non-destructive SQL policies, syntax checks, and dry-run query execution. |
|
Narrative Agent | Transforms raw tabular database records into executive business summaries and recommendations. |
|
π Repository Structure
mcp-text2sql-agent/
βββ config/
β βββ settings.py # Application settings & environment loader
β βββ __init__.py
βββ mcp_server/
β βββ db_adapter.py # PostgreSQL & Hive DB connection adapter
β βββ server.py # MCP Server tool registry & invocation handlers
β βββ __init__.py
βββ src/
β βββ agents/
β βββ state.py # LangGraph state schema definition
β βββ llm_factory.py # Anthropic Claude & offline mock LLM provider
β βββ orchestrator.py # Master dispatch & dynamic router node
β βββ text2sql_agent.py # Text-to-SQL generation node
β βββ uat_agent.py # User validation & execution node
β βββ narrative_agent.py # Executive narrative synthesis node
β βββ graph.py # LangGraph StateGraph assembly
βββ docker/
β βββ Dockerfile # Multi-stage production build
β βββ init_db.sql # Enterprise analytics sample database seed script
βββ k8s/
β βββ configmap.yaml # Staging environment config map
β βββ deployment.yaml # Kubernetes deployment spec (2 replicas)
β βββ service.yaml # Kubernetes cluster service spec
βββ tests/
β βββ test_mcp_server.py # Unit tests for MCP server tools
β βββ test_agents.py # Unit tests for individual agent nodes
β βββ test_graph_workflow.py # Integration tests for end-to-end workflow
βββ main.py # CLI runner & interactive agent shell
βββ docker-compose.yml # Local staging container stack
βββ pyproject.toml # Build & pytest configuration
βββ requirements.txt # Python dependencies
βββ README.md # Project documentationβ‘ Quick Start Guide
1. Local Setup
Clone the repository and install dependencies:
git clone https://github.com/your-username/mcp-text2sql-agent.git
cd mcp-text2sql-agent
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install requirements
pip install -r requirements.txt2. Environment Configuration
Copy the example environment file:
cp .env.example .envEdit .env to set your credentials:
ANTHROPIC_API_KEY=your_anthropic_api_key_here
ANTHROPIC_MODEL=claude-3-5-sonnet-20241022
DB_TYPE=postgres
DB_HOST=localhost
DB_PORT=5432
DB_NAME=analytics_db(Note: If no API key is provided, the system automatically runs in zero-dependency offline Mock Claude LLM Mode).
3. Run System via CLI
Run a single analytical prompt:
python main.py --query "Show top 3 revenue generating product categories in Q3 2025"Run in interactive shell mode:
python main.py --interactiveπ³ Docker & Containerization
Run the full analytics stack (PostgreSQL database with pre-populated enterprise sales data + Agent service):
docker-compose up --buildβΈοΈ Kubernetes Staging Deployment (CloudView)
Deploy the multi-agent system to a staging Kubernetes cluster:
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
# Verify deployment status
kubectl get pods -n analytics-stagingπ§ͺ Automated Testing
Run the full pytest suite (covers MCP server tools, individual agents, and end-to-end LangGraph state machine):
python -m pytest tests/ -vπ Sample Output Demonstration
Input Query: "What were the top 3 product categories by revenue in Q3 2025 across all regions?"
Generated SQL Query:
SELECT p.category, SUM(oi.quantity * oi.unit_price) AS total_revenue
FROM products p
JOIN order_items oi ON p.product_id = oi.product_id
JOIN orders o ON oi.order_id = o.order_id
WHERE o.status = 'COMPLETED'
GROUP BY p.category
ORDER BY total_revenue DESC
LIMIT 3;UAT Validation Status: APPROVED β
(Passed syntax checks & non-destructive security rules).
Executive Narrative Output:
Executive Summary & Strategic Insights
Primary Finding: Software and Hardware categories generated $16,800.00 total Q3 revenue.
Key Observation: Enterprise Cloud Suite and AI Analytics Server drive 68% of total gross sales.
Strategic Recommendation: Increase hardware allocation for Q4 and launch targeted enterprise bundle promotions.
π License
Distributed under the MIT License. See LICENSE for more information.
This server cannot be deployed
Maintenance
Related MCP Connectors
Query PostgreSQL databases in plain English β LLM-generated, safety-validated SQL.
- dataOAuthco.thinair
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
The BigQuery remote MCP server is a fully managed service that uses the Model Context Protocol to connect AI applications and LLMs to BigQuery data sources. It provides secure, standardized tools for AI agents to list datasets and tables, retrieve schemas, generate and execute SQL queries through natural language, and analyze dataβenabling direct access to enterprise analytics data without requiring manual SQL coding.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with PostgreSQL databases through the Model Context Protocol, providing database schema exploration, table structure inspection, and SQL query execution capabilities.15MIT
- AlicenseNot gradedqualityDmaintenanceAn enhanced Model Context Protocol server that enables LLMs to inspect database schemas with rich metadata and execute read-only SQL queries with safety checks.90 npm25MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to query, explore, and analyze PostgreSQL databases through the Model Context Protocol. It provides robust security features including read-only mode, schema restrictions, and query timeouts for safe data interaction.11 npmMIT
- FlicenseNot gradedqualityDmaintenanceA secure Model Context Protocol implementation that enables AI agents to query PostgreSQL databases through predefined tools for employee, project, and issue data. It protects sensitive credentials and prevents arbitrary SQL execution by acting as a controlled connector layer between the LLM and the database.-