FetchWebpageTool

class FetchWebpageTool @JvmOverloads constructor(allowPrivateNetwork: Boolean = false) : McpTool

Fetches a URL with OkHttp (15s connect/read timeouts, 30s overall call timeout) and extracts readable body text via Jsoup, stripping script/style/noscript/nav/footer/header before extraction. Reaches the network (openWorldHint); requires INTERNET (always-granted). Only http/https URLs are accepted; a malformed URL returns an "Invalid URL" error; non-2xx status, empty body, or any other failure returns a ToolResult.error. The response body is capped at 5 MB while reading and decoded with the Content-Type charset (see readBounded) regardless of max_length.

SSRF protection: by default the tool refuses loopback, private (RFC 1918 / fc00::/7), link-local (incl. the 169.254.169.254 metadata address), CGNAT, unspecified and multicast targets — checked at DNS resolution and again on every redirect hop (see NetworkGuard), so a public URL can't redirect into the LAN either. Pass allowPrivateNetwork = true (or use WebTools.all(context, allowPrivateNetwork = true)) to let the token holder reach the phone's local network deliberately.

Output map: title (String), url (echoed), content (text truncated to max_length), content_length (Int — full untruncated length of the extracted text), response_truncated (Boolean — the raw body exceeded the 5 MB read cap).

Parameters

allowPrivateNetwork

when true, disables the SSRF guard (default false).

Constructors

Link copied to clipboard
constructor(allowPrivateNetwork: Boolean = false)

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