Skip to main content
Glama

list_objects

Retrieve a list of objects, such as tables, views, sequences, or extensions, within a specified schema using this tool. Streamline schema exploration and data management for Postgres MCP workflows.

Instructions

List objects in a schema

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
object_typeNoObject type: 'table', 'view', 'sequence', or 'extension'table
schema_nameYesSchema name

Implementation Reference

  • The main handler function for the 'list_objects' tool. It lists database objects (tables, views, sequences, or extensions) in a specified schema by executing appropriate SQL queries against information_schema and pg_extension. The function is decorated with @mcp.tool, which also serves as registration. Input schema is defined inline using Pydantic Field.
    @mcp.tool(description="List objects in a schema")
    async def list_objects(
        schema_name: str = Field(description="Schema name"),
        object_type: str = Field(description="Object type: 'table', 'view', 'sequence', or 'extension'", default="table"),
    ) -> ResponseType:
        """List objects of a given type in a schema."""
        try:
            sql_driver = await get_sql_driver()
    
            if object_type in ("table", "view"):
                table_type = "BASE TABLE" if object_type == "table" else "VIEW"
                rows = await SafeSqlDriver.execute_param_query(
                    sql_driver,
                    """
                    SELECT table_schema, table_name, table_type
                    FROM information_schema.tables
                    WHERE table_schema = {} AND table_type = {}
                    ORDER BY table_name
                    """,
                    [schema_name, table_type],
                )
                objects = (
                    [{"schema": row.cells["table_schema"], "name": row.cells["table_name"], "type": row.cells["table_type"]} for row in rows]
                    if rows
                    else []
                )
    
            elif object_type == "sequence":
                rows = await SafeSqlDriver.execute_param_query(
                    sql_driver,
                    """
                    SELECT sequence_schema, sequence_name, data_type
                    FROM information_schema.sequences
                    WHERE sequence_schema = {}
                    ORDER BY sequence_name
                    """,
                    [schema_name],
                )
                objects = (
                    [{"schema": row.cells["sequence_schema"], "name": row.cells["sequence_name"], "data_type": row.cells["data_type"]} for row in rows]
                    if rows
                    else []
                )
    
            elif object_type == "extension":
                # Extensions are not schema-specific
                rows = await sql_driver.execute_query(
                    """
                    SELECT extname, extversion, extrelocatable
                    FROM pg_extension
                    ORDER BY extname
                    """
                )
                objects = (
                    [{"name": row.cells["extname"], "version": row.cells["extversion"], "relocatable": row.cells["extrelocatable"]} for row in rows]
                    if rows
                    else []
                )
    
            else:
                return format_error_response(f"Unsupported object type: {object_type}")
    
            return format_text_response(objects)
        except Exception as e:
            logger.error(f"Error listing objects: {e}")
            return format_error_response(str(e))
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 states a read operation ('List'), implying it's non-destructive, but fails to describe any behavioral traits like permissions required, pagination, rate limits, or what the output looks like (e.g., list format, error handling). This leaves significant gaps in understanding how the tool behaves in practice.

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 a single, efficient sentence ('List objects in a schema') that is front-loaded and wastes no words. It directly conveys the core action without unnecessary elaboration, making it highly concise and well-structured for quick comprehension.

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

Completeness2/5

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

Given the tool's complexity (2 parameters, no output schema, no annotations), the description is incomplete. It does not explain the return values (e.g., list format, data included), behavioral aspects like error conditions, or how it integrates with sibling tools. This lack of context makes it inadequate for an AI agent to fully understand and use the tool effectively.

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

Parameters3/5

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

The input schema has 100% description coverage, clearly documenting both parameters ('object_type' with default and allowed values, 'schema_name' as required). The description adds no additional meaning beyond the schema, such as explaining parameter interactions or usage examples. Given the high schema coverage, a baseline score of 3 is appropriate as the schema does the heavy lifting.

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

Purpose3/5

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

The description 'List objects in a schema' clearly states the verb ('List') and resource ('objects in a schema'), making the purpose understandable. However, it lacks specificity about what 'objects' means (e.g., database objects like tables, views) and does not distinguish it from sibling tools like 'list_schemas' or 'get_object_details', leaving room for ambiguity in tool selection.

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?

The description provides no guidance on when to use this tool versus alternatives. It does not mention sibling tools like 'list_schemas' (for listing schemas) or 'get_object_details' (for detailed object info), nor does it specify prerequisites or contexts for usage, such as needing a schema name or filtering by object type, leaving the agent without clear usage instructions.

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

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

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