Skip to main content
Glama
Derrbal

TestRail MCP Server

by Derrbal

Get TestRail Case Fields

get_case_fields

Retrieve available custom fields for test cases to ensure proper data structure and field mapping in TestRail test management systems.

Instructions

Returns a list of available test case custom fields.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler function for 'get_case_fields'. Calls the service layer getCaseFields(), handles errors with specific messages, and returns JSON-formatted result or error.
    async () => {
      logger.debug('Get case fields tool called');
      try {
        const result = await getCaseFields();
        logger.debug(`Get case fields tool completed successfully. Found ${result.length} fields`);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (err) {
        logger.error({ err }, 'Get case fields tool failed');
        const e = err as { type?: string; status?: number; message?: string };
        let message = 'Unexpected error';
        if (e?.type === 'auth') message = 'Authentication failed: check TESTRAIL_USER/API_KEY';
        else if (e?.type === 'rate_limited') message = 'Rate limited by TestRail; try again later';
        else if (e?.type === 'server') message = 'TestRail server error';
        else if (e?.type === 'network') message = 'Network error contacting TestRail';
        else if (e?.message) message = e.message;
    
        return {
          content: [
            { type: 'text', text: message },
          ],
          isError: true,
        };
      }
    },
  • Input schema for the get_case_fields tool: no parameters required (empty schema).
    {
      title: 'Get TestRail Case Fields',
      description: 'Returns a list of available test case custom fields.',
      inputSchema: {},
    },
  • src/server.ts:895-933 (registration)
    Registration of the 'get_case_fields' MCP tool using server.registerTool, including name, metadata/schema, and handler function.
    server.registerTool(
      'get_case_fields',
      {
        title: 'Get TestRail Case Fields',
        description: 'Returns a list of available test case custom fields.',
        inputSchema: {},
      },
      async () => {
        logger.debug('Get case fields tool called');
        try {
          const result = await getCaseFields();
          logger.debug(`Get case fields tool completed successfully. Found ${result.length} fields`);
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } catch (err) {
          logger.error({ err }, 'Get case fields tool failed');
          const e = err as { type?: string; status?: number; message?: string };
          let message = 'Unexpected error';
          if (e?.type === 'auth') message = 'Authentication failed: check TESTRAIL_USER/API_KEY';
          else if (e?.type === 'rate_limited') message = 'Rate limited by TestRail; try again later';
          else if (e?.type === 'server') message = 'TestRail server error';
          else if (e?.type === 'network') message = 'Network error contacting TestRail';
          else if (e?.message) message = e.message;
    
          return {
            content: [
              { type: 'text', text: message },
            ],
            isError: true,
          };
        }
      },
    );
  • Service layer function getCaseFields that fetches raw fields from client and maps to summary format (CaseFieldSummary[]). Called by MCP handler.
    export async function getCaseFields(): Promise<CaseFieldSummary[]> {
      const fields: TestRailCaseFieldDto[] = await testRailClient.getCaseFields();
      
      return fields.map((field) => ({
        id: field.id,
        label: field.label,
        name: field.name,
        system_name: field.system_name,
        type_id: field.type_id,
        description: field.description,
        display_order: field.display_order,
        configs: field.configs,
      }));
    }
  • Client layer HTTP call to TestRail API endpoint '/get_case_fields', with response validation, logging, and error normalization. Called by service layer.
    async getCaseFields(): Promise<TestRailCaseFieldDto[]> {
      try {
        const res = await this.http.get('/get_case_fields');
        logger.info({ 
          status: res.status, 
          dataType: typeof res.data,
          dataIsArray: Array.isArray(res.data)
        }, 'TestRail getCaseFields response info');
        
        if (res.status >= 200 && res.status < 300) {
          if (Array.isArray(res.data)) {
            return res.data as TestRailCaseFieldDto[];
          } else {
            logger.error({ 
              status: res.status, 
              responseData: res.data,
              dataType: typeof res.data 
            }, 'TestRail getCaseFields returned non-array response');
            throw Object.assign(new Error('API returned non-array response'), { 
              response: { status: 200 } // Make it look like a server error
            });
          }
        }
        throw Object.assign(new Error(`HTTP ${res.status}`), { response: res });
      } catch (err) {
        const normalized = this.normalizeError(err);
        const safeDetails = this.getSafeErrorDetails(err);
        logger.error({ err: normalized, details: safeDetails }, 'TestRail getCaseFields failed');
        throw normalized;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states it 'Returns a list,' implying a read-only operation, but doesn't specify if it requires authentication, has rate limits, returns paginated results, or what format the list takes (e.g., JSON array of field objects). For a tool with zero annotation coverage, this is insufficient transparency.

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, efficient sentence that front-loads the core purpose ('Returns a list...') with no wasted words. Every part of the sentence earns its place by specifying what is returned and for what resource, making it optimally concise and well-structured.

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

Completeness3/5

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

Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is minimally adequate. It states what the tool does but lacks context on usage, behavior, or output format. For a read operation with no complex inputs, this is acceptable but leaves gaps that could hinder an agent's effective use, especially without annotations to fill in behavioral details.

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

Parameters4/5

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

The input schema has 0 parameters with 100% coverage, so the schema fully documents the lack of inputs. The description doesn't need to add parameter details, and it correctly implies no parameters are required by not mentioning any. This meets the baseline for zero-parameter tools, though it doesn't explicitly state 'no parameters needed,' which would have warranted a 5.

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

Purpose4/5

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

The description clearly states the verb ('Returns') and resource ('list of available test case custom fields'), making the purpose immediately understandable. It distinguishes this from siblings like get_case or get_cases by specifying it returns custom fields rather than cases themselves. However, it doesn't explicitly contrast with all siblings, so it falls short of a perfect 5.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a project context), when it's appropriate (e.g., before creating cases with custom fields), or what siblings might be better for related tasks (like get_case for case details). This leaves the agent without contextual usage direction.

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/Derrbal/testrail-mcp'

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