Skip to main content
Glama
voducdan

metabase-mcp

by voducdan

list_tables

Retrieve a list of all tables in a database by supplying its ID. Outputs a formatted markdown table showing table details.

Instructions

List all tables in a specific database.

Args: database_id: The ID of the database to query.

Returns: Formatted markdown table showing table details.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'list_tables' tool handler function. It takes a database_id parameter, fetches table metadata from Metabase via GET /api/database/{database_id}/metadata, extracts table info (id, display_name, description, entity_type), sorts by display_name, and returns formatted markdown output.
    async def list_tables(database_id: int, ctx: Context) -> str:
        """
        List all tables in a specific database.
    
        Args:
            database_id: The ID of the database to query.
    
        Returns:
            Formatted markdown table showing table details.
        """
        try:
            await ctx.info(f"Fetching tables for database {database_id}")
            result = await metabase_client.request("GET", f"/database/{database_id}/metadata")
    
            # Extract and format tables
            tables = result.get("tables", [])
            await ctx.debug(f"Found {len(tables)} tables in database {database_id}")
    
            formatted_tables = [
                {
                    "table_id": table.get("id"),
                    "display_name": table.get("display_name"),
                    "description": table.get("description") or "No description",
                    "entity_type": table.get("entity_type")
                }
                for table in tables
            ]
    
            # Sort for better readability
            formatted_tables.sort(key=lambda x: x.get("display_name", ""))
    
            # Generate markdown output
            markdown_output = f"# Tables in Database {database_id}\n\n"
            markdown_output += f"**Total Tables:** {len(formatted_tables)}\n\n"
    
            if not formatted_tables:
                await ctx.warning(f"No tables found in database {database_id}")
                markdown_output += "*No tables found in this database.*\n"
                return markdown_output
    
            # Create markdown table
            markdown_output += "| Table ID | Display Name | Description | Entity Type |\n"
            markdown_output += "|----------|--------------|-------------|--------------|\n"
    
            for table in formatted_tables:
                table_id = table.get("table_id", "N/A")
                display_name = table.get("display_name", "N/A")
                description = table.get("description", "No description")
                entity_type = table.get("entity_type", "N/A")
    
                # Escape pipe characters
                description = description.replace("|", "\\|")
                display_name = display_name.replace("|", "\\|")
    
                markdown_output += f"| {table_id} | {display_name} | {description} | {entity_type} |\n"
    
            await ctx.info(f"Successfully formatted {len(formatted_tables)} tables")
            return markdown_output
    
        except Exception as e:
            error_msg = f"Error listing tables for database {database_id}: {e}"
            await ctx.error(error_msg)
            raise ToolError(error_msg) from e
  • server.py:159-159 (registration)
    The '@mcp.tool' decorator that registers the 'list_tables' function as an MCP tool with the FastMCP server instance.
    @mcp.tool
  • The function signature defines the input schema: 'database_id: int' is the required parameter, and 'ctx: Context' is the MCP context. The return type is 'str' (formatted markdown).
    async def list_tables(database_id: int, ctx: Context) -> str:

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description discloses the return format (formatted markdown table) and specifies the required input. While read-only behavior is implied, the lack of annotations makes this acceptable for a simple list operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is brief and well-structured, including purpose, args, and returns in a clean format with no unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers the core functionality, input, and output format. However, it lacks details on error handling or behavior with invalid database IDs, which would enhance completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description compensates by explaining that database_id is 'the ID of the database to query', adding semantic meaning beyond the schema's type-only constraint.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'list' and resource 'tables' scoped to a specific database, distinguishing it from sibling tools like list_databases or list_cards.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives such as get_table_fields or list_databases. The description provides no exclusions or context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.