delete_auth_user
Remove a user from Supabase authentication by their UUID. This tool deletes user accounts from the auth.users table using a service role key and direct database connection.
Instructions
Deletes a user from auth.users by their ID. Requires service_role key and direct DB connection.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | Yes | The UUID of the user to delete. |
Implementation Reference
- src/tools/delete_auth_user.ts:38-81 (handler)The main handler function for the delete_auth_user tool. It checks for direct PG connection availability, executes a DELETE query on auth.users table using a transaction, and returns success/failure based on rowCount.execute: async (input: DeleteAuthUserInput, context: ToolContext) => { const client = context.selfhostedClient; const { user_id } = input; // This operation requires elevated privileges and modifies data. // Prefer direct DB connection if available and service key is configured. if (!client.isPgAvailable()) { throw new Error('Direct database connection (DATABASE_URL) is required for deleting users but is not configured or available.'); } // Service role key check remains relevant for awareness, but remove console.warn // if (!client.getServiceRoleKey()) { // console.warn('Service role key not explicitly configured, direct DB connection might fail if privileges are insufficient.'); // } try { // Use executeTransactionWithPg for safety, though it's a single statement const result = await client.executeTransactionWithPg(async (pgClient) => { // Use parameter binding for safety const deleteResult = await pgClient.query( 'DELETE FROM auth.users WHERE id = $1', [user_id] ); return deleteResult; }); if (result.rowCount === 1) { return { success: true, message: `Successfully deleted user with ID: ${user_id}`, }; } // If rowCount was not 1, the user wasn't found/deleted return { success: false, message: `User with ID ${user_id} not found or could not be deleted.`, }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); console.error(`Error deleting user ${user_id}:`, errorMessage); // Rethrow for the main handler to format the error response throw new Error(`Failed to delete user ${user_id}: ${errorMessage}`); } },
- src/tools/delete_auth_user.ts:6-15 (schema)Zod schemas for input (user_id UUID) and output (success boolean, message string) of the delete_auth_user tool.const DeleteAuthUserInputSchema = z.object({ user_id: z.string().uuid().describe('The UUID of the user to delete.'), }); type DeleteAuthUserInput = z.infer<typeof DeleteAuthUserInputSchema>; // Output schema: Success status and message const DeleteAuthUserOutputSchema = z.object({ success: z.boolean(), message: z.string(), });
- src/tools/delete_auth_user.ts:18-29 (schema)Static JSON schema for MCP input capabilities of the delete_auth_user tool.const mcpInputSchema = { type: 'object', properties: { user_id: { type: 'string', format: 'uuid', description: 'The UUID of the user to delete.', }, }, required: ['user_id'], };
- src/index.ts:26-26 (registration)Import of the deleteAuthUserTool.import { deleteAuthUserTool } from './tools/delete_auth_user.js';
- src/index.ts:115-115 (registration)Registration of deleteAuthUserTool in the availableTools object used by the MCP server.[deleteAuthUserTool.name]: deleteAuthUserTool as AppTool,