Skip to main content
Glama
sussa3007

MySql MCP Server

list_databases

Retrieve a complete list of accessible databases on the MySQL MCP Server to manage connections efficiently and enhance structured data access for streamlined workflows.

Instructions

Get a list of all accessible databases on the server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
random_stringYesDummy parameter for no-parameter tools

Implementation Reference

  • Handler for the 'list_databases' tool. Executes 'SHOW DATABASES' query via executeQuery helper and returns the list of databases as JSON, with error handling.
    case "list_databases": {
      try {
        const rows = await executeQuery("SHOW DATABASES");
        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:231-244 (registration)
    Registration of the 'list_databases' tool in the ListToolsRequestHandler, including name, description, and input schema (dummy param for no-args tool).
    {
      name: "list_databases",
      description: "Get a list of all accessible databases on the server.",
      inputSchema: {
        type: "object",
        properties: {
          random_string: {
            type: "string",
            description: "Dummy parameter for no-parameter tools"
          }
        },
        required: ["random_string"]
      }
    },
  • Input schema definition for the 'list_databases' tool, requiring a dummy 'random_string' parameter.
    inputSchema: {
      type: "object",
      properties: {
        random_string: {
          type: "string",
          description: "Dummy parameter for no-parameter tools"
        }
      },
      required: ["random_string"]
    }
  • Shared helper function executeQuery used by list_databases to run the SQL query, includes read-only 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