list_databases
Retrieve a complete list of accessible databases on the MySQL MCP Server to manage connections efficiently and enhance structured data access for streamlined workflows.
Instructions
Get a list of all accessible databases on the server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| random_string | Yes | Dummy parameter for no-parameter tools |
Implementation Reference
- src/index.ts:484-505 (handler)Handler for the 'list_databases' tool. Executes 'SHOW DATABASES' query via executeQuery helper and returns the list of databases as JSON, with error handling.case "list_databases": { try { const rows = await executeQuery("SHOW DATABASES"); return { content: [{ type: "text", text: JSON.stringify(rows, null, 2) }], isError: false }; } catch (error) { return { content: [ { type: "text", text: error instanceof Error ? error.message : "Unknown error occurred" } ], isError: true }; } }
- src/index.ts:231-244 (registration)Registration of the 'list_databases' tool in the ListToolsRequestHandler, including name, description, and input schema (dummy param for no-args tool).{ name: "list_databases", description: "Get a list of all accessible databases on the server.", inputSchema: { type: "object", properties: { random_string: { type: "string", description: "Dummy parameter for no-parameter tools" } }, required: ["random_string"] } },
- src/index.ts:234-243 (schema)Input schema definition for the 'list_databases' tool, requiring a dummy 'random_string' parameter.inputSchema: { type: "object", properties: { random_string: { type: "string", description: "Dummy parameter for no-parameter tools" } }, required: ["random_string"] }
- src/index.ts:117-133 (helper)Shared helper function executeQuery used by list_databases to run the SQL query, includes read-only validation.async function executeQuery(sql: string, params: any[] = []): Promise<any> { const conn = await getConnection(); // Check if in readonly mode and validate query type if (connectionConfig.readonly) { const queryType = getQueryType(sql); if (isWriteOperation(queryType)) { throw new Error( "Server is in read-only mode. Write operations are not allowed." ); } } // Execute the query const [rows] = await conn.query(sql, params); return rows; }