mcp-server

PostgreSQL MCP Server

Query and manage PostgreSQL databases through MCP. Enables AI agents to run SQL queries, inspect schemas, and manage database operations.

Install
npx -y @modelcontextprotocol/server-postgres postgresql://user:pass@localhost/db

Overview

The PostgreSQL MCP server connects AI agents to PostgreSQL databases, enabling natural language to SQL translation, schema inspection, query execution, and result analysis. It supports read-only mode for safe exploration and write mode for database management. Connection strings are passed securely at startup, not through the conversation context. Used extensively in data analysis, business intelligence, and application development workflows.

Features

  • -Execute SQL queries with parameterized inputs
  • -Schema inspection (tables, columns, indexes, constraints)
  • -Read-only mode for safe data exploration
  • -Query result formatting (table, JSON, CSV)
  • -Transaction support for write operations

Security Considerations

Always use read-only connections for exploration. Never pass database credentials through conversation content. The PostgreSQL server should use least-privilege database users. Watch for SQL injection through prompt injection -- an attacker can trick the agent into running DROP TABLE via a carefully crafted web page.

Scan for vulnerabilities: npx hackmyagent secure

Source

Related Tools