Skip to main content
Glama
sharansahu

MCP SQL Agent

by sharansahu

search_tables

Locate tables or columns by searching for a specific keyword in your SQLite database. Ideal for efficient data discovery without manual browsing.

Instructions

Search for tables or columns containing a specific keyword

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MySQL implementation of the search_tables MCP tool handler. Searches database tables and columns for a given keyword using information_schema queries.
    @mcp.tool()
    def search_tables(keyword: str) -> str:
        """Search for tables or columns containing a specific keyword"""
        try:
            conn = mysql.connector.connect(**db_config)
            cursor = conn.cursor()
            
            # Get all tables
            tables_query = """
            SELECT TABLE_NAME 
            FROM information_schema.TABLES 
            WHERE TABLE_SCHEMA = %s
            """
            cursor.execute(tables_query, (db_config['database'],))
            tables = cursor.fetchall()
            
            matches = []
            
            for (table_name,) in tables:
                # Check if table name contains keyword
                if keyword.lower() in table_name.lower():
                    matches.append(f"Table: {table_name}")
                
                # Check columns
                columns_query = """
                SELECT COLUMN_NAME 
                FROM information_schema.COLUMNS 
                WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s
                """
                cursor.execute(columns_query, (db_config['database'], table_name))
                columns = cursor.fetchall()
                
                matching_columns = []
                for (column_name,) in columns:
                    if keyword.lower() in column_name.lower():
                        matching_columns.append(column_name)
                
                if matching_columns:
                    matches.append(f"Table '{table_name}' has columns: {', '.join(matching_columns)}")
            
            if matches:
                return f"Found matches for '{keyword}':\n" + "\n".join(matches)
            else:
                return f"No tables or columns found containing '{keyword}'"
                
        except Exception as e:
            return f"Error: {str(e)}"
        finally:
            if 'cursor' in locals():
                cursor.close()
            if 'conn' in locals():
                conn.close()
  • Oracle implementation of the search_tables MCP tool handler. Searches user tables and columns for a given keyword using Oracle system views.
    @mcp.tool()
    def search_tables(keyword: str) -> str:
        """Search for tables or columns containing a specific keyword"""
        try:
            conn = cx_Oracle.connect(**db_config)
            cursor = conn.cursor()
            
            # Get all tables
            tables_query = """
            SELECT table_name 
            FROM user_tables 
            ORDER BY table_name
            """
            cursor.execute(tables_query)
            tables = cursor.fetchall()
            
            matches = []
            
            for (table_name,) in tables:
                # Check if table name contains keyword
                if keyword.upper() in table_name.upper():
                    matches.append(f"Table: {table_name}")
                
                # Check columns
                columns_query = """
                SELECT column_name 
                FROM user_tab_columns 
                WHERE table_name = :1
                """
                cursor.execute(columns_query, (table_name,))
                columns = cursor.fetchall()
                
                matching_columns = []
                for (column_name,) in columns:
                    if keyword.upper() in column_name.upper():
                        matching_columns.append(column_name)
                
                if matching_columns:
                    matches.append(f"Table '{table_name}' has columns: {', '.join(matching_columns)}")
            
            if matches:
                return f"Found matches for '{keyword}':\n" + "\n".join(matches)
            else:
                return f"No tables or columns found containing '{keyword}'"
                
        except Exception as e:
            return f"Error: {str(e)}"
        finally:
            if 'cursor' in locals():
                cursor.close()
            if 'conn' in locals():
                conn.close()
  • SQLite implementation of the search_tables MCP tool handler. Searches tables and columns for a given keyword using sqlite_master and PRAGMA.
    @mcp.tool()
    def search_tables(keyword: str) -> str:
        """Search for tables or columns containing a specific keyword"""
        conn = sqlite3.connect(db_path)
        try:
            # Get all tables
            tables_query = "SELECT name FROM sqlite_master WHERE type='table';"
            tables = conn.execute(tables_query).fetchall()
            
            matches = []
            
            for (table_name,) in tables:
                # Check if table name contains keyword
                if keyword.lower() in table_name.lower():
                    matches.append(f"Table: {table_name}")
                
                # Check columns
                pragma_query = f"PRAGMA table_info({table_name});"
                columns = conn.execute(pragma_query).fetchall()
                
                matching_columns = []
                for column in columns:
                    column_name = column[1]
                    if keyword.lower() in column_name.lower():
                        matching_columns.append(column_name)
                
                if matching_columns:
                    matches.append(f"Table '{table_name}' has columns: {', '.join(matching_columns)}")
            
            if matches:
                return f"Found matches for '{keyword}':\n" + "\n".join(matches)
            else:
                return f"No tables or columns found containing '{keyword}'"
                
        except Exception as e:
            return f"Error: {str(e)}"
        finally:
            conn.close()
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 states the tool searches for tables or columns by keyword but does not disclose critical behavioral traits such as whether the search is case-sensitive, if it returns partial matches, the format of results (e.g., list of table names, detailed metadata), pagination, rate limits, or authentication requirements. For a search tool with zero annotation coverage, this is a significant gap in transparency.

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 a single, clear sentence: 'Search for tables or columns containing a specific keyword.' It is front-loaded with the core purpose, has no redundant or vague language, and efficiently conveys the essential information without waste. Every word earns its place, making it highly concise and well-structured.

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 (a search function with one parameter) and the presence of an output schema (which should cover return values), the description is minimally complete. It states what the tool does but lacks details on behavioral aspects like search behavior, result format, or error handling. With no annotations and low schema coverage, the description does not fully compensate, but the output schema may help, resulting in an adequate but incomplete overall context.

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?

The input schema has one parameter ('keyword') with 0% description coverage, meaning the schema provides no semantic details. The description adds value by explaining that the keyword is used to 'search for tables or columns,' giving basic context. However, it does not specify constraints (e.g., minimum length, allowed characters), examples, or how the keyword is applied (e.g., exact match vs. substring), leaving the agent with incomplete guidance. This meets the baseline for minimal parameter semantics.

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 tables or columns containing a specific keyword.' It specifies the verb ('search'), resource ('tables or columns'), and scope ('containing a specific keyword'), making the intent unambiguous. However, it does not explicitly differentiate from siblings like 'list_tables' (which might list all tables without searching) or 'describe_table' (which might describe a specific table), so it falls short of a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention siblings such as 'list_tables' (for listing all tables), 'describe_table' (for detailed info on a specific table), or 'query_data' (for querying data within tables), leaving the agent to infer usage context. This lack of explicit when-to-use or when-not-to-use instructions results in a low score.

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

Related 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/sharansahu/mcp-sql'

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