Skip to main content
Glama

chroma_add_documents

Enables adding text documents to a Chroma collection with optional metadata. Specify collection name, document IDs, and content for efficient data storage and retrieval.

Instructions

Add documents to a Chroma collection.

Args:
    collection_name: Name of the collection to add documents to
    documents: List of text documents to add
    ids: List of IDs for the documents (required)
    metadatas: Optional list of metadata dictionaries for each document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collection_nameYes
documentsYes
idsYes
metadatasNo

Implementation Reference

  • The chroma_add_documents tool handler. Decorated with @mcp.tool() for automatic registration in FastMCP. Implements document addition to ChromaDB collection with validation for empty inputs, ID uniqueness, and length matching. Uses get_chroma_client() helper and performs add operation.
    @mcp.tool()
    async def chroma_add_documents(
        collection_name: str,
        documents: List[str],
        ids: List[str],
        metadatas: List[Dict] | None = None
    ) -> str:
        """Add documents to a Chroma collection.
        
        Args:
            collection_name: Name of the collection to add documents to
            documents: List of text documents to add
            ids: List of IDs for the documents (required)
            metadatas: Optional list of metadata dictionaries for each document
        """
        if not documents:
            raise ValueError("The 'documents' list cannot be empty.")
        
        if not ids:
            raise ValueError("The 'ids' list is required and cannot be empty.")
        
        # Check if there are empty strings in the ids list
        if any(not id.strip() for id in ids):
            raise ValueError("IDs cannot be empty strings.")
        
        if len(ids) != len(documents):
            raise ValueError(f"Number of ids ({len(ids)}) must match number of documents ({len(documents)}).")
    
        client = get_chroma_client()
        try:
            collection = client.get_or_create_collection(collection_name)
            
            # Check for duplicate IDs
            existing_ids = collection.get(include=[])["ids"]
            duplicate_ids = [id for id in ids if id in existing_ids]
            
            if duplicate_ids:
                raise ValueError(
                    f"The following IDs already exist in collection '{collection_name}': {duplicate_ids}. "
                    f"Use 'chroma_update_documents' to update existing documents."
                )
            
            result = collection.add(
                documents=documents,
                metadatas=metadatas,
                ids=ids
            )
            
            # Check the return value
            if result and isinstance(result, dict):
                # If the return value is a dictionary, it may contain success information
                if 'success' in result and not result['success']:
                    raise Exception(f"Failed to add documents: {result.get('error', 'Unknown error')}")
                
                # If the return value contains the actual number added
                if 'count' in result:
                    return f"Successfully added {result['count']} documents to collection {collection_name}"
            
            # Default return
            return f"Successfully added {len(documents)} documents to collection {collection_name}, result is {result}"
        except Exception as e:
            raise Exception(f"Failed to add documents to collection '{collection_name}': {str(e)}") from e
  • The @mcp.tool() decorator registers the chroma_add_documents function as an MCP tool.
    @mcp.tool()
  • Input schema defined by function type hints: collection_name (str), documents (List[str]), ids (List[str]), metadatas (optional List[Dict]). Returns str confirmation.
    async def chroma_add_documents(
        collection_name: str,
        documents: List[str],
        ids: List[str],
        metadatas: List[Dict] | None = None
    ) -> str:
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral disclosure. It states the action ('Add documents') but doesn't describe what happens on success/failure, whether IDs must be unique, if documents are indexed immediately, rate limits, or authentication needs. For a mutation tool with zero annotation coverage, this leaves significant gaps in understanding the tool's behavior.

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 with the core purpose in the first sentence. The parameter list is organized but could be more integrated with the main description. No wasted sentences, though the structure is somewhat basic.

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 4 parameters with 0% schema coverage, no annotations, no output schema, and being a mutation tool in a complex sibling set, the description is incomplete. It covers basic parameter semantics but lacks behavioral context, usage guidance, error handling, and output expectations. For a document addition tool in a vector database context, more completeness is needed.

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 lists all 4 parameters with brief explanations, adding meaning beyond the bare schema (e.g., 'List of text documents', 'Optional list of metadata dictionaries'). However, it doesn't explain relationships between parameters (e.g., arrays must have same length), constraints (e.g., ID uniqueness), or provide examples, leaving some semantic gaps.

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 verb ('Add') and resource ('documents to a Chroma collection'), making the purpose immediately understandable. It distinguishes from siblings like chroma_delete_documents and chroma_update_documents by specifying addition rather than removal or modification. However, it doesn't explicitly contrast with chroma_create_collection or chroma_fork_collection in terms of collection-level vs document-level operations.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., collection must exist), when not to use it, or suggest alternatives like chroma_update_documents for modifying existing documents. 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/chroma-core/chroma-mcp'

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