Skip to main content
Glama
sajithrw

MCP MySQL Server

by sajithrw

mysql_describe_table

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

Instructions

Get the structure/schema of a specific table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name to describe
databaseNoDatabase name (uses current database if not specified)

Implementation Reference

  • The main handler function for the 'mysql_describe_table' tool. It validates input, constructs the DESCRIBE query for the specified table (optionally in a database), executes it using the MySQL pool, and returns the table structure as JSON-formatted text.
    private async handleDescribeTable(args: any) {
      if (!this.pool) {
        throw new Error("Not connected to MySQL. Use mysql_connect first.");
      }
    
      const { table, database } = args;
      
      if (!table) {
        throw new Error("Table name is required");
      }
    
      const fullTableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``;
    
      try {
        const [results] = await this.pool.execute(`DESCRIBE ${fullTableName}`);
        return {
          content: [
            {
              type: "text",
              text: `Table structure for '${table}':\n${JSON.stringify(results, null, 2)}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`Failed to describe table: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Input schema definition for the 'mysql_describe_table' tool, specifying a required 'table' string and optional 'database' string.
    inputSchema: {
      type: "object",
      properties: {
        table: {
          type: "string",
          description: "Table name to describe",
        },
        database: {
          type: "string",
          description: "Database name (uses current database if not specified)",
        },
      },
      required: ["table"],
    },
  • src/index.ts:178-195 (registration)
    Tool registration in the listTools response, defining name, description, and input schema for 'mysql_describe_table'.
    {
      name: "mysql_describe_table",
      description: "Get the structure/schema of a specific table",
      inputSchema: {
        type: "object",
        properties: {
          table: {
            type: "string",
            description: "Table name to describe",
          },
          database: {
            type: "string",
            description: "Database name (uses current database if not specified)",
          },
        },
        required: ["table"],
      },
    },
  • src/index.ts:257-258 (registration)
    Dispatch registration in the CallToolRequest handler switch statement, mapping 'mysql_describe_table' to its handler function.
    case "mysql_describe_table":
      return await this.handleDescribeTable(args);

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

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