search-movie
Search for movies and TV shows on Douban using keywords to find titles, details, and related content.
Instructions
search movies or tvs from douban by query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | query string, e.g. "python" |
Implementation Reference
- src/index.ts:95-117 (handler)The MCP tool handler function for 'search-movie'. It validates the query parameter, fetches movies using the searchMovies helper, formats the results into a markdown table using json2md, and returns the content as text.async (args) => { if (!args.q) { throw new McpError(ErrorCode.InvalidParams, "q must be provided") } const movies = await searchMovies(args) const text = json2md({ table: { headers: ['title', 'subtitle', 'publish_date', 'rating', 'id'], rows: movies.map(_ => ({ id: _.id, title: _.title, subtitle: _.card_subtitle, publish_date: _.year, rating: `${_.rating?.value || '0'} (${_.rating?.count || 0}人)`, })) } }) return { content: [{ type: 'text', text }] } }
- src/index.ts:92-94 (schema)Zod schema defining the input parameters for the 'search-movie' tool: a required query string 'q'.{ q: z.string().describe('query string, e.g. "python"') },
- src/index.ts:89-118 (registration)Registration of the 'search-movie' tool on the MCP server using server.tool(), specifying the tool name via TOOL.SEARCH_MOVIE, description, input schema, and handler.server.tool( TOOL.SEARCH_MOVIE, 'search movies or tvs from douban by query', { q: z.string().describe('query string, e.g. "python"') }, async (args) => { if (!args.q) { throw new McpError(ErrorCode.InvalidParams, "q must be provided") } const movies = await searchMovies(args) const text = json2md({ table: { headers: ['title', 'subtitle', 'publish_date', 'rating', 'id'], rows: movies.map(_ => ({ id: _.id, title: _.title, subtitle: _.card_subtitle, publish_date: _.year, rating: `${_.rating?.value || '0'} (${_.rating?.count || 0}人)`, })) } }) return { content: [{ type: 'text', text }] } } );
- src/api.ts:61-66 (helper)Core API helper function searchMovies that performs the actual API request to Frodo Douban API endpoint for searching movies by query and maps the response items to their target objects.export async function searchMovies(params: { q: string }) { const res = await requestFrodoApi(`/search/movie?q=${params.q}`) return res?.items ? res.items.map(_ => _.target) : []; }
- src/types.ts:98-130 (schema)TypeScript type definition for Douban.Movie, describing the structure of movie data used in the tool's output.interface Movie { /** 条目 id */ id: string; /** 中文名 */ title: string; /** 原名 */ original_title: string; /** 条目 URL */ alt: string; /** * 电影海报图,分别提供 288px x 465px(大),96px x 155px(中) 64px x 103px(小)尺寸 */ images: { small: string; medium: string; large: string; }; /** 评分信息 */ rating: { /** 平均评分 */ average: number; /** 评分人数 */ numRaters?: number; /** 评分人数(别名) */ ratings_count?: number; }; /** 如果条目类型是电影则为上映日期,如果是电视剧则为首播日期 */ pubdates: string[]; /** 年代 */ year: string; /** 条目分类, movie 或者 tv */ subtype: 'movie' | 'tv'; }