Skip to main content
Glama
Malove86

MCP MySQL Server

by Malove86

list_tables

Retrieve a complete list of tables in a MySQL database using the MCP MySQL Server interface, enabling efficient database management and navigation.

Instructions

List all tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
random_stringNoDummy parameter for no-parameter tools

Implementation Reference

  • The handler function for the 'list_tables' tool. It ensures a database connection, executes 'SHOW TABLES' query using the MySQL connection pool, logs the operation, and returns the list of tables as a formatted JSON string in the MCP response format.
    private async handleListTables(requestId: string) {
      await this.ensureConnection();
    
      try {
        console.error(`[${requestId}] Executing SHOW TABLES`);
        const [rows] = await this.pool!.query('SHOW TABLES');
        console.error(`[${requestId}] SHOW TABLES completed, found ${Array.isArray(rows) ? rows.length : 0} tables`);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(rows, null, 2),
            },
          ],
        };
      } catch (error) {
        const errorMsg = getErrorMessage(error);
        console.error(`[${requestId}] Failed to list tables: ${errorMsg}`);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to list tables: ${errorMsg}`
        );
      }
    }
  • src/index.ts:236-249 (registration)
    Registration of the 'list_tables' tool in the ListToolsRequestSchema handler. Defines the tool name, description, and input schema (with no required parameters).
    {
      name: 'list_tables',
      description: 'List all tables in the database',
      inputSchema: {
        type: 'object',
        properties: {
          random_string: {
            type: 'string',
            description: 'Dummy parameter for no-parameter tools',
          }
        },
        required: [], // 修改为可选参数
      },
    },
  • Input schema definition for the 'list_tables' tool, specifying an optional dummy parameter since the tool takes no real inputs.
    inputSchema: {
      type: 'object',
      properties: {
        random_string: {
          type: 'string',
          description: 'Dummy parameter for no-parameter tools',
        }
      },
      required: [], // 修改为可选参数
    },
Install Server

Other Tools

Related Tools

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

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