Skip to main content
Glama
yawlhead91

MariaDB MCP Server

by yawlhead91

list_tables

Retrieve all table names from a MariaDB database to inspect its structure and contents.

Instructions

List all tables in a specific database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNo

Implementation Reference

  • The core handler function for the 'list_tables' MCP tool. It is registered using the @mcp.tool() decorator and implements the logic to list tables in a MariaDB database using the SHOW TABLES SQL command, handling optional database specification and formatting the output as a bullet list.
    @mcp.tool()
    async def list_tables(database: Optional[str] = None) -> str:
        """List all tables in a specific database."""
        try:
            if database:
                # Use the specified database
                query = f"SHOW TABLES FROM `{database}`"
            else:
                # Use current database
                query = "SHOW TABLES"
            
            results = await db_connection.execute_query(query)
            
            if not results:
                db_name = database or "current database"
                return f"No tables found in {db_name}"
            
            # Get table name from result (column name varies)
            tables = []
            for row in results:
                # The column name is usually "Tables_in_<database_name>"
                table_name = list(row.values())[0]
                tables.append(table_name)
            
            db_name = database or "current database"
            return f"Tables in {db_name} ({len(tables)}):\n" + "\n".join(f"- {table}" for table in tables)
        
        except Exception as e:
            logger.error(f"Error listing tables: {e}")
            return f"Error listing tables: {str(e)}"

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/yawlhead91/mariadb-mcp'

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