Skip to main content
Glama
cloudthinker-ai

Postgres MCP Pro Plus

list_objects

Retrieve tables, views, sequences, or extensions from a PostgreSQL schema to manage database structure and analyze schema contents.

Instructions

List objects in a schema

Input Schema

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

Implementation Reference

  • The handler function implementing the 'list_objects' tool. It queries the database for objects of the specified type in the given schema (or all extensions), formats the results, and returns them as text. Includes input schema via Pydantic Fields and registration via @mcp.tool decorator.
    @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(format_objects_as_text(objects, object_type))
        except Exception as e:
            logger.error(f"Error listing objects: {e}")
            return format_error_response(str(e))
  • Helper function to format the list of database objects into a compact text string used by the list_objects tool.
    def format_objects_as_text(objects: list[dict], object_type: str) -> str:
        """Format object lists compactly without emojis/headers, preserving details."""
        if not objects:
            return f"No {object_type}s found."
    
        label_map = {"table": "Tables", "view": "Views", "sequence": "Sequences", "extension": "Extensions"}
        label = label_map.get(object_type, object_type.capitalize() + "s")
    
        def item_str(o: dict) -> str:
            if object_type in ("table", "view"):
                return f"{o['schema']}.{o['name']}({o['type']})"
            if object_type == "sequence":
                return f"{o['schema']}.{o['name']}({o['data_type']})"
            if object_type == "extension":
                return f"{o['name']} v{o['version']} reloc={o['relocatable']}"
            return str(o)
    
        items = "; ".join(item_str(o) for o in objects)
        return f"{label}({len(objects)}): {items}"
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the action without mentioning permissions, pagination, rate limits, or response format. For a tool with no annotation coverage, this is a significant gap in transparency.

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 extremely concise with a single sentence, 'List objects in a schema,' which is front-loaded and wastes no words. It efficiently conveys the core purpose without unnecessary elaboration.

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 lack of annotations and output schema, the description is incomplete. It doesn't explain what 'objects' entail, how results are returned, or any behavioral traits, making it inadequate for a tool with two parameters and no structured support.

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?

Schema description coverage is 100%, so the schema fully documents both parameters (schema_name and object_type). The description adds no additional meaning beyond what's in the schema, such as examples or constraints, resulting in a baseline score of 3.

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' states the basic action and resource (list objects in a schema), but it's vague about what 'objects' specifically means and doesn't differentiate from sibling tools like list_schemas or get_object_details. It provides a minimal viable purpose without specificity.

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 is provided on when to use this tool versus alternatives such as list_schemas or get_object_details. The description lacks context about use cases, prerequisites, or exclusions, leaving the agent with no explicit or implied 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

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/cloudthinker-ai/postgres-mcp-pro-plus'

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