Skip to main content
Glama

get-trending

Retrieve trending movies from The Movie Database (TMDB) API for day or week time windows to identify popular content.

Instructions

Get trending movies

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timeWindowNoTime window for trending movies

Implementation Reference

  • MCP tool handler for 'get-trending'. Validates input, calls getTrendingMovies from TMDB API wrapper, and handles errors.
    "get-trending": async ({ timeWindow = "week", }: { timeWindow?: "day" | "week"; }) => { try { // Return the raw results directly return await getTrendingMovies(timeWindow); } catch (error: unknown) { if (error instanceof Error) { throw new Error(`Failed to get trending movies: ${error.message}`); } throw new Error("Failed to get trending movies: Unknown error"); } },
  • Schema definition and metadata for the 'get-trending' tool, used in tool listing.
    "get-trending": { name: "get-trending", description: "Get trending movies", inputSchema: { type: "object", properties: { timeWindow: { type: "string", enum: ["day", "week"], description: "Time window for trending movies", }, }, required: [], }, },
  • src/handlers.ts:57-59 (registration)
    MCP server registration for listing tools, which exposes the 'get-trending' schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: Object.values(tools), }));
  • src/handlers.ts:62-98 (registration)
    MCP server request handler for calling tools, which dispatches to 'get-trending' handler based on name.
    server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const { name, arguments: args } = request.params; // Using type assertion to tell TypeScript this is a valid key const handler = toolHandlers[name as keyof typeof toolHandlers]; if (!handler) throw new Error(`Tool not found: ${name}`); // Execute the handler but wrap the response in the expected format const result = await handler(args as any); // Return in the format expected by the SDK return { tools: [{ name, inputSchema: { type: "object", properties: {} // This would ideally be populated with actual schema }, description: `Tool: ${name}`, result }] }; } catch (error) { // Properly handle errors if (error instanceof Error) { return { tools: [], error: error.message }; } return { tools: [], error: "An unknown error occurred" }; } });
  • Helper function implementing the core API logic for fetching trending movies from TMDB.
    export async function getTrendingMovies(timeWindow: 'day' | 'week' = 'week'): Promise<SearchMoviesResponse> { try { const response = await axiosWithRetry<SearchMoviesResponse>({ url: `/trending/movie/${timeWindow}` }); return response.data; } catch (error) { const err = error as Error; console.error('Error getting trending movies:', err.message); throw new Error(`Failed to get trending movies: ${err.message}`); } }

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/ShubhanshuSondhiya/MCP-TMDB'

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