Skip to main content
Glama
uarlouski

TestRail MCP Server

add_attachment_to_run

Add a file or directory (auto-zipped) as an attachment to a TestRail test run. Maximum upload size is 256MB.

Instructions

Add an attachment to a test run in TestRail. If the file_path points to a directory, it will be automatically zipped before uploading. Maximum upload size is 256MB.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
run_idYesThe ID of the test run to attach the file to
file_pathYesThe path to the file or directory to attach. Directories will be automatically zipped.

Implementation Reference

  • The main tool definition for 'add_attachment_to_run'. Contains the handler function that validates file existence, auto-zips directories using archiver, calls the client method, and cleans up temporary zip files.
    export const addAttachmentToRunTool: ToolDefinition<typeof parameters, TestRailClient> = {
        name: "add_attachment_to_run",
        description: "Add an attachment to a test run in TestRail. If the file_path points to a directory, it will be automatically zipped before uploading. Maximum upload size is 256MB.",
        parameters,
        handler: async ({ run_id, file_path }, client: TestRailClient) => {
            if (!fs.existsSync(file_path)) {
                throw new Error(`File or directory not found: ${file_path}`);
            }
    
            const stats = fs.statSync(file_path);
            let uploadPath: string = file_path;
            let filename: string = path.basename(file_path);
            let isTemporary = false;
    
            if (stats.isDirectory()) {
                const basename = path.basename(file_path);
                const tempDir = os.tmpdir();
                const zipPath = path.join(tempDir, `${basename}-${Date.now()}.zip`);
    
                await new Promise<void>((resolve, reject) => {
                    const output = fs.createWriteStream(zipPath);
                    const archive = archiver('zip', {
                        zlib: { level: 9 }
                    });
    
                    output.on('close', () => resolve());
                    archive.on('error', (err) => reject(err));
    
                    archive.pipe(output);
                    archive.directory(file_path, basename);
                    archive.finalize();
                });
    
                uploadPath = zipPath;
                filename = `${basename}.zip`;
                isTemporary = true;
            }
    
            try {
                const result = await client.addAttachmentToRun(run_id, uploadPath, filename);
                return AttachmentSchema.parse(result);
            } finally {
                if (isTemporary && fs.existsSync(uploadPath)) {
                    fs.unlinkSync(uploadPath);
                }
            }
        },
    };
  • Input schema for the tool: run_id (number) and file_path (string). Validated with Zod.
    const parameters = {
        run_id: z.number().describe("The ID of the test run to attach the file to"),
        file_path: z.string().describe("The path to the file or directory to attach. Directories will be automatically zipped."),
    }
  • Client method addAttachmentToRun that reads the file, creates a FormData blob, and sends a POST request to the TestRail API endpoint.
    async addAttachmentToRun(runId: number, filePath: string, filename: string): Promise<Attachment> {
        const fileBuffer = await fs.promises.readFile(filePath);
        const blob = new Blob([fileBuffer]);
        const formData = new FormData();
        formData.append('attachment', blob, filename);
    
        const headers: HeadersInit = {
            'Authorization': this.auth,
        };
    
        return this._executeRequest<Attachment>('POST', `${API_BASE_V2}/add_attachment_to_run/${runId}`, headers, formData);
    }
  • src/index.ts:21-21 (registration)
    Import of the addAttachmentToRunTool from its source file.
    import { addAttachmentToRunTool } from "./tools/add_attachment_to_run.js";
  • src/index.ts:74-74 (registration)
    Registration of addAttachmentToRunTool in the tools array that gets registered with the MCP server.
    addAttachmentToRunTool,
Behavior4/5

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

Discloses key behaviors beyond the schema: auto-zipping of directories and a 256MB upload limit. This is significant for an agent to understand side effects. Lacks idempotency and error details, but given no annotations, the description covers important traits.

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?

Extremely concise: two sentences with no filler. Front-loads the purpose and follows with key behaviors. Every sentence earns its place.

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?

For a tool with no output schema and a moderate complexity (2 params, simple action), the description covers core usage but omits return value or response behavior. It is adequate but not complete.

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%, so the parameters are fully described. The description adds no new parameter-level information beyond reinforcing that directories are zipped (already in file_path description). Baseline 3 is appropriate.

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 the action ('Add an attachment to a test run'), specifies the resource ('test run'), and includes additional behavioral details (auto-zipping, size limit). It effectively distinguishes from sibling tools, none of which handle attachments.

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?

Provides explicit context about directory handling and size limit, which guides when it's appropriate. However, it does not explicitly state when not to use it (e.g., for non-run attachments) or mention alternatives.

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