Skip to main content
Glama
afshinator

mcp-server-pexels

Get Pexels Details

pexels_get_details
Read-onlyIdempotent

Retrieve detailed information for a specific photo or video by providing its ID and type.

Instructions

Get detailed information about a specific photo or video by ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes
typeYes
force_refreshNo

Implementation Reference

  • The main handler function for pexels_get_details. Fetches and returns detailed info for a photo (by ID) or video (by ID), with caching, formatted text output, structured JSON, and resource_link blocks.
    export async function handleGetDetails(
      args: z.infer<typeof getDetailsSchema>,
    ): Promise<CallToolResult> {
      const start = Date.now();
      const { id, type, force_refresh: forceRefresh } = args;
      const cacheKey = makeCacheKey({ id, type });
    
      logDebug('tool: pexels_get_details', 'id:', id, 'type:', type);
    
      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 {
        if (type === 'photo') {
          const photo = await fetchPhotoDetails(id);
    
          const text = `Photo by [${photo.photographer}](${photo.photographer_url}) on Pexels
    
    **ID:** ${photo.id}
    **Dimensions:** ${photo.width}x${photo.height}
    **Color:** ${photo.avg_color}
    **Alt:** ${photo.alt || 'No description'}
    **Link:** ${photo.url}
    ![Preview](${photo.src.medium})`;
    
          const structured: z.infer<typeof photoOutputSchema> = {
            id: photo.id,
            kind: 'photo',
            creatorName: photo.photographer,
            creatorUrl: photo.photographer_url,
            pageUrl: photo.url,
            previewUrl: photo.src.medium,
            mediaUrl: photo.src.large2x || photo.src.medium,
            mediaMimeType: 'image/jpeg',
            dimensions: { width: photo.width, height: photo.height },
            avgColor: photo.avg_color,
            alt: photo.alt || '',
          };
    
          const result: ContentBlock[] = [
            { type: 'text', text },
            { type: 'resource_link', uri: photo.src.medium, name: 'Preview', mimeType: 'image/jpeg' },
            { type: 'text', text: JSON.stringify(structured) },
          ];
    
          setCache(cacheKey, result, 3600);
          logDebug('result:', 'type: photo', 'id:', id, `${Date.now() - start}ms`);
          return { content: result };
        } else {
          const video = await fetchVideoDetails(id);
          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' };
    
          const structured: z.infer<typeof videoOutputSchema> = {
            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,
          };
    
          const result: ContentBlock[] = [
            { type: 'text', text },
            mediaBlock,
            { type: 'text', text: JSON.stringify(structured) },
          ];
          setCache(cacheKey, result, 3600);
          logDebug('result:', 'type: video', 'id:', id, `${Date.now() - start}ms`);
          return { content: result };
        }
      } catch (error) {
        logDebug('error:', error instanceof Error ? error.message : String(error));
        return formatApiError(error);
      }
    }
  • Registers the tool named 'pexels_get_details' with the MCP server, including inputSchema, title, description, and annotations (readOnlyHint, idempotentHint).
    export function registerGetDetails(server: McpServer): void {
      server.registerTool(
        'pexels_get_details',
        {
          title: 'Get Pexels Details',
          description: 'Get detailed information about a specific photo or video by ID.',
          inputSchema: getDetailsSchema,
          annotations: {
            readOnlyHint: true,
            idempotentHint: true,
          },
        },
        (args) => handleGetDetails(args),
      );
    }
  • Input schema for getDetails: requires 'id' (positive int) and 'type' (photo|video), with optional 'force_refresh'.
    export const getDetailsSchema = z.object({
      id: z.number().int().positive(),
      type: z.enum(['photo', 'video']),
      force_refresh: z.boolean().optional(),
    });
  • Output schema for photo details returned in the structured JSON block.
    export const photoOutputSchema = z.object({
      id: z.number(),
      kind: z.literal('photo'),
      creatorName: z.string(),
      creatorUrl: z.string(),
      pageUrl: z.string(),
      previewUrl: z.string(),
      mediaUrl: z.string(),
      mediaMimeType: z.literal('image/jpeg'),
      dimensions: z.object({ width: z.number(), height: z.number() }),
      avgColor: z.string(),
      alt: z.string(),
    });
  • Output schema for video details returned in the structured JSON block.
    export const videoOutputSchema = z.object({
      id: z.number(),
      kind: z.literal('video'),
      creatorName: z.string(),
      creatorUrl: z.string(),
      pageUrl: z.string(),
      previewUrl: z.string(),
      mediaUrl: z.string(),
      mediaMimeType: z.string(),
      dimensions: z.object({ width: z.number(), height: z.number() }),
      durationSeconds: z.number(),
    });
Behavior4/5

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

Annotations already declare readOnlyHint and idempotentHint, so the description's burden is low. It adds that the tool returns 'detailed information', which is helpful but does not elaborate on force_refresh behavior. No contradictions.

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?

Single sentence, 12 words, front-loaded with purpose. No extraneous information; every word earns its place.

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?

Tool is simple with 3 params and no output schema. Description lacks details on force_refresh parameter and return format. With sibling search tools, agent could benefit from more behavioral context, but for basic usage it is minimally complete.

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%, so description must compensate. It only mentions 'ID' and 'photo or video', implicitly covering id and type. force_refresh is entirely undocumented, and no param details are provided.

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?

Description clearly states verb 'Get', resource 'detailed information about a specific photo or video', and qualifier 'by ID'. It directly distinguishes from search siblings that retrieve lists.

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?

Description implies use when you have an ID, but does not explicitly contrast with search tools or mention when not to use. No alternative is named, leaving the agent to infer usage context.

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