search_columns
Find database columns by name across all tables when you know the column name but not which table contains it. Returns matching columns with their table names.
Instructions
Search for columns by name across all tables.
Useful when you know a column name but not which table it's in.
Args:
search_term: Partial column name to search for (case-insensitive)
Returns:
JSON array of matching columns with their tables
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| search_term | Yes |
Implementation Reference
- mcp_postgres/server.py:233-264 (handler)The handler function for the 'search_columns' tool, registered via @mcp.tool(). It queries information_schema.columns to find columns matching the search term across all non-system tables and returns a JSON array of matches.@mcp.tool() async def search_columns(search_term: str) -> str: """Search for columns by name across all tables. Useful when you know a column name but not which table it's in. Args: search_term: Partial column name to search for (case-insensitive) Returns: JSON array of matching columns with their tables """ sql = """ SELECT table_schema, table_name, column_name, data_type FROM information_schema.columns WHERE table_schema NOT IN ('pg_catalog', 'information_schema') AND LOWER(column_name) LIKE LOWER($1) ORDER BY table_schema, table_name, column_name """ try: async with get_connection() as conn: rows = await conn.fetch(sql, f"%{search_term}%") results = [dict(row) for row in rows] return json.dumps(results, indent=2) except Exception as e: return json.dumps({"error": str(e)})