update_cases
Bulk update multiple test cases with the same field values. Use valid field names from get_case_fields to specify updates.
Instructions
Bulk update multiple test cases with the same field values. The update operation requires knowing valid field names that are returned by get_case_fields tool. More efficient than calling update_case multiple times.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| case_ids | Yes | Array of case IDs to update (e.g. [123, 456, 789]) | |
| fields | Yes | Must use system_name values from get_case_fields. Call get_case_fields with project_id first if field names are not already known. Using an unknown field name (e.g. 'label_ids') will result in an error. Example: {"priority_id": 2, "template_id": 1, "labels": [1, 2]} |
Implementation Reference
- src/tools/update_cases.ts:18-35 (handler)The updateCasesTool handler function that takes case_ids and fields, validates them, and calls client.updateCases to bulk-update test cases via TestRail API.
export const updateCasesTool: ToolDefinition<typeof parameters, TestRailClient> = { name: "update_cases", description: description.trim(), parameters, handler: async ({ case_ids, fields }, client) => { validateCaseFields(fields, await client.getCaseFields()); const caseData = await client.getCase(case_ids[0]); const updatedCases = await client.updateCases(caseData.suite_id, case_ids, fields); return { success: true, updated_count: updatedCases.length, case_ids: updatedCases.map(c => c.id), message: `Successfully updated ${updatedCases.length} test cases`, }; } }; - src/tools/update_cases.ts:7-10 (schema)Zod schema defining input parameters: case_ids (array of numbers) and fields (record of key-value pairs).
const parameters = { case_ids: z.array(z.number()).min(1).describe("Array of case IDs to update (e.g. [123, 456, 789])"), fields: z.record(z.string(), z.any()).describe(CASE_FIELDS_PARAM_DESCRIPTION), }; - src/client/testrail.ts:137-144 (helper)client.updateCases() method - makes the HTTP POST request to TestRail API endpoint /update_cases/{suite_id} with case_ids and fields.
async updateCases(suiteId: number, caseIds: number[], fields: Record<string, any>): Promise<Case[]> { const response = await this.post<{ updated_cases: Case[] }>(`${API_BASE_V2}/update_cases/${suiteId}`, { case_ids: caseIds, ...fields, }); return response.updated_cases; } - src/index.ts:87-115 (registration)Generic tool registration loop that calls server.registerTool() with each tool's name, description, input schema, and handler (including error handling).
for (const tool of tools) { server.registerTool( tool.name, { description: tool.description, inputSchema: tool.parameters, }, async (args: any) => { try { const output: Record<string, any> = await tool.handler(args, client); const sanitized = removeNullish(output); return { content: [ { type: "text" as const, text: JSON.stringify(sanitized), }, ], } as any; } catch (error: any) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true, }; } } ); } - src/utils/validator.ts:11-39 (helper)validateCaseFields helper function used to verify that the provided field names exist in the TestRail case schema before the update.
export function validateCaseFields(fields: Record<string, any> | string[], caseFields: CaseField[]): void { const fieldKeys = Array.isArray(fields) ? fields : Object.keys(fields); if (fieldKeys.length === 0) { return; } const customFieldSchemas = caseFields.filter(field => field.is_active).map(mapToFieldSchema); const validFieldNames = new Set( [...SYSTEM_FIELDS, ...customFieldSchemas].map(f => f.system_name) ); validFieldNames.add('id'); validFieldNames.add('suite_id'); const invalidFields: string[] = []; for (const key of fieldKeys) { if (!validFieldNames.has(key)) { invalidFields.push(key); } } if (invalidFields.length > 0) { const validKeysList = Array.from(validFieldNames).sort().join(', '); const invalidFieldsList = invalidFields.map(f => `'${f}'`).join(', '); throw new Error(`Invalid fields provided: ${invalidFieldsList}. Available fields are: ${validKeysList}`); } }