Skip to main content
Glama

testmo_upload_case_attachment

Upload a file attachment to a test case, automatically compressing large images. Requires an absolute path to a saved file.

Instructions

Upload a single file attachment to a test case. Large images are auto-compressed.

IMPORTANT: file_path must be an absolute path to a file saved on disk (e.g. /Users/jan/Desktop/screenshot.png). Pasted images or image data from the conversation cannot be uploaded — the user must save the file first and provide its path. If no path is provided or the user has not saved the file yet, ask them to save it and share the full file path.

Args: case_id: The test case ID. file_path: Absolute path to the local file to upload (e.g. /Users/jan/Desktop/screenshot.png).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
case_idYes
file_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The async function `testmo_upload_case_attachment` is the actual tool handler. It takes a `case_id` (int) and `file_path` (str), validates file_path, prepares the file via `_prepare_file` (compressing large images), and uploads it via `_upload` to the Testmo API endpoint `/cases/{case_id}/attachments/single`.
    @mcp.tool()
    async def testmo_upload_case_attachment(
        case_id: int,
        file_path: str,
    ) -> dict[str, Any]:
        """Upload a single file attachment to a test case. Large images are auto-compressed.
    
        IMPORTANT: file_path must be an absolute path to a file saved on disk (e.g. /Users/jan/Desktop/screenshot.png).
        Pasted images or image data from the conversation cannot be uploaded — the user must save the file first and provide its path.
        If no path is provided or the user has not saved the file yet, ask them to save it and share the full file path.
    
        Args:
            case_id: The test case ID.
            file_path: Absolute path to the local file to upload (e.g. /Users/jan/Desktop/screenshot.png).
        """
        if not file_path or not file_path.strip():
            raise ValueError("file_path is required. Ask the user to save the file to disk and provide the full path (e.g. /Users/jan/Desktop/screenshot.png).")
        filename, file_content, content_type = _prepare_file(file_path)
        return await _upload(
            f"/cases/{case_id}/attachments/single",
            [("file", (filename, file_content, content_type))],
        )
  • The `mcp` instance is imported from `..server`, which is a `FastMCP("testmo-mcp")` instance. The `@mcp.tool()` decorator on line 62 registers the tool.
    from ..server import mcp
  • The `_prepare_file` helper function reads a file from disk, compresses large images (>1MB) by converting to JPEG with adaptive quality, and returns the filename, bytes, and MIME content type.
    def _prepare_file(file_path: str) -> tuple[str, bytes, str]:
        """Read a file and compress it if it's a large image. Returns (filename, content, content_type)."""
        path = Path(file_path)
        if not path.exists():
            raise ValueError(f"File not found: {file_path}")
        file_content = path.read_bytes()
        suffix = path.suffix.lower()
        if suffix in IMAGE_EXTENSIONS and len(file_content) > MAX_IMAGE_SIZE:
            img = Image.open(io.BytesIO(file_content))
            img = img.convert("RGB")
            buf = io.BytesIO()
            quality = 85
            img.save(buf, format="JPEG", quality=quality, optimize=True)
            while buf.tell() > MAX_IMAGE_SIZE and quality > 20:
                quality -= 10
                buf = io.BytesIO()
                img.save(buf, format="JPEG", quality=quality, optimize=True)
            file_content = buf.getvalue()
            filename = path.stem + ".jpg"
            content_type = "image/jpeg"
        else:
            filename = path.name
            content_type = mimetypes.guess_type(path.name)[0] or "application/octet-stream"
        return filename, file_content, content_type
  • The `_upload` helper function performs the multipart form upload via httpx to the Testmo API, handling authentication and error responses. Used by the tool to send the file.
    async def _upload(
        endpoint: str,
        files: list[tuple[str, tuple[str, bytes, str]]],
    ) -> dict[str, Any]:
        """Upload one or more files via multipart form."""
        if not TESTMO_URL or not TESTMO_API_KEY:
            raise ValueError("TESTMO_URL and TESTMO_API_KEY must be set")
        async with httpx.AsyncClient(
            base_url=f"{TESTMO_URL}/api/v1/",
            headers={
                "Authorization": f"Bearer {TESTMO_API_KEY}",
                "Accept": "application/json",
            },
            timeout=httpx.Timeout(UPLOAD_TIMEOUT),
        ) as client:
            response = await client.post(endpoint, files=files)
            if response.status_code == 204:
                return {"success": True}
            if response.status_code >= 400:
                try:
                    error_body = response.json()
                except Exception:
                    error_body = response.text
                raise RuntimeError(f"Upload failed {response.status_code}: {error_body}")
            result = response.json()
            return result.get("result", result)
  • testmo-mcp.py:16-16 (registration)
    The `testmo.tools.attachments` module is imported in the main entry point, which causes the `@mcp.tool()` decorators in that module to execute and register all attachment tools including `testmo_upload_case_attachment`.
    import testmo.tools.attachments  # noqa: F401
Behavior3/5

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

Discloses auto-compression of large images, adding value beyond absence of annotations. However, does not mention file size limits, error handling, or permission requirements. With no annotations, more detail would be beneficial.

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

Conciseness4/5

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

Information is front-loaded with main purpose. Note and arguments section are clear but slightly redundant (e.g., repeated file path instructions). Could be trimmed slightly without loss.

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?

Covers essential aspects: purpose, file path constraints, compression behavior. With output schema present, lack of return value description is acceptable. Adequate for a simple two-parameter tool.

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?

Adds meaningful context to both parameters: case_id as 'The test case ID' and file_path with an example absolute path and explanation. Schema has 0% description coverage, so description compensates well.

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?

Explicitly states 'Upload a single file attachment to a test case' with specific verb and resource. Distinguishes from siblings like delete_case_attachments and the plural version (upload_case_attachments) by emphasizing single file.

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 prerequisites: file_path must be absolute path, pasted images not allowed, user must save file first. Instructs agent to ask user for path if not provided. Lacks mention of alternatives (e.g., plural version for multiple files) but usage context is clear.

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/strelec00/testmo-mcp'

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