search_hadith_by_topic
Find Hadith teachings on Islamic topics like prayer, fasting, charity, and faith using predefined topic mappings across major collections.
Instructions
Search Hadith collections by common Islamic topics. Uses predefined topic mappings for better results. Topics include: prayer, fasting, charity, hajj, faith, prophet, companions, knowledge, manners, family, marriage, death, jihad, repentance. The AI can suggest these topics to users based on their questions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topic | Yes | Topic to search for. Common topics: prayer, fasting, charity, hajj, faith, prophet, companions, knowledge, manners, family, marriage, death, jihad, repentance | |
| collections | No | Specific collections to search in (optional) | |
| max_results | No | Maximum number of results to return (default: 10) |
Implementation Reference
- src/tools/search.ts:443-468 (handler)The main handler function that implements the search_hadith_by_topic tool logic. It maps the input topic to relevant keywords and delegates the search to the underlying searchHadith function.export async function searchHadithByTopic( topic: string, collections?: string[], maxResults: number = 10 ): Promise<HadithSearchResult[]> { // Map common topics to search terms const topicKeywords: Record<string, string> = { 'prayer': 'prayer salah worship prostrate', 'fasting': 'fast fasting ramadan', 'charity': 'charity sadaqah alms', 'hajj': 'hajj pilgrimage kaaba', 'faith': 'faith belief iman', 'prophet': 'prophet messenger', 'companions': 'companion sahaba', 'knowledge': 'knowledge learn scholar', 'manners': 'manner behavior conduct', 'family': 'family parents children', 'marriage': 'marriage wife husband', 'death': 'death grave hereafter', 'jihad': 'jihad struggle strive', 'repentance': 'repent forgive sin', }; const searchQuery = topicKeywords[topic.toLowerCase()] || topic; return searchHadith(searchQuery, collections, maxResults); }
- The schema definition for the search_hadith_by_topic tool, including input parameters validation, description, and supported collections.{ name: 'search_hadith_by_topic', description: 'Search Hadith collections by common Islamic topics. Uses predefined topic mappings for better results. Topics include: prayer, fasting, charity, hajj, faith, prophet, companions, knowledge, manners, family, marriage, death, jihad, repentance. The AI can suggest these topics to users based on their questions.', inputSchema: { type: 'object', properties: { topic: { type: 'string', description: 'Topic to search for. Common topics: prayer, fasting, charity, hajj, faith, prophet, companions, knowledge, manners, family, marriage, death, jihad, repentance', }, collections: { type: 'array', description: 'Specific collections to search in (optional)', items: { type: 'string', enum: ['bukhari', 'muslim', 'abudawud', 'tirmidhi', 'nasai', 'ibnmajah'], }, }, max_results: { type: 'number', description: 'Maximum number of results to return (default: 10)', default: 10, }, }, required: ['topic'], }, },
- src/shared/tool-executor.ts:141-145 (registration)The switch case registration in the tool executor that handles calls to search_hadith_by_topic by invoking the handler function.case 'search_hadith_by_topic': { const { topic, collections, max_results = 10 } = args; result = await searchHadithByTopic(topic, collections, max_results); break; }