← Catalog

@alfonzjanfrithz/pi-websearch

Web search and URL content fetching tools for Pi coding agent

Package

Install

Install with PiG

pig install npm:@alfonzjanfrithz/pi-websearch

Install with Pi

pi install npm:@alfonzjanfrithz/pi-websearch
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.7.1 (README.md). PiG does not review it.

pi-websearch

Web search and URL content fetching tools for Pi coding agent.

Adapted from opencode's websearch.ts, mcp-websearch.ts, and webfetch.ts.

Registers two LLM-callable tools:

Install

pi install npm:@alfonzjanfrithz/pi-websearch
# or from GitHub
pi install git:github.com/alfonzjanfrithz/pi-websearch

Configuration

Search providers

VariableDescriptionRequired
BRAVE_API_KEYBrave Search API keyNo — optional
TAVILY_API_KEYTavily Search API keyNo — optional
GOOGLE_API_KEYGoogle Custom Search JSON API keyNo — optional (requires GOOGLE_CX)
GOOGLE_CXGoogle Programmable Search Engine IDNo — optional (requires GOOGLE_API_KEY)
SEARXNG_BASE_URLSearXNG instance URL (e.g. https://searx.be)No — optional
EXA_API_KEYExa API keyNo — works without
PARALLEL_API_KEYParallel API keyNo — works without
PI_WEBSEARCH_PROVIDERForce a provider: brave, tavily, google, searxng, exa, or parallelNo — auto-selects
PI_WEBSEARCH_DATE_RANGESet to 0 to disable date range filtering entirelyNo — enabled by default
PI_WEBSEARCH_CACHE_TTLCache time-to-live in secondsNo — default: 300 (5 minutes)
PI_WEBSEARCH_CACHE_MAXMaximum number of cached search resultsNo — default: 100
PI_WEBSEARCH_CACHESet to off to disable caching entirelyNo — enabled by default

Provider selection logic:

  1. PI_WEBSEARCH_PROVIDER override → that provider
  2. No override set → pick the highest-priority provider with configured credentials:
    • BRAVE_API_KEY → Brave
    • TAVILY_API_KEY → Tavily
    • GOOGLE_API_KEY + GOOGLE_CX → Google
    • SEARXNG_BASE_URL → SearXNG
  3. No keys configured → deterministic hash of session ID → 50/50 split between Exa and Parallel

Fallback — If a provider fails (invalid key, rate limit, timeout, server error), the tool automatically tries the next available provider in the priority chain.

Web fetch

No API keys needed. Fetches URLs directly, converts HTML to markdown using turndown. No third-party services.

Tools

websearch

Search the web and return relevant content.

ParameterTypeRequiredDescription
querystringyesSearch query
numResultsnumbernoNumber of results (default: 8)
dateRange"last_day" | "last_week" | "last_month" | "last_3m" | "last_6m" | "last_9m" | "last_year" | "ytd"noFilter results by recency

Date range mapping — Each provider maps dateRange to its native API parameter:

dateRangeLabelBraveTavilyGoogleSearXNGExaParallel
last_day24hfreshness=pdtime_range=daydateRestrict=d1time_range=dayISO date (1 day ago)—
last_week7dfreshness=pwtime_range=weekdateRestrict=w1time_range=weekISO date (7 days ago)—
last_month30dfreshness=pmtime_range=monthdateRestrict=m1time_range=monthISO date (30 days ago)—
last_3m3mfreshness=<custom> ⚠️start_date=<ISO>dateRestrict=m3time_range=month ⚠️ISO date (90 days ago)—
last_6m6mfreshness=<custom> ⚠️start_date=<ISO>dateRestrict=m6time_range=year ⚠️ISO date (180 days ago)—
last_9m9mfreshness=<custom> ⚠️start_date=<ISO>dateRestrict=m9time_range=year ⚠️ISO date (270 days ago)—
last_year1yfreshness=pytime_range=yeardateRestrict=y1time_range=yearISO date (365 days ago)—
ytdYTDfreshness=<custom> ⚠️start_date=<ISO>dateRestrict=d<N> ⚠️time_range=year ⚠️ISO date (Jan 1)—

⚠️ = approximate mapping (see notes below)

Provider-specific date range notes:

  • Brave: Intermediate ranges use custom date ranges (YYYY-MM-DDtoYYYY-MM-DD). YTD computes from Jan 1 of the current year.
  • Tavily: Intermediate ranges and YTD use start_date (ISO date) instead of time_range presets, which provides exact dates.
  • Google: YTD is approximated as d<N> (days since Jan 1). All other ranges use native d[N]/w[N]/m[N]/y[N] units.
  • SearXNG: Only supports 4 presets (day/week/month/year). last_3m falls back to month, last_6m/last_9m/ytd fall back to year.
  • Exa: All ranges are computed as ISO startPublishedDate offsets — fully flexible.
  • Parallel: Does not support date filtering. The parameter is silently ignored.

Set PI_WEBSEARCH_DATE_RANGE=0 to completely disable the dateRange parameter (it will be stripped from all requests regardless of what the LLM passes).

webfetch

Fetch a URL and extract its content.

ParameterTypeRequiredDescription
urlstringyesURL to fetch
format"text" | "markdown" | "html"noOutput format (default: "markdown")
timeoutnumbernoTimeout in seconds (max 120)

Metadata extraction — When fetching HTML pages, webfetch automatically extracts structured metadata and includes it in the result:

FieldSource
titleOpenGraph (og:title) → JSON-LD headline → <title> → meta description
descriptionOpenGraph (og:description) → JSON-LD description → HTML meta description
authorOpenGraph (og:article:author) → JSON-LD author/creator → HTML meta author
publishedDateOpenGraph (og:article:published_time) → JSON-LD datePublished → HTML meta date
canonicalUrlOpenGraph (og:url) → <link rel="canonical">
imageOpenGraph (og:image) → JSON-LD image
siteNameOpenGraph (og:site_name)
typeOpenGraph (og:type) → JSON-LD @type

Features

  • 6 search providers with automatic fallback on failure
  • 8 date/recency filters via dateRange parameter (last_day, last_week, last_month, last_3m, last_6m, last_9m, last_year, ytd) with provider-specific mapping
  • Disable date range filtering via PI_WEBSEARCH_DATE_RANGE=0
  • Direct HTTP fetch with browser-like User-Agent
  • HTML→markdown via turndown, text extraction via htmlparser2
  • Cloudflare bot detection retry (honest UA fallback)
  • Image support (returned as base64 attachments)
  • Output truncation (50KB / 2000 lines, overflow saved to temp file)
  • Automatic page metadata extraction (OpenGraph, JSON-LD structured data, HTML meta tags)
  • Search result caching with TTL-based expiry and LRU eviction (Issue #2)
    • In-memory cache keyed by provider + query + dateRange + numResults
    • Default 5-minute TTL, configurable via PI_WEBSEARCH_CACHE_TTL
    • Default 100-entry max with LRU eviction, configurable via PI_WEBSEARCH_CACHE_MAX
    • Disable entirely with PI_WEBSEARCH_CACHE=off
    • Cache hits shown in TUI with "(cached)" indicator
    • Only successful results are cached; errors always fall through to the provider

Testing

Note: Public SearXNG instances often disable the JSON API or rate-limit it. For best results, self-host SearXNG and enable json in settings.yml:

search:
  formats:
    - html
    - json

License

MIT