CreateRecord
Insert new data records into specified collections within Astra DB, enabling structured storage and management through natural language commands on the MCP Server.
Instructions
Create a new record in a collection
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collectionName | Yes | Name of the collection to create the record in | |
| record | Yes | The record data to insert |
Input Schema (JSON Schema)
{
"properties": {
"collectionName": {
"description": "Name of the collection to create the record in",
"type": "string"
},
"record": {
"description": "The record data to insert",
"type": "object"
}
},
"required": [
"collectionName",
"record"
],
"type": "object"
}
Implementation Reference
- tools/CreateRecord.ts:25-47 (handler)The main handler function for the CreateRecord tool, which inserts a new record into the specified collection and returns the result with ID and success message.export async function CreateRecord(params: { collectionName: string; record: Record<string, any>; }): Promise<CreateRecordResult> { const { collectionName, record } = params; const collection = db.collection(collectionName); const result = await collection.insertOne(record); // Create a response that satisfies both the tests and the index.ts usage const id = record._id || result.insertedId; // Create the response object with all required properties const response: CreateRecordResult = { ...record, _id: id, id: id, message: `Record created successfully in collection '${collectionName}'`, success: true }; return response; }
- tools.ts:154-171 (schema)The input schema definition for the CreateRecord tool, used for validation in the MCP tool list.{ name: "CreateRecord", description: "Create a new record in a collection", inputSchema: { type: "object", properties: { collectionName: { type: "string", description: "Name of the collection to create the record in", }, record: { type: "object", description: "The record data to insert", }, }, required: ["collectionName", "record"], }, },
- index.ts:61-65 (registration)The request handler for listing tools, which registers and exposes the CreateRecord tool via the exported tools array from tools.ts.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools, }; });
- index.ts:172-184 (registration)The dispatch case in the main CallToolRequest handler that invokes the CreateRecord tool function.case "CreateRecord": const createRecordResult = await CreateRecord({ collectionName: args.collectionName as string, record: args.record as Record<string, any>, }); return { content: [ { type: "text", text: `${createRecordResult.message}\nID: ${createRecordResult.id}`, }, ], };
- tools/CreateRecord.ts:18-23 (schema)TypeScript type definition for the CreateRecord result, defining the expected output structure.type CreateRecordResult = Record<string, any> & { _id: string; id: string; message: string; success: boolean; };