AI data · Agent access

Postgres MCP server: give agents safe access to production data

A Postgres MCP server lets an agent query your database. The safe version is mostly database configuration, on PostgreSQL that runs in your cloud or data center.

45 minutes with an engineer: we review your workload and sketch the design.

A Postgres MCP server exposes database tools to an AI agent over the Model Context Protocol. The protocol leaves access control to the server, so the database has to enforce it: a read-only role, row-level security, statement timeouts and an audit trail. The agent never gets more than that role can do.

160+AceMQ customers
10+Years running these systems
24/7Engineers on call
3Places it runs: our cloud, yours, your data center
Engines we run, on the platforms you already use
  • PostgreSQL
  • MySQL
  • MongoDB
  • Redis
  • Valkey
  • OpenSearch
  • Kafka
  • RabbitMQ
  • AWS
  • Google Cloud
  • Azure
  • Kubernetes
  • OpenShift
  • Prometheus
  • Grafana
  • Datadog
  • Dynatrace
  • Splunk

Why agent access to production data goes wrong

An agent writes its own SQL, so it will eventually write a query nobody planned for. If the database role behind the MCP server can do more than the agent should, the first bad query does more than it should.

Illustrative: plan names and shapes stand in for any provider's menu.
A role with too many privileges.
A server configured with an owner or superuser connection can read and change anything.
Unbounded queries.
A large scan or an accidental cross-join can slow production for everyone.
Data returned into the model's context.
Rows that reach the model are visible to whoever can see the conversation.
Instructions hidden in data.
Text stored in a row can try to steer the agent that reads it.
No record of what was asked.
Without an audit trail, an incident cannot be reconstructed.

The pattern: the database enforces the limits

The MCP specification says servers must validate tool inputs, implement access controls, rate limit calls and sanitise outputs. For a database server, the strongest place to enforce access is the database itself.

In MCP the client discovers tools with `tools/list` and invokes them with `tools/call`, and the specification recommends a human in the loop for sensitive operations (MCP tools specification, checked 30 Oct 2026). Authorisation is optional in the protocol and is defined for HTTP transports; stdio servers are expected to take credentials from the environment (MCP authorization, checked 30 Oct 2026). Either way, the credential the server holds decides what the agent can do.

ComponentRoleDocumentation
MCP serverExposes tools such as a query tool, validates inputs and limits callsMCP tools
Dedicated database roleThe only identity the server uses: no superuser, no row-security bypass, a connection limitCREATE ROLE and GRANT
Row-level securityLimits which rows the role can seeRow security policies
Read-only default and timeoutsBlocks writes and stops long queriesClient connection defaults
AuditRecords which statements ran, and which role ran thempgAudit

Documentation checked 30 Oct 2026.

agent-role.sql (example)
CREATE ROLE agent_ro LOGIN NOSUPERUSER NOBYPASSRLS CONNECTION LIMIT 5;
ALTER ROLE agent_ro SET default_transaction_read_only = on;
ALTER ROLE agent_ro SET statement_timeout = '5s';
ALTER ROLE agent_ro SET idle_in_transaction_session_timeout = '10s';

GRANT USAGE ON SCHEMA public TO agent_ro;
GRANT SELECT ON public.tickets TO agent_ro;

ALTER TABLE public.tickets ENABLE ROW LEVEL SECURITY;
CREATE POLICY agent_scope ON public.tickets FOR SELECT TO agent_ro
  USING (visibility = 'internal');

The example is a starting point, not a complete design. The table, column and policy names are placeholders, and the values should be tested against your own workload.

What the public PostgreSQL MCP servers do

Two public servers show the range. The original reference server runs every query in a read-only transaction, and a later server offers a restricted mode for production and an unrestricted mode for development.

ServerAccess control it documentsNote
Reference Postgres serverOne `query` tool. All queries run inside a READ ONLY transaction. Table schemas are exposed as resources.The repository was archived by its owner on 29 May 2025.
Postgres MCP ProUnrestricted mode for development. Restricted mode for production, with read-only transactions, SQL parsing that rejects COMMIT and ROLLBACK, and an execution time limit.The README notes that enabling unsafe stored procedure languages could circumvent these protections.

Source: each project's README, checked 30 Oct 2026. Neither is endorsed or operated by OSStend.

Both rely on the database for the final guarantee. A read-only transaction in the server is a second layer, not a replacement for a read-only role.

Limits to set on the role

Each limit is a setting on the role or the database. Together they bound what a single bad query can cost.

