mysql_list_databases
Retrieve a complete list of all databases available on your MySQL server to identify and select the appropriate database for operations.
Instructions
List all databases on the MySQL server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:346-364 (handler)The core handler function that checks for an active connection, executes the 'SHOW DATABASES' SQL query using the MySQL pool, formats the results as JSON, and returns them in the MCP response format.private async handleListDatabases() { if (!this.pool) { throw new Error("Not connected to MySQL. Use mysql_connect first."); } try { const [results] = await this.pool.execute("SHOW DATABASES"); return { content: [ { type: "text", text: `Available databases:\n${JSON.stringify(results, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to list databases: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:157-164 (registration)Registers the 'mysql_list_databases' tool in the ListTools response, including its name, description, and empty input schema (no parameters required).{ name: "mysql_list_databases", description: "List all databases on the MySQL server", inputSchema: { type: "object", properties: {}, }, },
- src/index.ts:253-254 (registration)Switch case in the CallToolRequest handler that dispatches calls to 'mysql_list_databases' to the specific handler function.case "mysql_list_databases": return await this.handleListDatabases();
- src/index.ts:160-163 (schema)Defines the input schema for the tool: an empty object (no input parameters required).inputSchema: { type: "object", properties: {}, },