UNPKG

anilist-mcp

Version:

AniList MCP server for accessing AniList API data

109 lines (108 loc) 3.71 kB
import { z } from "zod"; import { requireAuth } from "../utils/auth.js"; export function registerMediaTools(server, anilist) { // anilist.media.anime() server.tool("get_anime", "Get detailed information about an anime by its AniList ID", { id: z.number().describe("The AniList ID of the anime"), }, async ({ id }) => { try { const anime = await anilist.media.anime(id); return { content: [ { type: "text", text: JSON.stringify(anime, null, 2), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } }); // anilist.media.favouriteAnime() server.tool("favourite_anime", "[Requires Login] Favourite or unfavourite an anime by its ID", { id: z .number() .describe("The AniList ID of the anime to favourite/unfavourite"), }, async ({ id }) => { try { const auth = requireAuth(); if (!auth.isAuthorized) { return auth.errorResponse; } const result = await anilist.media.favouriteAnime(id); return { content: [ { type: "text", text: result ? `Successfully added anime with ID ${id} to favourites.` : `Anime with ID ${id} was removed from favourites or operation failed.`, }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } }); // anilist.media.favouriteManga() server.tool("favourite_manga", "[Requires Login] Favourite or unfavourite a manga by its ID", { id: z .number() .describe("The AniList ID of the manga to favourite/unfavourite"), }, async ({ id }) => { try { const auth = requireAuth(); if (!auth.isAuthorized) { return auth.errorResponse; } const result = await anilist.media.favouriteManga(id); return { content: [ { type: "text", text: result ? `Successfully added manga with ID ${id} to favourites.` : `Manga with ID ${id} was removed from favourites or operation failed.`, }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } }); // anilist.media.manga() server.tool("get_manga", "Get detailed information about a manga by its AniList ID", { id: z.number().describe("The AniList ID of the manga"), }, async ({ id }) => { try { const manga = await anilist.media.manga(id); return { content: [ { type: "text", text: JSON.stringify(manga, null, 2), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } }); }