Skip to main content
Glama
mrwyndham

PocketBase MCP Server

create_collection

Define a new data structure in PocketBase by specifying collection name, type, fields, and access rules to organize and manage database records.

Instructions

Create a new collection in PocketBase note never use created and updated because these are already created

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesUnique collection name (used as a table name for the records table)
typeNoType of the collectionbase
fieldsYesList with the collection fields
createRuleNoAPI rule for creating records
updateRuleNoAPI rule for updating records
deleteRuleNoAPI rule for deleting records
listRuleNoAPI rule for listing and viewing records
viewRuleNoAPI rule for viewing a single record
viewQueryNoSQL query for view collections
passwordAuthNoPassword authentication options

Implementation Reference

  • The handler function that implements the core logic for the 'create_collection' tool: authenticates as admin, appends default 'created' and 'updated' autodate fields, creates the collection using PocketBase API, and returns the result.
    private async createCollection(args: any) { try { // Authenticate with PocketBase await this.pb.collection("_superusers").authWithPassword(process.env.POCKETBASE_ADMIN_EMAIL ?? '', process.env.POCKETBASE_ADMIN_PASSWORD ?? ''); const defaultFields = [ { hidden: false, id: "autodate_created", name: "created", onCreate: true, onUpdate: false, presentable: false, system: false, type: "autodate" }, { hidden: false, id: "autodate_updated", name: "updated", onCreate: true, onUpdate: true, presentable: false, system: false, type: "autodate" } ]; const collectionData = { ...args, fields: [...(args.fields || []), ...defaultFields] }; const result = await this.pb.collections.create(collectionData as any); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error: unknown) { throw new McpError( ErrorCode.InternalError, `Failed to create collection: ${pocketbaseErrorMessage(error)}` ); }
  • Input schema/JSON Schema definition for the 'create_collection' tool parameters, including collection name, type, fields, rules, and auth options.
    inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Unique collection name (used as a table name for the records table)', }, type: { type: 'string', description: 'Type of the collection', enum: ['base', 'view', 'auth'], default: 'base', }, fields: { type: 'array', description: 'List with the collection fields', 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: ['name', 'fields'],
  • src/index.ts:51-123 (registration)
    Tool registration in the ListTools handler: defines name, description, and inputSchema for 'create_collection'.
    { name: 'create_collection', description: 'Create a new collection in PocketBase note never use created and updated because these are already created', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Unique collection name (used as a table name for the records table)', }, type: { type: 'string', description: 'Type of the collection', enum: ['base', 'view', 'auth'], default: 'base', }, fields: { type: 'array', description: 'List with the collection fields', 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: ['name', 'fields'], },
  • src/index.ts:671-672 (registration)
    Dispatch case in the central CallToolRequestHandler that routes 'create_collection' calls to the handler function.
    case 'create_collection': return await this.createCollection(request.params.arguments);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mrwyndham/pocketbase-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server