testmo_list_case_attachments
Retrieve all attachments linked to a specific test case by providing the case ID. Supports pagination and optional expansion of related entities.
Instructions
List all attachments for a test case.
Args: case_id: The test case ID. page: Page number (default: 1). per_page: Results per page (default: 100). Valid: 25, 50, 100. expands: Related entities to include.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| case_id | Yes | ||
| page | No | ||
| per_page | No | ||
| expands | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- testmo/tools/attachments.py:41-59 (handler)The handler function for the testmo_list_case_attachments tool. It is decorated with @mcp.tool() and makes a GET request to /cases/{case_id}/attachments with pagination and optional expands parameters.
@mcp.tool() async def testmo_list_case_attachments( case_id: int, page: int = 1, per_page: int = 100, expands: list[str] | None = None, ) -> dict[str, Any]: """List all attachments for a test case. Args: case_id: The test case ID. page: Page number (default: 1). per_page: Results per page (default: 100). Valid: 25, 50, 100. expands: Related entities to include. """ params: dict[str, Any] = {"page": page, "per_page": per_page} if expands: params["expands"] = ",".join(expands) return await _request("GET", f"/cases/{case_id}/attachments", params=params) - testmo/tools/attachments.py:42-46 (schema)Input schema for the tool: case_id (int, required), page (int, default 1), per_page (int, default 100), expands (optional list of strings). Returns dict[str, Any].
async def testmo_list_case_attachments( case_id: int, page: int = 1, per_page: int = 100, expands: list[str] | None = None, - testmo/tools/attachments.py:41-42 (registration)The tool is registered via the @mcp.tool() decorator on the FastMCP instance 'mcp' imported from testmo.server. The import of testmo.tools.attachments in testmo-mcp.py triggers the registration.
@mcp.tool() async def testmo_list_case_attachments( - testmo/tools/attachments.py:15-38 (helper)Helper function _prepare_file that reads/compresses files before upload. Not directly used by testmo_list_case_attachments (which only reads), but a supporting utility in the same module.
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 - testmo/client.py:25-49 (helper)The _request helper function used by testmo_list_case_attachments to make the actual HTTP GET request to the Testmo API.
async def _request( method: str, endpoint: str, data: dict[str, Any] | None = None, params: dict[str, Any] | None = None, ) -> dict[str, Any]: async with _get_client() as client: response = await client.request( method=method, url=endpoint, json=data, params=params, ) 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"Testmo API error {response.status_code}: " f"{json.dumps(error_body) if isinstance(error_body, dict) else error_body}" ) return response.json()