get_document_by_id
Retrieve a specific document by its ID from a designated scope and collection in a Couchbase cluster. Raises an exception if the document is not found.
Instructions
Get a document by its ID from the specified scope and collection. If the document is not found, it will raise an exception.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection_name | Yes | ||
| document_id | Yes | ||
| scope_name | Yes |
Implementation Reference
- src/tools/kv.py:19-37 (handler)The handler function that implements the core logic for retrieving a document by ID from a Couchbase bucket, scope, and collection.def get_document_by_id( ctx: Context, bucket_name: str, scope_name: str, collection_name: str, document_id: str, ) -> dict[str, Any]: """Get a document by its ID from the specified scope and collection. If the document is not found, it will raise an exception.""" cluster = get_cluster_connection(ctx) bucket = connect_to_bucket(cluster, bucket_name) try: collection = bucket.scope(scope_name).collection(collection_name) result = collection.get(document_id) return result.content_as[dict] except Exception as e: logger.error(f"Error getting document {document_id}: {e}") raise
- src/mcp_server.py:175-177 (registration)Registration of all tools, including get_document_by_id, to the FastMCP server instance via a loop over the ALL_TOOLS list.# Register all tools for tool in ALL_TOOLS: mcp.add_tool(tool)
- src/tools/__init__.py:35-50 (registration)The ALL_TOOLS list that includes get_document_by_id, used for bulk registration of tools.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, ]
- src/tools/__init__.py:11-15 (registration)Import of the get_document_by_id function from kv.py into the tools package for exposure and registration.from .kv import ( delete_document_by_id, get_document_by_id, upsert_document_by_id, )