mcp-postgres
MCP PostgreSQL Server
claude mcp add --transport stdio antonorlov-mcp-postgres-server npx -y mcp-postgres-server \ --env PG_HOST="your_host" \ --env PG_PORT="5432" \ --env PG_USER="your_user" \ --env PG_DATABASE="your_database" \ --env PG_PASSWORD="your_password"
How to use
This MCP server provides a PostgreSQL interface through a standardized Model Context Protocol (MCP) API. It exposes tools to connect to a PostgreSQL database, run queries, and manage schema and table information. Use it to securely connect, execute prepared statements, and retrieve results in a structured format. The available tools include: connect_db to establish a database connection with credentials, query to run SELECT statements with optional parameters, execute to perform INSERT/UPDATE/DELETE operations with prepared statements, list_schemas to list all schemas, list_tables to list tables in a schema, and describe_table to get the structure of a specific table. These tools are designed to support both PostgreSQL-style placeholders ($1, $2) and MySQL-style (?) placeholders, with automatic handling of parameter binding. You can mix and match tools to construct complex workflows, such as connecting to a database, listing available tables, describing a table, and then executing parameterized updates or queries as part of an automated process.
How to install
Prerequisites:
- Node.js and npm installed on your system
- Access to install npm packages
Installation steps:
-
Install the MCP PostgreSQL server package locally: npm install mcp-postgres-server
-
OR run directly with npx (no local install required): npx mcp-postgres-server
-
Configure the MCP server by setting the required environment variables as shown in the configuration example. These variables provide the connection details to your PostgreSQL database.
-
If you are using MCP in another orchestration, ensure the mcp_config format is loaded by your MCP runner, providing the postgres server entry with the proper environment values.
Additional notes
Tips and considerations:
- Ensure PG_HOST, PG_PORT, PG_USER, PG_PASSWORD, and PG_DATABASE are correctly set to connect to your PostgreSQL instance.
- The server supports prepared statements to mitigate SQL injection risks; use the query and execute tools with the params array for safe parameter binding.
- Placeholders can be PostgreSQL-style ($1, $2) or MySQL-style (?); the tool will adapt accordingly.
- Connections are automatically managed and cleaned up after operations to prevent leaks.
- If you encounter connection errors, verify network access to the PostgreSQL host and confirm that the database user has appropriate privileges.
- For security, avoid embedding plaintext credentials in logs; rely on environment variables and secure secret management when deploying.
- The server supports multiple schemas and provides list_schemas, list_tables, and describe_table to explore database metadata before performing data operations.
Related MCP Servers
zen
Selfhosted notes app. Single golang binary, notes stored as markdown within SQLite, full-text search, very low resource usage
MCP -Deepseek_R1
A Model Context Protocol (MCP) server implementation connecting Claude Desktop with DeepSeek's language models (R1/V3)
mcp-fhir
A Model Context Protocol implementation for FHIR
mcp
Inkdrop Model Context Protocol Server
mcp-appium-gestures
This is a Model Context Protocol (MCP) server providing resources and tools for Appium mobile gestures using Actions API..
dubco -npm
The (Unofficial) dubco-mcp-server enables AI assistants to manage Dub.co short links via the Model Context Protocol. It provides three MCP tools: create_link for generating new short URLs, update_link for modifying existing links, and delete_link for removing short links.