Skip to main content
Glama
hendrickcastro

MCP CosmosDB

mcp_get_document_by_id

Retrieve a specific document from an Azure CosmosDB container using its unique ID and partition key. This point read operation is an efficient method that requires both identifiers for accurate retrieval.

Instructions

Get a single document by its ID and partition key. This is the most efficient way to retrieve a specific document.

IMPORTANT: Both document_id and partition_key are required for a point read in CosmosDB. The partition_key type must match your container's partition key type.

Example: mcp_get_document_by_id({container_id: 'users', document_id: 'user-123', partition_key: 'user-123', connection_id: 'athlete'})

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
container_idYesThe ID/name of the container
document_idYesThe unique ID of the document (the 'id' field value)
partition_keyYesThe partition key value for the document. Must match the container's partition key path value.
connection_idNoID of the connection to use. Use mcp_list_connections to see available connections. If not specified, uses the default connection.

Implementation Reference

  • The main handler function that executes the mcp_get_document_by_id tool. It accepts container_id, document_id, partition_key, and optional connection_id. Uses CosmosDB's point read via container.item(id, partitionKey).read() to retrieve a single document by its ID and partition key.
    export const mcp_get_document_by_id = async (args: { 
      container_id: string; 
      document_id: string; 
      partition_key: PartitionKeyValue;
      connection_id?: string;
    }): Promise<ToolResult<DocumentInfo>> => {
      const { container_id, document_id, partition_key, connection_id } = args;
      log(`Executing mcp_get_document_by_id with: ${JSON.stringify(args)}`);
    
      try {
        const container = getContainer(container_id, connection_id);
        const { resource: document, statusCode } = await container.item(document_id, partition_key).read();
    
        if (!document) {
          return { success: false, error: `Document with id '${document_id}' not found` };
        }
    
        return { success: true, data: document };
      } catch (error: any) {
        log(`Error in mcp_get_document_by_id for document ${document_id}: ${error.message}`);
        return { success: false, error: error.message };
      }
    };
  • The input schema and tool registration definition for mcp_get_document_by_id. Defines the tool name, description, and inputSchema with required parameters: container_id (string), document_id (string), and partition_key (string|number|boolean).
      // 7. Get Document by ID
      {
        name: "mcp_get_document_by_id",
        description: `Get a single document by its ID and partition key. This is the most efficient way to retrieve a specific document.
    
    IMPORTANT: Both document_id and partition_key are required for a point read in CosmosDB.
    The partition_key type must match your container's partition key type.
    
    Example: mcp_get_document_by_id({container_id: 'users', document_id: 'user-123', partition_key: 'user-123', connection_id: 'athlete'})`,
        inputSchema: {
          type: "object",
          properties: {
            container_id: {
              type: "string",
              description: "The ID/name of the container"
            },
            document_id: {
              type: "string",
              description: "The unique ID of the document (the 'id' field value)"
            },
            partition_key: {
              type: ["string", "number", "boolean"],
              description: "The partition key value for the document. Must match the container's partition key path value."
            },
            ...connectionIdProperty
          },
          required: ["container_id", "document_id", "partition_key"]
        }
  • src/server.ts:141-142 (registration)
    The server-side dispatch that routes the 'mcp_get_document_by_id' tool call to the handler function via toolHandlers.mcp_get_document_by_id(input as any).
    case 'mcp_get_document_by_id':
        result = await toolHandlers.mcp_get_document_by_id(input as any);
  • The barrel export that re-exports mcp_get_document_by_id from dataOperations.ts so it's accessible via the tools module.
    export {
      mcp_list_connections,
      mcp_execute_query,
      mcp_get_documents,
      mcp_get_document_by_id,
      mcp_analyze_schema,
      mcp_create_document,
      mcp_update_document,
      mcp_delete_document,
      mcp_upsert_document
    } from './dataOperations.js';
  • src/mcp-server.ts:1-3 (registration)
    The mcp-server.ts barrel file that re-exports all tools from ./tools/index.js, making them accessible to server.ts via import * as toolHandlers.
    // Import all tools from the modular structure
    export * from './tools/index.js';
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. It describes the operation as a point read and gives constraints, but does not disclose what happens on missing document (e.g., null vs error), nor any permissions or rate limits. Basic behavior is covered but lacks detail on outcomes.

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 concise: two short paragraphs and a code example. It front-loads the core purpose, then provides crucial usage notes, and ends with an illustrative example. Every sentence adds value without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is largely complete given the tool's simplicity and the presence of a full input schema. However, it lacks any mention of the return format (e.g., the document object), which is relevant since there is no output schema. This is a minor gap for a retrieval tool.

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

Parameters5/5

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

Schema coverage is 100%, but description adds significant value: it explains the importance of partition_key type matching, that both ID and partition key are required for a point read, and provides a concrete example. This enriches understanding beyond the schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Get a single document by its ID and partition key.' It uses specific verb ('get') and resource ('document'), and differentiates from siblings by noting it is the 'most efficient way to retrieve a specific document,' contrasting with query or list tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly requires both document_id and partition_key for a point read, and notes the partition_key type must match the container's key type. It provides an example. While it doesn't explicitly state when not to use it, the conditions for correct usage are clear.

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/hendrickcastro/MCPCosmosDB'

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