#!/usr/bin/env python3
"""
Test Docker MCP Server with PgBouncer
"""
import asyncio
import psycopg
async def test_direct_connection():
"""Test connection through PgBouncer directly"""
print("=" * 60)
print("TESTING PGBOUNCER CONNECTION (via Docker network)")
print("=" * 60)
# Connection string matching what MCP server uses
conn_str = "host=pgbouncer port=6432 dbname=dev_pg user=dev_pg_adm_01 password='SB_G5AZ)46NY$zOCsP.:gz*JM<1P'"
try:
# Note: This will fail from host machine since 'pgbouncer' is only resolvable in Docker network
# But it demonstrates the connection parameters
print(f"\nConnection string (from MCP perspective):")
print(f" host=pgbouncer port=6432 dbname=dev_pg user=dev_pg_adm_01")
print(f"\n✓ MCP Server in Docker will use these parameters")
print(f"✓ This routes through PgBouncer container")
print(f"✓ PgBouncer then connects to real PostgreSQL")
except Exception as e:
print(f"Error: {e}")
async def test_through_real_host():
"""Test what happens when bypassing PgBouncer"""
print("\n" + "=" * 60)
print("COMPARISON: DIRECT POSTGRESQL CONNECTION")
print("=" * 60)
# Direct connection (what LOCAL MCP servers use)
conn_str = "host=hz-dev-postgres.c9uoc8amwt13.us-west-2.rds.amazonaws.com port=5432 dbname=dev_pg user=dev_pg_adm_01 password='SB_G5AZ)46NY$zOCsP.:gz*JM<1P'"
try:
print(f"\nDirect connection string:")
print(f" host=hz-dev-postgres... port=5432")
print(f"\n✓ This is what LOCAL MCP servers use (AWS Secrets)")
print(f"✓ Bypasses PgBouncer entirely")
async with await psycopg.AsyncConnection.connect(conn_str) as conn:
result = await conn.execute("SELECT current_database(), current_user, inet_server_addr(), inet_server_port()")
row = await result.fetchone()
print(f"\n📊 Query Result:")
print(f" Database: {row[0]}")
print(f" User: {row[1]}")
print(f" Server IP: {row[2]}")
print(f" Server Port: {row[3]}")
except Exception as e:
print(f"Error: {e}")
async def main():
print("\n🔍 DOCKER MCP + PGBOUNCER ARCHITECTURE TEST\n")
await test_direct_connection()
await test_through_real_host()
print("\n" + "=" * 60)
print("SUMMARY")
print("=" * 60)
print("""
✅ Docker MCP Server: Configured to use PgBouncer
- Connection: pgbouncer:6432 (Docker network)
- PgBouncer pools connections to PostgreSQL
❌ Local MCP Servers: Bypass PgBouncer
- Connection: Direct to PostgreSQL (AWS Secrets)
- No connection pooling via PgBouncer
To test Docker MCP server's PgBouncer integration:
1. Stop local MCP servers
2. Configure Claude Code to use Docker MCP at http://localhost:3000/sse
3. OR use a test client that connects to Docker MCP endpoint
""")
if __name__ == "__main__":
asyncio.run(main())