Skip to main content
Glama
djalal

quran-mcp-server

by djalal

tafsir

Retrieve detailed Quranic tafsir (interpretation) by specifying tafsir ID, chapter, verse, or other parameters for in-depth understanding of Quranic verses.

Instructions

Get a single tafsir

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chapter_numberNoChapter number
fieldsNoComma separated fields of tafsir
hizb_numberNoHizb number
juz_numberNoJuz number
page_numberNoPage number
rub_el_hizb_numberNoRub el Hizb number
tafsir_idYesTafsir id
verse_keyNoVerse key

Implementation Reference

  • The handler function that executes the tool logic for 'tafsir': validates input using tafsirSchema, calls tafsirsService.getTafsir(), formats response as MCP content.
    export async function handleTafsir(args: any) {
      try {
        // Validate arguments
        const validatedArgs = tafsirSchema.parse(args);
        
        // Call the service
        const result = await tafsirsService.getTafsir(validatedArgs);
        
        // Log the response in verbose mode
        verboseLog('response', {
          tool: 'tafsir',
          result
        });
        
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2)
            }
          ]
        };
      } catch (error) {
        verboseLog('error', {
          tool: 'tafsir',
          error: error instanceof Error ? error.message : String(error)
        });
        
        // Use the standardized error response utility
        const { createErrorResponse } = require('../utils/error-handler');
        return createErrorResponse(error, 'tafsir');
      }
    }
  • Zod schema defining the input parameters for the 'tafsir' tool.
    export const tafsirSchema = z.object({
      tafsir_id: z.string().describe("Tafsir id"),
      fields: z.string().optional().describe("Comma separated fields of tafsir"),
      chapter_number: z.string().optional().describe("Chapter number"),
      juz_number: z.string().optional().describe("Juz number"),
      page_number: z.string().optional().describe("Page number"),
      hizb_number: z.string().optional().describe("Hizb number"),
      rub_el_hizb_number: z.string().optional().describe("Rub el Hizb number"),
      verse_key: z.string().optional().describe("Verse key"),
    });
  • src/server.ts:214-218 (registration)
    Registration of the 'tafsir' tool in the listTools response, including name, description, and input schema.
    {
      name: ApiTools.tafsir,
      description: "Get a single tafsir",
      inputSchema: zodToJsonSchema(tafsirsSchemas.tafsir),
    },
  • src/server.ts:299-300 (registration)
    Dispatch case in CallToolRequest handler that routes 'tafsir' tool calls to handleTafsir function.
    case ApiTools.tafsir:
      return await handleTafsir(request.params.arguments);
  • Service method implementing the core API call to Quran.com for retrieving tafsir data, building URL and query params.
    async getTafsir(params: z.infer<typeof tafsirSchema>): Promise<TafsirResponse> {
      try {
        // Validate parameters
        const validatedParams = tafsirSchema.parse(params);
        
        // Build the URL based on the provided parameters
        let url = `${API_BASE_URL}/quran/tafsirs/${validatedParams.tafsir_id}`;
        
        // Prepare query parameters
        const queryParams: any = {};
        
        // Add optional parameters if provided
        if (validatedParams.fields) queryParams.fields = validatedParams.fields;
        if (validatedParams.chapter_number) queryParams.chapter_number = validatedParams.chapter_number;
        if (validatedParams.juz_number) queryParams.juz_number = validatedParams.juz_number;
        if (validatedParams.page_number) queryParams.page_number = validatedParams.page_number;
        if (validatedParams.hizb_number) queryParams.hizb_number = validatedParams.hizb_number;
        if (validatedParams.rub_el_hizb_number) queryParams.rub_el_hizb_number = validatedParams.rub_el_hizb_number;
        if (validatedParams.verse_key) queryParams.verse_key = validatedParams.verse_key;
        
        // Make request to Quran.com API
        const data = await makeApiRequest(url, queryParams);
        
        return {
          success: true,
          message: "tafsir executed successfully",
          data
        };
      } catch (error) {
        verboseLog('error', {
          method: 'getTafsir',
          error: error instanceof Error ? error.message : String(error)
        });
        
        if (error instanceof z.ZodError) {
          throw new ApiError(`Validation error: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`, 400);
        }
        
        // Re-throw other errors
        throw error;
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states it's a read operation ('Get'), which implies safety, but doesn't cover aspects like authentication needs, rate limits, error handling, or what 'tafsir' entails (e.g., religious commentary). This leaves significant gaps for a tool with 8 parameters.

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 a single, efficient sentence that front-loads the core purpose ('Get a single tafsir'). There's no wasted wording, making it easy to parse quickly, though it could benefit from more context given the lack of annotations.

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

Completeness2/5

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

Given the complexity (8 parameters, no annotations, no output schema), the description is inadequate. It doesn't explain what a 'tafsir' is, how parameters interact (e.g., if 'tafsir_id' is required, what do other parameters do?), or the return format, leaving the agent with insufficient context for effective use.

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%, with each parameter clearly documented in the schema (e.g., 'chapter_number' as 'Chapter number'). The description adds no additional meaning beyond the schema, but since the schema is comprehensive, the baseline score of 3 is appropriate as it doesn't detract value.

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

Purpose4/5

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

The description clearly states the action ('Get') and resource ('a single tafsir'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'tafsirs' (which likely lists multiple tafsirs) or 'tafsir-info' (which might provide metadata), leaving some ambiguity about when to choose this specific tool.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'tafsirs' and 'tafsir-info', there's no indication of how this tool differs in context or functionality, leaving the agent to infer usage from the name alone.

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

Related 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/djalal/quran-mcp-server'

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