Skip to main content
Glama

get_random_hadith

Retrieve a random Hadith from Islamic collections for daily inspiration or study, with optional filtering by specific collections like Bukhari or Muslim.

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 implements get_random_hadith logic: selects random collection if unspecified, picks random hadith number, and fetches using getHadith.
    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);
    }
  • Tool schema definition including name, description, and input validation schema.
    {
      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 registration in the central switch dispatcher that maps tool name to handler execution.
    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