anilist-mcp
Version:
AniList MCP server for accessing AniList API data
83 lines (82 loc) • 2.75 kB
JavaScript
import { z } from "zod";
import { requireAuth } from "../utils/auth.js";
export function registerThreadTools(server, anilist) {
// anilist.thread.delete()
server.tool("delete_thread", "[Requires Login] Delete a thread by its ID", {
id: z.number().describe("The AniList thread ID to delete"),
}, async ({ id }) => {
try {
const auth = requireAuth();
if (!auth.isAuthorized) {
return auth.errorResponse;
}
const result = await anilist.thread.delete(id);
return {
content: [
{
type: "text",
text: result
? `Successfully deleted thread with ID ${id}.`
: `Failed to delete thread with ID ${id}.`,
},
],
};
}
catch (error) {
return {
content: [{ type: "text", text: `Error: ${error.message}` }],
isError: true,
};
}
});
// anilist.thread.get()
server.tool("get_thread", "Get a specific thread by its AniList ID", {
id: z.number().describe("The AniList ID of the thread"),
}, async ({ id }) => {
try {
const thread = await anilist.thread.get(id);
return {
content: [
{
type: "text",
text: JSON.stringify(thread, null, 2),
},
],
};
}
catch (error) {
return {
content: [{ type: "text", text: `Error: ${error.message}` }],
isError: true,
};
}
});
// anilist.thread.getComments()
server.tool("get_thread_comments", "Get comments for a specific thread", {
id: z.number().describe("The AniList thread ID"),
page: z.number().optional().default(1).describe("The page number"),
perPage: z
.number()
.optional()
.default(25)
.describe("How many comments per page"),
}, async ({ id, page = 1, perPage = 25 }) => {
try {
const comments = await anilist.thread.getComments(id, page, perPage);
return {
content: [
{
type: "text",
text: JSON.stringify(comments, null, 2),
},
],
};
}
catch (error) {
return {
content: [{ type: "text", text: `Error: ${error.message}` }],
isError: true,
};
}
});
}