Skip to main content
Glama

get_schema_for_collection

Retrieve the schema structure of a Couchbase collection by analyzing its data with an INFER query, returning field names and data types.

Instructions

Get the schema for a collection in the specified scope. Returns a dictionary with the collection name and the schema returned by running INFER query on the Couchbase collection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bucket_nameYes
scope_nameYes
collection_nameYes

Implementation Reference

  • The handler function implementing the get_schema_for_collection tool. It runs an 'INFER' SQL++ query on the specified bucket.scope.collection to retrieve and return the schema information.
    def get_schema_for_collection(
        ctx: Context, bucket_name: str, scope_name: str, collection_name: str
    ) -> dict[str, Any]:
        """Get the schema for a collection in the specified scope.
        Returns a dictionary with the collection name and the schema returned by running INFER query on the Couchbase collection.
        """
        schema = {"collection_name": collection_name, "schema": []}
        try:
            query = f"INFER `{collection_name}`"
            result = run_sql_plus_plus_query(ctx, bucket_name, scope_name, query)
            # Result is a list of list of schemas. We convert it to a list of schemas.
            if result:
                schema["schema"] = result[0]
        except Exception as e:
            logger.error(f"Error getting schema: {e}")
            raise
        return schema
  • Registers the get_schema_for_collection tool (along with others from ALL_TOOLS) with the FastMCP server instance.
    for tool in ALL_TOOLS:
        mcp.add_tool(tool)
  • Includes get_schema_for_collection in the ALL_TOOLS list used for server registration.
    get_schema_for_collection,
  • Imports the get_schema_for_collection handler from query.py for exposure via __init__.
    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,
    )

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