Skip to main content
Glama

liara_get_database_connection

Retrieve database connection details including host, port, and credentials for managing applications on the Liara cloud platform.

Instructions

Get database connection information (host, port, credentials)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNameYesThe name of the database

Implementation Reference

  • Core implementation that retrieves complete database connection information (host, port, username, password, connection string) from the Liara API. Handles multiple endpoints, fallbacks for missing fields, default usernames/ports per DB type, and builds connection strings. Used by the liara_get_database_connection MCP tool.
    export async function getDatabaseConnection(
        client: LiaraClient,
        databaseName: string
    ): Promise<DatabaseConnectionInfo> {
        validateRequired(databaseName, 'Database name');
        
        const warnings: string[] = [];
        let dbDetails: DatabaseDetails | null = null;
        
        // Try primary endpoint: /v1/databases/{name}
        try {
            dbDetails = await client.get<DatabaseDetails>(`/v1/databases/${databaseName}`);
        } catch (error: any) {
            const { LiaraMcpError } = await import('../utils/errors.js');
            throw new LiaraMcpError(
                `Failed to fetch database details: ${error.message}`,
                'DATABASE_FETCH_ERROR',
                { databaseName, error: error.message },
                [
                    'Verify the database name is correct',
                    'Check if the database exists',
                    'Ensure you have permission to access this database'
                ]
            );
        }
        
        // Try alternative endpoint for connection info if primary doesn't have password
        let connectionInfo: DatabaseDetails | null = null;
        if (!dbDetails.password && !dbDetails.rootPassword && !dbDetails.connectionString) {
            try {
                // Some APIs have a separate connection endpoint
                connectionInfo = await client.get<DatabaseDetails>(
                    `/v1/databases/${databaseName}/connection`
                );
            } catch (error: any) {
                // This endpoint might not exist, that's okay
                warnings.push('Connection-specific endpoint not available, using database details');
            }
        }
        
        // Merge connection info if available
        if (connectionInfo) {
            dbDetails = {
                ...dbDetails,
                ...connectionInfo,
                connection: connectionInfo.connection || dbDetails.connection,
            };
        }
        
        // Extract connection info from nested connection object if present
        if (dbDetails.connection) {
            dbDetails = {
                ...dbDetails,
                hostname: dbDetails.connection.host || dbDetails.hostname,
                port: dbDetails.connection.port || dbDetails.port,
                username: dbDetails.connection.username || dbDetails.username,
                password: dbDetails.connection.password || dbDetails.password,
                database: dbDetails.connection.database || dbDetails.database,
            };
        }
        
        // Validate we have minimum required fields
        const host = dbDetails.hostname || dbDetails.host || dbDetails.internalHostname;
        if (!host) {
            const { LiaraMcpError } = await import('../utils/errors.js');
            throw new LiaraMcpError(
                'Database connection info missing host',
                'INCOMPLETE_CONNECTION_INFO',
                { databaseName, dbDetails },
                [
                    'Verify the database exists and is accessible',
                    'Check if the database is running',
                    'Use liara_get_database to check database status',
                    'The database may need to be started first'
                ]
            );
        }
        
        // Extract password with better fallback logic
        const password = dbDetails.password || 
                        dbDetails.rootPassword || 
                        (dbDetails.connection?.password) || 
                        '';
        
        const passwordAvailable = !!password;
        
        if (!passwordAvailable) {
            warnings.push(
                'Password not returned by API. You may need to:',
                '1. Check the dashboard connection tab for the password',
                '2. Reset the password using liara_reset_database_password',
                '3. Use the password that was shown when the database was created'
            );
        }
        
        // Extract username with better defaults based on database type
        let username = dbDetails.username || 
                      dbDetails.user || 
                      (dbDetails.connection?.username);
        
        // Set default username based on database type if not provided
        if (!username) {
            switch (dbDetails.type) {
                case 'postgres':
                    username = 'postgres';
                    break;
                case 'redis':
                    username = 'default'; // Redis often doesn't use usernames
                    break;
                default:
                    username = 'root';
            }
            warnings.push(`Username not provided, using default: ${username}`);
        }
        
        // Build connection info
        const connectionInfoResult: DatabaseConnectionInfo = {
            host,
            port: dbDetails.port || getDefaultPort(dbDetails.type),
            username,
            password,
            database: dbDetails.database || dbDetails.name || databaseName,
            connectionString: dbDetails.connectionString || buildConnectionString({
                ...dbDetails,
                username,
                password,
            }),
            passwordAvailable,
            warnings: warnings.length > 0 ? warnings : undefined,
        };
        
        return connectionInfoResult;
    }
  • Type/schema definition for the output of the database connection tool, including all connection parameters and metadata.
    export interface DatabaseConnectionInfo {
        host: string;
        port: number;
        username: string;
        password: string;
        database: string;
        connectionString?: string;
        passwordAvailable: boolean; // Indicates if password was successfully retrieved
        warnings?: string[]; // Any warnings about missing or incomplete info
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states this is a 'Get' operation, implying read-only behavior, but doesn't clarify if it requires specific permissions, returns sensitive credentials, has rate limits, or what format the output takes. For a tool that likely handles credentials, this lack of detail is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. It directly states what the tool does and what information it retrieves, making it easy to parse quickly. Every part of the sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (retrieving connection info likely involving credentials), no annotations, and no output schema, the description is minimally adequate. It specifies the type of information returned but doesn't cover behavioral aspects like security implications or output format. For a tool with potential sensitivity, it should do more to be fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the single parameter 'databaseName' clearly documented in the schema. The description doesn't add any parameter-specific details beyond what the schema provides, such as examples or constraints. Given the high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and the resource ('database connection information'), specifying what information is retrieved (host, port, credentials). It distinguishes from siblings like 'liara_get_database' by focusing on connection details rather than general database metadata. However, it doesn't explicitly contrast with all similar tools, keeping it at a 4 rather than 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. For example, it doesn't mention whether this should be used after creating a database, for configuration purposes, or in what scenarios connection info is needed. Without such context, the agent must infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/razavioo/liara-mcp'

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