Skip to main content
Glama

list_tables

Retrieve all tables from a PostgreSQL schema to understand database structure. Specify a schema name to view its tables and their types.

Instructions

List all tables in a specific schema.

Args:
    schema: Schema name to list tables from (default: public)
    
Returns:
    List of tables with name and type

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNopublic

Implementation Reference

  • MCP tool handler for 'list_tables'. Fetches tables using PostgresClient and formats output using TableSummary models.
    @mcp.tool()
    @handle_db_error
    def list_tables(schema: str = "public") -> dict:
        """List all tables in a specific schema.
        
        Args:
            schema: Schema name to list tables from (default: public)
            
        Returns:
            List of tables with name and type
        """
        client = get_client()
        tables = client.list_tables(schema)
        
        return {
            "schema": schema,
            "tables": [TableSummary.from_row(t).model_dump() for t in tables],
        }
  • Pydantic model defining the output schema for table summaries in list_tables response.
    class TableSummary(BaseModel):
        """Table info for list responses."""
        
        model_config = {"populate_by_name": True}
        
        name: str
        type: str = "BASE TABLE"
        schema_name: str = "public"
        
        @classmethod
        def from_row(cls, row: dict) -> "TableSummary":
            return cls(
                name=row.get("table_name", ""),
                type=row.get("table_type", "BASE TABLE"),
                schema_name=row.get("table_schema", "public"),
            )
  • FastMCP decorator registering the list_tables function as an MCP tool.
    @mcp.tool()
  • Core implementation in PostgresClient that queries information_schema.tables to list tables in a schema.
    def list_tables(self, schema: str = "public") -> list[dict]:
        """List all tables in a schema.
        
        Args:
            schema: Schema name (default: public)
            
        Returns:
            List of table dicts
        """
        query = """
            SELECT table_name, table_type, table_schema
            FROM information_schema.tables 
            WHERE table_schema = %s
            ORDER BY table_name
        """
        with self.get_cursor() as cursor:
            cursor.execute(query, (schema,))
            return [dict(row) for row in cursor.fetchall()]
Behavior2/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 mentions the return format ('List of tables with name and type'), which adds some context, but lacks details on permissions, pagination, error handling, or performance characteristics. This is a significant gap for a tool with zero annotation coverage.

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 appropriately sized and front-loaded, with a clear purpose statement followed by structured sections for Args and Returns. Every sentence earns its place, providing essential information without waste.

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

Completeness3/5

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

Given the tool's low complexity and lack of annotations or output schema, the description is moderately complete. It covers the purpose, parameter, and return format, but lacks behavioral details like side effects or error conditions, which are important for a read operation in a database context.

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 adds substantial meaning beyond the input schema, which has 0% description coverage. It explains the parameter's purpose ('Schema name to list tables from'), provides a default value ('default: public'), and clarifies the return semantics, compensating fully for the schema's lack of documentation.

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 specific action ('List all tables') and resource ('in a specific schema'), distinguishing it from siblings like list_views, list_functions, or list_schemas. It precisely defines the scope and target, avoiding vagueness.

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

Usage Guidelines4/5

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

The description implies usage context by specifying 'in a specific schema' and providing a default value, which helps differentiate from broader tools like get_database_info. However, it does not explicitly state when not to use it or name alternatives, such as list_views for view-specific listings.

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/JaviMaligno/postgres-mcp'

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