Skip to main content
Glama
afshinator

mcp-server-pexels

Search Pexels Videos

pexels_search_videos
Read-onlyIdempotent

Search for stock videos by query with optional orientation, size, and locale filters. Returns HD-quality .mp4 links with mandatory attribution.

Instructions

Search for stock videos by query with optional filters. Returns HD-quality .mp4 links with mandatory attribution.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
orientationNo
sizeNo
localeNo
per_pageNo
force_refreshNo

Implementation Reference

  • The main handler function `handleVideoSearch` that executes the pexels_search_videos tool logic. It accepts a query and optional filters (orientation, size, locale, per_page), checks cache, calls the Pexels API via fetchVideoSearch, formats results, and returns content blocks with video metadata, attribution, and resource links.
    export async function handleVideoSearch(
      args: z.infer<typeof videoSearchSchema>,
    ): Promise<CallToolResult> {
      const start = Date.now();
      const forceRefresh = args.force_refresh ?? false;
      const params = {
        query: args.query,
        orientation: args.orientation,
        size: args.size,
        locale: args.locale,
        per_page: args.per_page || 5,
      };
    
      logDebug('tool: pexels_search_videos', 'params:', JSON.stringify(params));
    
      const cacheKey = makeCacheKey(params);
    
      if (!forceRefresh) {
        const cached = getFromCache<ContentBlock[]>(cacheKey);
        if (cached) {
          logDebug('cache: HIT', 'key:', cacheKey, `${Date.now() - start}ms`);
          return { content: cached };
        }
        logDebug('cache: MISS', 'key:', cacheKey);
      }
    
      try {
        const response = await fetchVideoSearch(params);
        const videos = response.videos?.slice(0, params.per_page) || [];
        const contentBlocks = videos.flatMap(formatVideoResult);
        const structured = { results: videos.map(buildVideoStructuredData) };
        contentBlocks.push({ type: 'text', text: JSON.stringify(structured) });
        setCache(cacheKey, contentBlocks, 600);
        logDebug('result:', 'count:', videos.length, `${Date.now() - start}ms`);
        return { content: contentBlocks };
      } catch (error) {
        logDebug('error:', error instanceof Error ? error.message : String(error));
        return formatApiError(error);
      }
    }
  • The registration function `registerVideoSearch` that registers the tool 'pexels_search_videos' with the MCP server, including its title, description, input schema (videoSearchSchema), and annotations (readOnlyHint, idempotentHint).
    export function registerVideoSearch(server: McpServer): void {
      server.registerTool(
        'pexels_search_videos',
        {
          title: 'Search Pexels Videos',
          description:
            'Search for stock videos by query with optional filters. Returns HD-quality .mp4 links with mandatory attribution.',
          inputSchema: videoSearchSchema,
          annotations: {
            readOnlyHint: true,
            idempotentHint: true,
          },
        },
        (args) => handleVideoSearch(args),
      );
    }
  • The `videoSearchSchema` Zod schema defining the input validation for pexels_search_videos: query (string trimmed to 100 chars), optional orientation, size, locale, per_page (1-10), and force_refresh boolean.
    export const videoSearchSchema = z.object({
      query: z.string().trim().transform((val) => val.slice(0, 100)),
      orientation: z.enum(['landscape', 'portrait', 'square']).optional(),
      size: z.enum(['large', 'medium', 'small']).optional(),
      locale: z.string().optional(),
      per_page: z.number().min(1).max(10).optional(),
      force_refresh: z.boolean().optional(),
    });
  • Helper function `buildVideoStructuredData` that transforms a PexelsVideo into structured output data with id, creator info, URLs, dimensions, and duration.
    export function buildVideoStructuredData(video: PexelsVideo): z.infer<typeof videoOutputSchema> {
      const bestFile = chooseBestVideo(video.video_files);
      const validMp4 = bestFile?.file_type === 'video/mp4' ? bestFile : undefined;
      return {
        id: video.id,
        kind: 'video',
        creatorName: video.user.name,
        creatorUrl: video.user.url,
        pageUrl: video.url,
        previewUrl: video.image,
        mediaUrl: validMp4?.link || video.image,
        mediaMimeType: validMp4 ? 'video/mp4' : 'image/jpeg',
        dimensions: { width: video.width, height: video.height },
        durationSeconds: video.duration,
      };
    }
  • Helper function `formatVideoResult` that formats a single PexelsVideo into ContentBlock array containing a text block with markdown attribution and a resource_link block pointing to the video file or preview image.
    export function formatVideoResult(video: PexelsVideo): ContentBlock[] {
      const bestFile = chooseBestVideo(video.video_files);
    
      const text = `Video by [${video.user.name}](${video.user.url}) on Pexels
    
    **ID:** ${video.id}
    **Dimensions:** ${video.width}x${video.height}
    **Duration:** ${video.duration}s
    **Link:** ${video.url}
    ![Preview](${video.image})`;
    
      const validMp4 = bestFile?.file_type === 'video/mp4' ? bestFile : undefined;
      const mediaBlock: ContentBlock = validMp4
        ? { type: 'resource_link', uri: validMp4.link, name: 'Video', mimeType: 'video/mp4' }
        : { type: 'resource_link', uri: video.image, name: 'Preview', mimeType: 'image/jpeg' };
    
      return [{ type: 'text', text }, mediaBlock];
    }
Behavior4/5

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

Annotations already declare readOnlyHint and idempotentHint. The description adds valuable context: 'Returns HD-quality .mp4 links with mandatory attribution', disclosing output format and a legal requirement beyond annotations.

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

Conciseness5/5

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

The description is a single sentence of 14 words, efficiently covering the core purpose and key output constraints without any fluff.

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?

Given 6 parameters and no output schema, the description omits crucial details like pagination behavior, result structure, and meaning of parameters. The agent lacks enough context to fully leverage the tool's features.

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

Parameters2/5

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

Schema description coverage is 0% and the description only mentions 'optional filters' without explaining individual parameters like orientation, size, locale, or force_refresh. The description adds no meaning beyond what the schema provides.

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 verb 'Search' and resource 'stock videos by query', and distinguishes from sibling tools like pexels_get_details and pexels_search_photos by specifying the resource type and output format.

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

Usage Guidelines3/5

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

The description implies usage for searching stock videos with optional filters, but does not provide explicit guidance on when to use this tool versus alternatives or mention prerequisites or exclusions.

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/afshinator/mcp-server-pexels'

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