Skip to main content
Glama

indexVisualContent

Analyze video frames to create a searchable visual index using OCR, feature recognition, and optional AI descriptions for content discovery.

Instructions

Build a real visual index for a video using extracted frames, Apple Vision OCR, Apple Vision feature prints, and optional Gemini frame descriptions. Returns frame evidence with local image paths.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
videoIdOrUrlYesVideo ID or URL to index visually
intervalSecNoFrame sampling interval in seconds (default 20)
maxFramesNoMaximum frames to analyze (default 12)
imageFormatNo
widthNo
autoDownloadNoAutomatically download a small local video copy if none exists (default true)
downloadFormatNoVideo format used if auto-download is needed (default worst_video)
forceReindexNoRe-run OCR/description analysis even if frames are already indexed
includeGeminiDescriptionsNoUse Gemini to describe each frame when a Gemini key is configured
includeGeminiEmbeddingsNoGenerate Gemini embeddings over OCR/description text for semantic retrieval (default true when Gemini key is available)
dryRunNo

Implementation Reference

  • The `indexVideo` method in `VisualSearchEngine` is the handler for indexing visual content of a video, including OCR, scene description, and semantic embeddings.
    async indexVideo(params: IndexVisualContentParams): Promise<IndexVisualContentResult> {
      const videoId = params.videoId;
      const sourceVideoUrl = params.sourceVideoUrl ?? `https://www.youtube.com/watch?v=${videoId}`;
      const intervalSec = clamp(params.intervalSec ?? 20, 2, 3600);
      const maxFrames = clamp(params.maxFrames ?? 12, 1, 100);
    
      const includeGeminiDescriptions = params.includeGeminiDescriptions ?? this.geminiDescriber.available;
      const descriptionProvider: "none" | "gemini" = includeGeminiDescriptions && this.geminiDescriber.available ? "gemini" : "none";
    
      const embeddingSelection = resolveGeminiEmbeddingSelection(params.includeGeminiEmbeddings);
      const embeddingProvider = embeddingSelection ? await createEmbeddingProvider(embeddingSelection) : null;
      const embeddingProviderKind: "none" | "gemini" = embeddingProvider ? "gemini" : "none";
    
      if (params.forceReindex) {
        this.store.removeFramesForVideo(videoId);
      }
    
      let autoDownloaded = false;
      let videoAssetPath = this.findVideoAsset(videoId)?.filePath;
      if (!videoAssetPath && (params.autoDownload ?? true)) {
        const download = await this.mediaDownloader.download({
          videoIdOrUrl: videoId,
          format: params.downloadFormat ?? "worst_video",
        });
        videoAssetPath = download.asset.filePath;
        autoDownloaded = true;
      }
    
      if (!videoAssetPath) {
        throw new Error(`No local video asset found for ${videoId}. Run downloadAsset first or allow autoDownload.`);
      }
    
      const keyframes = await this.thumbnailExtractor.extractKeyframes({
        videoId,
        videoPath: videoAssetPath,
        intervalSec,
        maxFrames,
        imageFormat: params.imageFormat,
        width: params.width,
      });
    
      const existingByPath = new Map(this.store.listFrames({ videoId }).map((frame) => [frame.framePath, frame]));
      const pendingAssets = keyframes.assets.filter((asset) => params.forceReindex || !existingByPath.has(asset.filePath));
    
      // Run OCR and Gemini descriptions IN PARALLEL — they're independent
      const [analyses, descriptions] = await Promise.all([
        pendingAssets.length > 0
          ? this.visionAnalyzer.analyzeFrames(pendingAssets.map((asset) => asset.filePath))
          : Promise.resolve([]),
        descriptionProvider === "gemini"
        ? this.geminiDescriber.describeFrames(pendingAssets.map((asset) => ({
          framePath: asset.filePath,
          videoId,
          timestampSec: asset.timestampSec ?? 0,
        })))
        : Promise.resolve([]),
      ]);
      const analysisByPath = new Map(analyses.map((analysis) => [analysis.framePath, analysis]));
      const descriptionByPath = new Map(descriptions.map((item) => [item.framePath, item.description]));
    
      const retrievalTexts = pendingAssets.map((asset) => {
        const analysis = analysisByPath.get(asset.filePath);
        const description = descriptionByPath.get(asset.filePath);
        return buildRetrievalText({
          timestampSec: asset.timestampSec ?? 0,
          ocrText: analysis?.ocrText,
          visualDescription: description,
        });
      });
    
      const textEmbeddings = embeddingProvider
        ? await embeddingProvider.embedDocuments(retrievalTexts.map((text) => text || "frame without visible text"))
        : [];
      const embeddingByPath = new Map<string, number[]>();
      pendingAssets.forEach((asset, index) => {
        if (textEmbeddings[index]?.length) {
          embeddingByPath.set(asset.filePath, textEmbeddings[index]!);
        }
      });
    
      const evidence: VisualIndexRecord[] = [];
      for (const asset of keyframes.assets) {
        const existing = existingByPath.get(asset.filePath);
        if (existing && !params.forceReindex) {
          evidence.push(existing);
          continue;
        }
    
        const analysis = analysisByPath.get(asset.filePath);
        const visualDescription = descriptionByPath.get(asset.filePath);
        const retrievalText = buildRetrievalText({
          timestampSec: asset.timestampSec ?? 0,
          ocrText: analysis?.ocrText,
          visualDescription,
        });
    
        const record = this.store.upsertFrame({
          videoId,
          frameAssetId: asset.assetId,
          framePath: asset.filePath,
          timestampSec: asset.timestampSec ?? 0,
          sourceVideoUrl,
          sourceVideoTitle: params.sourceVideoTitle,
          ocrText: analysis?.ocrText,
          ocrConfidence: analysis?.ocrConfidence,
          visualDescription,
          retrievalText,
          featureVector: analysis?.featureVector,
          textEmbedding: embeddingByPath.get(asset.filePath),
          descriptionModel: descriptionProvider === "gemini" ? this.geminiDescriber.model : undefined,
          embeddingProvider: embeddingProviderKind,
          embeddingModel: embeddingProvider?.selection.model,
          embeddingDimensions: embeddingProvider?.selection.dimensions,
        });
        evidence.push(record);
      }
    
      return {
        videoId,
        sourceVideoUrl,
        sourceVideoTitle: params.sourceVideoTitle,
        videoAssetPath,
        autoDownloaded,
        framesExtracted: keyframes.framesExtracted,
        framesAnalyzed: pendingAssets.length,
        framesIndexed: evidence.length,
        intervalSec,
        maxFrames,
        descriptionProvider,
        descriptionModel: descriptionProvider === "gemini" ? this.geminiDescriber.model : undefined,
        embeddingProvider: embeddingProviderKind,
        embeddingModel: embeddingProvider?.selection.model,
        embeddingDimensions: embeddingProvider?.selection.dimensions,
        evidence: evidence.sort((a, b) => a.timestampSec - b.timestampSec).slice(0, 12),
        limitations: buildIndexLimitations(descriptionProvider, embeddingProviderKind),
      };
    }
  • The tool `indexVisualContent` is registered in the main MCP server request handler and calls the `service.indexVisualContent` method.
    case "indexVisualContent":
      return service.indexVisualContent(
        {
          videoIdOrUrl: readString(args, "videoIdOrUrl"),
          intervalSec: optionalNumber(args, "intervalSec"),
          maxFrames: optionalNumber(args, "maxFrames"),
          imageFormat: optionalEnum(args, "imageFormat", ["jpg", "png", "webp"]),
          width: optionalNumber(args, "width"),
          autoDownload: optionalBoolean(args, "autoDownload"),
          downloadFormat: optionalEnum(args, "downloadFormat", ["best_video", "worst_video"]),
          forceReindex: optionalBoolean(args, "forceReindex"),
          includeGeminiDescriptions: optionalBoolean(args, "includeGeminiDescriptions"),
          includeGeminiEmbeddings: optionalBoolean(args, "includeGeminiEmbeddings"),
        },
        { dryRun },
      );
  • The JSON schema definition for the `indexVisualContent` tool within the MCP server definition.
      name: "indexVisualContent",
      description: "Build a real visual index for a video using extracted frames, Apple Vision OCR, Apple Vision feature prints, and optional Gemini frame descriptions. Returns frame evidence with local image paths.",
      inputSchema: {
        type: "object",
        properties: {
          videoIdOrUrl: { type: "string", description: "Video ID or URL to index visually" },
          intervalSec: { type: "number", minimum: 2, maximum: 3600, description: "Frame sampling interval in seconds (default 20)" },
          maxFrames: { type: "number", minimum: 1, maximum: 100, description: "Maximum frames to analyze (default 12)" },
          imageFormat: { type: "string", enum: ["jpg", "png", "webp"] },
          width: { type: "number", minimum: 160, maximum: 3840 },
          autoDownload: { type: "boolean", description: "Automatically download a small local video copy if none exists (default true)" },
          downloadFormat: { type: "string", enum: ["best_video", "worst_video"], description: "Video format used if auto-download is needed (default worst_video)" },
          forceReindex: { type: "boolean", description: "Re-run OCR/description analysis even if frames are already indexed" },
          includeGeminiDescriptions: { type: "boolean", description: "Use Gemini to describe each frame when a Gemini key is configured" },
          includeGeminiEmbeddings: { type: "boolean", description: "Generate Gemini embeddings over OCR/description text for semantic retrieval (default true when Gemini key is available)" },
          dryRun: { type: "boolean" },
        },
        required: ["videoIdOrUrl"],
        additionalProperties: false,
      },
    },
