Skip to main content
Glama

get_tafsir

Retrieve scholarly commentary and explanations for specific Quran verses to understand their context and interpretation. Provides access to Tafsir sources for deeper insight into Islamic texts.

Instructions

Get Tafsir (commentary/explanation) for a specific Quran verse. Provides scholarly interpretation and context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
surahYesSurah number (1-114)
ayahYesAyah (verse) number
tafsirNoTafsir source (default: en-tafisr-ibn-kathir). Use list_tafsir_sources to see all options.en-tafisr-ibn-kathir

Implementation Reference

  • The core handler function that implements the get_tafsir tool logic: input validation, caching, API fetching, and error handling.
    export async function getTafsir(
      surah: number,
      ayah: number,
      tafsirSlug: string = 'en-tafisr-ibn-kathir'
    ): Promise<TafsirResponse> {
      // Validate inputs
      if (!isValidSurah(surah)) {
        throw new QuranMCPError(
          `Invalid surah number: ${surah}. Must be between 1 and 114.`,
          'INVALID_SURAH'
        );
      }
    
      if (!isValidAyah(surah, ayah)) {
        const surahInfo = getSurahInfo(surah);
        throw new QuranMCPError(
          `Invalid ayah number: ${ayah}. Surah ${surah} has ${surahInfo?.ayahs} ayahs.`,
          'INVALID_AYAH'
        );
      }
    
      // Check if tafsir source exists
      const tafsirSource = TAFSIR_SOURCES.find(t => t.slug === tafsirSlug);
      if (!tafsirSource) {
        throw new QuranMCPError(
          `Unknown tafsir source: ${tafsirSlug}. Available sources: ${TAFSIR_SOURCES.map(t => t.slug).join(', ')}`,
          'INVALID_TAFSIR_SOURCE'
        );
      }
    
      // Create cache key
      const cacheKey = `tafsir:${tafsirSlug}:${surah}:${ayah}`;
    
      // Try to get from cache or fetch
      return tafsirCacheService.getOrSet(cacheKey, async () => {
        const url = `${API_ENDPOINTS.TAFSIR}/${tafsirSlug}/${surah}/${ayah}.json`;
        
        try {
          const data = await fetchJSON<any>(url);
          
          return {
            surah,
            ayah,
            text: data.text || data.tafsir || '',
            tafsir_name: tafsirSource.name,
            language: tafsirSource.language,
          };
        } catch (error) {
          if (error instanceof QuranMCPError) {
            throw error;
          }
          throw new QuranMCPError(
            `Failed to fetch tafsir: ${(error as Error).message}`,
            'TAFSIR_FETCH_ERROR'
          );
        }
      });
    }
  • MCP tool registration definition including name, description, and input schema for get_tafsir.
    {
      name: 'get_tafsir',
      description: 'Get Tafsir (commentary/explanation) for a specific Quran verse. Provides scholarly interpretation and context.',
      inputSchema: {
        type: 'object',
        properties: {
          surah: {
            type: 'number',
            description: 'Surah number (1-114)',
            minimum: 1,
            maximum: 114,
          },
          ayah: {
            type: 'number',
            description: 'Ayah (verse) number',
            minimum: 1,
          },
          tafsir: {
            type: 'string',
            description: 'Tafsir source (default: en-tafisr-ibn-kathir). Use list_tafsir_sources to see all options.',
            default: 'en-tafisr-ibn-kathir',
          },
        },
        required: ['surah', 'ayah'],
      },
    },
  • TypeScript interface defining the input parameters for the getTafsir function.
    export interface GetTafsirParams {
      surah: number;
      ayah: number;
      tafsir?: string;
    }
  • Tool dispatcher case that invokes the getTafsir handler with parsed arguments.
    case 'get_tafsir': {
      const { surah, ayah, tafsir = 'en-tafisr-ibn-kathir' } = args;
      result = await getTafsir(surah, ayah, tafsir);
      break;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that the tool provides 'scholarly interpretation and context,' which adds behavioral context beyond a basic fetch. However, it lacks details on permissions, rate limits, error handling, or output format (e.g., text length, structure), leaving gaps for a tool with no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two concise sentences with zero waste: the first states the purpose, and the second elaborates on the content provided. It is front-loaded with the core function and efficiently adds value without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is somewhat complete for a read-only tool but lacks details on behavioral aspects like output structure or error cases. It covers the purpose and hints at usage via the schema, but more context on what the return looks like would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly (e.g., surah range, ayah minimum, tafsir default and alternative tool). The description adds no additional parameter semantics beyond what the schema provides, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get Tafsir') and resource ('for a specific Quran verse'), distinguishing it from siblings like get_quran_verse (which likely returns the verse text) or list_tafsir_sources (which lists available sources). It explicitly mentions 'scholarly interpretation and context' to clarify what Tafsir entails.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when seeking commentary on a Quran verse, and the input schema's description for the 'tafsir' parameter references list_tafsir_sources as an alternative for exploring options. However, it does not explicitly state when not to use this tool (e.g., vs. get_quran_verse for just the text) or other exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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