Skip to main content
Glama
fadlee

PocketBase MCP Server

by fadlee

authenticate_user

Verify user credentials and generate authentication tokens for accessing PocketBase database resources. Provide email and password to obtain secure session tokens with configurable auto-refresh settings.

Instructions

Authenticate a user and get auth token

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
autoRefreshThresholdNoTime in seconds that will trigger token auto refresh before its expiration (default: 30 minutes)
collectionNoAuth collection name (default: 'users')
emailYesUser email or identity field value
passwordYesUser password

Implementation Reference

  • Creates the ToolHandler for 'authenticate_user' which authenticates a user using PocketBase's authWithPassword method, handles errors, and returns a JSON response.
    export function createAuthenticateUserHandler(pb: PocketBase): ToolHandler {
      return async (args: AuthenticateUserArgs) => {
        try {
          const collection = args.collection || "users";
          const autoRefreshThreshold = args.autoRefreshThreshold || 1800; // 30 minutes
          
          const result = await pb
            .collection(collection)
            .authWithPassword(args.email, args.password, {
              autoRefreshThreshold,
            });
          
          return createJsonResponse(result);
        } catch (error: unknown) {
          throw handlePocketBaseError("authenticate user", error);
        }
      };
    }
  • src/server.ts:152-156 (registration)
    Registers the 'authenticate_user' tool in the MCP server with its name, description, input schema, and handler.
      name: "authenticate_user",
      description: "Authenticate a user and get auth token",
      inputSchema: authenticateUserSchema,
      handler: createAuthenticateUserHandler(pb),
    },
  • Defines the JSON input schema for the 'authenticate_user' tool, specifying properties like email, password, and optional collection and autoRefreshThreshold.
    export const authenticateUserSchema = {
      type: "object",
      properties: {
        collection: {
          type: "string",
          description: "Auth collection name (default: 'users')",
        },
        email: {
          type: "string",
          description: "User email or identity field value",
        },
        password: {
          type: "string",
          description: "User password",
        },
        autoRefreshThreshold: {
          type: "number",
          description: "Time in seconds that will trigger token auto refresh before its expiration (default: 30 minutes)",
        },
      },
      required: ["email", "password"],
    };
  • TypeScript interface defining the input arguments for the authenticate_user handler.
    export interface AuthenticateUserArgs {
      collection?: string;
      email: string;
      password: string;
      autoRefreshThreshold?: number;
    }

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

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