Skip to main content
Glama

get_queries_not_selective

Identify queries with poor selectivity by analyzing Couchbase system data to find index scans returning many more documents than final results.

Instructions

Get queries that are not very selective from the system:completed_requests catalog.

Args:
    limit: Number of queries to return (default: 10)

Returns:
    List of queries where index scans return significantly more documents than the final result

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core implementation of the get_queries_not_selective tool handler. It executes a query on system:completed_requests to find non-selective queries where index scans return more documents than the final result set, using a helper function for execution.
    def get_queries_not_selective(ctx: Context, limit: int = 10) -> list[dict[str, Any]]:
        """Get queries that are not very selective from the system:completed_requests catalog.
    
        Args:
            limit: Number of queries to return (default: 10)
    
        Returns:
            List of queries where index scans return significantly more documents than the final result
        """
        query = """
        SELECT statement,
           AVG(phaseCounts.`indexScan` - resultCount) AS diff
        FROM system:completed_requests
        WHERE phaseCounts.`indexScan` > resultCount
        GROUP BY statement
        ORDER BY diff DESC
        LIMIT $limit
        """
    
        return _run_query_tool_with_empty_message(
            ctx,
            query,
            limit=limit,
            empty_message=(
                "No non-selective queries were found in system:completed_requests."
            ),
        )
  • Registration of the get_queries_not_selective tool via import into the main tools __init__.py module, making it available for MCP tool registration.
    # Query tools
    from .query import (
        get_longest_running_queries,
        get_most_frequent_queries,
        get_queries_not_selective,
        get_queries_not_using_covering_index,
        get_queries_using_primary_index,
        get_queries_with_large_result_count,
        get_queries_with_largest_response_sizes,
        get_schema_for_collection,
        run_sql_plus_plus_query,
    )
  • Inclusion of get_queries_not_selective in the ALL_TOOLS list for convenient bulk registration of all MCP tools.
    ALL_TOOLS = [
        get_buckets_in_cluster,
        get_server_configuration_status,
        test_cluster_connection,
        get_scopes_and_collections_in_bucket,
        get_collections_in_scope,
        get_scopes_in_bucket,
        get_document_by_id,
        upsert_document_by_id,
        delete_document_by_id,
        get_schema_for_collection,
        run_sql_plus_plus_query,
        get_index_advisor_recommendations,
        list_indexes,
        get_cluster_health_and_services,
        get_queries_not_selective,
        get_queries_not_using_covering_index,
        get_queries_using_primary_index,
        get_queries_with_large_result_count,
        get_queries_with_largest_response_sizes,
        get_longest_running_queries,
        get_most_frequent_queries,
    ]
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. It mentions the data source ('system:completed_requests catalog') and the selection criteria, but doesn't disclose behavioral aspects like whether this is a read-only operation, if it requires specific permissions, potential performance impact, or how results are sorted/ordered. For a diagnostic tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 efficiently structured with a clear purpose statement followed by separate 'Args' and 'Returns' sections. Every sentence adds value: the first defines what the tool does, the second explains the parameter, and the third clarifies the return criteria. There's no redundant information or unnecessary elaboration.

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 (query analysis), no annotations, and the presence of an output schema (which handles return value documentation), the description is minimally adequate. It covers the purpose, parameter, and return criteria, but lacks important context about when to use it among similar tools and behavioral aspects like permissions or performance characteristics. The output schema existence reduces the burden, but gaps remain.

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?

With only one parameter and 0% schema description coverage, the description fully compensates by explaining the 'limit' parameter's purpose and default value. The schema provides the data type and default, but the description adds the semantic meaning ('Number of queries to return'). Since there are no other parameters, this is sufficient for the single parameter's 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 verb 'Get' and the resource 'queries that are not very selective' from the 'system:completed_requests catalog'. It specifies the type of queries (where index scans return significantly more documents than final results), which distinguishes it from generic query retrieval tools. However, it doesn't explicitly differentiate from similar sibling tools like 'get_queries_with_large_result_count' or 'get_longest_running_queries'.

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. With multiple sibling tools for query analysis (e.g., 'get_queries_not_using_covering_index', 'get_queries_with_large_result_count'), there's no indication of what problem this specifically addresses or when it's preferred over other query diagnostic tools. The context is implied but not explicit.

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/Couchbase-Ecosystem/mcp-server-couchbase'

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