Skip to main content
Glama
zhaojw-php

MySQL ReadOnly MCP Server

by zhaojw-php

mysql_list_databases

Retrieve a list of all databases available in a MySQL server. This tool provides read-only access to database names for exploration and analysis.

Instructions

List all available databases

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler case for the mysql_list_databases tool. It invokes mysqlConnection.listDatabases() and returns the JSON-formatted result as text content.
    case 'mysql_list_databases': {
      const result = await mysqlConnection.listDatabases();
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • src/index.ts:77-84 (registration)
    Registration of the mysql_list_databases tool in the listTools handler, including its name, description, and empty input schema.
    {
      name: 'mysql_list_databases',
      description: 'List all available databases',
      inputSchema: {
        type: 'object',
        properties: {},
      },
    },
  • Core implementation of listDatabases method in MySQLConnection class. Executes 'SHOW DATABASES' query, extracts database names, and filters out system databases.
    async listDatabases(): Promise<string[]> {
      const query = 'SHOW DATABASES';
      const result = await this.executeQuery(query);
    
      // Extract database names from result
      return result.rows.map((row: any) => {
        const key = Object.keys(row)[0]; // Get the first column name
        return row[key];
      }).filter((db: string) => {
        // Filter out system databases
        return !['information_schema', 'mysql', 'performance_schema', 'sys'].includes(db);
      });
    }

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/zhaojw-php/mysql-readonly-mcp'

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