update_collection
Modify an existing collection's structure, rules, or authentication settings in PocketBase databases to adapt to changing application requirements.
Instructions
Update an existing collection in PocketBase (admin only)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collectionIdOrName | Yes | ID or name of the collection to update | |
| name | No | New unique collection name | |
| type | No | Type of the collection | |
| fields | No | List with the new collection fields. If not empty, the old schema will be replaced with the new one. | |
| createRule | No | API rule for creating records | |
| updateRule | No | API rule for updating records | |
| deleteRule | No | API rule for deleting records | |
| listRule | No | API rule for listing and viewing records | |
| viewRule | No | API rule for viewing a single record | |
| viewQuery | No | SQL query for view collections | |
| passwordAuth | No | Password authentication options |
Implementation Reference
- src/index.ts:763-784 (handler)The main handler function that executes the update_collection tool. It authenticates as an admin using environment variables, destructures the arguments, updates the collection using PocketBase SDK, and returns the result as MCP content.
private async updateCollection(args: any) { try { // Authenticate with PocketBase as admin await this.pb.collection("_superusers").authWithPassword(process.env.POCKETBASE_ADMIN_EMAIL ?? '', process.env.POCKETBASE_ADMIN_PASSWORD ?? ''); const { collectionIdOrName, ...updateData } = args; const result = await this.pb.collections.update(collectionIdOrName, updateData as any); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error: unknown) { throw new McpError( ErrorCode.InternalError, `Failed to update collection: ${pocketbaseErrorMessage(error)}` ); } } - src/index.ts:128-200 (schema)The input schema defining the parameters for the update_collection tool, including collectionIdOrName (required), optional fields, rules, and auth options.
inputSchema: { type: 'object', properties: { collectionIdOrName: { type: 'string', description: 'ID or name of the collection to update', }, name: { type: 'string', description: 'New unique collection name', }, type: { type: 'string', description: 'Type of the collection', enum: ['base', 'view', 'auth'], }, fields: { type: 'array', description: 'List with the new collection fields. If not empty, the old schema will be replaced with the new one.', items: { type: 'object', properties: { name: { type: 'string', description: 'Field name' }, type: { type: 'string', description: 'Field type', enum: ['bool', 'date', 'number', 'text', 'email', 'url', 'editor', 'autodate', 'select', 'file', 'relation', 'json'] }, required: { type: 'boolean', description: 'Is field required?' }, values: { type: 'array', items: { type: 'string' }, description: 'Allowed values for select type fields', }, collectionId: { type: 'string', description: 'Collection ID for relation type fields' } }, }, }, createRule: { type: 'string', description: 'API rule for creating records', }, updateRule: { type: 'string', description: 'API rule for updating records', }, deleteRule: { type: 'string', description: 'API rule for deleting records', }, listRule: { type: 'string', description: 'API rule for listing and viewing records', }, viewRule: { type: 'string', description: 'API rule for viewing a single record', }, viewQuery: { type: 'string', description: 'SQL query for view collections', }, passwordAuth: { type: 'object', description: 'Password authentication options', properties: { enabled: { type: 'boolean', description: 'Is password authentication enabled?' }, identityFields: { type: 'array', items: { type: 'string' }, description: 'Fields used for identity in password authentication', }, }, }, }, required: ['collectionIdOrName'], }, - src/index.ts:673-674 (registration)The switch case in the CallToolRequestSchema handler that dispatches calls to the update_collection tool to its handler function.
case 'update_collection': return await this.updateCollection(request.params.arguments); - src/index.ts:125-201 (registration)The tool specification registered in the ListToolsRequestSchema response, including name, description, and inputSchema.
{ name: 'update_collection', description: 'Update an existing collection in PocketBase (admin only)', inputSchema: { type: 'object', properties: { collectionIdOrName: { type: 'string', description: 'ID or name of the collection to update', }, name: { type: 'string', description: 'New unique collection name', }, type: { type: 'string', description: 'Type of the collection', enum: ['base', 'view', 'auth'], }, fields: { type: 'array', description: 'List with the new collection fields. If not empty, the old schema will be replaced with the new one.', items: { type: 'object', properties: { name: { type: 'string', description: 'Field name' }, type: { type: 'string', description: 'Field type', enum: ['bool', 'date', 'number', 'text', 'email', 'url', 'editor', 'autodate', 'select', 'file', 'relation', 'json'] }, required: { type: 'boolean', description: 'Is field required?' }, values: { type: 'array', items: { type: 'string' }, description: 'Allowed values for select type fields', }, collectionId: { type: 'string', description: 'Collection ID for relation type fields' } }, }, }, createRule: { type: 'string', description: 'API rule for creating records', }, updateRule: { type: 'string', description: 'API rule for updating records', }, deleteRule: { type: 'string', description: 'API rule for deleting records', }, listRule: { type: 'string', description: 'API rule for listing and viewing records', }, viewRule: { type: 'string', description: 'API rule for viewing a single record', }, viewQuery: { type: 'string', description: 'SQL query for view collections', }, passwordAuth: { type: 'object', description: 'Password authentication options', properties: { enabled: { type: 'boolean', description: 'Is password authentication enabled?' }, identityFields: { type: 'array', items: { type: 'string' }, description: 'Fields used for identity in password authentication', }, }, }, }, required: ['collectionIdOrName'], }, },