Skip to main content
Glama
sajithrw

MCP MySQL Server

by sajithrw

mysql_list_databases

Retrieve a complete list of all databases available on your MySQL server for database management and selection purposes.

Instructions

List all databases on the MySQL server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'mysql_list_databases' tool. It verifies an active connection, executes the 'SHOW DATABASES' SQL query using the MySQL pool, formats the results as a JSON string, and returns them in the tool response format.
    private async handleListDatabases() { if (!this.pool) { throw new Error("Not connected to MySQL. Use mysql_connect first."); } try { const [results] = await this.pool.execute("SHOW DATABASES"); return { content: [ { type: "text", text: `Available databases:\n${JSON.stringify(results, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to list databases: ${error instanceof Error ? error.message : String(error)}`); } }
  • src/index.ts:253-254 (registration)
    Switch case in the CallToolRequest handler that dispatches calls to the mysql_list_databases tool to its handler function.
    case "mysql_list_databases": return await this.handleListDatabases();
  • Tool schema and registration in the ListToolsRequest response, defining the tool name, description, and empty input schema (no parameters required).
    { name: "mysql_list_databases", description: "List all databases on the MySQL server", inputSchema: { type: "object", properties: {}, }, },
  • src/index.ts:97-242 (registration)
    Overall tool registration handler where mysql_list_databases is listed among other tools.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "mysql_connect", description: "Connect to a MySQL database with provided connection parameters", inputSchema: { type: "object", properties: { host: { type: "string", description: "MySQL server hostname or IP address", }, port: { type: "number", description: "MySQL server port (default: 3306)", default: 3306, }, user: { type: "string", description: "Database username", }, password: { type: "string", description: "Database password", }, database: { type: "string", description: "Database name (optional)", }, ssl: { type: "boolean", description: "Use SSL connection (default: false)", default: false, }, }, required: ["host", "user", "password"], }, }, { name: "mysql_query", description: "Execute a SQL query on the connected MySQL database", inputSchema: { type: "object", properties: { query: { type: "string", description: "SQL query to execute", }, parameters: { type: "array", description: "Parameters for prepared statement (optional)", items: { type: "string", }, }, }, required: ["query"], }, }, { name: "mysql_list_databases", description: "List all databases on the MySQL server", inputSchema: { type: "object", properties: {}, }, }, { name: "mysql_list_tables", description: "List all tables in the current or specified database", inputSchema: { type: "object", properties: { database: { type: "string", description: "Database name (uses current database if not specified)", }, }, }, }, { name: "mysql_describe_table", description: "Get the structure/schema of a specific table", inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to describe", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], }, }, { name: "mysql_show_indexes", description: "Show indexes for a specific table", inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to show indexes for", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], }, }, { name: "mysql_get_table_stats", description: "Get statistics about a table (row count, size, etc.)", inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to get statistics for", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], }, }, { name: "mysql_disconnect", description: "Disconnect from the MySQL database", inputSchema: { type: "object", properties: {}, }, }, ], }; });

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/sajithrw/mcp-mysql'

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