Skip to main content
Glama
pickstar-2002

MySQL MCP Server

mysql_describe_table

View MySQL table structure including columns, data types, and constraints to understand database schema and plan queries.

Instructions

查看表结构

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableNameYes表名称
databaseNo数据库名称(可选)

Implementation Reference

  • Defines the input schema, description, and registers the mysql_describe_table tool in the ListTools response.
    {
      name: 'mysql_describe_table',
      description: '查看表结构',
      inputSchema: {
        type: 'object',
        properties: {
          tableName: { type: 'string', description: '表名称' },
          database: { type: 'string', description: '数据库名称(可选)' },
        },
        required: ['tableName'],
      },
    },
  • MCP server handler for mysql_describe_table tool that calls DatabaseManager.describeTable and returns formatted response.
    private async handleDescribeTable(args: { tableName: string; database?: string }): Promise<any> {
      const columns = await this.dbManager.describeTable(args.tableName, args.database);
      
      return {
        content: [
          {
            type: 'text',
            text: `表 ${args.tableName} 结构:\n${JSON.stringify(columns, null, 2)}`,
          },
        ],
      };
    }
  • Core implementation in DatabaseManager that executes the SQL query against information_schema.COLUMNS to retrieve table structure.
    async describeTable(tableName: string, database?: string): Promise<ColumnInfo[]> {
      const dbName = database || this.config?.database;
      if (!dbName) {
        throw new Error('请指定数据库名称');
      }
    
      const result = await this.query(`
        SELECT 
          COLUMN_NAME as field,
          COLUMN_TYPE as type,
          IS_NULLABLE as \`null\`,
          COLUMN_KEY as \`key\`,
          COLUMN_DEFAULT as \`default\`,
          EXTRA as extra,
          COLUMN_COMMENT as comment
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?
        ORDER BY ORDINAL_POSITION
      `, [dbName, tableName]);
      
      return result.rows as ColumnInfo[];
    }
  • Type definition for ColumnInfo used in the describeTable output.
    export interface ColumnInfo {
      field: string;
      type: string;
      null: string;
      key: string;
      default: string | null;
      extra: string;
      comment: string;

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

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