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
| Name | Required | Description | Default |
|---|---|---|---|
| autoRefreshThreshold | No | Time in seconds that will trigger token auto refresh before its expiration (default: 30 minutes) | |
| collection | No | Auth collection name (default: 'users') | |
| Yes | User email or identity field value | ||
| password | Yes | User password |
Implementation Reference
- src/tools/handlers/auth.ts:13-30 (handler)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), },
- src/tools/schemas/auth.ts:5-26 (schema)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"], };
- src/types/index.ts:116-121 (schema)TypeScript interface defining the input arguments for the authenticate_user handler.export interface AuthenticateUserArgs { collection?: string; email: string; password: string; autoRefreshThreshold?: number; }