Skip to main content
Glama

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
NameRequiredDescriptionDefault
videoIdOrUrlYesYouTube video URL or ID
collectionIdNoCustom collection ID (default: comments-{videoId})
maxTopLevelNoMax top-level comments to fetch
includeRepliesNoInclude reply threads (default: true)
maxRepliesPerThreadNo
orderNo
labelNoHuman-readable collection label
activateCollectionNoSet as active comment collection (default: true)
dryRunNo

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;
  • 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 },
      );
  • 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,
      },
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rajanrengasamy/vidlens-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server