describe_collection
Retrieve the schema and metadata of a specified collection to understand its structure and properties. Use this tool to manage and analyze collections in Typesense MCP Server efficiently.
Instructions
Retrieves the schema and metadata for a specific collection.
Args:
ctx (Context): The MCP context.
collection_name (str): The name of the collection to describe.
Returns:
dict | str: The collection schema dictionary or an error message string.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection_name | Yes |
Input Schema (JSON Schema)
{
"properties": {
"collection_name": {
"title": "Collection Name",
"type": "string"
}
},
"required": [
"collection_name"
],
"title": "describe_collectionArguments",
"type": "object"
}
Implementation Reference
- main.py:142-167 (handler)This is the handler function for the 'describe_collection' tool. It is decorated with @mcp.tool() for registration and implements the logic to retrieve the schema and metadata of a Typesense collection by name, handling various errors.@mcp.tool() async def describe_collection(ctx: Context, collection_name: str) -> dict | str: """ Retrieves the schema and metadata for a specific collection. Args: ctx (Context): The MCP context. collection_name (str): The name of the collection to describe. Returns: dict | str: The collection schema dictionary or an error message string. """ if not collection_name: return "Error: collection_name parameter is required." try: client: typesense.Client = ctx.request_context.lifespan_context.client collection_info = client.collections[collection_name].retrieve() return collection_info except typesense.exceptions.ObjectNotFound: return f"Error: Collection '{collection_name}' not found." except typesense.exceptions.TypesenseClientError as e: print(f"Error describing collection '{collection_name}': {e}") return f"Error describing collection '{collection_name}': {e}" except Exception as e: print(f"An unexpected error occurred while describing collection '{collection_name}': {e}") return f"An unexpected error occurred: {e}"