BulkCreateRecords
Create multiple database records in one operation to efficiently handle batch data insertion and maintain data consistency.
Instructions
Create multiple records in a single operation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | Array of record data to insert | |
| label | Yes | Label for all records | |
| transactionId | No | Optional transaction ID for atomic bulk creation |
Implementation Reference
- tools/BulkCreateRecords.ts:28-40 (handler)The core handler function implementing the BulkCreateRecords tool logic, using db.records.createMany for batch insertion.export async function BulkCreateRecords({ label, data, transactionId }: BulkCreateRecordsArgs): Promise<BulkCreateRecordsResult> { const result = await db.records.createMany({ label, data }, transactionId) const ids = result.data.map((record: any) => record.id()) return { message: `Successfully created ${ids.length} records with label '${label}'`, ids } }
- tools.ts:257-269 (registration)Registration of the BulkCreateRecords tool in the exported tools array used by MCP ListTools, including input schema.{ name: 'BulkCreateRecords', description: 'Create multiple records in a single operation', inputSchema: { type: 'object', properties: { label: { type: 'string', description: 'Label for all records' }, data: { type: 'array', items: { type: 'object' }, description: 'Array of record data to insert' }, transactionId: { type: 'string', description: 'Optional transaction ID for atomic bulk creation' } }, required: ['label', 'data'] } },
- tools/BulkCreateRecords.ts:17-26 (schema)TypeScript type definitions for input arguments and output result of the BulkCreateRecords handler.type BulkCreateRecordsArgs = { label: string data: Record<string, any>[] transactionId?: string } type BulkCreateRecordsResult = { message: string ids: string[] }
- index.ts:273-286 (handler)MCP server dispatcher case that invokes the BulkCreateRecords handler and formats the response for the MCP protocol.case 'BulkCreateRecords': const bulkCreateResult = await BulkCreateRecords({ label: args.label as string, data: args.data as Record<string, any>[], transactionId: args.transactionId as string | undefined }) return { content: [ { type: 'text', text: `${bulkCreateResult.message}\nIDs: ${bulkCreateResult.ids.join(', ')}` } ] }
- index.ts:35-35 (registration)Import of the BulkCreateRecords handler into the main index for use in the tool dispatcher.import { BulkCreateRecords } from './tools/BulkCreateRecords.js'