get_case
Retrieve detailed information about a test case, including custom fields, by providing its case ID.
Instructions
Get detailed information about a test case including its custom fields
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| case_id | Yes | The ID of the test case (e.g. '123' or 'C123') |
Implementation Reference
- src/tools/get_case.ts:15-45 (handler)The handler function that executes the get_case tool logic. It extracts the case ID, fetches the test case from TestRail, enriches it with section name, case type, priority, labels, references, and custom fields, and returns a TestCaseResponse.
handler: async ({ case_id }, client) => { const idString = case_id.toUpperCase().startsWith("C") ? case_id.substring(1) : case_id; const id = Number(idString); const testCase = await client.getCase(id); const [section, caseTypes, priorities, caseFields] = await Promise.all([ client.getSection(Number(testCase.section_id)), client.getCaseTypes(), client.getPriorities(), client.getCaseFields() ]); const caseType = caseTypes.find(t => t.id === testCase.type_id); const priority = priorities.find(p => p.id === testCase.priority_id); const customFields = processCustomFields(testCase, caseFields); const response: TestCaseResponse = { id: testCase.id, title: testCase.title, section: section.name, type: caseType ? caseType.name : "Unknown", priority: priority ? priority.name : "Unknown", labels: (testCase.labels || []).map((label) => LabelSchema.parse(label)), references: testCase.refs, updated_on: testCase.updated_on, ...customFields }; return response; } - src/tools/get_case.ts:7-9 (schema)Input schema definition for the get_case tool: requires a case_id string parameter.
const parameters = { case_id: z.string().describe("The ID of the test case (e.g. '123' or 'C123')"), }; - src/index.ts:60-60 (registration)Registration of getCaseTool in the tools array that gets registered with the MCP server.
getCaseTool, - src/index.ts:7-7 (registration)Import of getCaseTool from the get_case.ts module.
import { getCaseTool } from "./tools/get_case.js"; - src/utils/mapper.ts:8-58 (helper)Helper function processCustomFields used by the handler to map custom field system names to human-readable labels and resolve dropdown option values.
export function processCustomFields( testCase: Case, caseFields: CaseField[] ): Record<string, any> { if (!testCase) { throw new Error("Test case is undefined or null"); } const templateId = testCase.template_id; const result: Record<string, any> = {}; const applicableFields = caseFields.filter(field => field.include_all || field.template_ids.includes(templateId) ); const fieldNameMap = new Map<string, string>(); const dropdownOptionsMap = new Map<string, Map<string, string>>(); for (const field of applicableFields) { fieldNameMap.set(field.system_name, toSnakeCase(field.label)); const optionsMap = parseDropdownOptions(field); if (optionsMap.size > 0) { dropdownOptionsMap.set(field.system_name, optionsMap); } } for (const [key, value] of Object.entries(testCase)) { if (!key.startsWith("custom_")) continue; if (value === null || value === undefined) continue; if (!fieldNameMap.has(key)) { console.error(`No field mapping found for: ${key}`); result[key] = value; continue; } const outputKey = fieldNameMap.get(key)!; let finalValue = value; if (dropdownOptionsMap.has(key)) { const options = dropdownOptionsMap.get(key)!; const optionKey = String(value); finalValue = options.get(optionKey) || value; } result[outputKey] = sanitizeValue(finalValue); } return result; }