list_tables
Retrieve a list of all tables in the current MySQL database. Use this tool to quickly access and manage table names for efficient database navigation and query execution.
Instructions
Get a list of tables in the current database.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| random_string | Yes | Dummy parameter for no-parameter tools |
Input Schema (JSON Schema)
{
"properties": {
"random_string": {
"description": "Dummy parameter for no-parameter tools",
"type": "string"
}
},
"required": [
"random_string"
],
"type": "object"
}
Implementation Reference
- src/index.ts:431-452 (handler)The handler for the "list_tables" tool within the CallToolRequestSchema switch statement. It executes a "SHOW TABLES" query using the shared executeQuery function and returns the result as JSON or an error message.case "list_tables": { try { const rows = await executeQuery("SHOW TABLES"); return { content: [{ type: "text", text: JSON.stringify(rows, null, 2) }], isError: false }; } catch (error) { return { content: [ { type: "text", text: error instanceof Error ? error.message : "Unknown error occurred" } ], isError: true }; } }
- src/index.ts:203-216 (registration)Registration of the "list_tables" tool in the ListToolsRequestSchema response. Includes the tool name, description, and input schema definition (using a dummy parameter since no real inputs are needed).{ name: "list_tables", description: "Get a list of tables in the current database.", inputSchema: { type: "object", properties: { random_string: { type: "string", description: "Dummy parameter for no-parameter tools" } }, required: ["random_string"] } },
- src/index.ts:206-215 (schema)Input schema for the "list_tables" tool, which requires a dummy 'random_string' parameter as it's a no-parameter tool.inputSchema: { type: "object", properties: { random_string: { type: "string", description: "Dummy parameter for no-parameter tools" } }, required: ["random_string"] }
- src/index.ts:117-133 (helper)Shared helper function 'executeQuery' used by the list_tables handler to safely execute the SQL query, including read-only mode validation.async function executeQuery(sql: string, params: any[] = []): Promise<any> { const conn = await getConnection(); // Check if in readonly mode and validate query type if (connectionConfig.readonly) { const queryType = getQueryType(sql); if (isWriteOperation(queryType)) { throw new Error( "Server is in read-only mode. Write operations are not allowed." ); } } // Execute the query const [rows] = await conn.query(sql, params); return rows; }