authenticate_user
Verify user identity by authenticating with email and password in PocketBase MCP Server, supporting admin access and custom collection checks.
Instructions
Authenticate a user with email and password
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | No | Collection name (default: users) | users |
| Yes | User email | ||
| isAdmin | No | Whether to authenticate as an admin (uses _superusers collection) | |
| password | Yes | User password |
Implementation Reference
- src/index.ts:878-909 (handler)The handler function that authenticates a user using PocketBase's authWithPassword method. Supports admin auth via env vars or regular users. Returns JSON auth data.private async authenticateUser(args: any) { try { // Use _superusers collection for admin authentication const collection = args.isAdmin ? '_superusers' : (args.collection || 'users'); // For admin authentication, use environment variables if email/password not provided const email = args.isAdmin && !args.email ? process.env.POCKETBASE_ADMIN_EMAIL : args.email; const password = args.isAdmin && !args.password ? process.env.POCKETBASE_ADMIN_PASSWORD : args.password; if (!email || !password) { throw new Error('Email and password are required for authentication'); } const authData = await this.pb .collection(collection) .authWithPassword(email, password); return { content: [ { type: 'text', text: JSON.stringify(authData, null, 2), }, ], }; } catch (error: unknown) { throw new McpError( ErrorCode.InternalError, `Authentication failed: ${pocketbaseErrorMessage(error)}` ); } }
- src/index.ts:307-330 (schema)Input schema for the authenticate_user tool, defining required email/password and optional collection/isAdmin.inputSchema: { type: 'object', properties: { email: { type: 'string', description: 'User email', }, password: { type: 'string', description: 'User password', }, collection: { type: 'string', description: 'Collection name (default: users)', default: 'users' }, isAdmin: { type: 'boolean', description: 'Whether to authenticate as an admin (uses _superusers collection)', default: false } }, required: ['email', 'password'], },
- src/index.ts:304-331 (registration)Tool registration in the setTools call, including name, description, and input schema.{ name: 'authenticate_user', description: 'Authenticate a user with email and password', inputSchema: { type: 'object', properties: { email: { type: 'string', description: 'User email', }, password: { type: 'string', description: 'User password', }, collection: { type: 'string', description: 'Collection name (default: users)', default: 'users' }, isAdmin: { type: 'boolean', description: 'Whether to authenticate as an admin (uses _superusers collection)', default: false } }, required: ['email', 'password'], }, },