get_database_info
Retrieve PostgreSQL database version, connection details, and configuration settings for monitoring and troubleshooting database instances.
Instructions
Get database and connection information.
Returns:
Database version, connection info, and settings
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- postgres_mcp/server.py:379-389 (handler)MCP tool handler for 'get_database_info'. This is the entrypoint registered via @mcp.tool() that fetches and returns database information by delegating to the PostgresClient.@mcp.tool() @handle_db_error def get_database_info() -> dict: """Get database and connection information. Returns: Database version, connection info, and settings """ client = get_client() return client.get_database_info()
- Core implementation of database info retrieval in PostgresClient class. Executes SQL queries to gather version, connection details, and settings.def get_database_info(self) -> dict[str, Any]: """Get database and connection information. Returns: Dict with database info """ with self.get_cursor() as cursor: cursor.execute("SELECT version()") version_row = cursor.fetchone() cursor.execute(""" SELECT current_database() AS database, current_user AS user, inet_server_addr() AS host, inet_server_port() AS port, pg_encoding_to_char(encoding) AS encoding, current_setting('TimeZone') AS timezone, current_setting('max_connections')::int AS max_connections FROM pg_database WHERE datname = current_database() """) info_row = cursor.fetchone() cursor.execute("SELECT count(*) AS current_connections FROM pg_stat_activity") conn_row = cursor.fetchone() result = dict(info_row) if info_row else {} result["version"] = version_row["version"] if version_row else "" result["current_connections"] = conn_row["current_connections"] if conn_row else 0 return result
- postgres_mcp/server.py:379-379 (registration)The @mcp.tool() decorator registers the get_database_info function as an MCP tool.@mcp.tool()