get_database_stats
Retrieve database statistics and information using existing DBeaver connections to analyze database performance and structure.
Instructions
Get statistics and information about a database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connectionId | Yes | The ID or name of the DBeaver connection |
Implementation Reference
- src/index.ts:918-934 (handler)The primary MCP tool handler for get_database_stats. Validates the connection ID, retrieves the connection, calls the DBeaverClient helper, and returns the stats as JSON text content.private async handleGetDatabaseStats(args: { connectionId: string }) { const connectionId = sanitizeConnectionId(args.connectionId); const connection = await this.configParser.getConnection(connectionId); if (!connection) { throw new McpError(ErrorCode.InvalidParams, `Connection not found: ${connectionId}`); } const stats = await this.dbeaverClient.getDatabaseStats(connection); return { content: [{ type: 'text' as const, text: JSON.stringify(stats, null, 2), }], }; }
- src/index.ts:394-403 (schema)Input schema validation for the get_database_stats tool, defining the required connectionId parameter.inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'The ID or name of the DBeaver connection', }, }, required: ['connectionId'], },
- src/index.ts:391-404 (registration)Tool registration entry in the ListTools response, including name, description, and input schema.{ name: 'get_database_stats', description: 'Get statistics and information about a database', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'The ID or name of the DBeaver connection', }, }, required: ['connectionId'], }, },
- src/dbeaver-client.ts:387-416 (helper)Supporting method in DBeaverClient that implements the core logic: lists tables to count them and executes a version query.async getDatabaseStats(connection: DBeaverConnection): Promise<DatabaseStats> { const startTime = Date.now(); try { // Get table count const tables = await this.listTables(connection, undefined, true); const tableCount = tables.length; // Get server version const versionQuery = this.getTestQuery(connection.driver); const versionResult = await this.executeQuery(connection, versionQuery); const serverVersion = this.extractVersionFromResult(versionResult) || 'Unknown'; return { connectionId: connection.id, tableCount, totalSize: 'Unknown', // Would need specific queries per database type connectionTime: Date.now() - startTime, serverVersion }; } catch (error) { return { connectionId: connection.id, tableCount: 0, totalSize: 'Unknown', connectionTime: Date.now() - startTime, serverVersion: 'Unknown' }; } }
- src/types.ts:82-89 (schema)TypeScript interface defining the structure of the DatabaseStats return object used by the tool.export interface DatabaseStats { connectionId: string; tableCount: number; totalSize: string; connectionTime: number; serverVersion: string; uptime?: string; }