get_templates
Retrieve available test case templates for a specific project. These template IDs define the fields available when creating or updating test cases.
Instructions
Get available test case templates for a project. Template IDs determine which fields are available when creating or updating test cases
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_templates.ts:10-21 (handler)Main tool definition including the handler function that calls client.getTemplates and parses results via TemplateSchema
export const getTemplatesTool: ToolDefinition<typeof parameters, TestRailClient> = { name: "get_templates", description: "Get available test case templates for a project. Template IDs determine which fields are available when creating or updating test cases", parameters, handler: async ({ project_id }, client) => { const templates = await client.getTemplates(project_id); return { templates: templates.map(t => TemplateSchema.parse(t)), }; } }; - src/types/testrail.ts:83-87 (schema)TemplateSchema: zod validation schema defining id, name, and is_default fields
export const TemplateSchema = z.object({ id: z.number(), name: z.string(), is_default: z.boolean(), }); - src/tools/get_templates.ts:6-8 (schema)Input parameter schema requiring project_id (number)
const parameters = { project_id: z.number().describe("The ID of the project. Use get_projects to find available projects"), }; - src/client/testrail.ts:123-130 (helper)getTemplates method on TestRailClient: fetches templates from TestRail API with caching
async getTemplates(projectId: number): Promise<Template[]> { if (!this.templatesPromiseMap.has(projectId.toString())) { this.templatesPromiseMap.set( projectId.toString(), this.get<Template[]>(`${API_BASE_V2}/get_templates/${projectId}`) ); } return this.templatesPromiseMap.get(projectId.toString())!; - src/index.ts:10-63 (registration)Import and inclusion of getTemplatesTool in the tools array, registered via server.registerTool
import { getTemplatesTool } from "./tools/get_templates.js"; import { updateCaseTool } from "./tools/update_case.js"; import { updateCasesTool } from "./tools/update_cases.js"; import { addCaseTool } from "./tools/add_case.js"; import { getSectionsTool } from "./tools/get_sections.js"; import { getProjectsTool } from "./tools/get_projects.js"; import { addRunTool } from "./tools/add_run.js"; import { getStatusesTool } from "./tools/get_statuses.js"; import { getPrioritiesTool } from "./tools/get_priorities.js"; import { getTestsTool } from "./tools/get_tests.js"; import { addResultsTool } from "./tools/add_results.js"; import { addAttachmentToRunTool } from "./tools/add_attachment_to_run.js"; import { addResultsForCasesTool } from "./tools/add_results_for_cases.js"; import { getLabelsTool } from "./tools/get_labels.js"; import { getSharedStepsTool } from "./tools/shared_steps/get_shared_steps.js"; import { getSharedStepTool } from "./tools/shared_steps/get_shared_step.js"; import { getSharedStepHistoryTool } from "./tools/shared_steps/get_shared_step_history.js"; import { addSharedStepTool } from "./tools/shared_steps/add_shared_step.js"; import { updateSharedStepTool } from "./tools/shared_steps/update_shared_step.js"; import { deleteSharedStepTool } from "./tools/shared_steps/delete_shared_step.js"; import { removeNullish } from "./utils/sanitizer.js"; import z from "zod"; const EnvSchema = z.object({ TESTRAIL_INSTANCE_URL: z.url('Must be a valid TestRail URL'), TESTRAIL_USERNAME: z.email('Must be a valid email address'), TESTRAIL_API_KEY: z.string().min(1, 'API key is required'), TESTRAIL_ENABLE_SHARED_STEPS: z.string().optional().transform(val => val === 'true') }); const parseResult = EnvSchema.safeParse(process.env); if (!parseResult.success) { console.error( "Invalid TestRail environment configuration:", JSON.stringify(z.treeifyError(parseResult.error), null, 2)); process.exit(1); } const { TESTRAIL_INSTANCE_URL, TESTRAIL_USERNAME, TESTRAIL_API_KEY, TESTRAIL_ENABLE_SHARED_STEPS } = parseResult.data; const server = new McpServer({ name: "TestRail MCP Server", version: "1.9.0", }); const client = new TestRailClient(TESTRAIL_INSTANCE_URL, TESTRAIL_USERNAME, TESTRAIL_API_KEY); const tools = [ getProjectsTool, getCaseTool, getCasesTool, getCaseFieldsTool, getTemplatesTool,