Skip to main content
Glama
seotarek

MCP Postgres Guard

by seotarek

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: PostgreSQL MCP Server

🛠️ 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.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to safely explore, analyze, and maintain PostgreSQL databases with read-only mode by default, SQL injection prevention, query performance analysis, and optional write operations.
    37 npm
    Apache 2.0
  • F
    license
    A
    quality
    D
    maintenance
    Enables AI agents to inspect and query PostgreSQL databases safely, with features like listing tables, retrieving schemas, and running read-only SQL queries.
    3
    -
  • F
    license
    Not graded
    quality
    F
    maintenance
    Provides a secure, schema-aware PostgreSQL database agent for LLMs, enabling natural language queries and validated SQL execution with strong security guardrails.
    18 npm
    5
    -
  • A
    license
    Not graded
    quality
    A
    maintenance
    SQL guardrails for AI agents, sitting between the agent and Postgres to enforce policies, block destructive queries, and audit all access.
    4
    MIT