Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

list_tables

Retrieve all table names from a MySQL database to understand its structure. Specify a database or use the current connection to view available 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

  • Handler function that gets a connection pool, executes a SHOW TABLES query (optionally scoped to a specific database), extracts table names from results, and returns both text and structured content 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 using Zod defining an optional 'database' string parameter for specifying the database to list tables from.
    { database: z.string().optional().describe("Database name (optional, uses current if not specified)"), },
  • src/index.ts:233-262 (registration)
    Complete registration of the 'list_tables' tool via McpServer.tool(), including 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