PostgreSQL conversational agent with Claude DeepSeek Multi KP
π§ Conversational PostgreSQL Agent Enable AI-driven conversations with your PostgreSQL database using a secure and visual-free agent powered by n8nβs Model C...
π Nodes & Integrations Used (11)
π Implementation & Setup Guide
π§ 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 `ListTables` and `GetTableSchema` - 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 | | ListTables, 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
- π₯ Upload both workflow files into your n8n instance:
- - `Build_your_own_PostgreSQL_MCP_server_No_visuals_.json`
- - `checkdatabase.json`
- π Set up PostgreSQL credentials (e.g. βPostgres account 3β)
- π§ Confirm model setup:
- - Claude 3.5 Haiku for the main agent
- - DeepSeek for the subflow
- π Use the `/mcp/...` URL from the MCP Server Trigger to connect your frontend or chatbot
- π£ 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 | |------------------------------|---------------------------|---------------------------------| | Handles multi-KPI questions | β No | β Yes | | Secure query execution | β Yes | β Yes | | Structured response | β οΈ JSON / raw | β Clean natural language | | Cost-efficiency | β οΈ More calls | β Optimized with fewer calls | | Endpoint support | β Manual interaction | β MCP-ready (`/mcp/...`) |
π Prefer something more lightweight and cost-sensitive? Try the original Conversing with Data template (single KPI + chart support): [Conversing with Data: Transforming Text into SQL Queries and Visual Curves](https://n8n.io/workflows/3497-conversing-with-data-transforming-text-into-sql-queries-and-visual-curves)
> I used this version for over 3 months and only spent **$0.80 total**, making it a great entry point if you're just getting started or on a limited budget.
---
π More from the Same Creator
Looking for a different kind of AI reporting workflow?
Explore: **Customer Feedback Analysis with AI, QuickChart & HTML Report Generator** β Automatically analyze customer input and generate full reports with insights and charts. [Customer Feedback Analysis with AI, QuickChart & HTML Report Generator](https://n8n.io/workflows/3642-customer-feedback-analysis-with-ai-quickchart-and-html-report-generator)
β‘ How to import this workflow into n8n:
- Click the Direct Download JSON button above to save
PostgreSQL_conversational_agent_with_Claude_DeepSeek_Multi_KP.json. - Log in to your n8n Cloud or self-hosted n8n instance.
- In your workflow canvas, click the menu in top-right and select Import from File (or paste the JSON directly).
- Configure your credentials (e.g. API keys, database URLs) in the corresponding node settings.
- Click Execute Workflow to test and switch to Active!
Related AI Agents Workflows
View All in AI Agents β5 ways to process images PDFs with Gemini AI in n8n
How it works Many users have asked in the support forum about different methods to analyze images and PDF documents with Google Gemini AI in n8n. This workfl...
7 AI Sales Assistant
Production-ready n8n automation template for 7 AI Sales Assistant built by AhiXLight. Seamlessly connects Airtop Tool, Slack, Airtop with 24 configured nodes.
AAVE portfolio professional AI agent Telegram Email GPT 4o
A next-generation AI-powered DeFi health monitor that tracks wallet positions across Aave V3 using GPT-4o and LangChain. It delivers human-readable reports v...
Access control for AI agents RBAC using Airtable and Telegram
Purpose This workflow allows granular control over the access to tools connected to AI Agents (including Multi-Agent setups) using Role Based Access Control....