Skip to main content
Glama

get_most_frequent_queries

Retrieve the most frequently executed queries from Couchbase's completed_requests catalog to identify common usage patterns and optimize database performance.

Instructions

Get the N most frequent queries from the system:completed_requests catalog.

Args: limit: Number of queries to return (default: 10) Returns: List of queries with their frequency count

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo

Implementation Reference

  • The primary handler function for the 'get_most_frequent_queries' tool. It executes a SQL++ query on system:completed_requests to find the most frequent user queries, excluding system and DDL queries, and handles empty results gracefully.
    def get_most_frequent_queries(ctx: Context, limit: int = 10) -> list[dict[str, Any]]: """Get the N most frequent queries from the system:completed_requests catalog. Args: limit: Number of queries to return (default: 10) Returns: List of queries with their frequency count """ query = """ SELECT statement, COUNT(1) AS queries FROM system:completed_requests WHERE UPPER(statement) NOT LIKE 'INFER %' AND UPPER(statement) NOT LIKE 'CREATE INDEX%' AND UPPER(statement) NOT LIKE 'CREATE PRIMARY INDEX%' AND UPPER(statement) NOT LIKE 'EXPLAIN %' AND UPPER(statement) NOT LIKE 'ADVISE %' AND UPPER(statement) NOT LIKE '% SYSTEM:%' GROUP BY statement LETTING queries = COUNT(1) ORDER BY queries DESC LIMIT $limit """ return _run_query_tool_with_empty_message( ctx, query, limit=limit, empty_message=( "No completed queries were available to calculate most frequent queries." ), )
  • Helper utility function used by get_most_frequent_queries (and other query analysis tools) to run cluster-level queries and provide a standardized empty result message.
    def _run_query_tool_with_empty_message( ctx: Context, query: str, *, limit: int, empty_message: str, extra_payload: dict[str, Any] | None = None, **query_kwargs: Any, ) -> list[dict[str, Any]]: """Execute a cluster query with a consistent empty-result response.""" results = run_cluster_query(ctx, query, limit=limit, **query_kwargs) if results: return results payload: dict[str, Any] = {"message": empty_message, "results": []} if extra_payload: payload.update(extra_payload) return [payload]
  • Registration of the get_most_frequent_queries tool in the ALL_TOOLS list, which is used to register all MCP tools with the server.
    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, ]
  • Import of the get_most_frequent_queries handler from the query module into the tools package.
    from .query import ( get_longest_running_queries, get_most_frequent_queries,

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