Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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
  • The @mcp.tool() decorator registers the get_database_info function as an MCP tool.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JaviMaligno/postgres-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server