Behavior3/5

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

With no annotations, the description carries the full burden. It discloses key behavioral traits: the tool performs indexing (implying read/write operations), uses specific technologies (Apple Vision, Gemini), and returns 'frame evidence with local image paths'. However, it lacks details on permissions, rate limits, or side effects like file creation, which are important for a tool with 11 parameters.

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 front-loaded with the core purpose and technologies, followed by the return value. It's concise with two sentences, but could be slightly more structured by explicitly separating input and output aspects.

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

Completeness3/5

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

Given the complexity (11 parameters, no annotations, no output schema), the description is incomplete. It covers the purpose and return format, but lacks details on error handling, performance implications, or example use cases, leaving gaps for an agent to fully understand tool behavior.

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 73%, providing good baseline documentation. The description adds minimal parameter semantics beyond the schema, only implying that 'videoIdOrUrl' is the target and 'intervalSec'/'maxFrames' relate to frame sampling. It doesn't explain interactions between parameters like 'autoDownload' and 'downloadFormat', so it meets but doesn't exceed the baseline.

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 ('Build a real visual index for a video') and resources used ('using extracted frames, Apple Vision OCR, Apple Vision feature prints, and optional Gemini frame descriptions'), distinguishing it from siblings like 'extractKeyframes' or 'searchVisualContent' by focusing on comprehensive indexing rather than extraction or search.

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?

No explicit guidance on when to use this tool versus alternatives is provided. It mentions optional features like Gemini descriptions, but doesn't clarify scenarios where this tool is preferred over simpler siblings like 'extractKeyframes' or broader ones like 'buildVideoDossier'.

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