Skip to main content
Glama
zhaojw-php

MySQL ReadOnly MCP Server

by zhaojw-php

mysql_list_tables

Retrieve a list of all tables in a MySQL database to explore its structure and available data.

Instructions

List all tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNoDatabase name (optional, defaults to configured database)

Implementation Reference

  • Core handler logic for the mysql_list_tables tool: executes SHOW TABLES query and extracts table names.
    async listTables(database?: string): Promise<string[]> {
      const dbName = database || this.config.database;
      if (!dbName) {
        throw new Error('No database specified');
      }
    
      const query = `SHOW TABLES FROM \`${dbName}\``;
      const result = await this.executeQuery(query);
    
      // Extract table names from result
      return result.rows.map((row: any) => {
        const key = Object.keys(row)[0]; // Get the first column name
        return row[key];
      });
    }
  • MCP tool dispatcher case for mysql_list_tables: parses args, calls listTables, and returns JSON response.
    case 'mysql_list_tables': {
      const { database } = args as { database?: string };
      const result = await mysqlConnection.listTables(database);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • Tool schema and registration: defines name, description, and input schema for mysql_list_tables.
    {
      name: 'mysql_list_tables',
      description: 'List all tables in the database',
      inputSchema: {
        type: 'object',
        properties: {
          database: {
            type: 'string',
            description: 'Database name (optional, defaults to configured database)',
          },
        },
      },
    },

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