PostgreSQL Conversational Agent with Claude & DeepSeek (Multi-KPI, Secure)
# Conversational PostgreSQL Agent Enable AI-driven conversations with your PostgreSQL database using a secure and visual-free agent powered by n8n's Model Context Protocol (MCP). This template allows users to ask multiple KPIs in a single message, returning consolidated insights - more efficient than the original Conversing with Data template. --- ## Why This Template Unlike the Conversing with Data workflow, which handles one KPI per message, this version: - Supports multi-KPI questions - Returns structured, human-readable reports - Uses fewer AI calls, making it faster and cheaper - Avoids raw SQL execution for enhanced security **Estimated cost per full multi-request run: ~$0.01** This template is optimized for efficiency. Each message can return 2-4 KPIs (You can change the MaxIteration of the Agent to make it more, it is currently set up at 30 iterations) using a single Claude 3.5 Haiku session and DeepSeek-based SQL generation - balancing speed, reasoning, and affordability. --- ## Sample Use Case **User:** "Can you show product performance, revenue trends, and top 5 customers?" **Agent:** - Uses `Listables` and `GetableSchema` - Generates three SQL queries using `get_query_and_data` - Returns: **Product Performance** 1. High-Waist Jeans - 10 units, $1,027 revenue 2. Denim Jacket - 10 units, $783 revenue **Sales Trends** - Peak Month: January 2024 - 32 units, $2,378 - Average Monthly Units: 10-16 **Customer Insights** 1. Bob Brown - $1,520 spent 2. Diana Wilson - $925 spent All from one natural prompt. --- ## Real-World Interaction Screenshot  --- ## What's Inside | Node | Purpose | |----------------------------|-----------------------------------------------------------| | MCP Server Trigger | Receives user queries via `/mcp/...` | | AI Agent + Memory | Understands and plans multi-step queries | | Think Tool | Breaks down the user's question into structured goals | | get_query_and_data | Generates SQL securely from natural language | | Listables, GetSchema | AI tools to explore DB safely | | Read/Insert/Update Tools | Execute structured operations (never raw SQL) | | checkdatabase Subflow | Validates SQL, formats response as clean text | --- ## Model Selection Recommendations This template uses two types of models, selected for cost-performance balance and role alignment: **1. Claude 3.5 Haiku (Anthropic) - for the MCP Agent** The main conversational agent uses Claude 3.5 Haiku, ideal for MCP because it was built by Anthropic - the creators of the MCP standard. It's fast, affordable, and performs excellently in tool-calling and reasoning tasks. **2. DeepSeek - for the SQL subworkflow** The subworkflow that turns natural language into SQL uses DeepSeek. It's one of the most affordable and performant models available today for structured outputs like SQL, making it a perfect fit for utility logic. This setup provides top-tier reasoning + low-cost execution. --- ## Security Benefits - No raw SQL accepted from the user or LLM - All queries are parameterized - Schema is dynamically retrieved - Final output is clean, safe, and human-readable --- ## Try a Prompt > "Show me the top 5 products by units sold and revenue, total monthly sales trend, and top 5 customers by spending." In one message, the agent will: - Generate and run multiple queries - Use the schema to validate logic - Return a single, comprehensive answer --- ## How to Use 1. Upload both workflow files into your n8n instance: - `Build_your_own_PostgreSQL_MCP_server_No_visuals_.json` - `checkdatabase.json` 2. Set up PostgreSQL credentials (e.g., "Postgres account 3") 3. Confirm model setup: - Claude 3.5 Haiku for the main agent - DeepSeek for the subflow 4. Use the `/mcp/...` URL from the MCP Server Trigger to connect your frontend or chatbot 5. Ask questions naturally - the agent takes care of planning, querying, and formatting --- ## Customization Ideas - Swap Claude or DeepSeek for OpenAI, Mistral, Gemini, etc. - Export insights to Slack, Notion, or Google Sheets - Add Switch nodes to control access to specific tables - Integrate with any front-end app, internal dashboard, or bot --- ## What's Included - `Build_your_own_PostgreSQL_MCP_server_No_visuals_.json` - MCP agent logic - `checkdatabase.json` - SQL generation and formatting utility workflow These must be uploaded into your n8n workspace for the template to function. --- ## Comparison: Conversing with Data vs This Workflow | Feature | Conversing with Data | This Workflow |
New buyers can create an account from the cart to unlock a controlled $10 first-purchase credit on eligible orders of $25+.
Related bundle
Content Repurposing Engine
8 hand-picked workflows for $29.00.
That is $3.63 each, vs $14.99 for this one alone.
View bundleSecure checkout powered by Stripe
Tags
Support
How to import this workflow into n8n
- 1Purchase or download the workflow to get the n8n workflow JSON file.
- 2In your n8n instance, open Workflows and choose "Import from File" (or paste the JSON with Ctrl+V on the canvas).
- 3Open each node marked with a credential warning and connect your own accounts and API keys.
- 4Run the workflow once manually to verify the data flow, then toggle it to Active.
Related AI workflows
- Launch Your First AI-Powered Chatbot with Actionable Tools$9.99
- Automate AI Video Creation and YouTube Upload with Google Sheets$14.99
- Build a WhatsApp Assistant with Memory, Google Suite, Multi-AI, Research, and Imaging$24.99
- Automate Blog Post Creation and Publishing with GPT, Leonardo AI, and WordPress$14.99
- Automate SEO Keyword Generation with ChatGPT from Google Sheets$3.99
- Email Agent$500.99
More from hippolyte-hu
Need this deployed? We'll set it up for you.
Our automation experts deploy this workflow in your stack, connect your accounts, and verify it works — or build a custom solution from scratch.