list_comments
List top-level YouTube video comments, newest first. Fetch comment IDs, authors, text, and like counts by providing a video ID.
Instructions
List top-level comment threads on a video (newest first). Returns comment IDs, authors, text, and like counts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| video_id | Yes | Video ID to list comments from | |
| max_results | No |
Implementation Reference
- src/tools/comments.ts:29-45 (handler)The handler function that executes the 'list_comments' tool logic. It calls client.listComments(video_id, max_results) and formats the output.
async (args) => { const data = await client.listComments(args.video_id, args.max_results); const lines = [ `Found ${data.items.length} comment thread(s) on ${args.video_id}:`, ...data.items.map((thread) => { const top = thread.snippet?.topLevelComment?.snippet; const id = thread.snippet?.topLevelComment?.id ?? "?"; const author = top?.authorDisplayName ?? "?"; const text = (top?.textOriginal ?? "").replace(/\s+/g, " ").slice(0, 160); const likes = top?.likeCount ?? 0; const replies = thread.snippet?.totalReplyCount ?? 0; return ` ${id} — ${author} (${likes}❤, ${replies}↩): ${text}`; }), ]; return { content: [{ type: "text" as const, text: lines.join("\n") }] }; }, ); - src/tools/comments.ts:5-8 (schema)Input schema for list_comments: video_id (string) and optional max_results (number, 1-100, default 20).
const listCommentsSchema = { video_id: z.string().describe("Video ID to list comments from"), max_results: z.number().int().min(1).max(100).default(20), }; - src/tools/comments.ts:24-45 (registration)The registerCommentTools function that calls server.tool('list_comments', ...) to register the tool with the MCP server.
export function registerCommentTools(server: McpServer, client: YouTubeClient): void { server.tool( "list_comments", "List top-level comment threads on a video (newest first). Returns comment IDs, authors, text, and like counts.", listCommentsSchema, async (args) => { const data = await client.listComments(args.video_id, args.max_results); const lines = [ `Found ${data.items.length} comment thread(s) on ${args.video_id}:`, ...data.items.map((thread) => { const top = thread.snippet?.topLevelComment?.snippet; const id = thread.snippet?.topLevelComment?.id ?? "?"; const author = top?.authorDisplayName ?? "?"; const text = (top?.textOriginal ?? "").replace(/\s+/g, " ").slice(0, 160); const likes = top?.likeCount ?? 0; const replies = thread.snippet?.totalReplyCount ?? 0; return ` ${id} — ${author} (${likes}❤, ${replies}↩): ${text}`; }), ]; return { content: [{ type: "text" as const, text: lines.join("\n") }] }; }, ); - src/server.ts:49-49 (registration)Where registerCommentTools is called from server.ts to wire up the tool.
registerCommentTools(s, youtube); - src/youtube/client.ts:206-213 (helper)The YouTubeClient.listComments helper method that performs the actual API call to /commentThreads.
listComments(videoId: string, maxResults = 20): Promise<{ items: CommentThread[] }> { return this.dataGet("/commentThreads", { part: "snippet,replies", videoId, maxResults: String(maxResults), order: "time", }); }