Skip to main content
Glama
djalal

quran-mcp-server

by djalal

tafsirs

Access a comprehensive list of available Quranic tafsir explanations by specifying the language. Integrate with the Quran.com corpus via the official REST API v4 to enhance Quranic studies.

Instructions

Get list of available tafsirs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageNoLanguage

Implementation Reference

  • The handler function for the 'tafsirs' tool. It validates the input arguments using tafsirsSchema, calls tafsirsService.listTafsirs, logs the response, and returns the result as MCP-formatted content. Handles errors using createErrorResponse.
    export async function handleTafsirs(args: any) {
      try {
        // Validate arguments
        const validatedArgs = tafsirsSchema.parse(args);
        
        // Call the service
        const result = await tafsirsService.listTafsirs(validatedArgs);
        
        // Log the response in verbose mode
        verboseLog('response', {
          tool: 'tafsirs',
          result
        });
        
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2)
            }
          ]
        };
      } catch (error) {
        verboseLog('error', {
          tool: 'tafsirs',
          error: error instanceof Error ? error.message : String(error)
        });
        
        // Use the standardized error response utility
        const { createErrorResponse } = require('../utils/error-handler');
        return createErrorResponse(error, 'tafsirs');
      }
    }
  • Zod input schema for the 'tafsirs' tool, defining an optional 'language' parameter.
    export const tafsirsSchema = z.object({
      language: z.string().optional().describe("Language"),
    });
  • src/server.ts:295-296 (registration)
    Dispatch logic in the callTool handler that routes calls to the 'tafsirs' tool to the handleTafsirs function.
    case ApiTools.tafsirs:
      return await handleTafsirs(request.params.arguments);
  • src/server.ts:204-208 (registration)
    Registration of the 'tafsirs' tool in the listTools response, including name, description, input schema, and examples.
      name: ApiTools.tafsirs,
      description: "Get list of available tafsirs",
      inputSchema: zodToJsonSchema(tafsirsSchemas.tafsirs),
      examples: toolExamples['tafsirs'],
    },
  • The core service method listTafsirs in TafsirsService class. Fetches tafsirs list from Quran.com API (/resources/tafsirs) with caching, language param support, verbose logging, error handling, and fallback to mock data if API fails.
    async listTafsirs(params: z.infer<typeof tafsirsSchema>): Promise<TafsirsResponse> {
      try {
        // Validate parameters
        const validatedParams = tafsirsSchema.parse(params);
        
        // Check cache first
        const now = Date.now();
        if (this.tafsirsCache && (now - this.cacheTimestamp < CACHE_DURATION_MS)) {
          verboseLog('response', {
            method: 'listTafsirs',
            source: 'cache',
            age: `${(now - this.cacheTimestamp) / 1000} seconds`
          });
          
          return {
            success: true,
            message: "tafsirs executed successfully (from cache)",
            data: this.tafsirsCache
          };
        }
        
        try {
          // Make request to Quran.com API
          const url = `${API_BASE_URL}/resources/tafsirs`;
          const response = await makeApiRequest(url, {
            language: validatedParams.language
          });
          
          verboseLog('response', {
            method: 'listTafsirs',
            source: 'api',
            dataSize: JSON.stringify(response).length
          });
          
          // Update cache
          this.tafsirsCache = response;
          this.cacheTimestamp = now;
          
          return {
            success: true,
            message: "tafsirs executed successfully",
            data: response
          };
        } catch (axiosError) {
          verboseLog('error', {
            method: 'listTafsirs',
            error: axiosError instanceof Error ? axiosError.message : String(axiosError)
          });
          
          // If the API call fails, return mock data
          verboseLog('response', {
            method: 'listTafsirs',
            source: 'mock',
            reason: 'API unavailable'
          });
          
          const mockData = this.getTafsirsMockData();
          
          return {
            success: true,
            message: "tafsirs executed with mock data (API unavailable)",
            data: mockData
          };
        }
      } catch (error) {
        verboseLog('error', {
          method: 'listTafsirs',
          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);
        }
        
        // Return mock data as a fallback for any error
        verboseLog('response', {
          method: 'listTafsirs',
          source: 'mock',
          reason: 'error occurred'
        });
        
        const mockData = this.getTafsirsMockData();
        
        return {
          success: true,
          message: "tafsirs executed with mock data (error occurred)",
          data: mockData
        };
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It only states the basic action ('Get list') without mentioning whether this is a read-only operation, if it requires authentication, what the return format looks like, or any rate limits. For a tool with zero annotation coverage, this is insufficient.

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 with zero wasted words. It's front-loaded with the core purpose, making it easy to parse and understand immediately.

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 lack of annotations and output schema, the description is incomplete. It doesn't explain what a 'tafsir' is in this context, what the returned list contains, or any behavioral traits. For a tool with no structured support, more context is needed to be fully helpful.

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?

The schema description coverage is 100%, with the single parameter 'language' documented in the schema. The description adds no additional parameter information beyond what the schema provides, so it meets the baseline score of 3 where the schema handles the heavy lifting.

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 list') and resource ('available tafsirs'), making the purpose immediately understandable. It doesn't differentiate from sibling tools like 'tafsir' or 'tafsir-info', which prevents a perfect score, but it's unambiguous about what the tool does.

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 like 'tafsir' or 'tafsir-info'. It lacks any context about prerequisites, exclusions, or typical use cases, leaving the agent to infer usage from the purpose 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