Skip to main content
Glama
MCP Postgres Guard

MCP Postgres Guard

MCP Postgres Guard πŸ˜πŸ›‘οΈ

License: MIT Python 3.8+ MCP Protocol

A security-first Model Context Protocol (MCP) server for PostgreSQL: query auditing, destructive command interception, and SQL injection prevention for autonomous AI agents.

Developed by Tarek Mohamed (@seotarek)


πŸ“Œ Why MCP Postgres Guard?

Allowing AI agents (Claude, Cursor, LangChain agents) direct SQL access creates severe operational risks: accidental table dropping, unbounded deletions, or SQL injection. MCP Postgres Guard intercepts and audits all agent-generated SQL queries before they reach your database:

[ AI Agent / Claude / Cursor ]
               β”‚
               β–Ό
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚           MCP Postgres Guard Server          β”‚
 β”‚  β€’ Destructive Query Blocker (DROP/TRUNCATE) β”‚
 β”‚  β€’ Unbounded DELETE/UPDATE Prevention        β”‚
 β”‚  β€’ Stacked Query & RCE Probe Detection       β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚ (Only If Verified Safe)
                        β–Ό
             [ Production Database ]

Related MCP server: Safe DB Gateway

πŸ› οΈ MCP Tools

  • pg_validate_query: Validates whether a SQL statement is safe to execute for an autonomous agent.

  • pg_check_read_only: Enforces a strict read-only policy (SELECT / EXPLAIN only).


πŸš€ Claude Desktop Configuration

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "postgres-guard": {
      "command": "python",
      "args": ["-m", "mcp_postgres_guard.server"],
      "cwd": "/path/to/mcp-postgres-guard"
    }
  }
}

πŸ“œ License

Licensed under the MIT License.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      SQL guardrails for AI agents, sitting between the agent and Postgres to enforce policies, block destructive queries, and audit all access.
      5
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to query PostgreSQL databases securely with read-only defaults, PII masking, rate limiting, and human-approved, expiring mutation tokens.
      9
      1
      Apache 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to query a Postgres database read-only through a policy layer rather than a raw connection string. Enforces table and column allowlists, row limits, mandatory predicates, PII masking and append-only audit logging, while refusing writes, joins, subqueries and unlisted functions.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to query Postgres, BigQuery and DuckDB read-only through policy-checked SQL, with AST-based guards that refuse writes and dangerous functions, column masking on the way out, and an audit log of every query. Also exposes schema browsing and query-planning tools so agents can see allowed tables, columns and costs before running anything.
      MIT