Skip to main content
Glama

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
NameRequiredDescriptionDefault
collectionNoHadith collection (optional). If not specified, picks from any collection.

Implementation Reference

  • 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'], }, }, }, },
  • 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; }

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/Prince77-7/quranMCP'

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