---
title: "PostgreSQL MCP Integration with Read-Only Views | CustomMCP.com"
description: "Expose approved PostgreSQL views to an AI client through bounded, read-only MCP tools with row limits, statement timeouts and no arbitrary SQL."
canonical: https://custommcp.com/integrations/postgresql/
updated: 2026-11-29
release_state: APPROVED_FOR_RELEASE
license: content all rights reserved; reference code MIT
generator: CustomMCP static generator 2.1.0
---

# PostgreSQL MCP integration with bounded, read-only access

> A PostgreSQL MCP integration exposes allowlisted views or functions through read-only tools. It uses a dedicated database role, parameterized queries, statement timeouts and row limits. Arbitrary SQL, schema changes and writes are excluded from the default profile.

The safe database integration is not a text-to-SQL endpoint. It is a small set of named views with a dedicated role, limits and no path to a write.

## What the integration exposes

| Tool | Input | Returns | Guardrail |
| --- | --- | --- | --- |
| list_views | none | Names and descriptions of approved views | Allowlist only |
| describe_view | view | Column names, types and descriptions | Allowlist only |
| query_view | view, filters, limit | Rows from one approved view | Parameterized, 100-row cap |
| get_row | view, key | One row by primary key | Allowlist and key type check |

*Default PostgreSQL tool surface*

## Why not text-to-SQL

Text-to-SQL is impressive in a demo and difficult to bound in production. The model can write a join that scans a large table, read columns the user should not see, or construct a statement that is valid but expensive.

Named views move the modeling decision into the database, where you can review it, grant it and explain it. The model chooses filters, not the schema. If a workflow needs a new question answered, you add a view and review the query plan.

## Prerequisites

- A dedicated login role with SELECT on the approved views only.

- A read replica or a low-privilege schema for production reads.

- Views that already enforce row-level security or tenant filters.

- A network path from the runtime with TLS and an IP allowlist.

- A statement timeout and a connection pool size agreed with your DBA.

- A documented owner for view changes.

## Controls that are not optional

| Control | Setting | Effect |
| --- | --- | --- |
| Statement timeout | 5 seconds, tuned per view | Stops expensive accidental queries |
| Row limit | 100 rows per call | Keeps results inside the model context |
| Parameterization | Every filter bound as a parameter | Prevents SQL injection |
| Identifier allowlist | Exact view and column names | Prevents schema probing |
| Role permissions | SELECT only, no schema usage beyond views | Prevents writes and DDL |
| Logging | Query fingerprint, actor, duration | Supports review without storing row data |

*Database control baseline*

## Performance and failure behavior

We test each view with representative data and record its plan and p95 latency. A view that cannot answer within the timeout is rewritten, indexed or removed from the surface; we do not raise the timeout to hide a slow query.

When the database is unavailable, the tool returns a bounded error with a retry hint. The server does not retry non-idempotent work, and it never returns a partial row set without labeling it.

## Frequently asked questions

### Can the assistant write to the database?

Not in the default profile. The role has SELECT only, and write tools are excluded. If a write is required, it becomes a separate, narrowly scoped tool with approval and idempotency.

### Can it run any SQL the model writes?

No. The model selects a view and supplies parameterized filters. The server validates the view against an allowlist and rejects anything else.

### Does this work with row-level security?

Yes, and we recommend it. The database role should see only the rows the tenant or user is allowed to see, so the boundary is enforced below the MCP server as well.

### What about sensitive columns?

They are excluded from the view or masked before the view is granted. We do not rely on the model to avoid selecting them.

## Related

- [Integration patterns we can scope today](https://custommcp.com/integrations/)
- [MCP security checklist: 20 controls before you expose a tool](https://custommcp.com/resources/mcp-security-checklist/)
- [Enterprise knowledge retrieval that shows its sources](https://custommcp.com/use-cases/knowledge/)
- [Connect one system to one AI client, without opening everything](https://custommcp.com/services/mcp-integration/)

---

Canonical HTML: https://custommcp.com/integrations/postgresql/
Machine index: https://custommcp.com/llms.txt
Agent onboarding: https://custommcp.com/agents/
Last verified: 2026-11-29
