easy-pg-admin-mcp
v0.1.1
Published
High privilege PostgreSQL admin MCP server for database and role management
Maintainers
Readme
easy-pg-admin-mcp
一個高權限的 PostgreSQL 管理型 MCP server,專門處理 database、role 與 database-level grants 管理。
這個專案的定位是 DBA 類工具,不提供任意 SQL 執行,也不處理 schema、table、view、index、trigger、function 管理。資料查詢與 schema/table 操作請使用 easy-pg-mcp。
功能
- 列出、建立、檢視 database,並修改 owner
- 列出、建立、修改、刪除 PostgreSQL roles
- 授予與撤銷 role membership
- 授予與撤銷 database-level privileges
- 對危險刪除操作提供短效確認 token
可用工具
| 工具 | 說明 |
| --- | --- |
| pg_list_databases | 列出目前 PostgreSQL instance 內的 databases |
| pg_create_database | 建立 PostgreSQL database |
| pg_describe_database | 檢視 PostgreSQL database |
| pg_alter_database_owner | 修改 database owner |
| pg_drop_database | 提出刪除 database 的請求並回傳確認 token |
| pg_list_roles | 列出 PostgreSQL roles |
| pg_create_role | 建立不支援 SUPERUSER 的 PostgreSQL role |
| pg_alter_role_password | 修改 role 密碼 |
| pg_alter_role_attributes | 修改支援的 role attributes |
| pg_drop_role | 提出刪除 role 的請求並回傳確認 token |
| pg_grant_role | 將 role 授予另一個 role |
| pg_revoke_role | 從另一個 role 撤銷 role |
| pg_show_role_memberships | 顯示 role membership |
| pg_grant_privileges | 對 role 授予 database-level privileges |
| pg_revoke_privileges | 從 role 撤銷 database-level privileges |
| pg_show_grants | 顯示 role 的 database-level grants |
| pg_confirm_task | 確認並執行先前產生的危險操作 token |
安全性
- 不提供原始 SQL passthrough
- 不處理 schema、table、view、index、trigger、function 管理
- 不支援建立或修改 SUPERUSER role
pg_drop_database與pg_drop_role一律要經過pg_confirm_taskpg_drop_role不提供REASSIGN OWNED或DROP OWNED- confirmation token 是隨機產生、只能使用一次、且會在短時間後過期
設定
請使用環境變數設定,風格與其他 easy-*-mcp 專案一致。
| 變數 | 必填 | 預設值 | 說明 |
| --- | --- | --- | --- |
| PG_CONNECTION_STRING | 條件必填 | - | PostgreSQL connection string;提供時優先使用 |
| PG_HOST | 條件必填 | - | 未提供 connection string 時使用的 PostgreSQL host |
| PG_PORT | 否 | 5432 | PostgreSQL port |
| PG_USER | 條件必填 | - | 未提供 connection string 時使用的 PostgreSQL admin role |
| PG_PASSWORD | 否 | - | PostgreSQL 密碼 |
| PG_DATABASE | 條件必填 | - | 管理連線使用的預設 database |
| PG_CONNECTION_LIMIT | 否 | 10 | pool 最大 active connections |
| PG_CONNECTION_TIMEOUT | 否 | 10000 | 建立 PostgreSQL 連線的逾時時間,單位毫秒 |
| PG_IDLE_TIMEOUT | 否 | 30000 | idle connection timeout,單位毫秒 |
| PG_ENABLE_KEEP_ALIVE | 否 | true | 是否啟用 TCP keep-alive |
| PG_KEEP_ALIVE_INITIAL_DELAY | 否 | 0 | TCP keep-alive 初始延遲,單位毫秒 |
| PG_SSL | 否 | false | 可使用 true、false 或 no-verify |
| PG_ADMIN_TOKEN_TTL_SECONDS | 否 | 120 | confirmation token 的有效秒數 |
範例
PG_HOST=localhost
PG_PORT=5432
PG_USER=postgres
PG_PASSWORD=your_password
PG_DATABASE=postgres
PG_SSL=false
PG_ADMIN_TOKEN_TTL_SECONDS=120Claude Desktop 範例
{
"mcpServers": {
"easy-pg-admin-mcp": {
"command": "npx",
"args": ["-y", "easy-pg-admin-mcp"],
"env": {
"PG_HOST": "localhost",
"PG_PORT": "5432",
"PG_USER": "postgres",
"PG_PASSWORD": "your_password",
"PG_DATABASE": "postgres",
"PG_SSL": "false",
"PG_ADMIN_TOKEN_TTL_SECONDS": "120"
}
}
}
}更新設定後,請重新啟動 Claude Desktop。
備註
pg_drop_database與pg_drop_role不會直接執行- 這兩個動作會先產生 token,使用者確認後才會透過
pg_confirm_task真正執行 - token 是短效且單次使用,不會保留成長期 pending queue
