Skip to main content
Glama

get_random_verse

Retrieve a random Quran verse for daily inspiration, with optional English translation to support reflection and learning.

Instructions

Get a random verse from the Quran. Great for daily inspiration!

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_translationNoWhether to include English translation (default: true)
translationNoTranslation to use (default: en.asad)en.asad

Implementation Reference

  • The core handler function that selects a random surah and ayah, fetches the Arabic text, and optionally the translation using helper functions.
    export async function getRandomVerse(
      includeTranslation: boolean = true,
      translationSlug: string = 'en.asad'
    ): Promise<{ arabic: QuranVerse; translation?: QuranVerse; surahInfo: any }> {
      // Pick random surah
      const randomSurah = Math.floor(Math.random() * 114) + 1;
      const surahInfo = getSurahInfo(randomSurah);
      
      if (!surahInfo) {
        throw new QuranMCPError('Failed to get random verse', 'RANDOM_VERSE_ERROR');
      }
    
      // Pick random ayah from that surah
      const randomAyah = Math.floor(Math.random() * surahInfo.ayahs) + 1;
    
      const arabic = await getQuranArabic(randomSurah, randomAyah);
      
      if (includeTranslation) {
        const translation = await getQuranTranslation(randomSurah, randomAyah, translationSlug);
        return { arabic, translation, surahInfo };
      }
    
      return { arabic, surahInfo };
    }
  • MCP tool definition including name, description, and input schema for validation.
    {
      name: 'get_random_verse',
      description: 'Get a random verse from the Quran. Great for daily inspiration!',
      inputSchema: {
        type: 'object',
        properties: {
          include_translation: {
            type: 'boolean',
            description: 'Whether to include English translation (default: true)',
            default: true,
          },
          translation: {
            type: 'string',
            description: 'Translation to use (default: en.asad)',
            default: 'en.asad',
          },
        },
      },
    },
  • Registration in the tool dispatcher switch statement that maps the tool name to the handler execution.
    case 'get_random_verse': {
      const { include_translation = true, translation = 'en.asad' } = args;
      result = await getRandomVerse(include_translation, translation);
      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