postgresql-mcp
A general-purpose PostgreSQL MCP server with full read-write SQL access, atomic multi-statement transactions, and schema inspection. Works with any PostgreSQL instance — local, Supabase, AWS RDS, or self-hosted — and connects to Claude, Cursor, Windsurf, or any MCP-compatible AI client.
README
postgresql-mcp
<a href="https://glama.ai/mcp/servers/sarmadparvez/postgresql-mcp"> <img width="380" height="200" src="https://glama.ai/mcp/servers/sarmadparvez/postgresql-mcp/badge" /> </a>
A Model Context Protocol (MCP) server for PostgreSQL with full read-write support, atomic transactions, and schema inspection. Works with Claude Desktop, Cursor, Windsurf, and any MCP-compatible AI client.
Connect any PostgreSQL database — local, Supabase, AWS RDS, or self-hosted — to your AI assistant in seconds.
Features
- Full read-write SQL access (
SELECT,INSERT,UPDATE,DELETE,CREATE,DROP) - Atomic multi-statement transactions with automatic rollback on failure
- Schema inspection: columns, types, nullability, defaults, primary keys
- Optional read-only mode via
?mode=readonly - No cloud lock-in — works with any standard PostgreSQL connection string
- Single file, minimal dependencies
Why this exists
There are two other PostgreSQL MCP servers worth knowing about, and neither fully covers the general-purpose use case:
Anthropic's official @modelcontextprotocol/server-postgres is strictly read-only — it exposes only a single query tool that runs inside a READ ONLY transaction. No writes, no DDL, no transactions. It was also deprecated and archived in July 2025.
Microsoft's azure-postgresql-mcp does support writes and DDL, but it is built specifically for Azure Database for PostgreSQL Flexible Server. While it technically accepts standard PG* environment variables (so a local connection may work), local use is untested and unsupported. Several tools require Microsoft Entra authentication and Azure-specific APIs that won't function outside Azure. It also pulls in Azure SDK dependencies you don't need for a non-Azure setup. It is currently in Preview.
This server is the alternative for everything else: local PostgreSQL, self-hosted, Supabase, RDS, or any standard PostgreSQL instance. It is a single dependency-light file with no cloud lock-in, full read-write support, atomic multi-statement transactions, and an optional ?mode=readonly flag when you want to restrict access.
Requirements
- Node.js 18+
- A running PostgreSQL database
Installation
npm install -g @sarmadparvez/postgresql-mcp
Or run directly without installing (requires npm 7+ / Node.js 18+):
npx @sarmadparvez/postgresql-mcp <postgresql-connection-string>
Usage
postgresql-mcp <postgresql-connection-string>
Examples:
# Read-write access
postgresql-mcp postgresql://user:pass@localhost:5432/mydb
# Read-only mode (disables execute and transaction tools)
postgresql-mcp postgresql://user:pass@localhost:5432/mydb?mode=readonly
Or with npx (requires npm 7+ / Node.js 18+):
npx @sarmadparvez/postgresql-mcp postgresql://user:pass@localhost:5432/mydb
npx @sarmadparvez/postgresql-mcp postgresql://user:pass@localhost:5432/mydb?mode=readonly
Tools
| Tool | Available in | Description |
|---|---|---|
query |
Always | Execute a read-only SELECT query. Runs inside a READ ONLY transaction. Returns rows as JSON. |
execute |
Read-write mode | Execute a write SQL statement (INSERT, UPDATE, DELETE, CREATE, DROP, etc.). Returns rows affected. |
schema |
Always | List columns, types, nullability, defaults, and primary keys for tables in a given schema. Optionally filter to a specific table. |
list_tables |
Always | List all base tables in a schema with their disk size. |
transaction |
Read-write mode | Execute multiple SQL statements atomically. Rolls back all statements if any one fails. |
Read-Only Mode
Append ?mode=readonly to the connection string to start the server in read-only mode. This disables the execute and transaction tools, leaving only query, schema, and list_tables.
Claude Desktop Configuration
First, install the package globally:
npm install -g @sarmadparvez/postgresql-mcp
Then find the paths to node and the installed script:
which node
# e.g. /usr/local/bin/node
# nvm users: /Users/yourname/.nvm/versions/node/v22.12.0/bin/node
npm root -g
# e.g. /usr/local/lib/node_modules
# nvm users: /Users/yourname/.nvm/versions/node/v22.12.0/lib/node_modules
Add this to your claude_desktop_config.json:
- Replace
commandwith the output ofwhich node - Replace the prefix of the script path with the output of
npm root -g— the suffix/@sarmadparvez/postgresql-mcp/index.jsstays the same
{
"mcpServers": {
"postgres": {
"command": "/usr/local/bin/node",
"args": [
"/usr/local/lib/node_modules/@sarmadparvez/postgresql-mcp/index.js",
"postgresql://user:pass@localhost:5432/mydb"
]
}
}
}
For read-only access, append ?mode=readonly to the connection string:
{
"mcpServers": {
"postgres-readonly": {
"command": "/usr/local/bin/node",
"args": [
"/usr/local/lib/node_modules/@sarmadparvez/postgresql-mcp/index.js",
"postgresql://user:pass@localhost:5432/mydb?mode=readonly"
]
}
}
}
Compatible AI Clients
This MCP server works with any client that supports the Model Context Protocol:
- Claude Desktop (Anthropic)
- Cursor
- Windsurf
- Any other MCP-compatible client
Dependencies
@modelcontextprotocol/sdk— MCP server frameworkpg— PostgreSQL clientzod— Schema validation for tool inputs
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。