search_books
Search for books on Aladin by title, author, publisher, or keyword. Retrieve results with customizable parameters such as maximum results and starting index for precise book discovery.
Instructions
알라딘에서 도서를 검색합니다.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxResults | No | 최대 결과 개수 | |
| query | Yes | 검색어 | |
| searchType | No | 검색 타입 | Title |
| start | No | 검색 시작 번호 |
Implementation Reference
- src/index.ts:189-241 (handler)The anonymous async handler function that implements the core logic of the 'search_books' tool, performing the Aladin API search and processing results into BookSearchResult objects.async ({ query, searchType, maxResults, start }) => { try { if (!query) { throw new Error('검색어를 입력해주세요.'); } const params = { Query: query, QueryType: searchType, MaxResults: maxResults, start: start, SearchTarget: 'Book', Cover: 'Big' }; const result = await callAladinApi('ItemSearch.aspx', params); const books: BookSearchResult[] = result.item?.map((item: any) => ({ title: item.title || '', author: item.author || '', publisher: item.publisher || '', pubDate: item.pubDate || '', isbn: item.isbn || '', isbn13: item.isbn13 || '', cover: item.cover || '', categoryName: item.categoryName || '', description: item.description || '', priceStandard: item.priceStandard || 0, priceSales: item.priceSales || 0, link: item.link || '', pages: item.subInfo?.itemPage || undefined, pricePerPage: (item.priceStandard > 0 && item.subInfo?.itemPage > 0) ? parseFloat((item.priceStandard / item.subInfo.itemPage).toFixed(2)) : undefined })) || []; return { content: [{ type: 'text', text: `📚 도서 검색 결과 (${query})\n\n검색된 도서 수: ${books.length}권\n\n${JSON.stringify(books, null, 2)}` }] }; } catch (error) { logger.error(`도서 검색 중 오류 발생: ${error}`); return { content: [{ type: 'text', text: `도서 검색 중 오류가 발생했습니다: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/index.ts:182-187 (schema)Zod input schema definition for the 'search_books' tool parameters.inputSchema: { query: z.string().describe('검색어'), searchType: z.enum(['Title', 'Author', 'Publisher', 'Keyword']).default('Title').describe('검색 타입'), maxResults: z.number().min(1).max(100).default(10).describe('최대 결과 개수'), start: z.number().min(1).default(1).describe('검색 시작 번호') }
- src/index.ts:177-242 (registration)Registration of the 'search_books' MCP tool using server.registerTool, including title, description, input schema, and inline handler.server.registerTool( 'search_books', { title: '도서 검색', description: '알라딘에서 도서를 검색합니다.', inputSchema: { query: z.string().describe('검색어'), searchType: z.enum(['Title', 'Author', 'Publisher', 'Keyword']).default('Title').describe('검색 타입'), maxResults: z.number().min(1).max(100).default(10).describe('최대 결과 개수'), start: z.number().min(1).default(1).describe('검색 시작 번호') } }, async ({ query, searchType, maxResults, start }) => { try { if (!query) { throw new Error('검색어를 입력해주세요.'); } const params = { Query: query, QueryType: searchType, MaxResults: maxResults, start: start, SearchTarget: 'Book', Cover: 'Big' }; const result = await callAladinApi('ItemSearch.aspx', params); const books: BookSearchResult[] = result.item?.map((item: any) => ({ title: item.title || '', author: item.author || '', publisher: item.publisher || '', pubDate: item.pubDate || '', isbn: item.isbn || '', isbn13: item.isbn13 || '', cover: item.cover || '', categoryName: item.categoryName || '', description: item.description || '', priceStandard: item.priceStandard || 0, priceSales: item.priceSales || 0, link: item.link || '', pages: item.subInfo?.itemPage || undefined, pricePerPage: (item.priceStandard > 0 && item.subInfo?.itemPage > 0) ? parseFloat((item.priceStandard / item.subInfo.itemPage).toFixed(2)) : undefined })) || []; return { content: [{ type: 'text', text: `📚 도서 검색 결과 (${query})\n\n검색된 도서 수: ${books.length}권\n\n${JSON.stringify(books, null, 2)}` }] }; } catch (error) { logger.error(`도서 검색 중 오류 발생: ${error}`); return { content: [{ type: 'text', text: `도서 검색 중 오류가 발생했습니다: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
- src/index.ts:122-137 (schema)TypeScript interface defining the structure of book search results used in the 'search_books' handler.interface BookSearchResult { title: string; author: string; publisher: string; pubDate: string; isbn: string; isbn13: string; cover: string; categoryName: string; description: string; priceStandard: number; priceSales: number; link: string; pages?: number; // 페이지 수 추가 pricePerPage?: number; // 쪽단가 추가 }
- src/index.ts:147-168 (helper)Utility helper function to make authenticated calls to the Aladin API, invoked by the 'search_books' handler.async function callAladinApi(endpoint: string, params: Record<string, any>): Promise<any> { if (!ALADIN_TTB_KEY || ALADIN_TTB_KEY.length === 0) { throw new Error('알라딘 API 키가 설정되지 않았습니다. ALADIN_TTB_KEY 환경변수를 올바르게 설정해주세요.'); } const baseParams = { ttbkey: ALADIN_TTB_KEY, output: 'js', version: '20131101' }; const finalParams = { ...baseParams, ...params }; const url = `${ALADIN_BASE_URL}/${endpoint}`; try { const response = await axios.get(url, { params: finalParams }); return response.data; } catch (error) { logger.error(`알라딘 API 호출 오류: ${error}`); throw error; } }