Skip to main content
Glama
djalal

quran-mcp-server

by djalal

verses-by_verse_key

Retrieve Quran verses by their key, including translations, word details, tafsirs, and audio recitations, using the Quran MCP server for structured and detailed results.

Instructions

Get verse by key

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
audioNoId of recitation
fieldsNoComma separated list of ayah fields
languageNoLanguage to fetch word translation
tafsirsNoComma separated ids of tafsirs
translation_fieldsNoComma separated list of translation fields
translationsNoComma separated ids of translations
verse_keyYesVerse key (chapter:verse)
word_fieldsNoComma separated list of word fields
wordsNoInclude words of each ayah

Implementation Reference

  • MCP tool handler: validates input using schema, calls versesService, logs, returns JSON stringified result or error.
    /**
     * Handler for the verses-by_verse_key tool
     */
    export async function handleVersesByVerseKey(args: any) {
      try {
        // Validate arguments
        const validatedArgs = versesByVerseKeySchema.parse(args);
        
        // Call the service
        const result = await versesService.versesByVerseKey(validatedArgs);
        
        // Log the response in verbose mode
        verboseLog('response', {
          tool: 'verses-by_verse_key',
          result
        });
        
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2)
            }
          ]
        };
      } catch (error) {
        verboseLog('error', {
          tool: 'verses-by_verse_key',
          error: error instanceof Error ? error.message : String(error)
        });
        
        if (error instanceof z.ZodError) {
          return {
            content: [{ 
              type: "text", 
              text: `Validation error: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`
            }],
            isError: true,
          };
        }
        
        return {
          content: [{ 
            type: "text", 
            text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
          }],
          isError: true,
        };
      }
    }
  • Zod input schema defining 'verse_key' required param and optional common verse params.
    /**
     * Schema for verses-by_verse_key
     */
    export const versesByVerseKeySchema = z.object({
      verse_key: z.string().describe("Verse key (chapter:verse)"),
      ...commonVerseParams,
    });
  • src/server.ts:166-171 (registration)
    Tool registration in MCP listTools handler: specifies name, description, inputSchema from Zod-to-JSON, and examples.
    {
      name: ApiTools.verses_by_verse_key,
      description: "Get verse by key",
      inputSchema: zodToJsonSchema(versesSchemas.versesByVerseKey),
      examples: toolExamples['verses-by_verse_key'],
    },
  • src/server.ts:275-276 (registration)
    Tool dispatch in MCP callTool handler: routes to the specific handler function.
    case ApiTools.verses_by_verse_key:
      return await handleVersesByVerseKey(request.params.arguments);
  • Service helper: builds Quran.com API URL /verses/by_key/{verse_key}, makes request with params, returns structured response.
     * Get verse by key
     * Get a specific ayah with key. Key is combination of surah number and ayah number.
     * 
     * @param {Object} params - The parameters for this operation
     * @returns {Promise<VersesByVerseKeyResponse>} The operation result
     * @throws {ApiError} If the operation fails
     */
    async versesByVerseKey(params: z.infer<typeof versesByVerseKeySchema>): Promise<VersesByVerseKeyResponse> {
      try {
        // Validate parameters
        const validatedParams = versesByVerseKeySchema.parse(params);
        
        const url = `${API_BASE_URL}/verses/by_key/${validatedParams.verse_key}`;
        
        // Make request to Quran.com API
        const data = await makeApiRequest(url, {
          language: validatedParams.language,
          words: validatedParams.words,
          translations: validatedParams.translations,
          audio: validatedParams.audio,
          tafsirs: validatedParams.tafsirs,
          word_fields: validatedParams.word_fields,
          translation_fields: validatedParams.translation_fields,
          fields: validatedParams.fields
        });
        
        return {
          success: true,
          message: "verses-by_verse_key executed successfully",
          data
        };
      } catch (error) {
        verboseLog('error', {
          method: 'versesByVerseKey',
          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 full burden. 'Get' implies a read-only operation, but it doesn't disclose behavioral traits like authentication needs, rate limits, error handling, or what happens with invalid keys. The description is too minimal to provide meaningful behavioral context for a tool with 9 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 extremely concise at 3 words, front-loaded with the core purpose. There's zero wasted language, though this conciseness comes at the cost of completeness for other dimensions.

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 tool's complexity (9 parameters, no annotations, no output schema), the description is inadequate. It doesn't explain what a 'verse' includes, what optional parameters like 'audio' or 'tafsirs' do, or what the return format looks like. For a data retrieval tool with many customization options, more context is needed.

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 parameters are well-documented in the schema. The description adds no additional meaning beyond implying 'verse_key' is the primary identifier. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't need to.

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

Purpose3/5

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

The description 'Get verse by key' states the basic action (get) and resource (verse), but is vague about what constitutes a 'verse key' and doesn't differentiate from sibling tools like 'verses-by_chapter_number' or 'random_verse'. It lacks specificity about what data is retrieved beyond the verse itself.

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?

No guidance is provided on when to use this tool versus alternatives. With multiple sibling tools for retrieving verses (e.g., 'verses-by_chapter_number', 'random_verse'), the description offers no context about when this key-based lookup is appropriate or what distinguishes it from other verse retrieval methods.

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