How to Configure n8n Postgres MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up an n8n postgres mcp server, attach a tool sub-node to an AI Agent node. Then give that tool a dedicated database role with read privileges. Teams often start by reusing an admin database user for speed. That shortcut gives the agent broad rights across every table and function. If a prompt fails or loops, the agent can read sensitive rows or drop data. How the n8n postgres mcp server architecture works The n8n AI Agent node pairs a chat model with one or more tools. You must attach

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To set up an n8n postgres mcp server, attach a tool sub-node to an AI Agent node. Then give that tool a dedicated database role with read privileges. Teams often start by reusing an admin database user for speed. That shortcut gives the agent broad rights across every table and function. If a prompt fails or loops, the agent can read sensitive rows or drop data.

How the n8n postgres mcp server architecture works

The n8n AI Agent node pairs a chat model with one or more tools. You must attach at least one tool sub-node to the AI Agent node. Based on the user prompt, the agent decides which tools to call. From version 1.82.0 onward, all AI Agent nodes run as a Tools Agent. Older agent type settings were deprecated and removed in version 3.0.

For database tasks, n8n provides a registry of MCP servers and built-in Postgres tool sub-nodes. These replace the older standalone SQL Agent mode. When a prompt arrives, the chat model writes a query and sends it through the tool. The tool logs in to Postgres with stored credentials and runs the query. Results return to the agent so it can answer the user.

Setting up Postgres roles for agent tools

Database admins control what the agent can touch by creating a dedicated Postgres role. You can grant the SELECT privilege on specific tables or views. Postgres also lets you grant SELECT on specific columns of a table. This helps when a table holds both safe columns and secret columns. If many workflows share the database, you can set up group roles. Individual agent users then receive membership in the group role.

You must also check default rights granted to the special PUBLIC role. By default, PUBLIC gets CONNECT and TEMPORARY rights on databases. It also gets EXECUTE rights on functions and procedures. An object owner can revoke these default rights from PUBLIC. In Postgres 15 and newer, users cannot create objects in the public schema by default. On older upgraded databases, admins must revoke CREATE on the public schema from PUBLIC.

Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native setup solves and what keeps the session active

A scoped Postgres role stops the agent from altering tables it does not own. Column grants also block queries that ask for restricted columns by name. This native setup decides which role can log in and which objects it can read.

Still, static database roles cannot inspect what an individual query does in flight. The SELECT privilege still allows COPY TO operations on allowed tables. A valid read role can pull millions of rows in one bad query. If a permitted column holds emails, phone numbers, or card numbers, Postgres sends them raw. The database does not rewrite matched fields in results before the model reads them. You also have to store static database keys inside the workflow app. Finally, native role grants do not tie individual agent queries to a human approver.

Check every Postgres query on the wire

Database roles and network rules decide who can open a session. They do not read what each SQL statement does after login. With hoop.dev, you run an open-source proxy, a sidecar for your Postgres. It runs beside your database and reads the Postgres wire protocol. Your apps and agents keep their login details and change only the host and port in the connection string their tool uses.

Before a query runs, hoop.dev guardrails check the statement by its effect, table, or pattern. They refuse bad deletes or drops with a real Postgres error. On the way back, hoop.dev data masking rewrites sensitive values in returned rows based on your rules. Every query and verdict goes to the audit trail. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for HIPAA, GDPR, and PCI DSS. See the code on GitHub.

Frequently asked questions

How do I connect Postgres to an n8n AI Agent node?

Add an AI Agent node to your canvas and attach a chat model. Then attach a Postgres tool sub-node or an entry from the MCP server registry. All current AI Agent nodes work as a Tools Agent and pick tools per task.

Can I restrict an agent to specific Postgres columns?

Yes, Postgres lets you grant the SELECT privilege on specific columns of a table. If the agent queries a column outside that grant, the database rejects the statement. Keep in mind that allowed columns still return raw emails or card numbers unless masked.

Why can my read-only agent role still run functions or create temp tables?

Postgres grants default privileges to the special PUBLIC role, which every role inherits. By default, PUBLIC has TEMPORARY rights on databases and EXECUTE rights on functions. The database owner must revoke these defaults from PUBLIC to lock down the role.

The query runs. The emails stay hidden.