PrintContentTool

class PrintContentTool(context: Context, activityProvider: () -> Activity? = { null }) : McpTool

Renders text or HTML content in an off-screen WebView and hands it to PrintManager.print, which opens the system print UI. Plain text is HTML-escaped and wrapped in a monospace <pre> block; pass is_html = true to print raw HTML as-is.

No permissions required, but an Activity is: PrintManager.print() must be called with an Activity context. The Activity comes from activityProvider (see PrintTools.all) or from context if it is itself an Activity; if neither yields a live Activity the tool returns an error. The WebView is created and loaded on the main thread; the call suspends until the page has loaded and the print job has been handed to the system (or LOAD_TIMEOUT_MS elapses). The WebView is strongly held by the print adapter wrapper and destroyed when the print flow finishes (or immediately on failure/timeout).

success indicates the print dialog was launched, not that anything was printed.

Output keys: success, job_name, content_length, message, job_id (may be null).

Constructors

Link copied to clipboard
constructor(context: Context, activityProvider: () -> Activity? = { null })

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