liara_get_database
Retrieve configuration details and status information for a specific database on the Liara cloud platform using its name.
Instructions
Get details of a specific database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The name of the database |
Implementation Reference
- src/services/databases.ts:21-27 (handler)Handler function that fetches specific database details from Liara API, matching the liara_get_database tool purpose for checking database status.export async function getDatabase( client: LiaraClient, name: string ): Promise<Database> { validateRequired(name, 'Database name'); return await client.get<Database>(`/v1/databases/${name}`); }
- src/api/types.ts:134-143 (schema)Type schema for Database object returned by the getDatabase function.export interface Database { _id: string; name: string; type: DatabaseType; planID: string; status: DatabaseStatus; version?: string; createdAt: string; updatedAt: string; }
- src/services/databases.ts:25-27 (helper)Core API call logic for retrieving database information.validateRequired(name, 'Database name'); return await client.get<Database>(`/v1/databases/${name}`); }
- src/services/databases.ts:170-302 (helper)Extended helper for getting database connection info, referenced indirectly via status check.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; }