Back to Home
avantifellows icon

mcp-postgres

Verified Safe

by avantifellows

Overview

Provides a read-only Model Context Protocol (MCP) server for AI tools (like Claude Code, Cursor) to query a PostgreSQL database directly.

Installation

Run Command
avanti-mcp-postgres

Environment Variables

  • AF_DB_HOST
  • AF_DB_PORT
  • AF_DB_USER
  • AF_DB_PASSWORD
  • AF_DB_NAME

Security Notes

The server implements robust read-only enforcement through the `is_read_only` function, which explicitly checks for and blocks all common write/destructive SQL keywords (INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE, CREATE, GRANT, REVOKE). This check is applied to all `query` calls and even to the `WHERE` clause in `count_rows`. Database credentials are loaded securely from environment variables, preventing hardcoding. Table and schema names in `sample_data` and `count_rows` are dynamically inserted with identifier quoting to mitigate SQL injection risk, though direct parameterization of identifiers isn't standard in `asyncpg`. No `eval` or similar dangerous dynamic code execution is present. Queries are logged locally.

Similar Servers

Stats

Interest Score55
Security Score9
Cost ClassMedium
Avg Tokens500
Stars1
Forks0
Last Update2025-12-11

Tags

MCPPostgreSQLDatabaseAI ToolsRead-only