CaptureScreenTool

Captures the device screen via MediaProjection and saves it as a PNG or JPEG.

Mirrors the display into an android.media.ImageReader through a android.hardware.display.VirtualDisplay owned by MediaProjectionHolder — created once per projection (Android 14+ allows only one createVirtualDisplay per projection) and reused by every call — and encodes the newest frame. Requires an active MediaProjection: the host app must obtain user consent and register the projection token via MediaProjectionHolder; if absent, returns an error. Destructive hint (it writes an image). On API 34+ the host must run a mediaProjection foreground service (manifest declares FOREGROUND_SERVICE_MEDIA_PROJECTION).

Storage. The image is inserted through MediaStore into Pictures/droid-mcp (using IS_PENDING on API 29+, so no storage permission is needed there). On API 28 the insert needs WRITE_EXTERNAL_STORAGE; without it the image is written to the app's private cache instead (saved_to = "cache").

Output keys: success, path (the image's filesystem path when MediaStore reports one, else the content URI; for cache saves the private file path), uri (content URI, or file:// URI for cache saves), saved_to (gallery or cache), width, height, format, size_bytes.

Constructors

Link copied to clipboard
constructor(context: Context)

Properties

Link copied to clipboard
open override val annotations: ToolAnnotations
Link copied to clipboard
open override val description: String
Link copied to clipboard
open override val name: String
Link copied to clipboard
open override val outputSchema: Map<String, Any>
Link copied to clipboard
open override val parameters: List<ToolParameter>

Functions

Link copied to clipboard
open suspend override fun execute(params: Map<String, Any>): ToolResult