mcp-postgresql
MCP Server for PostgreSQL
面向生产环境的 MCP 服务器 for PostgreSQL,将数据库操作暴露给 MCP 客户端(Claude Desktop、VS Code Copilot、Cursor 和兼容的主机)。
功能
查询执行(
SELECT、INSERT、UPDATE、DELETE)数据库发现与模式自省
表元数据检查(列、类型、可空性、默认值、主键)
索引与外键发现
环境驱动配置,确保安全部署
Related MCP server: Azure Database for PostgreSQL MCP Server
可用工具
工具 | 描述 |
| 执行 SQL 语句并返回行数或受影响的行数 |
| 从 |
| 返回表列元数据及主键标记 |
| 列出所有 PostgreSQL 数据库 |
| 列出表索引,包含定义及主键/唯一标志 |
| 列出表外键及引用的目标 |
要求
Node.js 18 及以上
能够访问 PostgreSQL 实例
MCP 主机到 PostgreSQL 的网络连接(host:port)
配置
使用环境变量设置连接参数:
变量 | 必填 | 默认值 | 描述 |
| 否 |
| PostgreSQL 主机或 IP |
| 否 |
| PostgreSQL TCP 端口 |
| 否 |
| 默认数据库 |
| 是 | — | 数据库用户 |
| 是 | — | 数据库密码 |
| 否 |
| 启用 SSL/TLS |
| 否 |
| 最大连接池连接数 |
| 否 |
| 连接池空闲超时(毫秒) |
| 否 |
| 传输模式: |
| 否 |
| HTTP 服务器端口(仅当 |
| 否 |
| HTTP 服务器绑定地址(仅当 |
使用方法
直接从 GitHub 运行
npx github:ferronicardoso/mcp-postgresqlClaude Code (CLI)
claude mcp add postgresql --scope user -- npx -y github:ferronicardoso/mcp-postgresql--scope 控制服务器注册的存储位置:
作用域 | 存储位置 | 可见范围 |
| 项目本地,未跟踪 | 仅你自己,仅在此项目中 |
| 项目根目录下的 | 任何克隆该仓库的人(提交以共享) |
| 你的全局 Claude Code 配置 | 你,跨所有项目 |
环境变量可以通过在 -- 前重复 --env KEY=VALUE 标志传递,例如:
Bash(Linux/macOS/WSL):
claude mcp add postgresql --scope user \
--env PGHOST=localhost \
--env PGPORT=5432 \
--env PGDATABASE=postgres \
--env PGUSER=postgres \
--env PGPASSWORD=your-password \
-- npx -y github:ferronicardoso/mcp-postgresqlPowerShell:
claude mcp add postgresql --scope user `
--env PGHOST=localhost `
--env PGPORT=5432 `
--env PGDATABASE=postgres `
--env PGUSER=postgres `
--env PGPASSWORD=your-password `
-- npx -y github:ferronicardoso/mcp-postgresqlCodex CLI
Bash(Linux/macOS/WSL):
codex mcp add postgresql \
--env PGHOST=localhost \
--env PGPORT=5432 \
--env PGDATABASE=postgres \
--env PGUSER=postgres \
--env PGPASSWORD=your-password \
npx -- -y github:ferronicardoso/mcp-postgresqlPowerShell:
codex mcp add postgresql `
--env PGHOST=localhost `
--env PGPORT=5432 `
--env PGDATABASE=postgres `
--env PGUSER=postgres `
--env PGPASSWORD=your-password `
npx -- -y github:ferronicardoso/mcp-postgresql这将注册服务器到 ~/.codex/config.toml。要移除,运行 codex mcp remove postgresql。
Claude Desktop 配置
%APPDATA%\\Claude\\claude_desktop_config.json:
{
"mcpServers": {
"postgresql": {
"command": "npx",
"args": ["github:ferronicardoso/mcp-postgresql"],
"env": {
"PGHOST": "localhost",
"PGPORT": "5432",
"PGDATABASE": "postgres",
"PGUSER": "postgres",
"PGPASSWORD": "your-password"
}
}
}
}VS Code MCP 配置
.vscode/mcp.json:
{
"servers": {
"postgresql": {
"command": "npx",
"args": ["github:ferronicardoso/mcp-postgresql"],
"env": {
"PGHOST": "localhost",
"PGPORT": "5432",
"PGDATABASE": "postgres",
"PGUSER": "postgres",
"PGPASSWORD": "your-password"
}
}
}
}使用 Docker 运行(HTTP 传输)
发布的镜像默认以 Streamable HTTP 模式运行,用作远程 MCP 端点(例如从 n8n 的 MCP 客户端工具节点或任何兼容 Streamable HTTP 的客户端):
Bash(Linux/macOS/WSL):
docker run -d --name mcp-postgresql \
-p 3002:3002 \
-e PGHOST=host.docker.internal \
-e PGPORT=5432 \
-e PGDATABASE=postgres \
-e PGUSER=postgres \
-e PGPASSWORD=your-password \
ghcr.io/ferronicardoso/mcp-postgresql:latestPowerShell:
docker run -d --name mcp-postgresql `
-p 3002:3002 `
-e PGHOST=host.docker.internal `
-e PGPORT=5432 `
-e PGDATABASE=postgres `
-e PGUSER=postgres `
-e PGPASSWORD=your-password `
ghcr.io/ferronicardoso/mcp-postgresql:latest然后 MCP 端点可通过 http://localhost:3002/mcp 访问。
本地开发
git clone https://github.com/ferronicardoso/mcp-postgresql
cd mcp-postgresql
npm install
npm run build启动编译后的服务器:
npm start构建与提交工作流
本仓库有意跟踪 dist/ 以支持 npx github:user/repo 的使用。
项目使用 Husky 的 pre-commit 钩子来:
构建 TypeScript(
npm run build)暂存生成的工件(
git add dist)
手动回退:
npm run build
git add dist安全注意事项
切勿提交真实凭据或
.env文件。生产环境优先使用最小权限数据库用户。
对于公共或不受信任的网络,启用加密(
PGSSL=true)并适当配置证书。
许可证
MIT © Raphael Augusto Ferroni Cardoso
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
- AlicenseNot gradedqualityCmaintenanceAn extensible MCP server for database operations that supports PostgreSQL for managing schemas, tables, data, and user permissions. It features automatic migration recording for DDL changes and integrates with various AI-powered editors like Cursor, Zed, and Claude Code.222MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) Server that allows AI models to securely interact with data hosted in Azure Database for PostgreSQL. It enables natural language querying, schema exploration, and data management through MCP clients like Claude Desktop and Visual Studio Code.MIT
- AlicenseNot gradedqualityCmaintenanceA production-ready MCP server for PostgreSQL — built for Claude Desktop, Claude Code, and any MCP-compatible AI agent.Apache 2.0
- AlicenseNot gradedqualityCmaintenanceA Model Context Protocol (MCP) server that provides secure database access to PostgreSQL through Kysely ORM, enabling Claude Desktop to interact with PostgreSQL databases using natural language.221ISC
Related MCP Connectors
MCP server for managing Prisma Postgres.
MCP server for interacting with the Supabase platform
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
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/ferronicardoso/mcp-postgresql'
If you have feedback or need assistance with the MCP directory API, please join our Discord server