add_review_record
Add a new review record to a custom type for storing evaluations of items like coffee, whisky, or wine, using defined schemas to organize data.
Instructions
Add a new review record to a type
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| typeName | Yes | Name of the review type | |
| data | Yes | Review data matching the type schema |
Implementation Reference
- src/tools/add-record.ts:29-69 (handler)The `addRecord` function that executes the core tool logic: validates parameters, checks type existence, validates data against schema, generates record ID, appends to storage, and returns success info.export async function addRecord( storage: StorageProvider, params: AddRecordParams ): Promise<AddRecordResult> { // Validate type name const typeName = validateTypeName(params.typeName); // Check if type exists const exists = await storage.typeExists(typeName); if (!exists) { throw new Error(`Review type "${typeName}" does not exist`); } // Read existing type data const typeData = await storage.readType(typeName); // Validate record against schema validateRecordAgainstSchema(params.data, typeData.schema); // Create new record const recordId = generateId(); const newRecord: ReviewRecord = { id: recordId, data: params.data as Record<string, string | number | boolean>, createdAt: getCurrentTimestamp(), }; // Add record to type typeData.records.push(newRecord); typeData.updatedAt = getCurrentTimestamp(); // Save updated type data await storage.writeType(typeName, typeData); return { success: true, typeName, recordId, message: `Record added to "${typeName}" with ID: ${recordId}`, }; }
- src/index.ts:110-123 (schema)Input schema definition for the `add_review_record` tool, specifying `typeName` and `data` parameters.inputSchema: { type: "object", properties: { typeName: { type: "string", description: "Name of the review type", }, data: { type: "object", description: "Review data matching the type schema", }, }, required: ["typeName", "data"], },
- src/index.ts:107-124 (registration)Registration of the `add_review_record` tool in the TOOLS array, including name, description, and input schema.{ name: "add_review_record", description: "Add a new review record to a type", inputSchema: { type: "object", properties: { typeName: { type: "string", description: "Name of the review type", }, data: { type: "object", description: "Review data matching the type schema", }, }, required: ["typeName", "data"], }, },
- src/index.ts:220-234 (registration)Dispatch handler in the CallToolRequest switch statement that invokes `addRecord` with parsed arguments and formats the response.case "add_review_record": { const params = args as { typeName: string; data: Record<string, unknown> }; if (!params?.typeName || !params?.data) { throw new Error("typeName and data are required"); } const result = await addRecord(storage, params); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }