importComments
Fetch YouTube video comments and index them into a local knowledge base for semantic search, enabling AI agents to analyze and retrieve insights from viewer discussions.
Instructions
Import a video's comments into the local comment knowledge base for semantic search. Fetches comments via the existing comment pipeline and indexes them for searchComments.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| videoIdOrUrl | Yes | YouTube video URL or ID | |
| collectionId | No | Custom collection ID (default: comments-{videoId}) | |
| maxTopLevel | No | Max top-level comments to fetch | |
| includeReplies | No | Include reply threads (default: true) | |
| maxRepliesPerThread | No | ||
| order | No | ||
| label | No | Human-readable collection label | |
| activateCollection | No | Set as active comment collection (default: true) | |
| dryRun | No |
Implementation Reference
- The 'importComments' method in 'CommentKnowledgeBase' class handles the logic of importing and indexing YouTube comments into a database.
importComments( seed: CommentCollectionSeed, items: CommentImportItem[], ): ImportCommentsOutput { this.ensureCollection(seed); const collectionId = seed.collectionId; let totalThreads = 0; let totalComments = 0; let chunksCreated = 0; const insertVideo = this.db.prepare(` INSERT OR REPLACE INTO comment_collection_videos (collection_id, video_id, title, channel_title, thread_count, comment_count, imported_at) VALUES (?, ?, ?, ?, ?, ?, ?) `); const insertChunk = this.db.prepare(` INSERT OR REPLACE INTO comment_chunks (chunk_id, collection_id, video_id, author, text, like_count, published_at, is_reply, parent_author, token_count, terms_json, doc_norm, embedding_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) `); this.db.exec("BEGIN"); try { for (const item of items) { this.deleteVideo(collectionId, item.videoId); let videoThreads = 0; let videoComments = 0; for (const thread of item.comments) { videoThreads += 1; - src/server/mcp-server.ts:1063-1076 (registration)The 'importComments' tool is registered in the 'executeTool' switch statement, which delegates the request to the 'service.importComments' method.
case "importComments": return service.importComments( { videoIdOrUrl: readString(args, "videoIdOrUrl"), collectionId: optionalString(args, "collectionId"), maxTopLevel: optionalNumber(args, "maxTopLevel"), includeReplies: optionalBoolean(args, "includeReplies"), maxRepliesPerThread: optionalNumber(args, "maxRepliesPerThread"), order: optionalEnum(args, "order", ["relevance", "time"]), label: optionalString(args, "label"), activateCollection: optionalBoolean(args, "activateCollection"), }, { dryRun }, ); - src/server/mcp-server.ts:580-598 (schema)The 'importComments' tool definition, including its name, description, and input schema, is defined within the 'tools' array in 'mcp-server.ts'.
name: "importComments", description: "Import a video's comments into the local comment knowledge base for semantic search. Fetches comments via the existing comment pipeline and indexes them for searchComments.", inputSchema: { type: "object", properties: { videoIdOrUrl: { type: "string", description: "YouTube video URL or ID" }, collectionId: { type: "string", description: "Custom collection ID (default: comments-{videoId})" }, maxTopLevel: { type: "number", minimum: 1, maximum: 200, description: "Max top-level comments to fetch" }, includeReplies: { type: "boolean", description: "Include reply threads (default: true)" }, maxRepliesPerThread: { type: "number", minimum: 0, maximum: 20 }, order: { type: "string", enum: ["relevance", "time"] }, label: { type: "string", description: "Human-readable collection label" }, activateCollection: { type: "boolean", description: "Set as active comment collection (default: true)" }, dryRun: { type: "boolean" }, }, required: ["videoIdOrUrl"], additionalProperties: false, }, },