get_trending_gifs
Retrieve currently trending GIFs from Giphy with options to filter by content rating and control result quantity for integration into applications and content.
Instructions
Get currently trending GIFs on Giphy
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of objects to return (default: 10, max: 50) | |
| offset | No | Results offset (default: 0) | |
| rating | No | Content rating (g, pg, pg-13, r) |
Implementation Reference
- src/service.ts:74-104 (handler)Core handler function that fetches and formats trending GIFs from the Giphy API using axios.export async function getTrendingGifs(params: { limit?: number; offset?: number; rating?: "g" | "pg" | "pg-13" | "r"; }) { const { limit = 10, offset = 0, rating = "g" } = params; const searchParams = { limit, offset, rating, }; const url = buildUrl("trending", searchParams); try { const response = await axios.get(url); const responseData = response.data as GiphyResponse; return formatGifs(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); } }
- src/server.ts:69-85 (handler)MCP server request handler case that parses arguments, calls the service function, and returns the JSON response.case "get_trending_gifs": { const trendingParams = args as { limit?: number; offset?: number; rating?: "g" | "pg" | "pg-13" | "r"; }; const gifs = await getTrendingGifs(trendingParams); return { content: [ { type: "text", text: JSON.stringify({ gifs }), }, ], }; }
- src/tools.ts:47-66 (schema)Tool definition including name, description, and input schema for validation.export const getTrendingGifsTool: Tool = { name: "get_trending_gifs", description: "Get currently trending GIFs on Giphy", inputSchema: { type: "object", properties: { limit: { type: "number", description: "Maximum number of objects to return (default: 10, max: 50)", }, offset: { type: "number", description: "Results offset (default: 0)" }, 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 tool in the MCP server's list of available tools.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [searchGifsTool, getRandomGifTool, getTrendingGifsTool], }; });