Skip to main content
Glama
sussa3007

MySql MCP Server

list_tables

Retrieve a list of all tables in the current MySQL database. Use this tool to quickly access and manage table names for efficient database navigation and query execution.

Instructions

Get a list of tables in the current database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
random_stringYesDummy parameter for no-parameter tools

Implementation Reference

  • The handler for the "list_tables" tool within the CallToolRequestSchema switch statement. It executes a "SHOW TABLES" query using the shared executeQuery function and returns the result as JSON or an error message.
    case "list_tables": {
      try {
        const rows = await executeQuery("SHOW TABLES");
        return {
          content: [{ type: "text", text: JSON.stringify(rows, null, 2) }],
          isError: false
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text:
                error instanceof Error
                  ? error.message
                  : "Unknown error occurred"
            }
          ],
          isError: true
        };
      }
    }
  • src/index.ts:203-216 (registration)
    Registration of the "list_tables" tool in the ListToolsRequestSchema response. Includes the tool name, description, and input schema definition (using a dummy parameter since no real inputs are needed).
    {
      name: "list_tables",
      description: "Get a list of tables in the current database.",
      inputSchema: {
        type: "object",
        properties: {
          random_string: {
            type: "string",
            description: "Dummy parameter for no-parameter tools"
          }
        },
        required: ["random_string"]
      }
    },
  • Input schema for the "list_tables" tool, which requires a dummy 'random_string' parameter as it's a no-parameter tool.
    inputSchema: {
      type: "object",
      properties: {
        random_string: {
          type: "string",
          description: "Dummy parameter for no-parameter tools"
        }
      },
      required: ["random_string"]
    }
  • Shared helper function 'executeQuery' used by the list_tables handler to safely execute the SQL query, including read-only mode validation.
    async function executeQuery(sql: string, params: any[] = []): Promise<any> {
      const conn = await getConnection();
    
      // Check if in readonly mode and validate query type
      if (connectionConfig.readonly) {
        const queryType = getQueryType(sql);
        if (isWriteOperation(queryType)) {
          throw new Error(
            "Server is in read-only mode. Write operations are not allowed."
          );
        }
      }
    
      // Execute the query
      const [rows] = await conn.query(sql, params);
      return rows;
    }
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/sussa3007/mysql-mcp'

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