list_tables
Retrieve all tables within a MariaDB database. Use this tool to explore database schemas and inspect table structures for better data management and analysis.
Instructions
List all tables in a specific database.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No |
Implementation Reference
- src/mariadb_mcp/server.py:200-229 (handler)The handler function for the list_tables tool. It executes a SHOW TABLES query on the specified or current database, extracts table names from the results, and formats them as a list. The @mcp.tool() decorator registers it as an MCP tool.@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)}"