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 analyze data volume.

Instructions

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

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "database": { "description": "Database name (uses current database if not specified)", "type": "string" }, "table": { "description": "Table name to get statistics for", "type": "string" } }, "required": [ "table" ], "type": "object" }

Implementation Reference

  • The handler function that implements the mysql_get_table_stats tool. It queries the INFORMATION_SCHEMA.TABLES for statistics like row count, data length, index length, etc., for the specified table.
    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)
    Registration of the mysql_get_table_stats tool in the ListTools response, including its description and input schema definition.
    { 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)
    The switch case that routes calls to the mysql_get_table_stats tool to its handler function.
    case "mysql_get_table_stats": return await this.handleGetTableStats(args);

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