PostgreSQL MCP AllAccess

PostgreSQL MCP AllAccess

Enables interaction with PostgreSQL databases through a production-ready MCP server with global connection pooling, automatic AWS password rotation, and comprehensive SQL operations. Supports multiple concurrent Claude sessions while maintaining efficient connection limits to the database.

Category
访问服务器

README

PostgreSQL MCP AllAccess

Production-ready PostgreSQL MCP server with global connection pooling, PgBouncer integration, and automatic password rotation for AWS RDS.

Quick Start (2 minutes)

With AWS Secrets Manager

# 1. Set AWS credentials
export AWS_ACCESS_KEY_ID=your_key
export AWS_SECRET_ACCESS_KEY=your_secret
export AWS_REGION=us-west-2

# 2. Deploy (fetches DB credentials from AWS)
python3 deploy_with_aws_secrets.py

# 3. Restart Claude Code to connect
# The deploy script shows the URL - it's http://localhost:3000/sse

That's it! The MCP server is now running and Claude Code will auto-detect it.

Optional: Set custom AWS secret names:

export AWS_SECRET_NAME=your/secret/name
export AWS_PASSWORD_SECRET_NAME=rds!your-password-id
python3 deploy_with_aws_secrets.py

Without AWS (Simple Credentials)

# 1. Copy .env.example and fill in your database credentials
cd /path/to/postgres_mcp_allaccess
cp .env.example .env
# Edit .env and fill in the REQUIRED fields (first 5 lines)

# 2. Deploy (docker-compose reads .env automatically)
docker-compose up -d

# 3. Restart Claude Code to connect
# MCP server is at http://localhost:3000/sse

What You Get

Global connection pooling - 15 max connections to PostgreSQL (configurable) ✅ Automatic password rotation - Zero downtime when AWS rotates passwords ✅ Transaction-level pooling - Efficient connection reuse across all queries ✅ Production ready - Health checks, logging, monitoring built-in

How It Works

Multiple Claude Sessions → MCP Server → PgBouncer → PostgreSQL
   (90+ clients)          (max 15)     (max 15)    (sees ≤15 connections)
  • PgBouncer enforces max 15 connections to your PostgreSQL database
  • Automatic queueing - Extra requests wait, then process when connections free up
  • Zero config needed - Default settings work for most use cases

Common Tasks

Check if it's running

curl http://localhost:3000/health
# Should show: "OK - Pool: 2/15 connections"

View logs

docker-compose logs -f

Stop server

docker-compose down

Change connection limits

Edit pgbouncer/pgbouncer.ini:

default_pool_size = 10      # Max connections to PostgreSQL

Then redeploy: docker-compose up -d --build

Available Tools (Use in Claude)

Query Execution:

  • list_tables - List tables in a schema
  • execute_query - Run any SQL query
  • describe_table - See table structure
  • execute_file - Run SQL from a file

Schema Operations:

  • list_schemas - List all schemas
  • search_tables - Find tables by name pattern
  • get_database_context - Overview of database structure

Analysis:

  • explain_query - Get query execution plan
  • analyze_query - Performance analysis
  • suggest_indexes - Index recommendations

Session:

  • get_session_info - Current session status
  • get_query_history - View query history

Troubleshooting

Claude Code can't connect

Solution: Restart Claude Code after deploying the MCP server.

"Pool not initialized" error

Solution: Run any query first - pool initializes on first use.

Container won't start

# Check what went wrong
docker-compose logs

# Common fixes:
# 1. Port 3000 in use: Change MCP_SSE_PORT in .env
# 2. Bad credentials: Check .env file or AWS secrets
# 3. Build cache issue: docker-compose up -d --build --force-recreate

Connection timeout

Increase pool timeout (default 30 seconds):

export POSTGRES_POOL_TIMEOUT=60
python3 deploy_with_aws_secrets.py  # or docker-compose up -d

Too many connections to PostgreSQL

Check your limit:

docker exec -e PGPASSWORD='your_pass' postgres-mcp-allaccess \
  psql -h localhost -p 6432 -U your_user -d your_db \
  -c "SELECT count(*) FROM pg_stat_activity WHERE usename='your_user'"

Should show 2-15 connections (never exceeds default_pool_size).

Configuration

Connection Pool Settings

Environment variables (set before deploying):

POSTGRES_MAX_CONNECTIONS=15     # MCP pool size
POSTGRES_MIN_CONNECTIONS=2      # Warm connections
POSTGRES_POOL_TIMEOUT=30        # Queue wait time (seconds)

PgBouncer limits (edit pgbouncer/pgbouncer.ini):

default_pool_size = 15          # MAX connections to PostgreSQL
min_pool_size = 2               # MIN kept alive
pool_mode = transaction         # Release after each transaction

Understanding the Pool

Question: If 90 Claude sessions query at once, does PostgreSQL see 90 connections?

Answer: NO! PostgreSQL sees maximum 15 connections (or whatever you set in default_pool_size).

  • Connections auto-release after each query
  • Extra requests queue and process when connections free up
  • No session management needed - everything is automatic

Automatic Password Rotation

When AWS rotates your password:

  1. Next query fails with auth error
  2. MCP fetches new password from AWS Secrets Manager
  3. Updates both MCP pool and PgBouncer
  4. Retries query - succeeds!

Zero downtime. No restart needed.

Requirements:

  • Deploy with deploy_with_aws_secrets.py (AWS credentials available)
  • AWS secret names configured (done automatically)

Security

Never commit:

  • .env files
  • *.log files
  • config/postgres_config.ini

Safe to commit:

  • AWS secret names (e.g., "postgres/dev/db")
  • Database hostnames (e.g., "mydb.rds.amazonaws.com")

All sensitive data is gitignored automatically.

Advanced

Project Structure

postgres_mcp_allaccess/
├── deploy_with_aws_secrets.py   # AWS deployment script
├── docker-compose.yml            # Container orchestration
├── Dockerfile                    # Single container (MCP + PgBouncer)
├── docker-entrypoint.sh          # Startup script
├── pgbouncer/pgbouncer.ini       # Connection pool config
└── src/postgres_mcp_allaccess/
    ├── server.py                 # MCP server
    ├── database.py               # Global pool + auto rotation
    ├── pgbouncer_manager.py      # PgBouncer control
    └── transports/sse_transport.py  # HTTP/SSE transport

Health Monitoring

# Health check endpoint
curl http://localhost:3000/health

# Check PgBouncer process
docker exec postgres-mcp-allaccess ps aux | grep pgbouncer

# View all environment variables
docker exec postgres-mcp-allaccess env | grep -E "POSTGRES|AWS|PGBOUNCER"

Manual Password Refresh

# Force refresh from AWS (if auto-rotation fails)
docker-compose restart

License

Apache License 2.0 - See LICENSE file for details.

Support

  • Issues: https://github.com/yty-build/postgres_mcp_allaccess/issues
  • Discussions: https://github.com/yty-build/postgres_mcp_allaccess/discussions
  • Security: Report privately via GitHub Security Advisories

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选