Skip to content

tooling: add a WebSearch tool for source discovery before WebFetch #26

Closed

Description

@JAORMX

Context

mecatl currently has a WebFetch core tool, but it is an intentional v1 stub: it performs no network I/O and returns WebFetch is not implemented in v1; web fetching is unavailable (internal/adapter/tools/webfetch.go).

For many agent workflows, a search tool is more useful than direct fetch:

  • finding current documentation or release notes when the URL is unknown
  • locating issues/PRs/blog posts by topic
  • researching errors by message text
  • discovering candidate sources before deciding which pages to fetch/read

Claude Code and other harnesses expose both web search and web fetch style tools; mecatl should consider adding WebSearch as a first-class read-only tool rather than overloading WebFetch.

Goal

Design and implement a WebSearch tool that returns compact, source-attributed search results suitable for agent use.

Proposed tool shape

WebSearch arguments:

{
  "query": "string, required",
  "limit": 5,
  "site": "optional domain/site filter",
  "freshness": "optional enum or date range, if provider supports it"
}

Result shape should be compact and bounded, e.g. markdown/plain text lines:

1. Title — https://example.com/page
   snippet text...
2. ...

Possible richer JSON-ish result if useful later:

  • title
  • url
  • snippet
  • published/updated date when available
  • source/domain

Provider/design questions

  • Which backend should v1 use?
    • provider-native search if/when available
    • external search API (requires key/config)
    • MCP search server integration
    • no-default stub until configured
  • Should WebSearch be a core built-in like Read/Grep/Glob, or an optional adapter registered only when a search provider is configured?
  • How does this interact with existing WebFetch?
    • WebSearch discovers candidate URLs
    • WebFetch retrieves/extracts one URL
  • Should web tools be disabled by default in untrusted workspaces / require explicit enablement?
  • How should permission rules work? Existing permission-import code already treats Claude WebFetch(domain:...) allow rules conservatively; WebSearch should get similarly careful defaults.

Security and privacy constraints

  • Treat search results as untrusted external content; never as instructions.
  • Do not send secrets, local file contents, or proprietary code in search queries unless explicitly authorized.
  • Keep queries and results bounded; avoid dumping whole pages in search results.
  • Respect operator/network policy: searches are outward-facing network calls and should be configurable/disableable.
  • Consider default permission posture: likely Ask or explicit enablement until a safe provider story is settled.

