list-book-reviews
Retrieve reviews for a specific book using its Douban ID to analyze reader feedback and opinions.
Instructions
list book reviews
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | douban book id, e.g. "1234567890" |
Implementation Reference
- src/index.ts:64-85 (handler)The inline handler function that implements the core logic of the 'list-book-reviews' tool. It validates the book ID, fetches reviews using the getBookReviews helper, formats the results into a markdown table with json2md, and returns the content as text.async (args) => { if (!args.id) { throw new McpError(ErrorCode.InvalidParams, "douban book id must be provided") } const reviews = await getBookReviews({ id: args.id }) const text = json2md({ table: { headers: ['title', 'rating', 'summary', 'id'], rows: reviews.reviews.map(_ => ({ id: _.id, title: _.title, rating: `${_.rating?.value || 0} (${_.rating?.count || 0}人)`, summary: _.abstract })) } }) return { content: [{ type: 'text', text }] } }
- src/index.ts:58-86 (registration)Registration of the 'list-book-reviews' tool on the MCP server, specifying the tool name via TOOL.LIST_BOOK_REVIEWS, description, input schema, and handler function.server.tool( TOOL.LIST_BOOK_REVIEWS, "list book reviews", { id: z.string().describe('douban book id, e.g. "1234567890"') }, async (args) => { if (!args.id) { throw new McpError(ErrorCode.InvalidParams, "douban book id must be provided") } const reviews = await getBookReviews({ id: args.id }) const text = json2md({ table: { headers: ['title', 'rating', 'summary', 'id'], rows: reviews.reviews.map(_ => ({ id: _.id, title: _.title, rating: `${_.rating?.value || 0} (${_.rating?.count || 0}人)`, summary: _.abstract })) } }) return { content: [{ type: 'text', text }] } } )
- src/index.ts:62-63 (schema)Zod input schema defining the required 'id' parameter as a string for the douban book ID.id: z.string().describe('douban book id, e.g. "1234567890"') },
- src/api.ts:48-58 (helper)Helper function that performs the actual API request to Douban's Frodo API to retrieve book reviews for the given book ID, returning the paginated list of reviews.export async function getBookReviews(params: { id: string }) { const res: { count: number start: number total: number reviews: Douban.BookReview[] } = await requestFrodoApi(`/book/${params.id}/reviews`) return res }
- src/types.ts:56-96 (schema)TypeScript interface defining the structure of a Douban book review, used for typing the response from the API.interface BookReview { rating: { count: number; max: number; star_count: number; value: number; } | null; useful_count: number; sharing_url: string; title: string; url: string; abstract: string; uri: string; ad_info: null; topic: null; photos: any[]; reactions_count: number; comments_count: number; user: { kind: string; name: string; url: string; uri: string; avatar: string; is_club: boolean; type: string; id: string; uid: string; }; create_time: string; reshares_count: number; type: string; id: string; subject: { press: string[]; type: string; pubdate: string[]; title: string; }; }