Integrations
Allows interaction with PostgreSQL databases, providing tools for listing schemas, tables, describing table structures, querying relationships, and executing SQL queries.
PostgreSQL MCP Server
A PostgreSQL MCP server implementation using the Model Context Protocol (MCP) Python SDK- an open protocol that enables seamless integration between LLM applications and external data sources. This server allows AI agents to interact with PostgreSQL databases through a standardized interface.
Features
- List database schemas
- List tables within schemas
- Describe table structures
- List table constraints and relationships
- Get foreign key information
- Execute SQL queries
Quick Start
Installation
Installing via Smithery
To install PostgreSQL MCP Server for Claude Desktop automatically via Smithery:
Manual Installation
- Clone this repository:
- Create and activate a virtual environment (recommended):
- Install dependencies:
Usage
- Start the MCP server.Copy
- The server provides the following tools:
query
: Execute SQL queries against the databaselist_schemas
: List all available schemaslist_tables
: List all tables in a specific schemadescribe_table
: Get detailed information about a table's structureget_foreign_keys
: Get foreign key relationships for a tablefind_relationships
: Discover both explicit and implied relationships for a table
Running with Docker
Build the image:
Run the container without a database connection (the server stays inspectable):
Run with a live PostgreSQL database by supplying POSTGRES_CONNECTION_STRING
:
If the environment variable is omitted, the server boots normally and all database‑backed tools return a friendly “connection string is not set” message until you provide it.
Configuration with mcp.json
To integrate this server with MCP-compatible tools (like Cursor), add it to your ~/.cursor/mcp.json
:
If POSTGRES_CONNECTION_STRING
is omitted, the server still starts and is fully inspectable; database‑backed tools will simply return an informative error until the variable is provided.
Replace:
/path/to/venv
with your virtual environment path/path/to/postgres_server.py
with the absolute path to the server script
Security
- Never expose sensitive database credentials in your code
- Use environment variables or secure configuration files for database connection strings
- Consider using connection pooling for better resource management
- Implement proper access controls and user authentication
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Related Projects
License
MIT License
Copyright (c) 2025 gldc
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables AI agents to interact with PostgreSQL databases through the Model Context Protocol, providing database schema exploration, table structure inspection, and SQL query execution capabilities.
Related MCP Servers
- AsecurityAlicenseAqualityAllows AI assistants to list tables, read data, and execute SQL queries through a controlled interface, making database exploration and analysis safer and more structured.Last updated -1360PythonMIT License
- -securityFlicense-qualityA server that allows AI models to interact with PostgreSQL databases through a standardized protocol, providing database schema information and SQL query execution capabilities.Last updated -JavaScript
- -securityAlicense-qualityA Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.Last updated -619TypeScriptAGPL 3.0
- AsecurityAlicenseAqualityEnables AI models to interact with PostgreSQL databases through a standardized interface, supporting operations like queries, table manipulation, and schema inspection.Last updated -51272JavaScriptMIT License