Skip to main content
Glama
mirenqinggege

postgres-mcp

list_objects

Read-only

List tables, views, sequences, or extensions in a specified Postgres schema.

Instructions

List objects in a schema

Input Schema

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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'list_objects' tool handler function. Accepts schema_name and object_type (table, view, sequence, or extension) and queries the database via SqlDriver/SafeSqlDriver returning formatted text results.
    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))
  • Input schema for list_objects defined via type annotations and Pydantic Field. Parameters: schema_name (str), object_type (str, default='table'). Output is ResponseType (list of TextContent/ImageContent/EmbeddedResource).
    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"),
  • Tool registration via the @mcp.tool decorator on the FastMCP 'mcp' instance, with description and ToolAnnotations metadata including readOnlyHint=True.
    @mcp.tool(
        description="List objects in a schema",
        annotations=ToolAnnotations(
            title="List Objects",
            readOnlyHint=True,
        ),
    )
Behavior3/5

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

Annotations already provide readOnlyHint=true, so the safe read behavior is known. Description adds only the schema scoping, no further behavioral details like pagination or results format. Adequate with annotations but not enriched.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence is very concise but could be slightly more informative. No wasted words, but front-loading is minimal.

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?

For a simple listing tool with an output schema, the description is minimally adequate. Missing usage guidelines and behavioral details make it incomplete for nuanced decisions.

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% with both parameters documented. Description adds no extra meaning beyond the schema, so baseline score applies.

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?

Description 'List objects in a schema' uses a specific verb and resource, clearly distinguishing from sibling tools like list_schemas (lists schemas) and get_object_details (details on a specific object).

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 such as get_object_details or analyze_* tools. Lacks explicit when/when-not context.

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

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