mysql_describe_table
Retrieve the structure of a MySQL table, including columns, data types, and constraints, by specifying the table and optional database name via the MySQL MCP Server.
Instructions
查看表结构
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | 数据库名称(可选) | |
| tableName | Yes | 表名称 |
Implementation Reference
- src/database.ts:149-170 (handler)Core handler implementation: executes DESCRIBE-like query on information_schema.COLUMNS to retrieve table structure (columns, types, nullability, etc.). This is the exact logic for mysql_describe_table.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/server.ts:356-367 (handler)MCP server handler wrapper: calls DatabaseManager.describeTable and returns formatted text 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/server.ts:105-116 (schema)Tool schema definition: input schema for mysql_describe_table including parameters tableName (required) and database (optional).{ name: 'mysql_describe_table', description: '查看表结构', inputSchema: { type: 'object', properties: { tableName: { type: 'string', description: '表名称' }, database: { type: 'string', description: '数据库名称(可选)' }, }, required: ['tableName'], }, },
- src/server.ts:245-246 (registration)Tool dispatch registration: switch case mapping tool name to handler in CallToolRequest handler.case 'mysql_describe_table': return await this.handleDescribeTable(args as any);