Skip to main content
Glama
Darkstar326

MCP MySQL Server

by Darkstar326

mysql_list_tables

Lists all tables in a MySQL database to inspect schema structure and available data. Specify a database name or use the current connection.

Instructions

List all tables in the current or specified database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNoDatabase name (uses current database if not specified)

Implementation Reference

  • The main 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:248-267 (registration)
    The switch statement in the CallToolRequest handler that dispatches to the mysql_list_tables handler based on the tool name.
    switch (name) { case "mysql_connect": return await this.handleConnect(args); case "mysql_query": return await this.handleQuery(args); case "mysql_list_databases": return await this.handleListDatabases(); case "mysql_list_tables": return await this.handleListTables(args); case "mysql_describe_table": return await this.handleDescribeTable(args); case "mysql_show_indexes": return await this.handleShowIndexes(args); case "mysql_get_table_stats": return await this.handleGetTableStats(args); case "mysql_disconnect": return await this.handleDisconnect(); default: throw new Error(`Unknown tool: ${name}`); }
  • src/index.ts:165-177 (registration)
    The tool registration object in the ListTools response, including name, description, and input schema for mysql_list_tables.
    { 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)", }, }, }, },
  • The input schema definition for the mysql_list_tables tool.
    inputSchema: { type: "object", properties: { database: { type: "string", description: "Database name (uses current database if not specified)", }, }, },

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