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
| Name | Required | Description | Default |
|---|---|---|---|
| collectionName | Yes | Name of the collection containing the record | |
| record | Yes | The updated record data | |
| recordId | Yes | ID of the record to update |
Input Schema (JSON Schema)
{
"properties": {
"collectionName": {
"description": "Name of the collection containing the record",
"type": "string"
},
"record": {
"description": "The updated record data",
"type": "object"
},
"recordId": {
"description": "ID of the record to update",
"type": "string"
}
},
"required": [
"collectionName",
"recordId",
"record"
],
"type": "object"
}
Implementation Reference
- tools/UpdateRecord.ts:17-45 (handler)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}'`, }; }
- tools.ts:172-193 (schema)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, }, ], };