Skip to main content
Glama
avarant

Typesense MCP Server

export_collection

Export all documents from a specified collection in Typesense. Handles large datasets but may be memory-intensive for very large collections. Useful for data backup, migration, or analysis.

Instructions

Exports all documents from a specific collection.

Warning: This can be memory-intensive for very large collections.

Args:
    ctx (Context): The MCP context.
    collection_name (str): The name of the collection to export.

Returns:
    list[dict] | str: A list of document dictionaries or an error message string.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collection_nameYes

Implementation Reference

  • main.py:170-209 (handler)
    The handler function for the 'export_collection' MCP tool. It exports all documents from the specified Typesense collection using the export() method, parsing JSON lines into a list of dicts, with comprehensive error handling.
    @mcp.tool()
    async def export_collection(ctx: Context, collection_name: str) -> list[dict] | str:
        """
        Exports all documents from a specific collection.
    
        Warning: This can be memory-intensive for very large collections.
    
        Args:
            ctx (Context): The MCP context.
            collection_name (str): The name of the collection to export.
    
        Returns:
            list[dict] | str: A list of document dictionaries or an error message string.
        """
        if not collection_name:
            return "Error: collection_name parameter is required."
    
        documents = []
        try:
            client: typesense.Client = ctx.request_context.lifespan_context.client
            # Check if collection exists first to give a clearer error
            _ = client.collections[collection_name].retrieve() # Check existence synchronously
    
            exported_lines = client.collections[collection_name].documents.export()
            for line in exported_lines:
                try:
                    documents.append(json.loads(line))
                except json.JSONDecodeError:
                    print(f"Warning: Could not decode JSON line during export: {line}")
                    # Decide whether to skip or raise an error
                    continue
            return documents
        except typesense.exceptions.ObjectNotFound:
            return f"Error: Collection '{collection_name}' not found."
        except typesense.exceptions.TypesenseClientError as e:
            print(f"Error exporting collection '{collection_name}': {e}")
            return f"Error exporting collection '{collection_name}': {e}"
        except Exception as e:
            print(f"An unexpected error occurred while exporting collection '{collection_name}': {e}")
            return f"An unexpected error occurred: {e}"
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It usefully warns about memory intensity for large collections, which is valuable operational context. However, it doesn't mention other important behaviors: whether this requires special permissions, what format the exported documents are in (beyond 'list of dictionaries'), whether it's paginated or streams results, or potential timeout/rate limit considerations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the core purpose is stated first, followed by a warning, then parameter and return documentation. Every sentence earns its place, though the Args/Returns formatting is somewhat verbose for a single parameter. No redundant information is included.

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

Completeness3/5

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

Given the tool's moderate complexity (export operation with memory implications), no annotations, and no output schema, the description is partially complete. It covers the basic operation and a key warning, but lacks details about authentication needs, error conditions beyond 'error message string', output format specifics, or performance characteristics. The return type documentation is minimal ('list of document dictionaries').

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must compensate. It does explain the single parameter ('collection_name') as 'The name of the collection to export', which adds basic meaning beyond the schema's title 'Collection Name'. However, it doesn't provide format expectations, constraints (e.g., naming rules), or examples—just a minimal definition.

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

Purpose4/5

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

The description clearly states the tool's purpose with a specific verb ('Exports') and resource ('all documents from a specific collection'). It distinguishes itself from siblings like 'list_collections' (metadata only) and 'describe_collection' (schema info), but doesn't explicitly differentiate from 'import_documents_from_csv' (inverse operation) or 'truncate_collection' (deletion vs export).

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'list_collections' (for metadata) or 'search' (for filtered queries). The warning about memory intensity is helpful but doesn't constitute usage guidance—it's a behavioral constraint rather than a recommendation about when this tool is appropriate.

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

Related 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/avarant/typesense-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server