anilist_whoami
Verify your AniList authentication and confirm which account is connected. Use this tool to debug token issues or check your setup.
Instructions
Check which AniList account is authenticated and verify the token works. Use when the user wants to confirm their setup or debug auth issues.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/info.ts:69-128 (handler)The execute handler for the anilist_whoami tool. Checks for ANILIST_TOKEN, queries the AniList Viewer API to get authenticated user info (name, ID, score format, profile URL), and compares it with ANILIST_USERNAME env var.
execute: async () => { if (!process.env.ANILIST_TOKEN) { const lines = [ "ANILIST_TOKEN is not set.", "Set it to enable authenticated features (write operations, score format detection).", "Get a token at: https://anilist.co/settings/developer", ]; const envUser = process.env.ANILIST_USERNAME; if (envUser) { lines.push( "", `ANILIST_USERNAME is set to "${envUser}" (read-only mode).`, ); } return lines.join("\n"); } try { const data = await anilistClient.query<ViewerResponse>( VIEWER_QUERY, {}, { cache: "stats" }, ); if (!data.Viewer) { return throwToolError( new Error("No viewer data returned"), "checking authentication", ); } const v = data.Viewer; const lines = [ `Authenticated as: ${v.name}`, `AniList ID: ${v.id}`, `Score format: ${v.mediaListOptions.scoreFormat}`, `Profile: ${v.siteUrl}`, ]; // Check if Anilist username matches const envUser = process.env.ANILIST_USERNAME; if (envUser) { const match = envUser.toLowerCase() === v.name.toLowerCase(); lines.push( "", match ? `ANILIST_USERNAME "${envUser}" matches authenticated user.` : `ANILIST_USERNAME "${envUser}" does not match authenticated user "${v.name}".`, ); } else { lines.push( "", "ANILIST_USERNAME is not set. Tools will require a username argument.", ); } return lines.join("\n"); } catch (error) { return throwToolError(error, "checking authentication"); } }, - src/tools/info.ts:62-62 (schema)Empty input schema (z.object({})) for anilist_whoami, as it requires no parameters.
parameters: z.object({}), - src/tools/info.ts:54-129 (registration)Registration via registerInfoTools() which calls server.addTool() to register anilist_whoami on the FastMCP server.
export function registerInfoTools(server: FastMCP): void { // === Who Am I === server.addTool({ name: "anilist_whoami", description: "Check which AniList account is authenticated and verify the token works. " + "Use when the user wants to confirm their setup or debug auth issues.", parameters: z.object({}), annotations: { title: "Who Am I", readOnlyHint: true, destructiveHint: false, openWorldHint: true, }, execute: async () => { if (!process.env.ANILIST_TOKEN) { const lines = [ "ANILIST_TOKEN is not set.", "Set it to enable authenticated features (write operations, score format detection).", "Get a token at: https://anilist.co/settings/developer", ]; const envUser = process.env.ANILIST_USERNAME; if (envUser) { lines.push( "", `ANILIST_USERNAME is set to "${envUser}" (read-only mode).`, ); } return lines.join("\n"); } try { const data = await anilistClient.query<ViewerResponse>( VIEWER_QUERY, {}, { cache: "stats" }, ); if (!data.Viewer) { return throwToolError( new Error("No viewer data returned"), "checking authentication", ); } const v = data.Viewer; const lines = [ `Authenticated as: ${v.name}`, `AniList ID: ${v.id}`, `Score format: ${v.mediaListOptions.scoreFormat}`, `Profile: ${v.siteUrl}`, ]; // Check if Anilist username matches const envUser = process.env.ANILIST_USERNAME; if (envUser) { const match = envUser.toLowerCase() === v.name.toLowerCase(); lines.push( "", match ? `ANILIST_USERNAME "${envUser}" matches authenticated user.` : `ANILIST_USERNAME "${envUser}" does not match authenticated user "${v.name}".`, ); } else { lines.push( "", "ANILIST_USERNAME is not set. Tools will require a username argument.", ); } return lines.join("\n"); } catch (error) { return throwToolError(error, "checking authentication"); } }, }); - src/api/queries.ts:588-600 (helper)VIEWER_QUERY - the GraphQL query used by the handler to fetch viewer data (id, name, avatar, siteUrl, mediaListOptions.scoreFormat).
export const VIEWER_QUERY = ` query Viewer { Viewer { id name avatar { medium } siteUrl mediaListOptions { scoreFormat } } } `; - src/types.ts:393-403 (helper)ViewerResponse TypeScript interface defining the shape of the API response from the Viewer query.
export interface ViewerResponse { Viewer: { id: number; name: string; avatar: { medium: string | null }; siteUrl: string; mediaListOptions: { scoreFormat: ScoreFormat; }; }; }