Illustrative shape: real designs start from your metrics.
Setting or controlWhat it boundsHow to approach it
`default_transaction_read_only`WritesSet on the agent role so every transaction starts read-only.
`statement_timeout`Query durationSet a short value on the role. Raise it only for named reporting use.
`idle_in_transaction_session_timeout`Sessions that hold locks while idleSet on the role, so an abandoned session ends.
Connection limit on the roleConcurrent sessionsKeep it low and put a pool in front.
Column and table grantsWhat can be read at allGrant SELECT on named tables, or on views that hide columns. Do not grant on whole schemas by default.
Row-level securityWhich rows can be readKey policies to the database role, or to a value set by a layer the agent's SQL cannot reach.
Read replicaLoad on the primaryPoint the server at a replica when query volume or cost matters.

Settings are documented in the PostgreSQL manual, checked 30 Oct 2026.

Pitfalls to design for

These risks follow from how PostgreSQL and MCP behave, as documented. They are properties of the pattern rather than of one product.

Owners and superusers bypass row security.
Superusers and roles with BYPASSRLS always bypass it, and table owners normally do too. Connect as a role that is none of these (PostgreSQL docs).
A policy that reads a session setting can be defeated.
If the role can run arbitrary SQL, it can usually set the value itself. Key the policy to the role.
Views can bypass the base table's row security.
A view runs with its owner's privileges unless it is created with `security_invoker` (PostgreSQL 15 and later). See CREATE VIEW, and test the result.
Tool output goes to the model.
The MCP specification asks servers to sanitise outputs. Mask or exclude sensitive columns at the database, since the model cannot unsee a value.
Stdio configuration holds the credential.
Authorisation for stdio servers comes from the environment, so protect the file and the process that holds the connection string.
Enterprise only

What OSStend runs, where it runs and who it is not for

OSStend designs, moves and runs PostgreSQL in its own cloud, in your cloud account or co-managed in your data center. The role, grant and replica design for agent access is part of the cluster design you sign off.

Agent access sits next to other parts of the AI data layer, such as agent memory, which keeps durable state for the agent in the same PostgreSQL. Context engineering explains how the rows an agent reads become part of what the model sees.

Contact us if

  • Agents need to read production data, and the data must stay in your own environment.
  • A security review wants a documented role, policy and audit design.
  • You want the database run by engineers who also run your other engines.
Talk to an engineer

Not a fit if

  • The agent only needs a small, public dataset. A copy exported to a file is simpler.
  • You want agents to write to production tables. That needs its own design, which this page does not cover.
FAQ

Questions about the PostgreSQL MCP server

A PostgreSQL MCP server gives an agent database tools, and the database role behind it sets what the agent can do. These are the questions teams ask most before connecting one to production data.

Talk to an engineer →

What is a PostgreSQL MCP server?

A PostgreSQL MCP server, also called a Postgres MCP server, is a program that exposes PostgreSQL to an AI agent through the Model Context Protocol. It offers tools, such as running a query, that the agent can discover and call.

What is an MCP database?

An MCP database is a database exposed to an AI agent through an MCP server. The server offers tools such as running a query, and the database role behind it decides what the agent can read or change. A PostgreSQL MCP server is the PostgreSQL case.

Is a Postgres MCP server safe for production?

It can be, when the database enforces the limits. Use a dedicated read-only role, row-level security, statement timeouts and an audit trail, and prefer a read replica. A server that connects as an owner or superuser is not safe for production.

Does MCP handle authentication?

Authorisation is optional in the protocol. For HTTP transports the specification describes an OAuth-based flow, and stdio servers are expected to take credentials from the environment. In both cases the database role decides what the agent can do.

Can row-level security stop an agent seeing other tenants' rows?

Yes, if the role is not a superuser, a table owner or a BYPASSRLS role, and the policy cannot be changed by the agent's own SQL. Test it with queries that try to cross the boundary.

Should an agent write to the database?

Start read-only. Writes need their own role, narrow grants and review, since an agent can issue a statement nobody planned for.

Talk to an engineer

Talk to an engineer about agent access

Bring the data your agents need and where it lives. An engineer will help you design the role, the policies and the audit trail.

  • A design sketch for your workload, not a plan menu
  • A zero-downtime cutover path for what you run today
  • A price for that design, after the review
See pricing →

Your request goes to the OSStend team. No newsletter sign-up.

Get a quoteTalk to an engineer
2Engines
3Where should it run?
4What do you need?

Your request goes to the OSStend team. No newsletter sign-up.