MCP PostgreSQL Server is an MCP server that enables AI models to interact with PostgreSQL databases through a standardized interface. Built for developers, data analysts, and software engineers, it connects Model Context Protocol clients directly to relational database instances. The server allows agents to inspect database structure by listing schemas, enumerating tables within specific schemas, and retrieving column definitions and table designs. Beyond schema inspection, it allows AI tools to perform parameterized read queries using SELECT statements, as well as write operations such as INSERT, UPDATE, and DELETE. It features prepared statement support to safeguard against SQL injection, accepting both standard PostgreSQL dollar placeholders and MySQL-style question mark placeholders. The server handles database connections through standard configuration variables, provides automatic connection cleanup, and offers validation and detailed error reporting for missing parameters and invalid queries during execution.
Category: Databases & Data Stores
Tags: database, postgresql, relational, SQL
mcpServers object using the following stdio definition: json { "mcpServers": { "postgres": { "type": "stdio", "command": "npx", "args": ["-y", "mcp-postgres-server"], "env": { "PG_HOST": "your_host", "PG_PORT": "5432", "PG_USER": "your_user", "PG_PASSWORD": "your_password", "PG_DATABASE": "your_database" } } } } 3. Replace the environment variable placeholders (PG_HOST, PG_PORT, PG_USER, PG_PASSWORD, PG_DATABASE) with your actual PostgreSQL database credentials. 4. Save the configuration file and restart your MCP client to initialize the server.Part of MCP Servers
You can install MCP PostgreSQL Server via npm using the command npm install mcp-postgres-server or run it directly using npx. To register it with an MCP client, add the npx execution configuration and database environment variables such as PG_HOST, PG_PORT, PG_USER, PG_PASSWORD, and PG_DATABASE into your client configuration file.
The server provides tools to connect to PostgreSQL databases, list schemas, list tables within schemas, describe table structures, and run parameterized queries. It supports SELECT operations via the query tool and handles data modifications including INSERT, UPDATE, and DELETE statements via the execute tool.
Yes, MCP PostgreSQL Server uses prepared statements for both read and write operations to protect against SQL injection. It supports parameter bindings using standard PostgreSQL numeric placeholders like $1 and $2, as well as MySQL-style question mark placeholders.
Yes, MCP PostgreSQL Server is an open-source project distributed under the MIT license. You can view its source code, contribute, and report issues through its repository on GitHub.