home / mcp / postgresql mcp server
A Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.
Configuration
View docs{
"mcpServers": {
"sembojatech-mcp-postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"
]
}
}
}You can use this MCP server to give large language models read-only access to PostgreSQL databases. It lets you inspect schemas and run safe read-only queries without modifying data, enabling informed, data-backed responses from your models.
You connect to the PostgreSQL MCP server through an MCP client and pick a configured server. Use the available tool to run read-only SQL queries and rely on the automatically discovered table schemas to understand database structure. When you execute a query, every operation runs inside a read-only transaction to protect data integrity.
Prerequisites you need before installing: a container runtime (Docker) or Node.js/npm if you prefer running the server through npm/npx, and access to your PostgreSQL database URL.
{
"mcpServers": {
"postgres_docker": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"
]
},
"postgres_npx": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}Notes and options described in the sources include different ways to run the MCP server. When using Docker on macOS and targeting a PostgreSQL server on the host, use host.docker.internal in the connection URL. You can also provide the database URL directly in MCP configurations.
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_url",
"description": "PostgreSQL URL (e.g. postgresql://user:[email protected]:5432/mydb)"
}
],
"servers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"${input:pg_url}"
]
}
}
}
}Execute read-only SQL queries against the connected PostgreSQL database within a READ ONLY transaction. Returns results without modifying data.