get_sections
Retrieve all sections for a project, returning section IDs and names needed to add test cases.
Instructions
Get all sections for a project. Returns section IDs and names that can be used with add_case
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | The ID of the project. Use get_projects to find available projects |
Implementation Reference
- src/tools/get_sections.ts:10-21 (handler)Handler function implementing the get_sections tool logic. Takes project_id, calls client.getSections, and returns parsed sections.
export const getSectionsTool: ToolDefinition<typeof parameters, TestRailClient> = { name: "get_sections", description: "Get all sections for a project. Returns section IDs and names that can be used with add_case", parameters, handler: async ({ project_id }, client) => { const sections = await client.getSections(project_id); return { sections: sections.map(s => SectionSchema.parse(s)), }; } }; - src/tools/get_sections.ts:6-8 (schema)Input schema for get_sections tool: requires a project_id number.
const parameters = { project_id: z.number().describe("The ID of the project. Use get_projects to find available projects"), }; - src/types/testrail.ts:57-63 (schema)Zod schema for Section output type, used to validate/parse the API response.
export const SectionSchema = z.object({ id: z.number(), name: z.string(), description: z.string().nullish(), parent_id: z.number().nullish(), suite_id: z.number(), }); - src/index.ts:58-115 (registration)Registration of get_sections tool in the tools array and registered via server.registerTool with its name, description, input schema, and handler wrapper.
const tools = [ getProjectsTool, getCaseTool, getCasesTool, getCaseFieldsTool, getTemplatesTool, getSectionsTool, updateCaseTool, updateCasesTool, addCaseTool, addRunTool, getStatusesTool, getPrioritiesTool, getTestsTool, addResultsTool, addResultsForCasesTool, addAttachmentToRunTool, getLabelsTool, ] if (TESTRAIL_ENABLE_SHARED_STEPS) { tools.push(getSharedStepsTool as any); tools.push(getSharedStepTool as any); tools.push(getSharedStepHistoryTool as any); tools.push(addSharedStepTool as any); tools.push(updateSharedStepTool as any); tools.push(deleteSharedStepTool as any); } 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:154-157 (helper)TestRailClient method that calls the TestRail API to fetch sections for a given project with pagination.
async getSections(projectId: number): Promise<Section[]> { const url = `${API_BASE_V2}/get_sections/${projectId}`; return this.paginateAll<Section>(url, 'sections'); }