Skip to main content
Glama
TeeDDub

Aladin Book Search MCP Server

by TeeDDub

search_categories

Search for book categories using Aladin's database, prioritizing top-level categories. Specify a term and define the number of results for accurate category discovery.

Instructions

알라딘 도서 카테고리를 검색합니다. 상위 레벨 카테고리를 우선으로 표시합니다.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxResultsNo최대 결과 개수
searchTermYes검색할 카테고리 이름

Implementation Reference

  • Core implementation of the category search logic. Traverses the category tree recursively, matches search term case-insensitively, prioritizes lower levels, and returns formatted CategoryInfo with full path.
    function searchCategories(searchTerm: string, data: any): CategoryInfo[] { const results: Array<CategoryInfo & { level: number; fullPath: string }> = []; function traverse(node: CategoryNode, path: string[] = [], currentLevel: number = 1) { // 현재 노드의 카테고리 정보 확인 if (node.categories) { for (const category of node.categories) { if (category.name.toLowerCase().includes(searchTerm.toLowerCase())) { results.push({ ...category, level: currentLevel, fullPath: `${path.join(' > ')} > ${category.name}`, name: category.name // 원본 이름 유지 }); } } } // 자식 노드 순회 if (node.children) { for (const [childName, childNode] of Object.entries(node.children)) { traverse(childNode, [...path, childName], currentLevel + 1); } } } for (const [rootName, rootNode] of Object.entries(data)) { traverse(rootNode as CategoryNode, [rootName]); } // 레벨별로 정렬 (level 1이 가장 우선, 같은 레벨에서는 이름순) results.sort((a, b) => { if (a.level !== b.level) { return a.level - b.level; } return a.name.localeCompare(b.name); }); // 결과 반환 시 fullPath를 name으로 설정 return results.map(result => ({ cid: result.cid, name: result.fullPath, mall: result.mall })); }
  • src/index.ts:672-736 (registration)
    MCP tool registration for 'search_categories'. Defines title, description, Zod input schema, and async handler that uses the searchCategories function to process input and return formatted results.
    server.registerTool( 'search_categories', { title: '카테고리 검색', description: '알라딘 도서 카테고리를 검색합니다. 상위 레벨 카테고리를 우선으로 표시합니다.', inputSchema: { searchTerm: z.string().describe('검색할 카테고리 이름'), maxResults: z.number().min(1).max(50).default(20).describe('최대 결과 개수') } }, async ({ searchTerm, maxResults }) => { try { const allCategories = searchCategories(searchTerm, categoryData); const categories = allCategories.slice(0, maxResults); if (categories.length === 0) { return { content: [{ type: 'text', text: `'${searchTerm}'과 관련된 카테고리를 찾을 수 없습니다.` }] }; } // 레벨별로 그룹화 const levelGroups: { [level: string]: any[] } = {}; categories.forEach(cat => { const level = cat.name.split(' > ').length - 1; if (!levelGroups[level]) { levelGroups[level] = []; } levelGroups[level].push(cat); }); let resultText = `'${searchTerm}' 검색 결과 (${categories.length}개${allCategories.length > maxResults ? `, 총 ${allCategories.length}개 중 상위 ${maxResults}개 표시` : ''}):\n\n`; // 레벨별로 표시 Object.keys(levelGroups).sort((a, b) => Number(a) - Number(b)).forEach(level => { const levelName = level === '1' ? '대분류' : level === '2' ? '중분류' : '소분류'; resultText += `📚 ${levelName} (Level ${level}):\n`; levelGroups[level].forEach((cat, index) => { resultText += `${index + 1}. ${cat.name}\n`; resultText += ` CID: ${cat.cid} | 몰: ${cat.mall}\n`; }); resultText += '\n'; }); return { content: [{ type: 'text', text: resultText }] }; } catch (error) { logger.error(`카테고리 검색 중 오류 발생: ${error}`); return { content: [{ type: 'text', text: `카테고리 검색 중 오류가 발생했습니다: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • TypeScript interface defining the structure of category information returned by the search function.
    interface CategoryInfo { cid: string; name: string; mall: string; }
  • Zod input schema validation for the tool parameters: searchTerm (string) and maxResults (number with constraints).
    inputSchema: { searchTerm: z.string().describe('검색할 카테고리 이름'), maxResults: z.number().min(1).max(50).default(20).describe('최대 결과 개수') }
  • Usage of searchCategories function within the 'get_popular_categories' tool to find categories for popular terms.
    const categories = searchCategories(popular.searchTerm, categoryData);

Other Tools

Related Tools

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/TeeDDub/mcp-aladin-books-server'

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