get_random_hadith
Retrieve a random Hadith from Islamic collections for daily inspiration and spiritual guidance. Choose from specific collections or get any random selection.
Instructions
Get a random Hadith from a collection. Great for daily inspiration!
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | No | Hadith collection (optional). If not specified, picks from any collection. |
Implementation Reference
- src/tools/hadith.ts:111-128 (handler)Core handler function that selects a random Hadith collection if none specified, picks a random Hadith number within that collection, and delegates to getHadith to fetch the content.export async function getRandomHadith(collection?: string): Promise<HadithResponse> { // If no collection specified, pick a random one const selectedCollection = collection || HADITH_COLLECTIONS[Math.floor(Math.random() * HADITH_COLLECTIONS.length)].slug; const collectionInfo = HADITH_COLLECTIONS.find(c => c.slug === selectedCollection); if (!collectionInfo) { throw new QuranMCPError( `Unknown hadith collection: ${selectedCollection}`, 'INVALID_COLLECTION' ); } // Get random hadith number const randomNumber = Math.floor(Math.random() * collectionInfo.totalHadiths) + 1; return getHadith(selectedCollection, randomNumber); }
- MCP tool schema definition including name, description, and input schema for the get_random_hadith tool.{ name: 'get_random_hadith', description: 'Get a random Hadith from a collection. Great for daily inspiration!', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Hadith collection (optional). If not specified, picks from any collection.', enum: ['bukhari', 'muslim', 'abudawud', 'tirmidhi', 'nasai', 'ibnmajah'], }, }, }, },
- src/shared/tool-executor.ts:81-85 (registration)Tool execution registration in the switch statement that handles the 'get_random_hadith' case by extracting the collection parameter and calling the handler function.case 'get_random_hadith': { const { collection } = args; result = await getRandomHadith(collection); break; }