Skip to main content
Glama
privetin

Chroma MCP Server

by privetin

create_document

Generate and store new documents in Chroma's vector database with unique IDs, content, and metadata, enabling efficient semantic search and document management.

Instructions

Create a new document in the Chroma vector database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes
document_idYes
metadataNo

Implementation Reference

  • The core handler function for the 'create_document' tool. It validates inputs, checks for existing documents, processes metadata, and adds the document to the Chroma collection using collection.add().
    async def handle_create_document(arguments: dict) -> list[types.TextContent]:
        """Handle document creation with retry logic"""
        doc_id = arguments.get("document_id")
        content = arguments.get("content")
        metadata = arguments.get("metadata")
    
        if not doc_id or not content:
            raise DocumentOperationError("Missing document_id or content")
    
        try:
            # Check if document exists using get() instead of collection.get()
            try:
                existing = collection.get(
                    ids=[doc_id],
                    include=['metadatas']
                )
                if existing and existing['ids']:
                    raise DocumentOperationError(f"Document already exists [id={doc_id}]")
            except Exception as e:
                if "not found" not in str(e).lower():
                    raise
    
            # Process metadata
            if metadata:
                processed_metadata = {
                    k: str(v) if isinstance(v, (int, float)) else v
                    for k, v in metadata.items()
                }
            else:
                processed_metadata = {}
    
            # Add document
            collection.add(
                documents=[content],
                ids=[doc_id],
                metadatas=[processed_metadata]
            )
    
            return [
                types.TextContent(
                    type="text",
                    text=f"Created document '{doc_id}' successfully"
                )
            ]
        except DocumentOperationError:
            raise
        except Exception as e:
            raise DocumentOperationError(str(e))
  • Tool dispatch logic in the main call_tool handler that routes 'create_document' calls to the specific handle_create_document function.
    if name == "create_document":
        return await handle_create_document(arguments)
  • JSON schema definition for the 'create_document' tool inputs, used in server.command_options.
    "create_document": {
        "type": "object",
        "properties": {
            "document_id": {"type": "string"},
            "content": {"type": "string"},
            "metadata": {"type": "object", "additionalProperties": True}
        },
        "required": ["document_id", "content"]
    },
  • Tool registration in the list_tools handler, defining the 'create_document' tool with name, description, and input schema.
        name="create_document",
        description="Create a new document in the Chroma vector database",
        inputSchema={
            "type": "object",
            "properties": {
                "document_id": {"type": "string"},
                "content": {"type": "string"},
                "metadata": {
                    "type": "object",
                    "additionalProperties": True
                }
            },
            "required": ["document_id", "content"]
        }
    ),
  • Retry decorator applied to create_document handler (@retry_operation('create_document') at line 361), providing exponential backoff and error handling for Chroma operations.
    def retry_operation(operation_name: str):
        """Decorator to retry document operations with exponential backoff"""
        def decorator(func):
            @functools.wraps(func)
            async def wrapper(*args, **kwargs):
                max_retries = 3
                for attempt in range(max_retries):
                    try:
                        return await func(*args, **kwargs)
                    except DocumentOperationError as e:
                        if attempt == max_retries - 1:
                            raise e
                        await asyncio.sleep(2 ** attempt)
                    except Exception as e:
                        if attempt == max_retries - 1:
                            # Clean up error message
                            msg = str(e)
                            if msg.lower().startswith(operation_name.lower()):
                                msg = msg[len(operation_name):].lstrip(': ')
                            if msg.lower().startswith('failed'):
                                msg = msg[7:].lstrip(': ')
                            if msg.lower().startswith('search failed'):
                                msg = msg[13:].lstrip(': ')
                            
                            # Map error patterns to friendly messages
                            error_msg = msg.lower()
                            doc_id = kwargs.get('arguments', {}).get('document_id')
                            
                            if "not found" in error_msg:
                                error = f"Document not found{f' [id={doc_id}]' if doc_id else ''}"
                            elif "already exists" in error_msg:
                                error = f"Document already exists{f' [id={doc_id}]' if doc_id else ''}"
                            elif "invalid" in error_msg:
                                error = "Invalid input"
                            elif "filter" in error_msg:
                                error = "Invalid filter"
                            else:
                                error = "Operation failed"
                                
                            raise DocumentOperationError(error)
                        await asyncio.sleep(2 ** attempt)
                return None
            return wrapper
        return decorator
Behavior2/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. While 'Create' implies a write operation, it doesn't disclose important behavioral traits like required permissions, whether the operation is idempotent, error handling for duplicate document_ids, or what happens if metadata is omitted. This leaves significant gaps for a mutation tool.

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

Conciseness5/5

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

The description is a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a basic create operation and front-loads the essential information.

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?

For a mutation tool with 3 parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain the return value, error conditions, or provide enough context about the parameters and their relationships to enable reliable tool invocation.

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

Parameters2/5

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

With 0% schema description coverage for all 3 parameters, the description provides no information about parameter meanings, formats, or constraints. It doesn't explain what 'document_id' should be, what 'content' represents, or how 'metadata' should be structured, failing to compensate for the schema's lack of documentation.

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 action ('Create a new document') and target resource ('in the Chroma vector database'), providing specific verb+resource information. However, it doesn't distinguish this tool from its sibling 'update_document' in terms of when to use create versus update operations, which prevents a perfect score.

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 'update_document' or 'list_documents', nor does it mention prerequisites or constraints. It simply states what the tool does without contextual usage information.

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/privetin/chroma'

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