mysql_get_table_stats
Retrieve table statistics including row count and size information from MySQL databases for performance monitoring and capacity planning.
Instructions
Get statistics about a table (row count, size, etc.)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (uses current database if not specified) | |
| table | Yes | Table name to get statistics for |
Implementation Reference
- src/index.ts:449-491 (handler)Implements the mysql_get_table_stats tool by querying the INFORMATION_SCHEMA.TABLES for table statistics including row count, data length, index length, etc., after validating connection and inputs.private async handleGetTableStats(args: any) { if (!this.pool) { throw new Error("Not connected to MySQL. Use mysql_connect first."); } const { table, database } = args; if (!table) { throw new Error("Table name is required"); } try { // Get table information from information_schema const dbCondition = database ? `AND TABLE_SCHEMA = '${database}'` : ""; const query = ` SELECT TABLE_NAME, ENGINE, TABLE_ROWS, DATA_LENGTH, INDEX_LENGTH, DATA_FREE, AUTO_INCREMENT, CREATE_TIME, UPDATE_TIME, CHECK_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '${table}' ${dbCondition} `; const [results] = await this.pool.execute(query); return { content: [ { type: "text", text: `Statistics for table '${table}':\n${JSON.stringify(results, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to get table statistics: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:218-230 (schema)Defines the input schema for the mysql_get_table_stats tool, specifying parameters for table and optional database.type: "object", properties: { table: { type: "string", description: "Table name to get statistics for", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], },
- src/index.ts:214-231 (registration)Registers the mysql_get_table_stats tool in the listTools response, including its name, description, and input schema.{ name: "mysql_get_table_stats", description: "Get statistics about a table (row count, size, etc.)", inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to get statistics for", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], }, },
- src/index.ts:261-262 (registration)Dispatches calls to the mysql_get_table_stats tool to its handler function in the CallToolRequest switch statement.case "mysql_get_table_stats": return await this.handleGetTableStats(args);