Skip to main content
Glama
ImRieul

MySQL MCP Server

by ImRieul

describe_table

Display a table's schema including column names, types, constraints, and comments. Check structure before writing queries to avoid errors.

Instructions

Show the schema/structure of a table, including column names, types, constraints, and comments. Use this before writing queries to ensure correct column names and types. For inspecting all tables at once, use describe_all_tables instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name to describe.
databaseNoDatabase name. Uses the current database if omitted.

Implementation Reference

  • The main handler function for the describe_table tool. Validates identifiers, resolves the database, queries information_schema.COLUMNS for the table's schema, formats each column using formatColumn(), and returns the result.
    export function createDescribeTableHandler(runner: QueryRunner) {
      return async ({ table, database }: { table: string; database?: string }) => {
        const tableValidation = validateIdentifier(table, 'Table');
        if (!tableValidation.valid) {
          return {
            isError: true as const,
            content: [{ type: 'text' as const, text: tableValidation.message! }],
          };
        }
    
        if (database) {
          const dbValidation = validateIdentifier(database, 'Database');
          if (!dbValidation.valid) {
            return {
              isError: true as const,
              content: [{ type: 'text' as const, text: dbValidation.message! }],
            };
          }
        }
    
        try {
          return await runner.withConnection(async (query) => {
            const db = await resolveDatabase(query, database);
            if (!db) {
              return {
                isError: true as const,
                content: [
                  {
                    type: 'text' as const,
                    text: 'Error: No database selected. Specify a database name or set MYSQL_DATABASE.',
                  },
                ],
              };
            }
    
            const sql = `SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_KEY, COLUMN_DEFAULT, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ${quoteStringValue(db)} AND TABLE_NAME = ${quoteStringValue(table)} ORDER BY ORDINAL_POSITION`;
            const [rows] = await query(sql);
            const typedRows = rows as Record<string, unknown>[];
    
            if (typedRows.length === 0) {
              return {
                isError: true as const,
                content: [
                  {
                    type: 'text' as const,
                    text: `Error: Table '${table}' doesn't exist in database '${db}'.\nHint: use list_tables to check available tables.`,
                  },
                ],
              };
            }
    
            const columns = typedRows.map((r) =>
              formatColumn({
                name: String(r.COLUMN_NAME),
                type: String(r.COLUMN_TYPE),
                nullable: r.IS_NULLABLE === 'YES',
                key: String(r.COLUMN_KEY ?? ''),
                defaultValue: r.COLUMN_DEFAULT,
                extra: String(r.EXTRA ?? ''),
                comment: String(r.COLUMN_COMMENT ?? ''),
              }),
            );
            return {
              content: [{ type: 'text' as const, text: `${table}:\n${columns.join('\n')}` }],
            };
          });
        } catch (error) {
          return {
            isError: true as const,
            content: [{ type: 'text' as const, text: formatError(error) }],
          };
        }
      };
    }
  • Input schema definition for describe_table. Defines 'table' (required string) and 'database' (optional string) parameters with Zod validation.
    export const describeTableToolConfig = {
      title: 'Describe Table',
      description:
        'Show the schema/structure of a table, including column names, types, constraints, and comments. ' +
        'Use this before writing queries to ensure correct column names and types. ' +
        'For inspecting all tables at once, use describe_all_tables instead.',
      inputSchema: {
        table: z.string().describe('Table name to describe.'),
        database: z.string().optional().describe('Database name. Uses the current database if omitted.'),
      },
    };
  • Registration of the describe_table tool on the MCP server using server.tool() with name, description, input schema, and handler.
    server.tool(
      describeTableToolName,
      describeTableToolConfig.description,
      describeTableToolConfig.inputSchema,
      createDescribeTableHandler(runner),
    );
  • formatColumn helper used by the handler to format column information (name, type, nullable, key, default, extra, comment) into a readable string.
    export function formatColumn(col: ColumnInfo): string {
      let result = `${col.name} ${col.type}`;
      if (!col.nullable) result += ' NOT NULL';
      if (col.key === 'PRI') result += ' PK';
      else if (col.key === 'UNI') result += ' UNIQUE';
      else if (col.key === 'MUL') result += ' INDEX';
      if (col.defaultValue != null) result += ` DEFAULT ${col.defaultValue}`;
      if (col.extra) result += ` ${col.extra}`;
      if (col.comment) result += ` -- ${col.comment}`;
      return result;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must carry behavioral disclosure. It indicates the tool shows schema/structure without side effects, but lacks details on error handling (e.g., if table doesn't exist), authorization needs, or whether it's read-only. Adequate but not comprehensive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences: first explains purpose, second adds usage guidance and sibling reference. No redundant information; every sentence is valuable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple schema inspection tool with 2 params, the description covers purpose, usage, and differentiation. However, it omits mention of output format or error behavior. No output schema exists, so description could hint at return structure.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with both parameters well-described. The description does not add additional semantic meaning beyond what's in the schema, so baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description starts with 'Show the schema/structure of a table, including column names, types, constraints, and comments,' clearly identifying the verb and resource. It specifies the output content and distinguishes itself from the sibling tool 'describe_all_tables'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use: 'Use this before writing queries to ensure correct column names and types.' Also says to use 'describe_all_tables' instead for inspecting all tables, providing a clear alternative.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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