list_databases
List all databases on a MySQL server to discover available ones before querying. Returns a JSON array of database names.
Instructions
List all databases on the MySQL server. Use this as a starting point to discover available databases before querying. Returns a JSON array of database names.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/list-databases.ts:14-29 (handler)The core handler function that executes 'SHOW DATABASES' and returns the list as JSON. Created via createListDatabasesHandler factory which takes a QueryRunner.
export function createListDatabasesHandler(runner: QueryRunner) { return async () => { try { const [rows] = await runner.query('SHOW DATABASES'); const databases = (rows as Record<string, string>[]).map((r) => Object.values(r)[0]); return { content: [{ type: 'text' as const, text: JSON.stringify(databases) }], }; } catch (error) { return { isError: true as const, content: [{ type: 'text' as const, text: formatError(error) }], }; } }; } - src/tools/list-databases.ts:6-12 (schema)Configuration object defining the tool's title and description. No inputSchema is defined since list_databases takes no arguments.
export const listDatabasesToolConfig = { title: 'List Databases', description: 'List all databases on the MySQL server. ' + 'Use this as a starting point to discover available databases before querying. ' + 'Returns a JSON array of database names.', }; - src/tools/index.ts:28-28 (registration)Registration of the 'list_databases' tool on the MCP server via server.tool(). Note it only passes description (no inputSchema) since the tool takes no arguments.
server.tool(listDatabasesToolName, listDatabasesToolConfig.description, createListDatabasesHandler(runner)); - src/tools/list-databases.ts:4-4 (registration)Export of the tool name constant 'list_databases'.
export const listDatabasesToolName = 'list_databases'; - src/tools/error-hint.ts:4-4 (helper)Error hint referencing list_databases. When MySQL returns 'Unknown database', the error formatter appends a hint to use list_databases to check available databases.
[/Unknown database/i, 'Hint: use list_databases to check available databases.'],