npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@easy-mcps/postgresql-mcp-server

v2.0.7

Published

PostgreSQL MCP Server - 统一权限控制

Readme

PostgreSQL MCP Server

PostgreSQL 数据库的 MCP 服务器实现,支持统一的权限控制。

功能特性

  • ✅ 4 个工具:read_query, write_query, delete_query, ddl_query
  • ✅ 统一权限控制:通过 MCP_PERMISSIONS 配置
  • ✅ SQL 类型验证:每个工具只能执行对应类型的 SQL
  • ✅ 事务保护:只读操作使用 READ ONLY 事务

权限配置

通过环境变量 MCP_PERMISSIONS 配置权限,支持两种格式:

# JSON 数组格式
MCP_PERMISSIONS='["read","write"]'

# 逗号分隔格式
MCP_PERMISSIONS='read,write'

| 权限 | 默认值 | 说明 | |------|--------|------| | read | ✅ 开启 | SELECT 查询 | | write | ❌ 关闭 | INSERT/UPDATE 操作 | | delete | ❌ 关闭 | DELETE 操作(危险) | | ddl | ❌ 关闭 | CREATE/DROP/ALTER TABLE(危险) |

工具说明

| 工具 | SQL 类型 | 说明 | |------|----------|------| | read_query | SELECT | 执行 SELECT 查询(含 SHOW TABLES, DESC 等元数据查询) | | write_query | INSERT/UPDATE | 执行 INSERT 或 UPDATE 语句 | | delete_query | DELETE | 执行 DELETE 语句(危险操作) | | ddl_query | CREATE/DROP/ALTER TABLE | 执行 CREATE/DROP/ALTER TABLE 语句(危险操作) |

环境变量

# URL 格式(推荐)
POSTGRESQL_URL=postgresql://user:password@host:port/database

# 或使用独立环境变量
PGHOST=localhost
PGPORT=5432
PGUSER=postgres
PGPASSWORD=password
PGDATABASE=postgres
MCP_PERMISSIONS='["read","write"]'  # 可选,默认只有 read

# SSL 配置(Neon 等云数据库)
POSTGRESQL_URL=postgresql://user:pass@host/db?sslmode=require
POSTGRESQL_SSL=true

SSL 配置(适配 Neon 等云数据库)

通过 POSTGRESQL_SSLPGSSLMODE 环境变量控制 SSL:

| 取值 | 行为 | |------|------| | true / require / prefer | 启用 SSL,不验证证书 | | verify / verify-full / verify-ca | 启用 SSL,验证证书 | | false / disable | 禁用 SSL |

配置示例:

{
  "mcpServers": {
    "postgresql": {
      "command": "npx",
      "args": ["-y", "@easy-mcps/postgresql-mcp-server"],
      "env": {
        "POSTGRESQL_URL": "postgresql://user:pass@host/db?sslmode=require",
        "POSTGRESQL_SSL": "true",
        "MCP_PERMISSIONS": "read"
      }
    }
  }
}

使用方式

npx 直接运行

npx -y @easy-mcps/postgresql-mcp-server

带 SSL 运行(Neon 等云数据库):

POSTGRESQL_URL=postgresql://user:pass@host/db?sslmode=require POSTGRESQL_SSL=true npx -y @easy-mcps/postgresql-mcp-server

Claude Desktop / Cursor

基础配置:

{
  "mcpServers": {
    "postgresql": {
      "command": "npx",
      "args": ["-y", "@easy-mcps/postgresql-mcp-server"],
      "env": {
        "PGHOST": "localhost",
        "PGPORT": "5432",
        "PGUSER": "postgres",
        "PGPASSWORD": "password",
        "PGDATABASE": "postgres",
        "MCP_PERMISSIONS": "read,write"
      }
    }
  }
}

SSL 配置(Neon 等云数据库):

方式1:URL + SSL

{
  "mcpServers": {
    "postgresql": {
      "command": "npx",
      "args": ["-y", "@easy-mcps/postgresql-mcp-server"],
      "env": {
        "POSTGRESQL_URL": "postgresql://user:pass@host/db?sslmode=require",
        "POSTGRESQL_SSL": "true",
        "MCP_PERMISSIONS": "read"
      }
    }
  }
}

方式2:独立变量 + SSL

{
  "mcpServers": {
    "postgresql": {
      "command": "npx",
      "args": ["-y", "@easy-mcps/postgresql-mcp-server"],
      "env": {
        "PGHOST": "host",
        "PGPORT": "5432",
        "PGUSER": "user",
        "PGPASSWORD": "password",
        "PGDATABASE": "db",
        "POSTGRESQL_SSL": "true",
        "MCP_PERMISSIONS": "read"
      }
    }
  }
}

本地安装

npm install -g @easy-mcps/postgresql-mcp-server
postgresql-mcp-server

开发

npm install
npm run dev

License

MIT