UNPKG

anilist-mcp

Version:

AniList MCP server for accessing AniList API data

141 lines (140 loc) 4.44 kB
import { z } from "zod"; import { requireAuth } from "../utils/auth.js"; export function registerMiscTools(server, anilist, config) { // anilist.favouriteStudio() server.tool("favourite_studio", "[Requires Login] Favourite or unfavourite a studio by its ID", { id: z .number() .describe("The AniList ID of the studio to favourite/unfavourite"), }, { title: "Favourite/Unfavourite Studio", readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true, }, async ({ id }) => { try { const auth = requireAuth(config.anilistToken); if (!auth.isAuthorized) { return auth.errorResponse; } const result = await anilist.favouriteStudio(id); return { content: [ { type: "text", text: result ? `Successfully added studio with ID ${id} to favourites.` : `Studio with ID ${id} was removed from favourites or operation failed.`, }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } }); // anilist.genres() server.tool("get_genres", "Get all available genres on AniList", {}, { title: "Get Genres", readOnlyHint: true, openWorldHint: true, }, async () => { try { const genres = await anilist.genres(); return { content: [ { type: "text", text: JSON.stringify(genres, null, 2), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } }); // anilist.mediaTags() server.tool("get_media_tags", "Get all available media tags on AniList", {}, { title: "Get Media Tags", readOnlyHint: true, openWorldHint: true, }, async () => { try { const tags = await anilist.mediaTags(); return { content: [ { type: "text", text: JSON.stringify(tags, null, 2), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } }); // anilist.siteStatistics() server.tool("get_site_statistics", "Get AniList site statistics over the last seven days", {}, { title: "Get Site Statistics", readOnlyHint: true, openWorldHint: true, }, async () => { try { const statistics = await anilist.siteStatistics(); return { content: [ { type: "text", text: JSON.stringify(statistics, null, 2), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } }); // anilist.studio() server.tool("get_studio", "Get information about a studio by its AniList ID or name", { studio: z .union([z.string(), z.number()]) .describe("The studio ID or name"), }, { title: "Get Studio Information", readOnlyHint: true, openWorldHint: true, }, async ({ studio }) => { try { const studioInfo = await anilist.studio(studio); return { content: [ { type: "text", text: JSON.stringify(studioInfo, null, 2), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } }); }