Skip to main content
Glama

upsert_document_by_id

Insert or update a document in Couchbase using its ID, returning success status. Specify bucket, scope, collection, ID, and content for document management.

Instructions

Insert or update a document by its ID. Returns True on success, False on failure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bucket_nameYes
scope_nameYes
collection_nameYes
document_idYes
document_contentYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function that executes the upsert_document_by_id tool logic, connecting to Couchbase and performing the upsert operation.
    def upsert_document_by_id(
        ctx: Context,
        bucket_name: str,
        scope_name: str,
        collection_name: str,
        document_id: str,
        document_content: dict[str, Any],
    ) -> bool:
        """Insert or update a document by its ID.
        Returns True on success, False on failure."""
        cluster = get_cluster_connection(ctx)
        bucket = connect_to_bucket(cluster, bucket_name)
        try:
            collection = bucket.scope(scope_name).collection(collection_name)
            collection.upsert(document_id, document_content)
            logger.info(f"Successfully upserted document {document_id}")
            return True
        except Exception as e:
            logger.error(f"Error upserting document {document_id}: {e}")
            return False
  • Registers all tools, including upsert_document_by_id, with the FastMCP server instance.
    # Register all tools
    for tool in ALL_TOOLS:
        mcp.add_tool(tool)
  • Imports and exposes the upsert_document_by_id function for inclusion in the ALL_TOOLS list used for registration.
    # Key-Value tools
    from .kv import (
        delete_document_by_id,
        get_document_by_id,
        upsert_document_by_id,
    )
    
    # Query tools
    from .query import (
        get_longest_running_queries,
        get_most_frequent_queries,
        get_queries_not_selective,
        get_queries_not_using_covering_index,
        get_queries_using_primary_index,
        get_queries_with_large_result_count,
        get_queries_with_largest_response_sizes,
        get_schema_for_collection,
        run_sql_plus_plus_query,
    )
    
    # Server tools
    from .server import (
        get_buckets_in_cluster,
        get_cluster_health_and_services,
        get_collections_in_scope,
        get_scopes_and_collections_in_bucket,
        get_scopes_in_bucket,
        get_server_configuration_status,
        test_cluster_connection,
    )
    
    # List of all tools for easy registration
    ALL_TOOLS = [
        get_buckets_in_cluster,
        get_server_configuration_status,
        test_cluster_connection,
        get_scopes_and_collections_in_bucket,
        get_collections_in_scope,
        get_scopes_in_bucket,
        get_document_by_id,
        upsert_document_by_id,
        delete_document_by_id,
        get_schema_for_collection,
        run_sql_plus_plus_query,
        get_index_advisor_recommendations,
        list_indexes,
        get_cluster_health_and_services,
        get_queries_not_selective,
        get_queries_not_using_covering_index,
        get_queries_using_primary_index,
        get_queries_with_large_result_count,
        get_queries_with_largest_response_sizes,
        get_longest_running_queries,
        get_most_frequent_queries,
    ]
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. It mentions the return value (True/False on success/failure) but lacks details on permissions, error handling, rate limits, or side effects like overwriting existing documents. This is insufficient for a mutation tool with zero annotation coverage.

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 concise with two sentences that efficiently state the action and return value, with no wasted words. It's front-loaded with the core purpose, though it could be slightly more structured by hinting at parameter roles.

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 complexity of a 5-parameter mutation tool with no annotations, the description is incomplete—it lacks details on behavior, parameters, and usage context. However, the presence of an output schema (implied by 'Has output schema: true') reduces the need to explain return values, providing some baseline adequacy.

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?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It adds no information about the five parameters (e.g., bucket_name, document_content), leaving their semantics unclear beyond what the schema titles imply. This fails to address the coverage gap adequately.

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 ('Insert or update') and resource ('a document by its ID'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'delete_document_by_id' or 'get_document_by_id' beyond the obvious action difference, 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?

No guidance is provided on when to use this tool versus alternatives, such as distinguishing it from other document operations in the sibling list. The description lacks context on prerequisites, scenarios, or exclusions, leaving usage unclear beyond the basic action.

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

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/Couchbase-Ecosystem/mcp-server-couchbase'

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