Skip to main content
Glama
smith-nathanh

Oracle MCP Server

describe_table

Retrieve table structure details including columns, data types, and constraints from Oracle Database to understand schema design and relationships.

Instructions

Get detailed information about a table including columns, data types, and constraints

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYesName of the table to describe
ownerNoSchema owner (optional)

Implementation Reference

  • Main handler logic for the 'describe_table' tool within the @self.server.call_tool() handler. Extracts table_name and owner arguments, invokes DatabaseInspector.get_table_columns(), formats the result as JSON, and returns it as TextContent.
    elif name == "describe_table":
        table_name = arguments.get("table_name")
        owner = arguments.get("owner")
    
        columns = await self.inspector.get_table_columns(table_name, owner)
    
        result = {
            "table_name": table_name,
            "owner": owner,
            "columns": columns,
            "column_count": len(columns),
        }
    
        return [
            TextContent(
                type="text", text=json.dumps(result, indent=2, default=str)
            )
        ]
  • Input schema and metadata definition for the 'describe_table' tool, registered in the @self.server.list_tools() handler. Specifies required 'table_name' parameter and optional 'owner'.
    Tool(
        name="describe_table",
        description="Get detailed information about a table including columns, data types, and constraints",
        inputSchema={
            "type": "object",
            "properties": {
                "table_name": {
                    "type": "string",
                    "description": "Name of the table to describe",
                },
                "owner": {
                    "type": "string",
                    "description": "Schema owner (optional)",
                    "default": None,
                },
            },
            "required": ["table_name"],
        },
    ),
  • Core implementation in DatabaseInspector.get_table_columns(): Executes SQL query against all_tab_columns and all_col_comments to fetch table column metadata (name, type, length, nullable, default, comments), applies COLUMN_WHITE_LIST filtering, and returns structured list of column dictionaries.
    async def get_table_columns(
        self, table_name: str, owner: Optional[str] = None
    ) -> List[Dict[str, Any]]:
        """Get detailed column information for a table"""
        conn = await self.connection_manager.get_connection()
        try:
            cursor = conn.cursor()
    
            query = """
                SELECT 
                    c.column_name,
                    c.data_type,
                    c.data_length,
                    c.data_precision,
                    c.data_scale,
                    c.nullable,
                    c.data_default,
                    cc.comments as column_comment,
                    c.column_id
                FROM all_tab_columns c
                LEFT JOIN all_col_comments cc ON c.owner = cc.owner 
                    AND c.table_name = cc.table_name 
                    AND c.column_name = cc.column_name
                WHERE c.table_name = :table_name
            """
    
            params = [table_name]
    
            if owner:
                query += " AND c.owner = :owner"
                params.append(owner)
    
            query += " ORDER BY c.column_id"
    
            cursor.execute(query, params)
    
            columns = []
            for row in cursor:
                # Apply column whitelist if configured
                full_column_name = f"{table_name}.{row[0]}"
                if COLUMN_WHITE_LIST and COLUMN_WHITE_LIST != [""]:
                    if full_column_name not in COLUMN_WHITE_LIST:
                        continue
    
                columns.append(
                    {
                        "column_name": row[0],
                        "data_type": row[1],
                        "data_length": row[2],
                        "data_precision": row[3],
                        "data_scale": row[4],
                        "nullable": row[5],
                        "data_default": row[6],
                        "column_comment": row[7],
                        "column_id": row[8],
                    }
                )
    
            return columns
    
        finally:
            conn.close()

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/smith-nathanh/oracle-mcp-server'

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