list_tables
Retrieve a complete list of tables in a MySQL database using the MCP MySQL Server interface, enabling efficient database management and navigation.
Instructions
List all tables in the database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| random_string | No | Dummy parameter for no-parameter tools |
Input Schema (JSON Schema)
{
"properties": {
"random_string": {
"description": "Dummy parameter for no-parameter tools",
"type": "string"
}
},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:415-439 (handler)The handler function for the 'list_tables' tool. It ensures a database connection, executes 'SHOW TABLES' query using the MySQL connection pool, logs the operation, and returns the list of tables as a formatted JSON string in the MCP response format.private async handleListTables(requestId: string) { await this.ensureConnection(); try { console.error(`[${requestId}] Executing SHOW TABLES`); const [rows] = await this.pool!.query('SHOW TABLES'); console.error(`[${requestId}] SHOW TABLES completed, found ${Array.isArray(rows) ? rows.length : 0} tables`); return { content: [ { type: 'text', text: JSON.stringify(rows, null, 2), }, ], }; } catch (error) { const errorMsg = getErrorMessage(error); console.error(`[${requestId}] Failed to list tables: ${errorMsg}`); throw new McpError( ErrorCode.InternalError, `Failed to list tables: ${errorMsg}` ); } }
- src/index.ts:236-249 (registration)Registration of the 'list_tables' tool in the ListToolsRequestSchema handler. Defines the tool name, description, and input schema (with no required parameters).{ name: 'list_tables', description: 'List all tables in the database', inputSchema: { type: 'object', properties: { random_string: { type: 'string', description: 'Dummy parameter for no-parameter tools', } }, required: [], // 修改为可选参数 }, },
- src/index.ts:239-248 (schema)Input schema definition for the 'list_tables' tool, specifying an optional dummy parameter since the tool takes no real inputs.inputSchema: { type: 'object', properties: { random_string: { type: 'string', description: 'Dummy parameter for no-parameter tools', } }, required: [], // 修改为可选参数 },