Skip to main content
Glama

upsert_document_by_id

Insert or update a document in a Couchbase cluster using its ID by specifying the scope, collection, and content. Ensures data consistency with a success or failure return.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collection_nameYes
document_contentYes
document_idYes
scope_nameYes

Implementation Reference

  • The core handler function that executes the upsert_document_by_id tool logic using the Couchbase Python SDK to upsert a document in the specified bucket, scope, and collection.
    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
  • The registration loop where all tools, including upsert_document_by_id from ALL_TOOLS, are added to the FastMCP server instance.
    # Register all tools for tool in ALL_TOOLS: mcp.add_tool(tool)
  • The ALL_TOOLS list that collects all tool functions, including upsert_document_by_id, for bulk registration in the MCP server.
    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, ]
  • Import of the upsert_document_by_id handler from kv.py into the tools package for exposure in ALL_TOOLS.
    from .kv import ( delete_document_by_id, get_document_by_id, upsert_document_by_id, )

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

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