Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

describe_table

Retrieve the structure and schema of a MySQL database table to understand its columns, data types, and constraints.

Instructions

Get the structure/schema of a table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name
databaseNoDatabase name (optional)

Implementation Reference

  • Handler function executes DESCRIBE query on the specified table (optionally in a database) and returns the column structure including Field, Type, Null, Key, Default, Extra.
    async ({ table, database }) => { const p = await getPool(); const tableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``; const [rows] = await p.query<RowDataPacket[]>(`DESCRIBE ${tableName}`); const columns = rows as Array<{ Field: string; Type: string; Null: string; Key: string; Default: string | null; Extra: string; }>; const output = { table, database: database || null, columns }; return { content: [ { type: "text" as const, text: JSON.stringify(rows, null, 2), }, ], structuredContent: output, }; }
  • Zod input schema defining required 'table' name and optional 'database'.
    { table: z.string().describe("Table name"), database: z.string().optional().describe("Database name (optional)"), },
  • src/index.ts:265-298 (registration)
    Registration of the 'describe_table' tool using McpServer.tool method, including description, input schema, and inline handler.
    server.tool( "describe_table", "Get the structure/schema of a table", { table: z.string().describe("Table name"), database: z.string().optional().describe("Database name (optional)"), }, async ({ table, database }) => { const p = await getPool(); const tableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``; const [rows] = await p.query<RowDataPacket[]>(`DESCRIBE ${tableName}`); const columns = rows as Array<{ Field: string; Type: string; Null: string; Key: string; Default: string | null; Extra: string; }>; const output = { table, database: database || null, columns }; return { content: [ { type: "text" as const, text: JSON.stringify(rows, 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