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:
Behavior3/5

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

The description implies a read-only operation ('list') and specifies the return format (markdown table), but does not explicitly state side effects, authentication needs, or permissions. With no annotations, more behavioral details would be beneficial.

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?

Extremely concise with no wasted words. The key purpose is front-loaded, followed by structured Args/Returns sections.

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?

Given the tool's simplicity (one parameter) and the existence of an output schema (which covers return details), the description is sufficiently complete. It covers purpose, parameter explanation, and return format.

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?

The description adds meaning to the lone parameter 'database_id' ('The ID of the database to query') beyond the schema's type-only specification. This compensates for the 0% schema description coverage.

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 tool's action ('list'), resource ('tables'), and constraint ('in a specific database'), distinguishing it from siblings like 'list_databases' and 'get_table_fields'.

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. The description does not mention prerequisites, exclusions, or compare with similar tools like 'list_databases' or 'get_table_fields'.

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

Install Server

Other 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/voducdan/matebase-mcp'

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