get_trending
Retrieve trending movies, TV shows, or both by specifying media type (movie, tv, or all) and time window (day or week).
Instructions
Get trending movies, TV shows, or both.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| media_type | Yes | ||
| time_window | Yes |
Implementation Reference
- src/index.ts:130-139 (handler)The handler function for the 'get_trending' tool. It calls tmdbFetch on /trending/{media_type}/{time_window} and returns summarized results.
async ({ media_type, time_window }) => { try { const data = await tmdbFetch<{ results: any[] }>( `/trending/${media_type}/${time_window}` ); return jsonResult({ results: summarizeList(data.results) }); } catch (err) { return errorResult(err); } } - src/index.ts:126-129 (schema)Input schema for get_trending: media_type (movie/tv/all) and time_window (day/week), both using zod enums.
{ media_type: z.enum(["movie", "tv", "all"]), time_window: z.enum(["day", "week"]), }, - src/index.ts:123-140 (registration)Registration of the 'get_trending' tool on the MCP server via server.tool() with name, description, schema, and handler.
server.tool( "get_trending", "Get trending movies, TV shows, or both.", { media_type: z.enum(["movie", "tv", "all"]), time_window: z.enum(["day", "week"]), }, async ({ media_type, time_window }) => { try { const data = await tmdbFetch<{ results: any[] }>( `/trending/${media_type}/${time_window}` ); return jsonResult({ results: summarizeList(data.results) }); } catch (err) { return errorResult(err); } } ); - src/shape.ts:32-34 (helper)summarizeList helper function that slices and maps raw items through summarizeMovie.
export function summarizeList(items: RawMovie[] | undefined, limit = 20) { return (items ?? []).slice(0, limit).map(summarizeMovie); } - src/shape.ts:18-30 (helper)summarizeMovie helper that transforms raw movie/TV data into a condensed format with id, title, year, overview, rating, etc.
export function summarizeMovie(m: RawMovie) { const date = m.release_date ?? m.first_air_date ?? null; return { id: m.id, media_type: m.media_type ?? (m.first_air_date ? "tv" : "movie"), title: m.title ?? m.name ?? m.original_title ?? m.original_name ?? "", year: yearOf(date), overview: m.overview ?? "", rating: m.vote_average ?? null, vote_count: m.vote_count ?? null, poster: posterUrl(m.poster_path), }; }