list_databases
Retrieve all database names from a MySQL server to view available data repositories for management or query operations.
Instructions
List all databases on the MySQL server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:213-229 (handler)The handler function for the 'list_databases' tool. It retrieves the connection pool, executes 'SHOW DATABASES' to list all databases, maps the results to an array of database names, and returns both text and structured content.async () => { const p = await getPool(); const [rows] = await p.query<RowDataPacket[]>("SHOW DATABASES"); const databases = rows.map((row) => row.Database as string); const output = { databases }; return { content: [ { type: "text" as const, text: JSON.stringify(databases, null, 2), }, ], structuredContent: output, }; }
- src/index.ts:209-230 (registration)Registration of the 'list_databases' tool using McpServer's tool method, specifying name, description, input schema (empty), and inline handler function.server.tool( "list_databases", "List all databases on the MySQL server", {}, async () => { const p = await getPool(); const [rows] = await p.query<RowDataPacket[]>("SHOW DATABASES"); const databases = rows.map((row) => row.Database as string); const output = { databases }; return { content: [ { type: "text" as const, text: JSON.stringify(databases, null, 2), }, ], structuredContent: output, }; } );
- src/index.ts:212-212 (schema)Input schema for the 'list_databases' tool, defined as an empty object indicating no input parameters are required.{},
- src/index.ts:76-81 (helper)Shared helper function 'getPool' used by the list_databases handler to obtain the MySQL connection pool.async function getPool(): Promise<Pool> { if (!pool) { pool = mysql.createPool(getConnectionConfig()); } return pool; }