Read-only PostgreSQL server for schema inspection and query execution optimized for LLM integrations
The PostgreSQL MCP (Model Context Protocol) server provides read-only access to PostgreSQL databases, enabling machine learning models like Claude Desktop to inspect database schemas and execute queries. This server standardizes how AI applications interact with data sources through the Model Context Protocol, making it easier for developers to build integrations without worrying about underlying database details.
The PostgreSQL MCP server offers several key features that make it a powerful tool for AI application integration:
query
tool allows executing read-only SQL queries against the connected database. Each query is executed within a READ ONLY transaction, ensuring data integrity.The architecture of the PostgreSQL MCP server is designed around the Model Context Protocol, which provides a structured way for AI applications to request and receive data. The protocol flow can be visualized using Mermaid diagrams:
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
graph TD
A[PostgreSQL Database] --> B[Table Schemas]
B --> C{JSON Schema}
C -->|Data| D[MCP Server API]
D --> E[MCP Client]
style A fill:#f3e5f5
style B fill:#e8f5e8
style C fill:#e1f5fe
style D fill:#e4eaff
style E fill:#f7efff
To run the PostgreSQL MCP server using Docker:
host.docker.internal
if you are running on the host network.{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"
]
}
}
}
Alternatively, you can use npx
to start the PostgreSQL MCP server:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}
Replace /mydb
with your actual database name.
The PostgreSQL MCP server supports multiple clients, including:
MCP Client | Resources | Tools | Prompts |
---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ |
Continue | ✅ | ✅ | ✅ |
Cursor | ❌ | ✅ | ❌ |
This compatibility matrix ensures that developers can choose the right tools for their AI application without worrying about MCP client support.
The PostgreSQL MCP server is designed to be highly performant and compatible with various environments. It supports the following configurations:
localhost
simplifies configuration.To configure security settings, you can add username and password directly to the PostgreSQL URL or use environment variables:
postgresql://user:[email protected]:5432/mydb
For production environments, it is recommended to use environment variables for security best practices.
Q: How do I configure MCP clients that are not listed in the compatibility matrix?
Q: Can the PostgreSQL MCP server handle large databases efficiently?
Q: How do I secure the connection to the PostgreSQL database using this MCP server?
Q: Is there a way to optimize query performance with the PostgreSQL MCP server?
Q: Can this POSTGReSQL MCP server be used with other types of databases?
Contributions are welcome! To contribute to the PostgreSQL MCP server:
git clone https://github.com/modelcontextprotocol/postgres-mcp-server.git
docs/development.md
file.For more information on the Model Context Protocol ecosystem and resources:
By leveraging the PostgreSQL MCP server, developers can easily integrate AI applications with PostgreSQL databases, ensuring robust and secure data access.
Learn to connect to MCP servers over HTTP with Python SDK using SSE for efficient protocol communication
Explore community contributions to MCP including clients, servers, and projects for seamless integration
Python MCP client for testing servers avoid message limits and customize with API key
SingleStore MCP Server for database querying schema description ER diagram generation SSL support and TypeScript safety
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
Powerful GitLab MCP Server enables AI integration for project management, issues, files, and collaboration automation