Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

list_tables

Retrieve all database tables with optional filtering by schema, including views and system tables as needed for schema discovery.

Instructions

List all tables in the database.

Args:
    schema: Filter by schema name (default: all user schemas).
    include_views: Include views in results.
    include_system: Include system tables.

Returns:
    List of tables with schema, name, and type.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNo
include_viewsNo
include_systemNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core implementation of list_tables tool: executes SQL query on information_schema.tables, applies filters for types (tables/views), schemas, system objects, and allowed schemas, processes and returns structured list of tables.
    async def list_tables(
        schema: str | None = None,
        include_views: bool = True,
        include_system: bool = False,
    ) -> dict[str, Any]:
        """List all tables in the database.
    
        Args:
            schema: Filter by schema name.
            include_views: Include views in results.
            include_system: Include system tables.
    
        Returns:
            List of tables.
        """
        conn = await connection_manager.ensure_connected()
    
        try:
            # Build type filter
            table_types = ["'BASE TABLE'"]
            if include_views:
                table_types.append("'VIEW'")
    
            type_filter = f"table_type IN ({','.join(table_types)})"
    
            # Build schema filter
            schema_filter = ""
            if schema:
                schema_filter = f"AND table_schema = '{schema}'"
            elif not include_system:
                schema_filter = """
                    AND table_schema NOT IN (
                        'crdb_internal', 'information_schema', 'pg_catalog', 'pg_extension'
                    )
                """
    
            query = f"""
                SELECT
                    table_schema,
                    table_name,
                    table_type
                FROM information_schema.tables
                WHERE {type_filter}
                {schema_filter}
                ORDER BY table_schema, table_name
            """
    
            async with conn.cursor() as cur:
                await cur.execute(query)
                rows = await cur.fetchall()
    
            tables = []
            for row in rows:
                schema_name = row.get("table_schema", "")
    
                # Check if schema is allowed
                if not _is_allowed_schema(schema_name):
                    continue
    
                tables.append(
                    {
                        "schema": schema_name,
                        "name": row.get("table_name", ""),
                        "type": "VIEW" if row.get("table_type") == "VIEW" else "TABLE",
                        "full_name": f"{schema_name}.{row.get('table_name', '')}",
                    }
                )
    
            return {
                "tables": tables,
                "count": len(tables),
                "database": connection_manager.current_database,
                "schema_filter": schema,
            }
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • MCP tool registration for 'list_tables' using @mcp.tool() decorator. Defines input schema via type hints and docstring, wraps the core handler from tables module with error handling.
    @mcp.tool()
    async def list_tables(
        schema: str | None = None,
        include_views: bool = True,
        include_system: bool = False,
    ) -> dict[str, Any]:
        """List all tables in the database.
    
        Args:
            schema: Filter by schema name (default: all user schemas).
            include_views: Include views in results.
            include_system: Include system tables.
    
        Returns:
            List of tables with schema, name, and type.
        """
        try:
            return await tables.list_tables(schema, include_views, include_system)
        except Exception as e:
            return {"status": "error", "error": str(e)}
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes what the tool does (list tables) and what it returns, but doesn't mention important behavioral aspects like whether this is a read-only operation, potential performance implications for large databases, or authentication requirements. The return format is mentioned but without details on structure or pagination.

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 perfectly structured and concise. It starts with the core purpose, then clearly documents parameters with their semantics, and ends with return information. Every sentence earns its place with no wasted words, and the information is front-loaded appropriately.

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 that there's an output schema (which handles return values), no annotations, and the description provides excellent parameter documentation, this is quite complete. The main gap is the lack of behavioral context around performance, permissions, or operational considerations, but for a listing tool with output schema, this is reasonably comprehensive.

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

Parameters5/5

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

The description provides excellent parameter semantics beyond the input schema. With 0% schema description coverage, the description fully compensates by explaining all three parameters: 'schema: Filter by schema name (default: all user schemas)', 'include_views: Include views in results', and 'include_system: Include system tables'. This adds crucial meaning not present in the bare schema.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'List all tables in the database' - a specific verb (list) and resource (tables). It distinguishes from some siblings like list_schemas or list_databases by focusing on tables, but doesn't explicitly differentiate from tools like describe_table or show_tables (if they existed).

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 is provided. While the purpose is clear, there's no mention of when to choose list_tables over other table-related tools like describe_table or get_table_stats, nor any prerequisites or context for usage.

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/bpamiri/cockroachdb-mcp'

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