Skip to main content
Glama
ferronicardoso

mcp-postgresql

MCP Server for PostgreSQL

Docker Publish GHCR Node.js

面向生产环境的 MCP 服务器 for PostgreSQL,将数据库操作暴露给 MCP 客户端(Claude Desktop、VS Code Copilot、Cursor 和兼容的主机)。

功能

  • 查询执行(SELECTINSERTUPDATEDELETE

  • 数据库发现与模式自省

  • 表元数据检查(列、类型、可空性、默认值、主键)

  • 索引与外键发现

  • 环境驱动配置,确保安全部署

Related MCP server: Azure Database for PostgreSQL MCP Server

可用工具

工具

描述

execute_query

执行 SQL 语句并返回行数或受影响的行数

list_tables

INFORMATION_SCHEMA.TABLES 列出表(可选的模式过滤器)

describe_table

返回表列元数据及主键标记

list_databases

列出所有 PostgreSQL 数据库

get_table_indexes

列出表索引,包含定义及主键/唯一标志

get_foreign_keys

列出表外键及引用的目标

要求

  • Node.js 18 及以上

  • 能够访问 PostgreSQL 实例

  • MCP 主机到 PostgreSQL 的网络连接(host:port)

配置

使用环境变量设置连接参数:

变量

必填

默认值

描述

PGHOST(或 POSTGRES_HOST

localhost

PostgreSQL 主机或 IP

PGPORT(或 POSTGRES_PORT

5432

PostgreSQL TCP 端口

PGDATABASE(或 POSTGRES_DB

postgres

默认数据库

PGUSER(或 POSTGRES_USER

数据库用户

PGPASSWORD(或 POSTGRES_PASSWORD

数据库密码

PGSSL(或 POSTGRES_SSL

false

启用 SSL/TLS

PGPOOL_MAX

10

最大连接池连接数

PGPOOL_IDLE_TIMEOUT_MS

30000

连接池空闲超时(毫秒)

MCP_TRANSPORT

stdio

传输模式:stdio(默认,用于 npx/Claude Desktop/VS Code)或 http(Streamable HTTP,用于 Docker/远程客户端如 n8n)

MCP_HTTP_PORT

3002

HTTP 服务器端口(仅当 MCP_TRANSPORT=http 时使用)

MCP_HTTP_HOST

0.0.0.0

HTTP 服务器绑定地址(仅当 MCP_TRANSPORT=http 时使用)

使用方法

直接从 GitHub 运行

npx github:ferronicardoso/mcp-postgresql

Claude Code (CLI)

claude mcp add postgresql --scope user -- npx -y github:ferronicardoso/mcp-postgresql

--scope 控制服务器注册的存储位置:

作用域

存储位置

可见范围

local(默认)

项目本地,未跟踪

仅你自己,仅在此项目中

project

项目根目录下的 .mcp.json

任何克隆该仓库的人(提交以共享)

user

你的全局 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-postgresql

PowerShell:

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-postgresql

Codex 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-postgresql

PowerShell:

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:latest

PowerShell:

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 钩子来:

  1. 构建 TypeScript(npm run build

  2. 暂存生成的工件(git add dist

手动回退:

npm run build
git add dist

安全注意事项

  • 切勿提交真实凭据或 .env 文件。

  • 生产环境优先使用最小权限数据库用户。

  • 对于公共或不受信任的网络,启用加密(PGSSL=true)并适当配置证书。

许可证

MIT © Raphael Augusto Ferroni Cardoso

Install Server
A
license - permissive license
A
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

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

  • A
    license
    Not graded
    quality
    C
    maintenance
    An 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.
    22
    2
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A 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
  • A
    license
    Not graded
    quality
    C
    maintenance
    A production-ready MCP server for PostgreSQL — built for Claude Desktop, Claude Code, and any MCP-compatible AI agent.
    Apache 2.0
  • A
    license
    Not graded
    quality
    C
    maintenance
    A 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.
    22
    1
    ISC

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

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