Skip to main content
Glama
magarcia

MCP Server Giphy

get_random_gif

Retrieve a random GIF from Giphy's library, with optional filtering by tag and content rating for appropriate use.

Instructions

Get a random GIF from Giphy, optionally filtered by tag

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tagNoTag to limit random results (optional)
ratingNoContent rating (g, pg, pg-13, r)

Implementation Reference

  • The main handler function that implements the logic to fetch a random GIF from the Giphy API, handling parameters like tag and rating, constructing the API URL, making the request with axios, formatting the response, and error handling.
    export async function getRandomGif(params: {
      tag?: string;
      rating?: "g" | "pg" | "pg-13" | "r";
    }) {
      const { tag, rating = "g" } = params;
    
      const searchParams: Record<string, string | number> = {
        rating,
      };
    
      if (tag) {
        searchParams.tag = tag;
      }
    
      const url = buildUrl("random", searchParams);
    
      try {
        const response = await axios.get(url);
        const responseData = response.data as GiphyRandomResponse;
        return formatGif(responseData.data);
      } catch (error) {
        let errorMsg = "Giphy API error";
    
        if (axios.isAxiosError(error) && error.response) {
          errorMsg = `${errorMsg}: ${error.response.status} ${error.response.statusText}`;
        } else if (error instanceof Error) {
          errorMsg = `${errorMsg}: ${error.message}`;
        }
    
        throw new Error(errorMsg);
      }
    }
  • The schema definition for the get_random_gif tool, including name, description, and input schema specifying optional tag and rating parameters.
    export const getRandomGifTool: Tool = {
      name: "get_random_gif",
      description: "Get a random GIF from Giphy, optionally filtered by tag",
      inputSchema: {
        type: "object",
        properties: {
          tag: {
            type: "string",
            description: "Tag to limit random results (optional)",
          },
          rating: {
            type: "string",
            enum: ["g", "pg", "pg-13", "r"],
            description: "Content rating (g, pg, pg-13, r)",
          },
        },
      },
    };
  • src/server.ts:107-111 (registration)
    Registration of the getRandomGifTool in the MCP server's list of available tools via the ListToolsRequestHandler.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [searchGifsTool, getRandomGifTool, getTrendingGifsTool],
      };
    });
  • The dispatch handler in the MCP server's CallToolRequestHandler that routes get_random_gif calls to the getRandomGif service function and formats the response.
    case "get_random_gif": {
      const randomParams = args as {
        tag?: string;
        rating?: "g" | "pg" | "pg-13" | "r";
      };
      const gif = await getRandomGif(randomParams);
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({ gif }),
          },
        ],
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the tool fetches from Giphy but doesn't disclose behavioral traits like rate limits, authentication needs, response format, or error handling. For an external API tool with zero annotation coverage, this is a significant gap in transparency.

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, efficient sentence that front-loads the core purpose ('Get a random GIF from Giphy') and adds optional detail ('optionally filtered by tag') without waste. Every word earns its place, making it appropriately sized and well-structured.

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 tool's moderate complexity (external API call with parameters) and no annotations or output schema, the description is minimally adequate. It covers the basic purpose but lacks details on behavior, response format, or error handling, leaving gaps that could hinder effective use by an agent.

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 100%, so the schema already documents both parameters ('tag' and 'rating') with descriptions and enum values. The description adds minimal value by mentioning optional tag filtering, but doesn't provide additional syntax or context beyond what the schema provides, meeting the baseline for high coverage.

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 ('Get a random GIF') and resource ('from Giphy'), with optional filtering by tag. It distinguishes from siblings by specifying 'random' (vs. 'trending' or 'search'), making the purpose explicit and differentiated.

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 random GIF retrieval, but provides no explicit guidance on when to use this tool versus alternatives like 'get_trending_gifs' or 'search_gifs'. It mentions optional tag filtering, which hints at context, but lacks clear when/when-not instructions or named alternatives.

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/magarcia/mcp-server-giphy'

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