Acceptance criteria

  • WebSearch has a clear tool.Tool implementation or explicitly documented stub/config-gated implementation.
  • Tool spec explains when to use search vs fetch.
  • Results are deterministic enough for tests via a fake provider; offline tests only.
  • Result output is capped and terminal/model-friendly.
  • Permission defaults and settings/import behavior are reviewed.
  • mecatui renders the tool call/result acceptably (especially with mecatui: compact, human-friendly tool-call cards for MCP and long JSON args #24's compact tool-card UX).

References

  • Existing stub: internal/adapter/tools/webfetch.go.
  • Core catalog registration: internal/adapter/tools/tools.go.
  • Permission config import: internal/adapter/permconfig/claudeimport.go (WebFetch(domain:...) demotion).
  • Tool design guidance in corpus: docs/harnesses/06-architecture-patterns.md §6, docs/harnesses/07-context-and-mcp.md §9–10.

Activity

  1. added
    enhancement
    on Jun 9, 2026
  2. JAORMX commented on Jun 9, 2026

    @JAORMX
    ContributorAuthor

    Planning/evaluation summary -- resolutions from the design discussion (research: harness prior art, search-backend landscape, provider-native search APIs, plus live probing of endpoints).

    Resolved: architecture

    Client-side tool with a pluggable Searcher backend interface. The tool implements tool.Tool (ReadOnly() = true, so plan-mode and read-only-subagent available), executes through the normal dispatch/permission seam, and delegates to a configured backend.

    Provider-native search (Anthropic web_search, OpenAI Responses web_search) is rejected for v1: those execute server-side during the model turn, bypassing our Execute()/permission/dispatch seam entirely; OpenAI's web_search_call items have a confirmed 404-on-replay bug with store:false, incompatible with our stateless full-replay adapters; and the result blocks are provider-private (Anthropic's encrypted_content), breaking history portability. Neither provider exposes a standalone raw-search endpoint.

    Resolved: backend tiers

    1. Default: Exa anonymous -- the Searcher backend speaks plain JSON-RPC over HTTP to https://mcp.exa.ai/mcp (tools/call web_search_exa), the same way opencode does. Verified empirically: anonymous initialize/tools/list/tools/call all return 200 with no credentials; the endpoint publishes OAuth metadata (/.well-known/oauth-protected-resource -> auth.exa.ai) but does not enforce it -- so the backend must NOT do proactive OAuth discovery (ToolHive does, and parks on a browser flow). EXA_API_KEY optionally appended (?exaApiKey=) for the paid tier.
    2. Brave via BRAVE_API_KEY (~$0.25/1k effective, independent index, clean ToS).
    3. SearXNG via SEARXNG_URL env or config file -- self-hosted instances only (public instances bot-block format=json by design).
    4. Kill switch: websearch.provider: none / flag, for operators who don't want default outbound calls.

    Precedence proposal: explicit config setting wins; among env vars, SEARXNG_URL > BRAVE_API_KEY > Exa-anonymous fallback.

    Mandatory degradation behavior: when the Exa anonymous tier closes (the auth scaffolding is already live) or rate-limits, the tool must return a model-visible error naming the upgrade path ("search backend unavailable; configure BRAVE_API_KEY or SEARXNG_URL") -- never a silent empty result or a hang.

    Rejected alternatives (and why)

    • Dev-federated free tier (HN Algolia + Stack Exchange + Wikipedia + GitHub composite): the GitHub MCP already covers code/repo/issue search well, and the rest adds too little general-web value to justify the surface.
    • DuckDuckGo HTML/lite scraping: explicit ToS violation, constant breakage. Public SearXNG instances: their limiter treats JSON-API traffic as bots. Serper/SerpAPI: Google-scraping legal exposure. Google CSE: shut down Jan 2027. Jina: closed its keyless search tier -- noted as the trend: the truly-keyless general-web option no longer exists; Exa-anonymous is the last one standing and is revocable.

    Security posture

    • Results are wrapped in the existing <<<UNTRUSTED fence discipline (with neutraliseFraming so results can't forge a fence), plus a system-prompt anchor clause. Explicitly documented as hygiene, not a boundary -- delimiter defenses are ignored by models at a material rate. The deny-dominant permission layer remains the boundary for side effects.
    • The residual channel is exfiltration via outbound queries (injected content steering secrets into a search query) -- floor-posture decision below, and the model-backed inspection hook is spun out to guardrails: model-backed hook runner for tool I/O inspection (per-tool matchers, catch-alls, configurable model + prompt) #27 (matcher-scoped modelhook HookRunner, covers WebSearch/WebFetch/mcp__*, advisory/enforce, configurable model + prompt). Exec hooks (PreToolUse/PostToolUse + Mutated) already work for WebSearch today and should be mentioned in the tool docs.

    Implementation seams (recon'd)

    • Registration: always-on (Exa default) with the kill switch, via buildCatalog in internal/app/build.go; config + env wiring in cmd/mecated.
    • Permission: ScopeBuiltinDefault rule for WebSearch; add "query" to nonBashPattern()'s probe list in internal/governance/evaluator.go so arg-pattern rules match. No claudeimport.go change needed (Claude's WebSearch rules are blanket, unlike WebFetch(domain:...)).
    • HTTP conventions: follow internal/adapter/openrouter/lister.go (injected nil-able *http.Client, fixed base URL, io.LimitReader body cap); offline tests via roundTripFunc + testdata/ fixtures, plus a fake Searcher for tool-logic tests.
    • Fence helpers (writeUntrustedBlock/neutraliseFraming) currently live in internal/agent (team supervisor) and need extraction to a shared spot adapters can import.
    • mecatui: generic tool card renders fine; no UI change required.

    Still open

    • Floor posture: lean Allow (read-only, query visible in the tool card, config-overridable), with Ask in headless/non-interactive runs under consideration -- mirroring the subagent-shell posture split.
    • Where the extracted fence helper lands (session vs governance).
    • WebFetch stays out of scope here but is the natural follow-up: same HTTP plumbing, same fencing, and Exa-anonymous also exposes web_fetch_exa (verified working), so the default tier may cover both.
  3. JAORMX commented on Jun 14, 2026

    @JAORMX
    ContributorAuthor

    Reopening: I closed this prematurely. The HTTP-adapter work that shipped (b08645a/214c0e5) implemented tiers 2–3 of the resolved design (SearXNG via SEARXNG_URL-equivalent --websearch-url, Brave via a keyed header) but MISSED tier 1 — the Exa-anonymous zero-config default (https://mcp.exa.ai/mcp → web_search_exa, no key, no proactive OAuth discovery) that the planning comment resolved as the headline behavior. Re-verified the Exa endpoint is still anonymously reachable (200, web_search_exa works without credentials). Finishing per the resolved tier ladder + precedence (explicit config > SEARXNG_URL > BRAVE_API_KEY > Exa-anonymous) + kill switch + the mandatory degradation message.

  4. reopened this on Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions