Back to home

Integrations · n8n

Secure database access for your n8n AI agents

Never hand an n8n AI agent raw SQL. Let it read through a scoped, read-only retrieval layer, and send every INSERT, UPDATE or DELETE it proposes through an allow/deny check before your Postgres or MySQL node runs.

With Claix this takes two HTTP Request calls: one to Retrieve for reads and one to Guard for writes. Typed answers, traces and a kill switch included.

At a glance

What you need in n8n

What you needWhat to use in n8nClaix endpoint
Answers from live dataAI Agent + HTTP Request Tool (or MCP Client Tool)POST /retrieve/{agent_name}
Safe writesHTTP Request → IF → Postgres/MySQLPOST /check-sql
Know what happenedWebhook trigger from Guard TracesGuard Traces
Emergency stopHTTP Request nodePOST /agents/pause/{agent_id}

The problem

Why a database credential is not enough

An n8n AI Agent node works as a Tools Agent: the model decides which tool to call and with which arguments. If one of those tools is a Postgres or MySQL tool with write permissions, the model can send any statement that credential allows.

A system prompt that says never delete anything is a request to the model, not a restriction on the database. The control has to sit outside the model and give the same answer every time.

Compared

Four ways to connect an n8n agent to a database

ApproachCan change data?Scoped tables/columns?Typed answers?Write rules?Audit
Postgres tool (read/write)Anything the role allowsManual GRANTs onlyNoPrompt onlyn8n execution log
Postgres tool (read-only)NoManual GRANTsNoN/An8n execution log
Generic DB MCP serverDependsDependsDependsDependsDepends
Claix Retrieve + GuardOnly after allowPer route and agentYesPlain-English rulesFull traces

How it works

What Claix does for your n8n agent

  • Retrieve (reads)

    Connect Postgres, MySQL, MariaDB or Supabase with a read-only role. Define routes (tables, columns, guide) and agents. Your n8n agent asks in plain language; Claix answers inside the perimeter you set—typed for IF nodes.

  • Guard (writes)

    Write rules in plain English. Claix turns them into exact rules with tests. Your workflow sends each proposed statement to Guard, gets allow or deny, then executes—or does not. Claix never touches your data.

  • Traces

    Every query and every verdict stays on record, with optional webhooks into Slack, email or a ticket when something is blocked.

Setup

Connect your database to n8n with Claix

You can wire the full flow in an afternoon. Keep the write credential only on the node that runs after Guard.

  1. 01

    Give Claix a read-only role

    Create a dedicated role with SELECT on the tables the agent needs. Connect it in the dashboard so Claix can draft the Data Map.

  2. 02

    Create a route and an agent

    Pick tables and columns, write a short guide, attach the route to an agent and choose reasoned mode if you want typed answers.

  3. 03

    Store the API key in n8n

    Header Auth credential named x-api-key (Bearer also works). Never put the key in a prompt.

  4. 04

    Add a Retrieve read tool

    HTTP Request Tool on the AI Agent: POST https://claix.dev/retrieve/{agent_name} with the question filled by $fromAI.

  5. 05

    Write Guard rules

    For example: agents can change reservation status but never delete; no statement may change more than 5 rows.

  6. 06

    Build a guarded write workflow

    Named actions only: Set (sql, params) → POST /check-sql → IF allowed → Postgres/MySQL write. Fail closed on anything else.

  7. 07

    Alerts and kill switch

    Point Guard denied webhooks at an n8n Webhook. Pause an agent with POST /agents/pause/{agent_id}. Cap successful queries per day, week or month.

Retrieve

HTTP Request Tool body for reads

The agent writes the question; your node owns the URL, auth and format. Several questions in one request come back in order.

{
  "questions": [
    {
      "question": "{{ $fromAI('question', 'The question to ask about the live data, in plain language') }}",
      "format": "string"
    }
  ]
}

Guard

Check before you write

Build the statement once and reuse it for the check and the write. Use $1/$2 for Postgres and ? for MySQL/MariaDB. When denied, send the reason back to the agent.

{
  "sql": "UPDATE reservations SET status = $1 WHERE id = $2",
  "params": ["cancelled", 4812]
}

Example

A restaurant operations assistant

What the user asksWhat happensResult
How many tables are booked tonight?Retrieve with format intA number the workflow can use
Is anyone on shift after midnight?Retrieve with format booleantrue/false for an IF node
Cancel reservation 4812Sub-workflow builds UPDATE → GuardAllowed, then Postgres runs
Delete all reservations from last monthAgent proposes DELETE → GuardDenied; nothing runs

Security

Checklist for n8n agents with database access

  • Read-only for Claix

    Use a read-only role for the Claix connection.

  • Write credential isolated

    Keep it only on the node after the Guard check—never on an agent tool.

  • Fail closed

    Only execute on HTTP 200 with allowed: true.

  • One statement per check

    Check exactly what you execute; store key in credentials; review traces.

Pricing

Pricing and a cost example

Every account gets 30 successful calls per month free, with no card. You only pay for successful calls (HTTP 200).

Retrieve · Claix Managed AI€0.10 / question
Retrieve · your LLM key (BYOK)€0.02 / question
Guard€0.01 / check
EnterpriseSelf-hosted · custom

Example: 1,000 questions and 1,000 write checks ≈ €100 + €10 with managed AI, or €20 + €10 with your own key (before the free 30 and provider tokens).

Frequently asked questions

How do I give an n8n AI agent access to my database safely?
Connect the database to a controlled layer with a read-only role, expose only specific tables and columns through a retrieval tool, and run every write through an allow/deny check before the database node executes. Claix does this with an HTTP Request Tool for reads and a Guard check for writes.
Can an n8n AI agent delete my database?
It can if you attach a database tool with delete permissions and rely on the prompt. To prevent it, use a read-only role for reads, keep the write credential away from agent tools, and require an allow verdict from Guard before any write.
Is a read-only Postgres user enough for an n8n agent?
It is a good baseline because the agent cannot write. It does not scope columns per agent unless you maintain grants by hand, it returns untyped rows, and it gives you no rules for the writes you will eventually want to allow.
Does Claix work with the n8n AI Agent node?
Yes. Call Retrieve from the HTTP Request Tool, use the MCP Client Tool with the Claix MCP tool, or call it from any HTTP Request node. Claix is a layer you call from the stack you already use.
Does Claix execute the INSERT, UPDATE or DELETE?
No. Retrieve uses a read-only role, and Guard only answers whether a proposed change is allowed. Your n8n workflow executes it.
Which databases does it support?
Any SQL database, including Postgres, MySQL and MariaDB, and Postgres-compatible setups such as Supabase.
Can I use my own LLM key?
Yes. With your own key from OpenAI, Google, Anthropic or xAI, the Claix fee drops from €0.10 to €0.02 per question and you pay your provider directly.
Can I self-host it?
Self-hosting is available on the Enterprise plan.

Wire Claix into your n8n agent

Scoped reads, checked writes, traces and a pause switch. Thirty successful calls per month free—enough to test the full flow.