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
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get-trending"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timeWindow | No | Time window for trending movies |
Implementation Reference
- src/tools.ts:90-104 (handler)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"); } }, - src/tools.ts:27-41 (schema)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" }; } }); - src/tmdb-api.ts:131-142 (helper)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}`); } }