get_auth_token
Retrieve an authentication token for Firebase Auth emulator users or list available users when no UID is specified.
Instructions
Get an ID token for a user in the Auth emulator. Lists users if no uid provided.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | No | User UID. If omitted, lists available users instead. |
Implementation Reference
- src/index.ts:318-347 (handler)The handler function 'handleGetAuthToken' that executes the logic to retrieve an Auth ID token or list users if no UID is provided.
async function handleGetAuthToken(uid?: string) { if (!uid) { // List users so the caller can pick one const result = await adminAuth.listUsers(20); return { message: "No uid provided. Available users:", users: result.users.map((u) => ({ uid: u.uid, email: u.email || undefined, displayName: u.displayName || undefined, })), }; } // Create a custom token and exchange it for an ID token via the emulator REST API const customToken = await adminAuth.createCustomToken(uid); const resp = await fetch( `http://${AUTH_EMULATOR_HOST}/identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=fake-api-key`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token: customToken, returnSecureToken: true }), } ); const data = await resp.json(); if (!data.idToken) { throw new Error(`Failed to get ID token: ${JSON.stringify(data)}`); } return { uid, idToken: data.idToken }; } - src/index.ts:220-228 (registration)The registration of the 'get_auth_token' tool in the MCP tools list.
name: "get_auth_token", description: "Get an ID token for a user in the Auth emulator. Lists users if no uid provided.", inputSchema: { type: "object" as const, properties: { uid: { type: "string", description: "User UID. If omitted, lists available users instead." }, }, }, },