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 }

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