Skip to main content
Glama

search_columns

Find database columns by name across PostgreSQL tables. Specify a search term to locate columns with matching names, optionally filtering by schema.

Instructions

Search for columns by name across all tables.

Args:
    search_term: Column name pattern to search (case-insensitive)
    schema: Optional schema to limit search (default: all user schemas)
    
Returns:
    List of matching columns with table information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
search_termYes
schemaNo

Implementation Reference

  • MCP tool handler for 'search_columns', decorated with @mcp.tool(). Delegates to PostgresClient.search_columns and formats the response.
    @mcp.tool()
    @handle_db_error
    def search_columns(search_term: str, schema: Optional[str] = None) -> dict:
        """Search for columns by name across all tables.
        
        Args:
            search_term: Column name pattern to search (case-insensitive)
            schema: Optional schema to limit search (default: all user schemas)
            
        Returns:
            List of matching columns with table information
        """
        client = get_client()
        columns = client.search_columns(search_term, schema)
        
        return {
            "search_term": search_term,
            "schema_filter": schema,
            "matches": columns,
            "count": len(columns),
        }
  • Core implementation of column search logic in PostgresClient class, executing SQL query against information_schema.columns.
    def search_columns(self, search_term: str, schema: Optional[str] = None) -> list[dict]:
        """Search for columns by name.
        
        Args:
            search_term: Column name pattern (supports LIKE wildcards)
            schema: Optional schema filter
            
        Returns:
            List of matching columns with table info
        """
        # Sanitize search term for LIKE pattern
        search_pattern = f"%{search_term}%"
        
        query = """
            SELECT 
                table_schema,
                table_name,
                column_name,
                data_type,
                is_nullable
            FROM information_schema.columns
            WHERE column_name ILIKE %s
        """
        params = [search_pattern]
        
        if schema:
            query += " AND table_schema = %s"
            params.append(schema)
        
        query += """
            AND table_schema NOT IN ('information_schema', 'pg_catalog')
            ORDER BY table_schema, table_name, column_name
            LIMIT 100
        """
        
        with self.get_cursor() as cursor:
            cursor.execute(query, params)
            return [dict(row) for row in cursor.fetchall()]
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions that the search is 'case-insensitive' and returns a 'List of matching columns with table information', which adds some context. However, it lacks details on permissions, rate limits, error handling, or whether the search is real-time or cached, leaving gaps for a mutation-like operation (searching across databases).

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

Conciseness5/5

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

The description is appropriately sized and front-loaded: the first sentence states the purpose clearly, followed by structured sections for 'Args' and 'Returns' that are concise and informative. Every sentence earns its place without redundancy, making it easy to scan and understand quickly.

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?

Given the tool's moderate complexity (searching across tables with 2 parameters), no annotations, and no output schema, the description is somewhat complete but has gaps. It covers the purpose and parameters well but lacks behavioral details like error cases or performance implications. The absence of an output schema means the description should ideally explain return values more thoroughly, which it does partially but not fully.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful semantics beyond the input schema, which has 0% description coverage. It explains that 'search_term' is a 'Column name pattern to search (case-insensitive)' and 'schema' is 'Optional schema to limit search (default: all user schemas)', clarifying usage and default behavior. This compensates well for the low schema coverage, though it doesn't detail pattern syntax (e.g., wildcards).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Search for columns by name across all tables.' This specifies the verb ('search'), resource ('columns'), and scope ('across all tables'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'describe_table' or 'list_tables', which is why it doesn't reach a score of 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by mentioning 'across all tables' and the optional 'schema' parameter to limit the search, but it doesn't provide explicit guidance on when to use this tool versus alternatives like 'describe_table' or 'list_tables'. There's no mention of prerequisites, exclusions, or specific scenarios where this tool is preferred over others.

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

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