mysql_list_tables
List all tables in a MySQL database to view structure and manage data organization. Specify a database name or use the current connection.
Instructions
列出指定数据库的所有表
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | 数据库名称(可选,使用当前连接的数据库) |
Implementation Reference
- src/server.ts:343-354 (handler)The handler function for the 'mysql_list_tables' tool. It calls DatabaseManager.listTables and returns the formatted result as tool content.private async handleListTables(args: { database?: string }): Promise<any> { const tables = await this.dbManager.listTables(args.database); return { content: [ { type: 'text', text: `表列表:\n${JSON.stringify(tables, null, 2)}`, }, ], }; }
- src/database.ts:123-144 (helper)Core implementation in DatabaseManager that executes the SQL query against information_schema.TABLES to list tables in the specified database.async listTables(database?: string): Promise<TableInfo[]> { const dbName = database || this.config?.database; if (!dbName) { throw new Error('请指定数据库名称'); } const result = await this.query(` SELECT TABLE_NAME as name, ENGINE as engine, TABLE_ROWS as rows, DATA_LENGTH as dataLength, INDEX_LENGTH as indexLength, TABLE_COMMENT as comment FROM information_schema.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME `, [dbName]); return result.rows as TableInfo[]; }
- src/server.ts:96-104 (schema)Input schema definition for the 'mysql_list_tables' tool, specifying optional 'database' parameter.name: 'mysql_list_tables', description: '列出指定数据库的所有表', inputSchema: { type: 'object', properties: { database: { type: 'string', description: '数据库名称(可选,使用当前连接的数据库)' }, }, }, },
- src/server.ts:243-244 (registration)Switch case registration that routes 'mysql_list_tables' tool calls to the handleListTables handler.case 'mysql_list_tables': return await this.handleListTables(args as any);