Skip to main content
Glama

get_object_details

Retrieve detailed information about PostgreSQL database objects like tables, views, sequences, or extensions to understand their structure and properties.

Instructions

Show detailed information about a database object

Input Schema

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

Implementation Reference

  • The `get_object_details` tool implementation which retrieves details for tables, views, sequences, and extensions from the database and returns them formatted as text.
    @mcp.tool(description="Show detailed information about a database object")
    async def get_object_details(
        schema_name: str = Field(description="Schema name"),
        object_name: str = Field(description="Object name"),
        object_type: str = Field(description="Object type: 'table', 'view', 'sequence', or 'extension'", default="table"),
    ) -> ResponseType:
        """Get detailed information about a database object."""
        try:
            sql_driver = await get_sql_driver()
    
            if object_type in ("table", "view"):
                # Get columns
                col_rows = await SafeSqlDriver.execute_param_query(
                    sql_driver,
                    """
                    SELECT column_name, data_type, is_nullable, column_default
                    FROM information_schema.columns
                    WHERE table_schema = {} AND table_name = {}
                    ORDER BY ordinal_position
                    """,
                    [schema_name, object_name],
                )
                columns = (
                    [
                        {
                            "column": r.cells["column_name"],
                            "data_type": r.cells["data_type"],
                            "is_nullable": r.cells["is_nullable"],
                            "default": r.cells["column_default"],
                        }
                        for r in col_rows
                    ]
                    if col_rows
                    else []
                )
    
                # Get constraints
                con_rows = await SafeSqlDriver.execute_param_query(
                    sql_driver,
                    """
                    SELECT tc.constraint_name, tc.constraint_type, kcu.column_name
                    FROM information_schema.table_constraints AS tc
                    LEFT JOIN information_schema.key_column_usage AS kcu
                      ON tc.constraint_name = kcu.constraint_name
                     AND tc.table_schema = kcu.table_schema
                    WHERE tc.table_schema = {} AND tc.table_name = {}
                    """,
                    [schema_name, object_name],
                )
    
                constraints = {}
                if con_rows:
                    for row in con_rows:
                        cname = row.cells["constraint_name"]
                        ctype = row.cells["constraint_type"]
                        col = row.cells["column_name"]
    
                        if cname not in constraints:
                            constraints[cname] = {"type": ctype, "columns": []}
                        if col:
                            constraints[cname]["columns"].append(col)
    
                constraints_list = [{"name": name, **data} for name, data in constraints.items()]
    
                # Get indexes
                idx_rows = await SafeSqlDriver.execute_param_query(
                    sql_driver,
                    """
                    SELECT indexname, indexdef
                    FROM pg_indexes
                    WHERE schemaname = {} AND tablename = {}
                    """,
                    [schema_name, object_name],
                )
    
                indexes = [{"name": r.cells["indexname"], "definition": r.cells["indexdef"]} for r in idx_rows] if idx_rows else []
    
                result = {
                    "basic": {"schema": schema_name, "name": object_name, "type": object_type},
                    "columns": columns,
                    "constraints": constraints_list,
                    "indexes": indexes,
                }
    
            elif object_type == "sequence":
                rows = await SafeSqlDriver.execute_param_query(
                    sql_driver,
                    """
                    SELECT sequence_schema, sequence_name, data_type, start_value, increment
                    FROM information_schema.sequences
                    WHERE sequence_schema = {} AND sequence_name = {}
                    """,
                    [schema_name, object_name],
                )
    
                if rows and rows[0]:
                    row = rows[0]
                    result = {
                        "schema": row.cells["sequence_schema"],
                        "name": row.cells["sequence_name"],
                        "data_type": row.cells["data_type"],
                        "start_value": row.cells["start_value"],
                        "increment": row.cells["increment"],
                    }
                else:
                    result = {}
    
            elif object_type == "extension":
                rows = await SafeSqlDriver.execute_param_query(
                    sql_driver,
                    """
                    SELECT extname, extversion, extrelocatable
                    FROM pg_extension
                    WHERE extname = {}
                    """,
                    [object_name],
                )
    
                if rows and rows[0]:
                    row = rows[0]
                    result = {"name": row.cells["extname"], "version": row.cells["extversion"], "relocatable": row.cells["extrelocatable"]}
                else:
                    result = {}
    
            else:
                return format_error_response(f"Unsupported object type: {object_type}")
    
            return format_text_response(result)
        except Exception as e:
            logger.error(f"Error getting object details: {e}")
            return format_error_response(str(e))

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.0

TDQS

A3.5/5.0
Behavior2/5

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

No annotations are provided, so the description carries full burden. It does not disclose any behavioral traits beyond the basic purpose (e.g., read-only, required permissions, side effects). Minimal transparency.

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?

The description is a single sentence, which is concise. However, it could be more precise by specifying what 'detailed information' includes. Still, no wasted words.

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 no output schema and no description of what 'detailed information' entails (columns, constraints, etc.), the description is incomplete for a details tool. Complexity is low, but more context is needed.

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 coverage is 100% with parameter descriptions that are minimal but sufficient. The description adds no additional meaning beyond the schema. Baseline 3 is appropriate.

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 uses a specific verb 'Show' and resource 'detailed information about a database object'. It clearly distinguishes from siblings like list_objects (which likely lists objects) and analyze_* tools.

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?

No explicit when-to-use or alternative guidance is provided, but the tool's purpose is straightforward enough. A score of 4 reflects the lack of explicit guidelines despite the clear context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.