create_record
Add a new record to a PocketBase collection by specifying the collection name or ID and providing the required data in key-value pairs.
Instructions
Create a new record in a PocketBase collection.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | The name or ID of the PocketBase collection. | |
| data | Yes | The data for the new record (key-value pairs). |
Implementation Reference
- src/tools/record-tools.ts:114-122 (handler)The primary handler function for the 'create_record' tool. It validates input, creates a new record in the specified PocketBase collection using the provided data, and returns the created record as a formatted JSON string.async function createRecord(args: CreateRecordArgs, pb: PocketBase): Promise<ToolResult> { if (!args.collection || !args.data) { throw invalidParamsError("Missing required arguments: collection, data"); } const record = await pb.collection(args.collection).create(args.data); return { content: [{ type: 'text', text: JSON.stringify(record, null, 2) }], }; }
- src/types/tool-types.ts:43-46 (schema)TypeScript interface defining the expected input arguments for the create_record tool: collection name and data object.export interface CreateRecordArgs { collection: string; data: any; }
- src/tools/record-tools.ts:38-50 (registration)ToolInfo object registering the 'create_record' tool, including its name, description, and JSON input schema for MCP client discovery.{ name: 'create_record', description: 'Create a new record in a PocketBase collection.', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'The name or ID of the PocketBase collection.' }, data: { type: 'object', description: 'The data for the new record (key-value pairs).', additionalProperties: true }, }, required: ['collection', 'data'], }, }, {
- src/tools/index.ts:15-25 (registration)Central registration function that aggregates and exports all tool definitions, including 'create_record' via listRecordTools().export function registerTools(): { tools: ToolInfo[] } { // Use ToolInfo[] const tools: ToolInfo[] = [ // Use ToolInfo[] ...listRecordTools(), ...listCollectionTools(), ...listFileTools(), ...listMigrationTools(), // Uncommented ...listLogTools(), // Add log tools ...listCronTools(), // Add cron tools ]; return { tools }; }
- src/tools/record-tools.ts:71-85 (helper)Dispatcher function for record-related tools that routes 'create_record' calls to the specific createRecord handler.export async function handleRecordToolCall(name: string, args: any, pb: PocketBase): Promise<ToolResult> { switch (name) { case 'fetch_record': return fetchRecord(args as FetchRecordArgs, pb); case 'list_records': return listRecords(args as ListRecordsArgs, pb); case 'create_record': return createRecord(args as CreateRecordArgs, pb); case 'update_record': return updateRecord(args as UpdateRecordArgs, pb); default: // This case should ideally not be reached due to routing in index.ts throw new Error(`Unknown record tool: ${name}`); } }