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 column definitions, data types, and constraints.

Instructions

Get the structure/schema of a table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name
databaseNoDatabase name (optional)

Implementation Reference

  • The handler function executes a DESCRIBE query on the specified table (optionally in a database) and returns the column structure including Field, Type, Null, Key, Default, and 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,
      };
    }
  • Input schema using Zod: required 'table' string and optional 'database' string.
    {
      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 via server.tool call, including name, description, input schema, and 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