Skip to main content
Glama
avarant

Typesense MCP Server

create_collection

Creates a new collection in Typesense databases by defining a schema with required fields and name, enabling structured data storage and search functionality.

Instructions

Creates a new collection with the provided schema.

Args:
    ctx (Context): The MCP context.
    schema (dict): The collection schema dictionary (must include 'name' and 'fields').

Returns:
    dict | str: The created collection schema dictionary or an error message string.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaYes

Implementation Reference

  • main.py:455-484 (handler)
    The handler function for the 'create_collection' tool. It is decorated with @mcp.tool(), which registers the tool in the FastMCP server. The function validates the schema input, accesses the Typesense client from the context, and creates the collection asynchronously, handling various exceptions.
    @mcp.tool()
    async def create_collection(ctx: Context, schema: dict) -> dict | str:
        """
        Creates a new collection with the provided schema.
    
        Args:
            ctx (Context): The MCP context.
            schema (dict): The collection schema dictionary (must include 'name' and 'fields').
    
        Returns:
            dict | str: The created collection schema dictionary or an error message string.
        """
        if not isinstance(schema, dict) or 'name' not in schema or 'fields' not in schema:
            return "Error: Invalid schema provided. Must be a dictionary with 'name' and 'fields' keys."
    
        try:
            client: typesense.Client = ctx.request_context.lifespan_context.client
            # Assuming create is async based on library structure
            created_collection = await client.collections.create(schema)
            return created_collection
        except typesense.exceptions.ObjectAlreadyExists:
            return f"Error: Collection '{schema.get('name')}' already exists."
        except typesense.exceptions.RequestMalformed as e:
             return f"Error: Malformed create collection request. Check schema format. Details: {e}"
        except typesense.exceptions.TypesenseClientError as e:
            print(f"Error creating collection '{schema.get('name')}': {e}")
            return f"Error creating collection '{schema.get('name')}': {e}"
        except Exception as e:
            print(f"An unexpected error occurred while creating collection '{schema.get('name')}': {e}")
            return f"An unexpected error occurred: {e}"
Behavior2/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 of behavioral disclosure. It states this is a creation operation, implying mutation, but doesn't cover permissions, idempotency, error handling, or side effects. The return type hint ('dict | str') is minimal. For a mutation tool with zero annotation coverage, this is insufficient.

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 well-structured with a purpose statement, Args section, and Returns section. It's front-loaded and avoids unnecessary details. However, the 'ctx' parameter documentation adds minimal value since it's a standard MCP context, slightly reducing efficiency.

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

Completeness2/5

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

Given the tool's complexity (mutation with nested objects), lack of annotations, no output schema, and low schema coverage, the description is incomplete. It doesn't explain the collection schema format, error conditions, or behavioral implications. The return type hint is vague ('dict | str'), failing to provide adequate context for the agent.

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?

Schema description coverage is 0%, so the description must compensate. It adds value by naming the parameter ('schema'), specifying it's a 'dict', and noting it 'must include 'name' and 'fields''. However, it doesn't fully explain the schema structure or constraints beyond this, leaving gaps. The baseline is 3 due to partial compensation.

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: 'Creates a new collection with the provided schema.' It specifies the verb ('creates') and resource ('collection'), and distinguishes it from siblings like 'delete_collection' or 'list_collections'. However, it doesn't explicitly differentiate from 'describe_collection' in terms of creation vs. description, keeping it at 4 rather than 5.

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. It doesn't mention prerequisites, when-not-to-use scenarios, or compare it to other collection-related tools like 'truncate_collection' or 'export_collection'. The agent must infer usage from the purpose alone.

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