Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

list_tables

Retrieve all tables in a MySQL database to understand its structure and available data. Specify a database name or use the current connection to view tables.

Instructions

List all tables in the current or specified database

Input Schema

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

Implementation Reference

  • The handler function for the 'list_tables' tool. It connects to the MySQL pool, executes 'SHOW TABLES' (optionally from a specific database), extracts table names from the result rows, and returns a structured response with the list of tables.
    async ({ database }) => { const p = await getPool(); let sql = "SHOW TABLES"; if (database) { sql = `SHOW TABLES FROM \`${database}\``; } const [rows] = await p.query<RowDataPacket[]>(sql); const tables = rows.map((row) => Object.values(row)[0] as string); const output = { tables, database: database || null }; return { content: [ { type: "text" as const, text: JSON.stringify(tables, null, 2), }, ], structuredContent: output, }; }
  • Input schema for the 'list_tables' tool using Zod, defining an optional 'database' parameter.
    { database: z.string().optional().describe("Database name (optional, uses current if not specified)"), },
  • src/index.ts:233-262 (registration)
    Registration of the 'list_tables' tool on the MCP server, specifying name, description, input schema, and handler function.
    server.tool( "list_tables", "List all tables in the current or specified database", { database: z.string().optional().describe("Database name (optional, uses current if not specified)"), }, async ({ database }) => { const p = await getPool(); let sql = "SHOW TABLES"; if (database) { sql = `SHOW TABLES FROM \`${database}\``; } const [rows] = await p.query<RowDataPacket[]>(sql); const tables = rows.map((row) => Object.values(row)[0] as string); const output = { tables, database: database || null }; return { content: [ { type: "text" as const, text: JSON.stringify(tables, null, 2), }, ], structuredContent: output, }; } );

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

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