list_databases
Lists all databases for a specified MariaDB or MySQL connection, enabling you to view available schemas and explore the database structure.
Instructions
Lists databases for the selected connection.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection | Yes |
Implementation Reference
- src/index.js:67-72 (handler)The handler for the 'list_databases' tool. It extracts the 'connection' argument from the request, validates it is present, then executes 'SHOW DATABASES' via db.runReadOnly and returns the results.
case "list_databases": { const connection = args?.connection; if (!connection) return fail("'connection' field is required."); const rows = await db.runReadOnly(connection, "SHOW DATABASES"); return ok(rows); } - src/tools.js:13-21 (schema)The schema/tool definition for 'list_databases'. Defines the tool name, description, and input schema requiring a 'connection' parameter that references readable connections.
name: "list_databases", description: "Lists databases for the selected connection.", inputSchema: { type: "object", properties: { connection: { type: "string", enum: readableConnections }, }, required: ["connection"], }, - src/index.js:31-37 (registration)Registration of all tool definitions including 'list_databases' via the ListToolsRequestSchema handler, which calls buildToolDefinitions to produce the full tool list.
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: buildToolDefinitions( readableConnections, writableConnections, allConnections, ), })); - src/db.js:86-95 (helper)The runReadOnly helper method used by the 'list_databases' handler. It asserts the connection is readable, obtains a connection from the pool, executes the SQL query (SHOW DATABASES), and releases the connection.
async runReadOnly(connectionName, sql, options = {}) { this.assertReadable(connectionName); const database = options.database || null; const conn = await this.getPool(connectionName, database).getConnection(); try { return await conn.query(sql); } finally { conn.release(); } }