Skip to main content
Glama
Darkstar326

MCP MySQL Server

by Darkstar326

mysql_get_table_stats

Retrieve table statistics including row count and size from MySQL databases to monitor performance and optimize storage.

Instructions

Get statistics about a table (row count, size, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name to get statistics for
databaseNoDatabase name (uses current database if not specified)

Implementation Reference

  • The handler function that implements the mysql_get_table_stats tool by querying INFORMATION_SCHEMA.TABLES for table statistics including row count, engine, data length, index length, and other metrics.
    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:214-231 (registration)
    Tool registration in the listTools handler, defining the name, description, and input schema for mysql_get_table_stats.
    { 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"], }, },
  • Input schema definition for the mysql_get_table_stats tool, specifying required 'table' parameter and optional 'database'.
    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"], },

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/Darkstar326/mcp-mysql'

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