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
| Name | Required | Description | Default |
|---|---|---|---|
| timeWindow | No | Time window for trending movies |
Implementation Reference
- src/tools.ts:90-104 (handler)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"); } },
- src/tools.ts:27-41 (schema)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: [], }, },
- src/tmdb-api.ts:131-142 (helper)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" }; } });