Skip to content

postgres-mcp-server: Multiple issues with IAM authentication and connection handling #2505

@ioudkerk

Description

@ioudkerk

Description

Several issues prevent the PostgreSQL MCP server from working correctly with IAM authentication on standalone RDS instances.

Issues Found

1. args.hostname reference error (Critical)

Location: server.py:726 (in main())

The CLI argument is defined as --db_endpoint but the code references args.hostname:

db_endpoint=args.hostname,  # Should be args.db_endpoint

This causes an AttributeError when starting the server.

2. Missing --username parameter for IAM auth

The server defaults to using the master username from RDS instance properties, but the master user often doesn't have the rds_iam role granted. Users need a way to specify a different database user for IAM authentication.

3. Connection lookup mismatch with cluster_identifier

The connection map uses cluster_identifier as part of the key. When the server starts with cluster_identifier=None but the MCP client passes cluster_identifier="" (empty string), the connection isn't found because None != "".

4. Async event loop conflict

The startup validation creates a connection pool in one event loop (asyncio.run()), but MCP runs in a different event loop. The aiorwlock.RWLock in the connection pool is bound to the first event loop and fails when used in the second:

Database connection error: <aiorwlock._RWLockCore object at ...> is bound to a different event loop

5. MCP client doesn't know startup parameters

When get_database_connection_info is called and no connections exist (due to issue #4 or first-time use), it returns []. The MCP client has no way to know the correct parameters to connect, requiring manual user input.

Steps to Reproduce

  1. Set up an RDS PostgreSQL instance with IAM authentication
  2. Create a database user with rds_iam role: GRANT rds_iam TO myuser;
  3. Try to start the MCP server:
uvx awslabs.postgres-mcp-server@latest \
  --region=us-east-1 \
  --db_type=RPG \
  --db_endpoint=mydb.xxx.us-east-1.rds.amazonaws.com \
  --database=mydb \
  --connection_method=PG_WIRE_IAM_PROTOCOL
  1. Observe AttributeError: 'Namespace' object has no attribute 'hostname'

Expected Behavior

The server should:

  1. Accept --username parameter for IAM authentication
  2. Start successfully and connect using the specified user
  3. Handle queries from MCP clients without connection lookup failures
  4. Provide startup parameters to clients so they know how to connect

Environment

  • postgres-mcp-server version: 1.23.3
  • Python: 3.10
  • AWS: RDS PostgreSQL (standalone instance, not Aurora)
  • Connection method: PG_WIRE_IAM_PROTOCOL

Proposed Fix

See PR #2504

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions