get_tests
Retrieve tests for a specific test run, with optional filtering by status IDs to narrow results.
Instructions
Get tests for a test run, optionally filtered by status
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| run_id | Yes | The ID of the test run | |
| status_id | No | Optional array of status IDs to filter by. Use get_statuses to retrieve available status IDs |
Implementation Reference
- src/tools/get_tests.ts:11-22 (handler)The handler function that executes the get_tests tool logic. Takes run_id and optional status_id filter, calls the TestRail API client, and returns parsed test results.
export const getTestsTool: ToolDefinition<typeof parameters, TestRailClient> = { name: "get_tests", description: "Get tests for a test run, optionally filtered by status", parameters, handler: async ({ run_id, status_id }, client: TestRailClient) => { const tests: Test[] = await client.getTests(run_id, status_id); return { tests: tests.map(test => TestSchema.parse(test)), }; }, }; - src/tools/get_tests.ts:6-9 (schema)Input parameter schema for get_tests tool: run_id (required number) and status_id (optional array of numbers).
const parameters = { run_id: z.number().describe("The ID of the test run"), status_id: z.array(z.number()).optional().describe("Optional array of status IDs to filter by. Use get_statuses to retrieve available status IDs"), } - src/types/testrail.ts:125-131 (schema)Zod schema defining the output shape of a Test object (id, case_id, status_id, title, run_id).
export const TestSchema = z.object({ id: z.number(), case_id: z.number(), status_id: z.number(), title: z.string(), run_id: z.number(), }) - src/index.ts:87-115 (registration)Registration of get_tests tool on the MCP server. The tool is included in the tools array (line 71) and registered via server.registerTool in the loop.
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/client/testrail.ts:172-180 (helper)TestRail API client method that calls the TestRail API endpoint get_tests with pagination support and optional status_id filter.
async getTests(runId: number, statusId?: number[]): Promise<Test[]> { let url = `${API_BASE_V2}/get_tests/${runId}`; if (statusId && statusId.length > 0) { url += `&status_id=${statusId.join(',')}`; } return this.paginateAll<Test>(url, 'tests'); }