list_databases
Retrieve all database names from a MySQL server to manage database inventory and access permissions.
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)Handler function that gets the MySQL connection pool, executes 'SHOW DATABASES' query, extracts database names, and returns formatted 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:212-212 (schema)Input schema for the list_databases tool, which requires no parameters.{},
- src/index.ts:209-230 (registration)Registration of the list_databases tool using McpServer.tool method, including name, description, schema, and handler.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, }; } );