Skip to main content
Glama
datastax

Astra DB MCP Server

Official

UpdateRecord

Modify an existing record in a specified collection using its unique ID and updated data. Integrates with Astra DB MCP Server to manage database records via natural language commands.

Instructions

Update an existing record in a collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionNameYesName of the collection containing the record
recordYesThe updated record data
recordIdYesID of the record to update

Implementation Reference

  • The core handler function that executes the UpdateRecord tool logic. It updates a specific record in a MongoDB collection by ID, removes _id from update data, and returns success message or throws error if not found.
    export async function UpdateRecord(params: {
      collectionName: string;
      recordId: string;
      record: Record<string, any>;
    }) {
      const { collectionName, recordId, record } = params;
    
      const collection = db.collection(collectionName);
    
      // Remove _id from the record if it exists, as it cannot be updated
      const updateData = { ...record };
      delete updateData._id;
    
      const result = await collection.updateOne(
        { _id: recordId },
        { $set: updateData }
      );
    
      if (result.matchedCount === 0) {
        throw new Error(
          `Record with ID '${recordId}' not found in collection '${collectionName}'`
        );
      }
    
      return {
        success: true,
        message: `Record '${recordId}' updated successfully in collection '${collectionName}'`,
      };
    }
  • Defines the tool's metadata including name, description, and input schema used for validation in MCP tool listing.
    {
      name: "UpdateRecord",
      description: "Update an existing record in a collection",
      inputSchema: {
        type: "object",
        properties: {
          collectionName: {
            type: "string",
            description: "Name of the collection containing the record",
          },
          recordId: {
            type: "string",
            description: "ID of the record to update",
          },
          record: {
            type: "object",
            description: "The updated record data",
          },
        },
        required: ["collectionName", "recordId", "record"],
      },
    },
  • index.ts:61-65 (registration)
    Registers the list tools handler which returns the tools array including UpdateRecord schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools,
      };
    });
  • index.ts:186-199 (registration)
    The switch case in the CallToolRequest handler that dispatches to the UpdateRecord function based on tool name.
    case "UpdateRecord":
      const updateRecordResult = await UpdateRecord({
        collectionName: args.collectionName as string,
        recordId: args.recordId as string,
        record: args.record as Record<string, any>,
      });
      return {
        content: [
          {
            type: "text",
            text: updateRecordResult.message,
          },
        ],
      };

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/datastax/astra-db-mcp'

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