mysql_list_tables
Lists all tables in a MySQL database to inspect schema structure and manage database organization.
Instructions
List all tables in the current or specified database
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "mysql_list_tables"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (uses current database if not specified) |
Implementation Reference
- src/index.ts:366-391 (handler)The handler function that implements the mysql_list_tables tool logic. It checks for an active connection, constructs a SHOW TABLES query (optionally for a specific database), executes it, and returns the list of tables.
private async handleListTables(args: any) { if (!this.pool) { throw new Error("Not connected to MySQL. Use mysql_connect first."); } const { database } = args; let query = "SHOW TABLES"; if (database) { query = `SHOW TABLES FROM \`${database}\``; } try { const [results] = await this.pool.execute(query); return { content: [ { type: "text", text: `Tables${database ? ` in database '${database}'` : ""}:\n${JSON.stringify(results, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to list tables: ${error instanceof Error ? error.message : String(error)}`); } } - src/index.ts:168-176 (schema)Input schema definition for the mysql_list_tables tool, specifying an optional database parameter.
inputSchema: { type: "object", properties: { database: { type: "string", description: "Database name (uses current database if not specified)", }, }, }, - src/index.ts:165-177 (registration)Registration of the mysql_list_tables tool in the ListToolsRequest handler, including name, description, and schema.
{ name: "mysql_list_tables", description: "List all tables in the current or specified database", inputSchema: { type: "object", properties: { database: { type: "string", description: "Database name (uses current database if not specified)", }, }, }, }, - src/index.ts:255-256 (registration)Switch case in the CallToolRequest handler that routes calls to mysql_list_tables to the appropriate handler function.
case "mysql_list_tables": return await this.handleListTables(args);