Skip to main content
Glama

get_test_case_by_key

Retrieve detailed test case information from Zebrunner Test Case Management using a specific case key, supporting multiple output formats for QA analysis.

Instructions

πŸ” Get detailed test case by key (βœ… Verified Working)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_keyNoProject key (e.g., 'android' or 'ANDROID') - auto-detected from case_key if not provided
case_keyYesTest case key (e.g., 'ANDROID-29', 'IOS-2')
formatNoOutput formatjson
include_debugNoInclude debug information in markdown
include_suite_hierarchyNoInclude featureSuiteId and rootSuiteId with suite hierarchy path
include_clickable_linksNoInclude clickable links to Zebrunner web UI

Implementation Reference

  • src/index.ts:221-240 (registration)
    Registration and inline handler implementation for the MCP tool 'get_test_case_by_key'. Fetches test case using ZebrunnerClient and returns formatted JSON and Markdown content.
    server.tool(
      "get_test_case_by_key",
      "Return detailed info of a test case by case_key and project_key (βœ… Working). Also returns a Markdown export of steps.",
      {
        case_key: z.string().min(1),
        project_key: z.string().min(1)
      },
      async (args) => {
        const { case_key, project_key } = args;
        const tc = await client.getTestCaseByKey(case_key, project_key);
        const parsed = TestCaseDetailsSchema.safeParse(tc);
        const data = parsed.success ? parsed.data : tc;
        const md = renderTestCaseMarkdown(tc);
        return {
          content: [
            { type: "text", text: `**JSON Data:**\n\n\`\`\`json\n${JSON.stringify(data, null, 2)}\n\`\`\`` },
            { type: "text", text: `**Markdown Export:**\n\n${md}` }
          ]
        };
      }
  • Zod input schema for the 'get_test_case_by_key' tool defining required parameters case_key and project_key.
    export const GetTestCaseByKeySchema = z.object({
      case_key: z.string().min(1),
      project_key: z.string().min(1)
    });
  • Helper function to render test case details as Markdown, used by the tool handler for the Markdown export.
    function renderTestCaseMarkdown(tcRaw: any): string {
      const id = tcRaw?.id ?? "N/A";
      const key = tcRaw?.key ?? "N/A";
      const title = tcRaw?.title ?? "(no title)";
      const description = tcRaw?.description ?? "";
      const priority = tcRaw?.priority?.name ?? "N/A";
      const automationState = tcRaw?.automationState?.name ?? "N/A";
      const createdBy = tcRaw?.createdBy?.username ?? "N/A";
      const lastModifiedBy = tcRaw?.lastModifiedBy?.username ?? "N/A";
    
      const header = `# Test Case: ${title}\n\n- **ID:** ${id}\n- **Key:** ${key}\n- **Priority:** ${priority}\n- **Automation State:** ${automationState}\n- **Created By:** ${createdBy}\n- **Last Modified By:** ${lastModifiedBy}\n\n`;
      const descBlock = description ? `## Description\n\n${description}\n\n` : "";
      
      // Handle custom fields
      let customFieldsBlock = "";
      if (tcRaw?.customField && typeof tcRaw.customField === 'object') {
        const fields = Object.entries(tcRaw.customField)
          .filter(([key, value]) => value !== null && value !== undefined && value !== "")
          .map(([key, value]) => `- **${key}:** ${value}`)
          .join('\n');
        if (fields) {
          customFieldsBlock = `## Custom Fields\n\n${fields}\n\n`;
        }
      }
    
      const steps = Array.isArray(tcRaw?.steps) ? tcRaw.steps : [];
    
      if (!steps.length) {
        return `${header}${descBlock}${customFieldsBlock}## Steps\n\n_No explicit steps provided._\n`;
      }
    
      const lines: string[] = [];
      lines.push(`${header}${descBlock}${customFieldsBlock}## Steps\n`);
    
      const pick = (obj: any, keys: string[], fallback?: any) => {
        for (const k of keys) {
          if (obj && Object.prototype.hasOwnProperty.call(obj, k) && obj[k] != null) {
            return obj[k];
          }
        }
        return fallback;
      };
    
      steps.forEach((s: any, idx: number) => {
        const num = pick(s, ["stepNumber", "number", "index", "order"], idx + 1);
        const action = pick(s, ["action", "actual", "step", "actionText", "instruction", "name"]);
        const expected = pick(s, ["expected", "expectedResult", "expectedText", "result"]);
        const data = pick(s, ["data", "inputs", "parameters", "payload"]);
    
        lines.push(`### Step ${num}`);
        if (action) lines.push(`- **Action:** ${action}`);
        if (expected) lines.push(`- **Expected:** ${expected}`);
        if (data !== undefined) {
          if (typeof data === "object") {
            lines.push(`- **Data:**\n${codeBlockJson(data)}`);
          } else {
            lines.push(`- **Data:** ${String(data)}`);
          }
        }
        if (!action && !expected) {
          lines.push(`- **Raw step:**\n${codeBlockJson(s)}`);
        }
        lines.push("");
      });
    
      return lines.join("\n");
    }
  • ZebrunnerClient helper method that performs the actual API call to retrieve test case by key and project.
    async getTestCaseByKey(caseKey: string, projectKey: string): Promise<any> {
      const res = await this.http.get(`/test-cases/key:${caseKey}`, {
        params: { projectKey }
      });
      // API returns {data: {...}} structure for this endpoint
      return res.data?.data || res.data;
    }
  • Duplicate legacy registration and handler in enhanced index file for backward compatibility.
    "get_test_case_by_key",
    "Legacy: Return detailed info of a test case by case_key and project_key (βœ… Working)",
    {
      case_key: z.string().min(1),
      project_key: z.string().min(1)
    },
    async (args) => {
      const { case_key, project_key } = args;
      try {
        const tc = await legacyClient.getTestCaseByKey(case_key, project_key);
        const parsed = TestCaseDetailsSchema.safeParse(tc);
        const data = parsed.success ? parsed.data : tc;
        const md = renderTestCaseMarkdown(tc);
        return {
          content: [
            { type: "text", text: `**JSON Data:**\n\n\`\`\`json\n${JSON.stringify(data, null, 2)}\n\`\`\`` },
            { type: "text", text: `**Markdown Export:**\n\n${md}` }
          ]
        };
      } catch (error: any) {
        return { 
          content: [{ 
            type: "text", 
            text: `Error: ${error.message}` 
          }] 
        };
      }
    }

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/maksimsarychau/mcp-zebrunner'

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