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
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | Yes | 表名称 | |
| database | No | 数据库名称(可选) |
Implementation Reference
- src/server.ts:105-116 (schema)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'], }, },
- src/server.ts:356-367 (handler)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)}`, }, ], }; }
- src/database.ts:149-170 (handler)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[]; }
- src/types.ts:26-33 (schema)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;