mysql_schema
Retrieve database schema for local WordPress sites. Lists all tables or details columns and indexes for a specified table.
Instructions
Inspect database schema. Without args: lists tables. With table: shows columns and indexes.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | No | Optional table name to inspect |
Implementation Reference
- src/index.ts:186-204 (handler)The handler for the 'mysql_schema' tool. If no table argument is given, it calls mysql.listTables() to list all tables. If a table argument is provided, it calls mysql.getTableColumns(table) and mysql.getTableIndexes(table) in parallel and returns the schema info.
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), }, ], }; } - src/index.ts:101-113 (schema)The tool schema/definition for 'mysql_schema'. It defines the tool name, description, and input schema with an optional 'table' string parameter.
{ 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', }, }, }, }, - src/index.ts:81-131 (registration)The 'mysql_schema' tool is registered as part of the 'tools' array on line 101-113 (within the array defined at line 81). The array is used in the ListToolsRequestSchema handler to advertise available tools.
const tools: Tool[] = [ { name: 'mysql_query', description: 'Execute a read-only SQL query against the Local WordPress database', inputSchema: { type: 'object', properties: { sql: { type: 'string', description: 'Single read-only SQL statement (SELECT/SHOW/DESCRIBE/EXPLAIN).', }, params: { type: 'array', description: 'Optional parameter values for placeholders (?).', items: { type: 'string' }, }, }, required: ['sql'], }, }, { 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', }, }, }, }, { name: 'mysql_current_site', description: 'Get information about the currently connected Local WordPress site, including how it was selected', inputSchema: { type: 'object', properties: {}, }, }, { name: 'mysql_list_sites', description: 'List all available Local WordPress sites and their running status', inputSchema: { type: 'object', properties: {}, }, }, ]; - src/mysql-client.ts:137-150 (helper)MySQLClient.listTables() method — queries information_schema.TABLES to list all base tables in the current database.
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); } - src/mysql-client.ts:152-168 (helper)MySQLClient.getTableColumns(table) method — queries information_schema.COLUMNS to get column details for a specific table.
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]); }