
ericzakariasson/pg-mcp-server 是从 https://github.com/ericzakariasson/pg-mcp-server. 导入的 MCP 服务器候选服务器。
概览
ericzakariasson/pg-mcp-server 是从 https://github.com/ericzakariasson/pg-mcp-server. 导入的 MCP 服务器候选服务器。
概述(AI 翻译)
一个用于PostgreSQL数据库的模型上下文协议服务器。使LLM能够通过受控接口查询和分析PostgreSQL数据库。
https://github.com/user-attachments/assets/6571c20c-91c9-4a6e-8332-13b587b79fbf
安装
添加到你的MCP客户端设置中:
配置
DATABASE_URL- PostgreSQL 连接字符串(必填)DANGEROUSLY_ALLOW_WRITE_OPS- 启用写入(默认:false)DEBUG- 启用调试日志(默认:false)PG_SSL_ROOT_CERT- TLS CA捆绑包的可选路径(例如AWS RDS全球捆绑包)
用途
运输
- 默认传输为stdio。切换到带有
--transport标志的HTTP。 - HTTP 模式为
/mcp的 MCP 可流式 HTTP 端点服务于PORT(默认3000)。 - 支持可流式HTTP的客户端应连接到
http://localhost:3000/mcp。
启动命令:
工具
query- 执行SQL查询
资源
postgres://tables- 列出所有表格postgres://table/{schema}/{table}- 获取表模式和样本数据
示例提示
这里有一个示例提示,用来测试你的MCP服务器是否正常工作:
数据分析与笔记本
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Postgres MCP Server
A Model Context Protocol server for PostgreSQL databases. Enables LLMs to query and analyze PostgreSQL databases through a controlled interface.
https://github.com/user-attachments/assets/6571c20c-91c9-4a6e-8332-13b587b79fbf
Installation
Add to your MCP client settings:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["--yes", "pg-mcp-server", "--transport", "stdio"],
"env": {
"DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres"
}
}
}
}
Configuration
DATABASE_URL- PostgreSQL connection string (required)DANGEROUSLY_ALLOW_WRITE_OPS- Enable writes (default:false)DEBUG- Enable debug logging (default:false)PG_SSL_ROOT_CERT- Optional path to a TLS CA bundle (e.g., AWS RDS global bundle)
Usage
Transports
- Default transport is stdio. Switch to HTTP with the
--transportflag. - HTTP mode serves the MCP Streamable HTTP endpoint at
/mcponPORT(default3000). - Clients that support Streamable HTTP should connect to
http://localhost:3000/mcp.
Start commands:
# stdio transport (default, via installed CLI)
pg-mcp-server --transport=stdio
# http transport
pg-mcp-server --transport=http
Tools
query- Execute SQL queries{ "sql": "SELECT * FROM users WHERE active = true LIMIT 10" }
Resources
postgres://tables- List all tablespostgres://table/{schema}/{table}- Get table schema and sample data
Example Prompts
Here’s an example prompt to test if your MCP server is working:
Show me the first 5 users from the database
Data Analysis & Notebooks
For data analysis and exploration, I’ve added a Cursor rule for using the MCP server together with notebooks in .cursor/rules/notebooks.mdc:
Quick Start with Docker
# Start PostgreSQL with sample data
bun run db:start
# Test with MCP Inspector
bun run inspector
# Stop PostgreSQL
bun run db:stop
Sample tables included: users, products, orders, order_items
Development
# Clone and install
git clone https://github.com/ericzakariasson/pg-mcp-server.git
cd pg-mcp-server
bun install
# Run (stdio transport)
bun run index.ts -- --transport=stdio
DEBUG=true bun run index.ts -- --transport=stdio
# Run (http transport)
bun run index.ts -- --transport=http
DEBUG=true bun run index.ts -- --transport=http
bun test # Run tests
Use local build in MCP client settings:
bun run build:js
{
"mcpServers": {
"postgres": {
"command": "node",
安装
npx --yes pg-mcp-server --transport stdio配置
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["--yes", "pg-mcp-server", "--transport", "stdio"],
"env": {
"DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres"
}
}
}
}