list_collections
Fetch a list of all collections in the Typesense server to manage and access schemas or handle errors with ease. Supports efficient database organization and retrieval.
Instructions
Retrieves a list of all collections in the Typesense server.
Args:
ctx (Context): The MCP context.
Returns:
list | str: A list of collection schemas or an error message string.Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:118-140 (handler)Handler function for the 'list_collections' tool. It uses the Typesense client from the context to retrieve all collections and returns the list or an error message.
@mcp.tool() async def list_collections(ctx: Context) -> list | str: """ Retrieves a list of all collections in the Typesense server. Args: ctx (Context): The MCP context. Returns: list | str: A list of collection schemas or an error message string. """ try: client: typesense.Client = ctx.request_context.lifespan_context.client collections = client.collections.retrieve() # The response is expected to be a list of dictionaries return collections except typesense.exceptions.TypesenseClientError as e: print(f"Error listing collections: {e}") return f"Error listing collections: {e}" except Exception as e: print(f"An unexpected error occurred while listing collections: {e}") return f"An unexpected error occurred: {e}"