Skip to main content
Glama
mabeldata

PocketBase MCP Server

by mabeldata

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
NameRequiredDescriptionDefault
collectionYesThe name or ID of the PocketBase collection.
dataYesThe data for the new record (key-value pairs).

Implementation Reference

  • 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) }],
        };
    }
  • TypeScript interface defining the expected input arguments for the create_record tool: collection name and data object.
    export interface CreateRecordArgs {
      collection: string;
      data: any;
    }
  • 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'],
        },
    },
    {
  • 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 };
    }
  • 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}`);
        }
    }

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/mabeldata/pocketbase-mcp'

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