Skip to main content
Glama
uarlouski

TestRail MCP Server

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

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesThe ID of the project. Use get_projects to find available projects

Implementation Reference

  • 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)),
            };
        }
    };
  • 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(),
    });
  • 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"),
    };
  • 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,
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided. The description implies a read-only operation through the verb 'get', but does not explicitly state that it is non-destructive, safe, or any required permissions. Since the name suggests read-only, a score of 3 is appropriate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence that conveys the core purpose and a functional consequence. It is front-loaded and contains no unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has one parameter, no output schema, and no annotations, the description adequately covers purpose and prerequisite. However, it could hint at the return format (e.g., list of template objects) or whether all templates are returned, but the lack of output schema reduces the need.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% for the single parameter project_id, and the schema description already tells the agent to use get_projects. The tool description adds context about template IDs affecting test case fields, but does not add new meaning to the parameter beyond what the schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states that the tool retrieves test case templates for a project and explains their significance (template IDs determine available fields). The verb 'get' is specific, and the resource 'templates' is well-defined, distinguishing it from siblings like get_cases or get_projects.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description indicates when to use the tool (to get templates for a project) and provides a prerequisite (use get_projects to find project IDs). However, it does not explicitly state when not to use it or mention alternatives, though no sibling tools overlap in function.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/uarlouski/testrail-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server