search-movie
Search for movies and TV shows on Douban using keywords to find relevant content and information.
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:89-118 (registration)Registration of the "search-movie" MCP tool, including description, Zod input schema for query 'q', and inline handler that fetches movies and formats them into a markdown table.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 (handler)Core implementation of movie search logic: queries the Frodo Douban API endpoint `/search/movie?q={q}` and extracts movie data from response items.export async function searchMovies(params: { q: string }) { const res = await requestFrodoApi(`/search/movie?q=${params.q}`) return res?.items ? res.items.map(_ => _.target) : []; }
- src/index.ts:92-94 (schema)Zod input schema defining the required 'q' parameter as a string for the search query.{ q: z.string().describe('query string, e.g. "python"') },
- src/types.ts:98-130 (schema)TypeScript interface defining the structure of a Douban Movie object, used implicitly in the handler's output processing.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'; }
- src/api.ts:147-174 (helper)Utility function for making authenticated requests to the Frodo Douban API, used by searchMovies to perform the actual HTTP fetch with signature and headers.const requestFrodoApi = async (url: string) => { const fullURL = 'https://frodo.douban.com/api/v2' + url; const date = dayjs().format('YYYYMMDD') const rParams = { os_rom: 'android', apiKey: '0dad551ec0f84ed02907ff5c42e8ec70', _ts: date, _sig: getFrodoSign(fullURL, date), }; const oUrl = new URL(fullURL) for (let key in rParams) { // @ts-ignore oUrl.searchParams.set(key, rParams[key]) } const req = await fetch(oUrl.toString(), { headers: { 'user-agent': getUA(), cookie: process.env.COOKIE || '' } }) return req.json() }