GetRecord
Retrieve a specific record from a specified collection in Astra DB using its unique ID. Simplify data access and management directly within the MCP Server.
Instructions
Get a specific record from a collection by ID
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collectionName | Yes | Name of the collection to get the record from | |
| recordId | Yes | ID of the record to retrieve |
Input Schema (JSON Schema)
{
"properties": {
"collectionName": {
"description": "Name of the collection to get the record from",
"type": "string"
},
"recordId": {
"description": "ID of the record to retrieve",
"type": "string"
}
},
"required": [
"collectionName",
"recordId"
],
"type": "object"
}
Implementation Reference
- tools/GetRecord.ts:18-33 (handler)The core handler function that retrieves a specific record from the given collection by its ID using the database client, sanitizes the data to prevent prompt injection, and returns it or null if not found.export async function GetRecord(params: { collectionName: string; recordId: string; }) { const { collectionName, recordId } = params; const collection = db.collection(collectionName); const record = await collection.findOne({ _id: recordId }); if (!record) { return null; } // Return sanitized record to prevent prompt injection attacks return sanitizeRecordData(record); }
- tools.ts:136-153 (schema)Defines the tool metadata including name, description, and input schema (JSON Schema) for validating parameters: collectionName and recordId.{ name: "GetRecord", description: "Get a specific record from a collection by ID", inputSchema: { type: "object", properties: { collectionName: { type: "string", description: "Name of the collection to get the record from", }, recordId: { type: "string", description: "ID of the record to retrieve", }, }, required: ["collectionName", "recordId"], }, },
- index.ts:156-170 (registration)Registers the tool handler in the MCP server's CallToolRequestSchema dispatcher by importing and invoking the GetRecord function in the switch case, adding extra sanitization and formatting the response as MCP content.case "GetRecord": const record = await GetRecord({ collectionName: args.collectionName as string, recordId: args.recordId as string, }); // Sanitize record to prevent prompt injection const sanitizedRecord = sanitizeRecordData(record); return { content: [ { type: "text", text: JSON.stringify(sanitizedRecord, null, 2), }, ], };