postgres-mcp-server
Provides tools for interacting with PostgreSQL databases, enabling schema discovery, table inspection, database, role, and permission listing, and running SQL queries (read-only by default, with optional write support).
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@postgres-mcp-serverwhat tables are in the public schema?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Postgres MCP Server
A Model Context Protocol (MCP) server for PostgreSQL databases. Connects AI assistants (Claude Desktop, Cursor, Antigravity, etc.) to a PostgreSQL database with schema discovery, catalog introspection, read-only analytical queries, and opt-in safe write operations.
Features
Schema Discovery: Inspect schemas, tables, views, column data types, primary keys, and uniqueness constraints (
list_tables,describe_table).Catalog & Governance Discovery: Discover visible databases, roles with attributes and memberships, and permissions across schemas, tables, and columns (
list_databases,list_roles,list_permissions).Bounded Read Queries: Run parameterized SQL queries with pagination (
limit,offset), strict maximum row limits, and automatic truncation detection (run_query).Gated Safe Writes: Write operations (
run_write_queryfor INSERT, UPDATE, DELETE, DDL) are disabled by default and require explicitALLOW_WRITE=1configuration.Security & Privacy First: Zero credential leakage. Connection strings, passwords, and internal stack traces are redacted from logs and tool responses. Parameterized SQL prevents SQL injection.
Stdio Transport: Seamlessly runs over stdio conforming to standard MCP protocol clients.
Related MCP server: PostgreSQL MCP Server
Quick Start
Running via NPX
# Set your connection string
export DATABASE_URL="postgres://user:password@localhost:5432/mydb"
# Optional: enable write mode
# export ALLOW_WRITE=1
# Start the server
npx @allensandiego/postgres-mcp-serverLocal Development
# Clone and install dependencies
git clone https://github.com/your-org/postgres-mcp-server.git
cd postgres-mcp-server
npm install
# Build
npm run build
# Run with tsx in development
npm run devConfiguration
Configure the server using environment variables:
Variable | Description | Default |
| Full PostgreSQL connection URI ( | None |
| Database host name |
|
| Database port number |
|
| Database name |
|
| Database user name |
|
| Database password | None |
| SSL configuration mode ( | Disabled |
| Enables write queries ( |
|
| Maximum rows returned per query |
|
| Per-query timeout in milliseconds |
|
| Maximum active database connections in pool |
|
MCP Tools Reference
1. list_tables
Discover all user schemas and their tables/views and columns without writing SQL.
Arguments:
schema(optional string): Filter tables by schema name (e.g."public").
Output: Array of
{ schema, name, type, columns: [{ name, dataType, nullable, isPrimaryKey, isUnique }] }.
2. describe_table
Retrieve detailed column specifications and primary key definitions for a table.
Arguments:
schema(required string): Schema name (e.g."public").table(required string): Table name (e.g."users").
Output:
{ schema, table, columns: [...], primaryKey?: string }.
3. list_databases
Discover databases visible and connectable to the connected user.
Arguments: None.
Output: Array of
{ name, owner, encoding, isTemplate, connectable }.
4. list_roles
Discover roles/users, their administrative attributes, and group memberships.
Arguments: None.
Output: Array of
{ name, superuser, canLogin, canCreateDb, canCreateRole, canBypassRls, memberOf, members }.
5. list_permissions
Discover granted privileges across schemas, tables, and columns.
Arguments:
objectType(optional string):"schema","table", or"column".schema(optional string): Schema name filter.table(optional string): Table name filter.
Output: Array of
{ grantor, grantee, objectType, objectName, privilege, grantable }.
6. run_query
Execute a read-only parameterized SELECT query.
Arguments:
sql(required string): Parameterized SQL statement (e.g."SELECT * FROM orders WHERE status = $1").params(optional array): Parameter substitution values.limit(optional integer): Page limit (capped atMAX_ROW_LIMIT).offset(optional integer): Page offset for pagination.
Output:
{ columns, rows, rowCount, truncated }.
7. run_write_query
Execute modifying SQL statements (INSERT, UPDATE, DELETE, DDL). Only active when ALLOW_WRITE=1.
Arguments:
sql(required string): SQL write statement.params(optional array): Parameter values.
Output:
{ rowCount }.
MCP Client Setup Examples
Claude Desktop Configuration (claude_desktop_config.json)
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["@allensandiego/postgres-mcp-server"],
"env": {
"DATABASE_URL": "postgres://username:password@localhost:5432/mydb",
"ALLOW_WRITE": "0"
}
}
}
}Antigravity / Cursor Configuration
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["@allensandiego/postgres-mcp-server"],
"env": {
"DATABASE_URL": "postgres://username:password@localhost:5432/mydb"
}
}
}
}Testing & Quality Gates
Run the automated test suite (unit + contract + integration tests):
npm testType checking:
npm run typecheckLinting:
npm run lintLicense
This project is licensed under the PolyForm Noncommercial License 1.0.0 - free for personal, educational, research, and non-commercial open-source use. Commercial use requires a commercial license.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Flicense-qualityDmaintenanceAn MCP server that enables AI assistants to interact with PostgreSQL databases by executing SQL queries and inspecting database schemas. It provides tools for standardized database exploration and management through the Model Context Protocol.
- Alicense-qualityDmaintenanceAn open-source MCP server for PostgreSQL schema introspection and guarded read-only queries. It enables MCP clients to discover schemas, tables, columns, indexes, relationships, and safe queryable data from a configured PostgreSQL database.13MIT
- Alicense-qualityDmaintenanceMCP server for PostgreSQL that enables Cursor and other MCP clients to execute SQL queries, list tables, and explore database schemas via HTTP.505MIT
- Alicense-qualityDmaintenanceA read-only MCP server for PostgreSQL that enables safe database introspection and querying via natural language.764MIT
Related MCP Connectors
MCP server for managing Prisma Postgres.
MCP server for interacting with the Supabase platform
GibsonAI MCP server: manage your databases with natural language
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/allensandiego/postgres-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server