Skip to main content
Glama
hendrickcastro

MCP CosmosDB

mcp_create_document

Create a new document in a CosmosDB container. Requires a unique 'id' field and partition key value within the partition. Specify container, document body, partition key, and optional connection.

Instructions

Create a new document in a CosmosDB container.

REQUIREMENTS:

  • The document MUST have an 'id' field (string)

  • The document MUST have the partition key field with a value

  • The 'id' must be unique within the partition

Example: mcp_create_document({ container_id: 'users', document: {id: 'user-456', email: 'test@example.com', status: 'active'}, partition_key: 'user-456', connection_id: 'athlete' })

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
container_idYesThe ID/name of the container
documentYesThe document to create. Must include 'id' field and the partition key field.
partition_keyYesThe partition key value for the document
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 creates a document in a CosmosDB container. Validates document has an 'id', creates the item via container.items.create(), and returns the created document's id, etag, timestamp, and request charge.
    export const mcp_create_document = async (args: CreateDocumentArgs & { connection_id?: string }): Promise<ToolResult<DocumentOperationResult>> => {
      const { container_id, document, partition_key, connection_id } = args;
      log(`Executing mcp_create_document with: ${JSON.stringify({ container_id, document_id: document.id, partition_key, connection_id })}`);
    
      try {
        // Validate modifications are allowed
        validateModificationAllowed('create_document', connection_id);
        
        // Validate document has an id
        if (!document.id) {
          return { success: false, error: "Document must have an 'id' field" };
        }
    
        const container = getContainer(container_id, connection_id);
        
        const { resource: createdDocument, requestCharge } = await container.items.create(
          document
        );
    
        if (!createdDocument) {
          return { success: false, error: "Failed to create document - no response from CosmosDB" };
        }
    
        return { 
          success: true, 
          data: {
            id: createdDocument.id,
            _etag: createdDocument._etag,
            _ts: createdDocument._ts,
            requestCharge: requestCharge || 0
          }
        };
      } catch (error: any) {
        log(`Error in mcp_create_document for container ${container_id}: ${error.message}`);
        
        // Provide more helpful error messages
        if (error.code === 409) {
          return { success: false, error: `Document with id '${document.id}' already exists in this partition` };
        }
        
        return { success: false, error: error.message };
      }
    };
  • Tool registration and input schema definition for 'mcp_create_document'. Defines the name, description, inputSchema (container_id, document, partition_key, optional connection_id), and required fields.
      // 9. Create Document
      {
        name: "mcp_create_document",
        description: `Create a new document in a CosmosDB container.
    
    REQUIREMENTS:
    - The document MUST have an 'id' field (string)
    - The document MUST have the partition key field with a value
    - The 'id' must be unique within the partition
    
    Example: mcp_create_document({
      container_id: 'users',
      document: {id: 'user-456', email: 'test@example.com', status: 'active'},
      partition_key: 'user-456',
      connection_id: 'athlete'
    })`,
        inputSchema: {
          type: "object",
          properties: {
            container_id: {
              type: "string",
              description: "The ID/name of the container"
            },
            document: {
              type: "object",
              description: "The document to create. Must include 'id' field and the partition key field."
            },
            partition_key: {
              type: ["string", "number", "boolean"],
              description: "The partition key value for the document"
            },
            ...connectionIdProperty
          },
          required: ["container_id", "document", "partition_key"]
        }
  • src/server.ts:149-151 (registration)
    Server-side registration where the tool name 'mcp_create_document' is matched and dispatched to the handler function.
    case 'mcp_create_document':
        result = await toolHandlers.mcp_create_document(input as any);
        break;
  • Re-export of mcp_create_document from dataOperations.ts, making it available to consumers of the tools module.
      mcp_create_document,
      mcp_update_document,
      mcp_delete_document,
      mcp_upsert_document
    } from './dataOperations.js';
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavior. It misses key details: what happens if the id already exists (error?), whether the document is returned upon creation, and any side effects. The uniqueness constraint is mentioned, but behavior on violation is not.

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 compact with a clear structure: a one-liner purpose, a bulleted list of requirements, and an example. Every part serves a purpose without redundancy.

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

Completeness2/5

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

Given no output schema, the description should explain what the tool returns (e.g., the created document or a success indicator). It also doesn't cover error cases or default behavior for connection_id. For a data-modifying tool, these are significant gaps.

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

Parameters3/5

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

Schema coverage is 100%, so baseline is 3. The description adds some value by stressing that 'id' must be unique within the partition and giving an example, but it largely restates schema info. No additional semantics for partition_key or connection_id beyond the schema.

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 'Create a new document in a CosmosDB container', which is a specific verb and resource. It differentiates from sibling tools like mcp_delete_document, mcp_update_document, and mcp_upsert_document by focusing exclusively on creation.

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

Usage Guidelines3/5

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

The description provides requirements and an example of when to use the tool, but it does not explicitly compare it to alternatives like mcp_upsert_document. An agent would benefit from knowing when to choose create over upsert or update.

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