Skip to main content
Glama

mysql_schema

Inspect WordPress database schema to list tables or view columns and indexes for development analysis.

Instructions

Inspect database schema. Without args: lists tables. With table: shows columns and indexes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableNoOptional table name to inspect

Implementation Reference

  • Handler function for the 'mysql_schema' tool. If no table is provided, lists all tables. Otherwise, fetches columns and indexes for the specified table using MySQLClient methods and returns JSON-formatted results.
    case 'mysql_schema': { const table = args.table as string | undefined; if (!table) { const tables = await mysql.listTables(); return { content: [{ type: 'text', text: JSON.stringify(tables, null, 2) }] }; } const [columns, indexes] = await Promise.all([ mysql.getTableColumns(table), mysql.getTableIndexes(table), ]); return { content: [ { type: 'text', text: JSON.stringify({ table, columns, indexes }, null, 2), }, ], }; }
  • Input schema definition for the mysql_schema tool, defining an optional 'table' string parameter.
    inputSchema: { type: 'object', properties: { table: { type: 'string', description: 'Optional table name to inspect', }, }, },
  • src/index.ts:81-94 (registration)
    Registration of the mysql_schema tool in the tools array returned by ListToolsRequestHandler.
    { name: 'mysql_schema', description: 'Inspect database schema. Without args: lists tables. With table: shows columns and indexes.', inputSchema: { type: 'object', properties: { table: { type: 'string', description: 'Optional table name to inspect', }, }, }, }, ];
  • Helper method to list all tables in the database, used when no table is specified in mysql_schema.
    async listTables(): Promise<any[]> { const sql = ` SELECT TABLE_NAME AS table_name, ENGINE AS engine, TABLE_ROWS AS table_rows, DATA_LENGTH AS data_length, INDEX_LENGTH AS index_length FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME `; return this.executeReadOnlyQuery(sql); }
  • Helper method to retrieve column information for a specific table, used in mysql_schema handler.
    async getTableColumns(table: string): Promise<any[]> { this.ensureSafeIdentifier(table); const sql = ` SELECT COLUMN_NAME AS column_name, COLUMN_TYPE AS column_type, DATA_TYPE AS data_type, IS_NULLABLE AS is_nullable, COLUMN_DEFAULT AS column_default, COLUMN_KEY AS column_key, EXTRA AS extra FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? ORDER BY ORDINAL_POSITION `; return this.executeReadOnlyQuery(sql, [table]); }
  • Helper method to retrieve index information for a specific table, used in mysql_schema handler.
    async getTableIndexes(table: string): Promise<any[]> { this.ensureSafeIdentifier(table); const sql = ` SELECT INDEX_NAME AS index_name, NON_UNIQUE AS non_unique, SEQ_IN_INDEX AS seq_in_index, COLUMN_NAME AS column_name, INDEX_TYPE AS index_type FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? ORDER BY index_name, seq_in_index `; return this.executeReadOnlyQuery(sql, [table]); }
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/verygoodplugins/mcp-local-wp'

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