Screenshot backend fallback chain does not catch IndexError, so one backend's failure aborts the whole capture

Author: naitik-forestallersCreated Sep 17, 2026Updated Sep 17, 2026

Summary

capture() walks the backend chain ["dxcam", "mss", "pillow"], but its except clause (src/windows_mcp/desktop/screenshot.py:174) only catches three exception types:

python
except (OSError, RuntimeError, ValueError):
    logger.warning(
        "Screenshot backend '%s' failed; trying next backend",
        backend_name,
        exc_info=selected != "auto",
    )

dxcam can raise IndexError — self.outputs[device_idx][output_idx] in dxcam/__init__.py:151, reached from get_dxcam_camera() at screenshot.py:66. IndexError is not in that tuple, so it propagates out of the loop, skips the perfectly usable mss and pillow backends, and surfaces to the caller as:

Error capturing screenshot: list index out of range. Please try again.

The "Please try again." is misleading — the failure is deterministic and retrying never helps.

Why it matters

This is independent of the underlying dxcam index bug (#416) and worth fixing on its own. The fallback chain exists precisely so that one backend misbehaving on unusual hardware degrades to a working one. Any backend that raises outside those three types defeats it. In my case pillow would have served the request correctly — it does so on every unfiltered screenshot.

Reproduction

Any condition that makes dxcam raise IndexError rather than one of the three caught types. On a hybrid-GPU laptop, Screenshot(display=[1]) does it every time.

Actual: whole capture aborts, no fallback attempted. Expected: dxcam failure is logged, chain continues to mss, then pillow, and a screenshot is returned.

Suggested fix

Catch Exception in the chain loop (keeping the per-backend logger.warning), and re-raise only if every backend in the chain has failed. Include the individual backend failures in the final error so the cause is not lost:

python
except Exception:
    logger.warning(
        "Screenshot backend '%s' failed; trying next backend",
        backend_name,
        exc_info=True,
    )
    failures.append((backend_name, sys.exc_info()[1]))

Environment

- Windows-MCP: 0.7.2 (Claude Desktop extension channel, ant.dir.cursortouch.windows-mcp)
- OS: Windows 11 Pro 10.0.26200
- Python: CPython 3.13.15 (uv-managed)
- uv: 0.12.5
- Displays: 2 - primary 2560x1600 (laptop, Intel iGPU), secondary 1920x1080 (external, NVIDIA RTX 5070 Laptop)
- GPUs: hybrid - Device[0] Intel(R) Graphics, Device[1] NVIDIA GeForce RTX 5070 Laptop GPU
- Screenshot backend: auto