Skip to main content
Glama

get_index_advisor_recommendations

Analyzes SQL++ queries to provide index recommendations for optimizing Couchbase database performance, including secondary and covering indexes.

Instructions

Get index recommendations from Couchbase Index Advisor for a given SQL++ query.

The Index Advisor analyzes the query and provides recommendations for optimal indexes.
This tool works with SELECT, UPDATE, DELETE, or MERGE queries.
The queries will be run on the specified scope in the specified bucket.

Returns a dictionary with:
- current_used_indexes: Array of currently used indexes (if any)
- recommended_indexes: Array of recommended secondary indexes (if any)
- recommended_covering_indexes: Array of recommended covering indexes (if any)

Each index object contains:
- index: The CREATE INDEX SQL++ command
- statements: Array of statement objects with the query and run count

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bucket_nameYes
scope_nameYes
queryYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function implementing the tool logic. It constructs and executes a SQL++ query using the Couchbase ADVISOR function to analyze the provided query and return index recommendations, including current used indexes, recommended indexes, and covering indexes.
    def get_index_advisor_recommendations(
        ctx: Context, bucket_name: str, scope_name: str, query: str
    ) -> dict[str, Any]:
        """Get index recommendations from Couchbase Index Advisor for a given SQL++ query.
    
        The Index Advisor analyzes the query and provides recommendations for optimal indexes.
        This tool works with SELECT, UPDATE, DELETE, or MERGE queries.
        The queries will be run on the specified scope in the specified bucket.
    
        Returns a dictionary with:
        - current_used_indexes: Array of currently used indexes (if any)
        - recommended_indexes: Array of recommended secondary indexes (if any)
        - recommended_covering_indexes: Array of recommended covering indexes (if any)
    
        Each index object contains:
        - index: The CREATE INDEX SQL++ command
        - statements: Array of statement objects with the query and run count
        """
        try:
            # Build the ADVISOR query
            advisor_query = f"SELECT ADVISOR('{query}') AS advisor_result"
    
            logger.info("Running Index Advisor for the provided query")
    
            # Execute the ADVISOR function at cluster level using run_sql_plus_plus_query
            advisor_results = run_sql_plus_plus_query(
                ctx, bucket_name, scope_name, advisor_query
            )
    
            if not advisor_results:
                return {
                    "message": "No recommendations available",
                    "current_used_indexes": [],
                    "recommended_indexes": [],
                    "recommended_covering_indexes": [],
                }
    
            # The result is wrapped in advisor_result key
            advisor_data = advisor_results[0].get("advisor_result", {})
    
            # Extract the relevant fields with defaults
            response = {
                "current_used_indexes": advisor_data.get("current_used_indexes", []),
                "recommended_indexes": advisor_data.get("recommended_indexes", []),
                "recommended_covering_indexes": advisor_data.get(
                    "recommended_covering_indexes", []
                ),
            }
    
            # Add summary information for better user experience
            response["summary"] = {
                "current_indexes_count": len(response["current_used_indexes"]),
                "recommended_indexes_count": len(response["recommended_indexes"]),
                "recommended_covering_indexes_count": len(
                    response["recommended_covering_indexes"]
                ),
                "has_recommendations": bool(
                    response["recommended_indexes"]
                    or response["recommended_covering_indexes"]
                ),
            }
    
            logger.info(
                f"Index Advisor completed. Found {response['summary']['recommended_indexes_count']} recommended indexes"
            )
    
            return response
    
        except Exception as e:
            logger.error(f"Error running Index Advisor: {e!s}", exc_info=True)
            raise
  • The tool function is imported from index.py (line 8) and included in the ALL_TOOLS list, which is used for bulk registration of all tools in the MCP 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,
    ]
  • The MCP server registers all tools from ALL_TOOLS, including get_index_advisor_recommendations, by calling mcp.add_tool(tool) in a loop.
    # Register all tools
    for tool in ALL_TOOLS:
        mcp.add_tool(tool)
Behavior3/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 discloses that the tool analyzes queries and provides recommendations, which implies a read-only, non-destructive operation. However, it lacks details on potential side effects (e.g., if analysis impacts performance), authentication needs, rate limits, or error handling. The description adds basic behavioral context but misses deeper operational traits.

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 well-structured and front-loaded, starting with the core purpose, followed by supported query types, execution context, and detailed return format. Each sentence adds value without redundancy, and the bulleted lists for return values are clear and efficient, making it easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (analyzing queries for index optimization) and the presence of an output schema (implied by the detailed return format in the description), the description is complete enough. It covers purpose, usage, parameters, and return values comprehensively, compensating for the lack of annotations and low schema coverage, ensuring an agent can understand and invoke it correctly.

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 0% schema description coverage, the description must compensate for the lack of parameter documentation in the schema. It explains that 'bucket_name' and 'scope_name' specify where the query runs, and 'query' is the SQL++ query to analyze. This adds meaningful semantics beyond the schema's generic titles, though it could elaborate on format constraints (e.g., query syntax requirements).

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

Purpose5/5

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

The description clearly states the specific action ('Get index recommendations'), the source ('from Couchbase Index Advisor'), and the target ('for a given SQL++ query'). It distinguishes this tool from sibling tools like 'list_indexes' (which lists existing indexes) and 'run_sql_plus_plus_query' (which executes queries) by focusing on analysis and recommendations rather than listing or execution.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: to analyze SQL++ queries (specifically SELECT, UPDATE, DELETE, or MERGE types) for index optimization. It mentions that queries run on a specified scope in a bucket, but it does not explicitly state when not to use it or name alternatives among siblings, such as 'get_queries_not_using_covering_index' for related diagnostics.

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