Skip to main content
Glama

search-book

Search for books on Douban using ISBN numbers or keyword queries to find specific titles and authors.

Instructions

search books from douban, either by ISBN or by query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
isbnNoISBN number, e.g. "9787501524044"
qNoquery string, e.g. "python"

Implementation Reference

  • The handler function for the 'search-book' tool. Validates input arguments, calls the searchBooks helper from api.ts, formats the book results into a markdown table using json2md, and returns the content.
    async (args) => { if (!args.isbn && !args.q) { throw new McpError(ErrorCode.InvalidParams, "Either q or isbn must be provided") } const books = await searchBooks(args) const text = json2md({ table: { headers: ['publish_date', 'title', 'author', 'rating' ,'id', 'isbn'], rows: books.map(_ => ({ id: _.id || '', title: _.title || '', author: (_.author || []).join('、'), publish_date: _.pubdate, isbn: _.isbn13 || '', rating: `${_.rating?.average || 0} (${_.rating?.numRaters || 0}人)` })) } }) return { content: [{ type: 'text', text }] } }
  • Zod input schema defining optional 'q' (query string) and 'isbn' parameters for the 'search-book' tool.
    { q: z.string().optional().describe('query string, e.g. "python"'), isbn: z.string().optional().describe('ISBN number, e.g. "9787501524044"') },
  • src/index.ts:25-27 (registration)
    Registration of the 'search-book' tool using McpServer.tool method, referencing TOOL.SEARCH_BOOK constant.
    server.tool( TOOL.SEARCH_BOOK, 'search books from douban, either by ISBN or by query',
  • Helper function searchBooks that dispatches to keyword or ISBN search based on input params and returns array of books.
    export async function searchBooks(params: { q?: string isbn?: string }) { if (params.q) { return searchByKeyword(params.q) } if (params.isbn) { return searchByISBN(params.isbn) } return [] }
  • Implementation of keyword-based book search via Douban V2 API, parsing and returning books.
    async function searchByKeyword (q: string) { const url = new URL('https://api.douban.com/v2/book/search') url.searchParams.set('q', q) url.searchParams.set('apikey', apiKey) const res: { count: number start: number total: number books: Douban.Book[] } = await (await fetch(url.toString(), { headers: FAKE_HEADERS })).json() return res?.books ? res.books.map(parseDoubanBook) : [] }
  • Implementation of ISBN-based book search via Douban V2 API, returning single book or empty.
    async function searchByISBN (isbn: string) { const url = new URL(`https://api.douban.com/v2/book/isbn/${isbn}`) url.searchParams.set('apikey', apiKey) const res: Douban.Book = await (await fetch(url.toString(), { headers: FAKE_HEADERS })).json() return res?.id ? [parseDoubanBook(res)] : [] }
  • TOOL enum defining the tool name constant SEARCH_BOOK = 'search-book'.
    export enum TOOL { SEARCH_BOOK = 'search-book', LIST_BOOK_REVIEWS = 'list-book-reviews', SEARCH_MOVIE = 'search-movie', LIST_MOVIE_REVIEWS = 'list-movie-reviews', BROWSE = 'browse', LIST_GROUP_TOPICS = 'list-group-topics', GET_GROUP_TOPIC_DETAIL = 'get-group-topic-detail' }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/moria97/douban-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server