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,
      },
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions fetching and indexing comments but omits critical details: whether this is a read-only or write operation, what permissions are needed, how long indexing takes, error handling, or what happens to existing indexed data. The phrase 'import' implies data ingestion but lacks operational specifics.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. Every word contributes to understanding the tool's function, though it could potentially benefit from slightly more detail given the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 9-parameter tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the tool returns, error conditions, side effects, or how the imported data persists. The mention of indexing for 'searchComments' hints at output but lacks concrete details about the resulting collection state or search readiness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 67% (6 of 9 parameters have descriptions). The description adds no parameter-specific information beyond what's in the schema. It mentions 'video's comments' which aligns with the 'videoIdOrUrl' parameter but provides no additional context about parameter usage, relationships, or default behaviors not covered in schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Import a video's comments') and resource ('into the local comment knowledge base'), with explicit purpose ('for semantic search'). It distinguishes from sibling tools like 'searchComments' by explaining this tool prepares data for that search functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description mentions the tool's relationship to 'searchComments' but provides no guidance on when to use this tool versus alternatives like 'readComments' or 'listCommentCollections'. No prerequisites, exclusions, or comparative context are given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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