Skip to main content
Glama

get-trending

Retrieve trending movies by specifying a time window (day or week) using the TMDB MCP Server to access The Movie Database API.

Instructions

Get trending movies

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timeWindowNoTime window for trending movies

Implementation Reference

  • The handler function for the 'get-trending' tool that executes the logic by calling getTrendingMovies from TMDB API.
    "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"); } },
  • The schema and metadata definition for the 'get-trending' tool, including input schema.
    "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: [], }, },
  • The core implementation of fetching trending movies from the TMDB API using axios.
    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}`); } }
  • src/handlers.ts:56-98 (registration)
    Registration of tool handlers in the MCP server, where 'get-trending' is made available via toolHandlers and tools objects.
    // Tool handlers server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: Object.values(tools), })); // This is the key fix - we need to format the response properly 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" }; } });

Other Tools

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

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