Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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, }; } );
  • Input schema for the 'list_databases' tool, defined as an empty object indicating no input parameters are required.
    {},
  • 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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nilsir/mcp-server-mysql'

If you have feedback or need assistance with the MCP directory API, please join our Discord server