update_record
Modify existing records in PocketBase collections by specifying the record ID and updated field values, with options to control response fields and expand related data.
Instructions
Update an existing record
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| data | Yes | Updated record data with field values matching the collection schema. Can use field modifiers like fieldName+, +fieldName, fieldName-. | |
| 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') | |
| id | Yes | Record ID |
Implementation Reference
- src/tools/handlers/record.ts:68-86 (handler)The core handler function that executes the update_record tool logic using PocketBase's update method on the specified collection and record ID.export function createUpdateRecordHandler(pb: PocketBase): ToolHandler { return async (args: UpdateRecordArgs) => { 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) .update(args.id, args.data, options); return createJsonResponse(result); } catch (error: unknown) { throw handlePocketBaseError("update record", error); } }; }
- src/tools/schemas/record.ts:67-92 (schema)The input schema definition for the update_record tool, specifying required and optional parameters for validation.export const updateRecordSchema = { type: "object", properties: { collection: { type: "string", description: "Collection name", }, id: { type: "string", description: "Record ID", }, data: { type: "object", description: "Updated record data with field values matching the collection schema. Can use field modifiers like fieldName+, +fieldName, fieldName-.", }, 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", "id", "data"], };
- src/server.ts:137-142 (registration)The registration of the update_record tool in the MCP server, linking the name, schema, and handler.{ name: "update_record", description: "Update an existing record", inputSchema: updateRecordSchema, handler: createUpdateRecordHandler(pb), },