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
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table to describe | |
| owner | No | Schema owner (optional) |
Implementation Reference
- src/oracle_mcp_server/server.py:781-798 (handler)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()