create_record
Add new records to PocketBase collections by specifying collection name and field data, with options to control returned fields and expand related records.
Instructions
Create a new record in a collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| data | Yes | Record data with field values matching the collection schema | |
| expand | No | Comma-separated list of relation fields to expand in the response (e.g. 'author,comments.user') | |
| fields | No | Comma-separated fields to return in the response (e.g. 'id,title,author') |
Implementation Reference
- src/tools/handlers/record.ts:15-33 (handler)The main handler function that executes the create_record tool logic by creating a new record in the specified PocketBase collection using the provided data and optional parameters.export function createCreateRecordHandler(pb: PocketBase): ToolHandler { return async (args: CreateRecordArgs) => { try { const options: any = {}; // Add optional parameters if (args.expand) options.expand = args.expand; if (args.fields) options.fields = args.fields; const result = await pb .collection(args.collection) .create(args.data, options); return createJsonResponse(result); } catch (error: unknown) { throw handlePocketBaseError("create record", error); } }; }
- src/tools/schemas/record.ts:5-26 (schema)JSON Schema defining the input structure and validation for the create_record tool.export const createRecordSchema = { type: "object", properties: { collection: { type: "string", description: "Collection name", }, data: { type: "object", description: "Record data with field values matching the collection schema", }, expand: { type: "string", description: "Comma-separated list of relation fields to expand in the response (e.g. 'author,comments.user')", }, fields: { type: "string", description: "Comma-separated fields to return in the response (e.g. 'id,title,author')", }, }, required: ["collection", "data"], };
- src/server.ts:126-130 (registration)Registration of the create_record tool in the MCP server, associating its name, description, input schema, and handler.name: "create_record", description: "Create a new record in a collection", inputSchema: createRecordSchema, handler: createCreateRecordHandler(pb), },
- src/types/index.ts:84-89 (schema)TypeScript interface defining the expected argument types for the create_record handler.export interface CreateRecordArgs { collection: string; data: Record<string, any>; expand?: string; fields?: string; }