Skip to main content
Glama

get_document_by_id

Retrieve a document from a Couchbase database by specifying its bucket, scope, collection, and document ID. Returns the document data or raises an exception if 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
NameRequiredDescriptionDefault
bucket_nameYes
scope_nameYes
collection_nameYes
document_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'get_document_by_id' tool. Retrieves a document from Couchbase using the cluster connection, bucket, scope, collection, and document ID. Returns the document content as dict or raises exception.
    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
  • Imports the get_document_by_id handler from the kv module into the tools package __init__, exposing it for use in ALL_TOOLS and server registration.
    from .kv import (
        delete_document_by_id,
        get_document_by_id,
        upsert_document_by_id,
    )
  • Registers all tools from ALL_TOOLS, including get_document_by_id, with the FastMCP server instance.
    # Register all tools
    for tool in ALL_TOOLS:
        mcp.add_tool(tool)
Behavior3/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 usefully states that 'If the document is not found, it will raise an exception,' which is important error behavior. However, it doesn't describe authentication requirements, rate limits, response format, or whether this is a read-only operation (though 'Get' implies reading).

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 concise with two sentences that each serve a purpose: the first states the core functionality, the second describes error behavior. It's front-loaded with the main purpose and wastes no words. However, it could be slightly more structured with explicit parameter context.

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 tool's moderate complexity (4 required parameters), no annotations, and the presence of an output schema, the description is partially complete. It covers the basic operation and error behavior but lacks parameter explanations, usage context, and behavioral details like authentication. The output schema existence reduces the need to describe return values, but more guidance is needed for proper tool selection.

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 and 4 parameters, the description adds minimal value beyond what the schema provides. It mentions 'specified scope and collection' which hints at scope_name and collection_name parameters, but doesn't explain bucket_name, document_id, or the hierarchical relationship between these parameters. The description doesn't compensate for the schema's lack of parameter descriptions.

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 'Get' and resource 'document by its ID', specifying the scope and collection context. It distinguishes from siblings like delete_document_by_id and upsert_document_by_id by focusing on retrieval rather than modification. However, it doesn't explicitly differentiate from other get_* tools that retrieve different resources.

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. It doesn't mention when to use get_document_by_id versus other get_* tools like get_schema_for_collection or get_scopes_in_bucket, nor does it specify prerequisites or appropriate contexts for document retrieval.

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