postgresdb-mcp
Provides tools for querying, listing tables, describing table structures, listing schemas, and listing configured environments for PostgreSQL databases. Supports multiple environments with write protection and schema scoping.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
postgresdb-mcp
A Model Context Protocol (MCP) server for inspecting and querying multiple PostgreSQL environments over stdio, with writes disabled by default.
Quick start
Install and start the server with one command (Node.js 22.12 or later):
npx --yes @nayzo/postgresdb-mcp --env /absolute/path/to/postgres.envCreate the configuration file first (see below). The server speaks MCP over stdin/stdout; use one of the client configurations below rather than typing SQL into its terminal. For reproducible deployments, pin the npm package version in the command.
Related MCP server: PostgreSQL MCP Server
Tools
Tool | Arguments | Result |
| none | Environment names, schema scope, TLS status, and write policy. |
|
| Visible user schemas and their relation counts. |
|
| Visible tables and views with column counts. |
|
| Column types, nullability, and defaults. |
|
|
|
For metadata tools, the default schema is the first configured schema, or public if no scope is set. To address a mixed-case identifier, include double quotes in the value as you would in SQL. query accepts scalar parameters (string, finite number, boolean, or null), e.g. {"env":"local","sql":"SELECT id FROM public.items WHERE id = $1","params":[42]}.
Client setup
Replace /absolute/path/to/postgres.env with the path to your configuration file. Keep credentials out of client settings.
Claude Code
claude mcp add --transport stdio postgresdb -- npx --yes @nayzo/postgresdb-mcp --env /absolute/path/to/postgres.envClaude Desktop
Add this entry to claude_desktop_config.json, then restart Claude Desktop:
{
"mcpServers": {
"postgresdb": {
"command": "npx",
"args": ["--yes", "@nayzo/postgresdb-mcp", "--env", "/absolute/path/to/postgres.env"]
}
}
}Cursor
Add this to .cursor/mcp.json in your project, or ~/.cursor/mcp.json for all projects:
{
"mcpServers": {
"postgresdb": {
"command": "npx",
"args": ["--yes", "@nayzo/postgresdb-mcp", "--env", "/absolute/path/to/postgres.env"]
}
}
}OpenCode
Add this to opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"postgresdb": {
"type": "local",
"command": ["npx", "--yes", "@nayzo/postgresdb-mcp", "--env", "/absolute/path/to/postgres.env"],
"enabled": true
}
}
}Configuration
Use a private dotenv file outside shared workspaces and restrict its file permissions. With --env, only the named file is loaded. Without it, the server tries .env in the current working directory and falls back to process variables only if the file does not exist. Use .env.dist as a starting point.
POSTGRES_LOCAL_HOST=127.0.0.1
POSTGRES_LOCAL_DATABASE=example
POSTGRES_LOCAL_USER=example_reader
POSTGRES_LOCAL_PASSWORD=replace-me
POSTGRES_LOCAL_SCHEMA=public
POSTGRES_LOCAL_ALLOW_WRITES=falseEach POSTGRES_<ENV>_HOST defines an environment, where <ENV> contains 1 to 32 uppercase ASCII letters or digits. Use the lowercase label in tool calls, such as local. Avoid putting private information in these labels or in exposed schemas.
Suffix | Default | Meaning |
| Required | PostgreSQL hostname or local socket directory. |
|
| PostgreSQL port ( |
| Required | Database name. |
| Required | Dedicated database role. |
| Required | Role password. |
| Unset | Up to 32 comma-separated schema identifiers. Unquoted names are folded to lowercase; double-quoted names are case-sensitive. An empty list is invalid. |
|
| Set to |
|
| Verify the server certificate when TLS is enabled. Keep enabled for remote connections. |
|
|
|
|
| Server-side PostgreSQL statement timeout ( |
|
| Maximum rows per result ( |
In dotenv files, wrap a schema list containing double-quoted identifiers in single quotes, for example POSTGRES_LOCAL_SCHEMA='public,"MixedCase"'.
Security and limits
Write protection: the PostgreSQL parser must recognize exactly one allowed statement. Reads always use
BEGIN READ ONLY, including on writable environments and when confirmation is supplied.INSERT,UPDATE,DELETE,MERGE, data-modifying CTEs, and row locks require both write gates. TheWRITEargument is a tool-level control, not proof of human approval; use your client's approval controls for write access.Supported SQL:
SELECT(includingWITH,VALUES, andTABLE), selectedSHOWsettings, and non-executingEXPLAINfor reads. SQL batches, session or transaction commands, DDL,COPY,DO,SELECT INTO, andEXPLAIN ANALYZEare unsupported, even with confirmation. Direct function calls are limited to selected PostgreSQL built-ins, such ascount,sum,lower, andgenerate_series. Usepg_catalog.<name>if an unqualified call is ambiguous.Schema scope: the server filters metadata, checks syntactic schema references, and uses a transaction-local search path with
pg_catalogfirst. System catalog lookups remain available subject to PostgreSQL grants. This is an additional safeguard, not a database permission boundary. Views, triggers, operators, casts, extensions, and functions can access objects indirectly and may have effects outside normal table writes.Database roles: use a read replica or dedicated PostgreSQL role with minimal grants. For isolated schemas, limit
USAGEand object privileges in PostgreSQL and reviewPUBLICgrants, including schema creation,TEMP, and function execution. Avoid using an owner, superuser, or role with elevated privileges. Separate read and write roles and keep production writes disabled unless necessary.Sensitive data: connection settings are not included in tool metadata, raw errors, or logs. Tool outputs still contain database data the role can see. Keep secrets out of queryable tables, view definitions, and column defaults, and review access to catalog data and extensions before granting access. Do not put secrets in SQL text or argument names.
Resource limits: each environment has its own pool of up to five connections. Query results are fetched in batches, with caps on returned rows and serialized row data.
truncatedmeans additional rows or row data were omitted. For reads,rowCountis the number of returned rows; for confirmed writes it is PostgreSQL's command count, which can exceed the output cap. Large individual PostgreSQL values can still be expensive to receive. Use explicit limits and narrow SELECT lists for large datasets. If a write fails during a network interruption, verify its outcome before retrying.
Development
Use a current Node.js 22 or 24 release (ESLint requires Node.js 22.13 or later in the 22.x line):
npm ci
npm run lint
npm run build
npm test
npm audit --omit=devTests use the Node.js test runner and the official MCP client. Set TEST_DATABASE_URL or all five of PGHOST, PGPORT, PGUSER, PGPASSWORD, and PGDATABASE to run the stdio integration suite against a disposable PostgreSQL database. If all five variables and the URL are set, the variables take precedence. The test role needs permission to create schemas in that database; the suite creates and removes its own fixtures. Without database configuration, the suite skips cleanly. CI runs against PostgreSQL 17 on Node.js 22 and 24.
The tagged release job uses npm Trusted Publishing. Configure nayzo/postgresdb-mcp, workflow ci.yml, and the GitHub environment npm as the package's trusted publisher. The tag must match package.json, and versions already present on npm are skipped. If the package does not yet exist and npm does not allow a publisher to be configured for it, establish the package and its trusted publisher before using the tag workflow.
License
MIT, by Ala Eddine Khefifi.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Related MCP Servers
- AlicenseNot gradedqualityNot gradedmaintenanceProvides AI assistants with safe, controlled access to PostgreSQL databases with read-only defaults, granular permissions, query safety features, and schema introspection capabilities.1-
- FlicenseAqualityDmaintenanceEnables AI agents to inspect and query PostgreSQL databases safely, with features like listing tables, retrieving schemas, and running read-only SQL queries.3-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases through natural language queries, schema inspection, and safe SQL execution.1ISC
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.2ISC