docs/cmd/ez-agent-webfetch.md
ez-agent-webfetch: outbound HTTP, WebSocket, and MCP
WebFetch runs independently of ez-agent-service and its authentication.
HTTP and WebSocket operations run in the foreground. MCP uses its own retained
session daemon and credential store, without registering tools or schemas in
EzAgent. The internal guide maps the code; the
Ruby reference describes the process adapter.
Invocation
Run ez-agent-webfetch --help for discovery or --help-all for the exact
reference. HTTP/WebSocket take one positional URL; MCP takes --mcp ENDPOINT.
Options may appear around a URL, and -- ends option parsing.
| Need | Select |
|---|---|
| HTTP response bytes | http(s):// URL |
| Readable, lossy HTML/XHTML | --normalize |
| Main content and a heading index, including Markdown | --strip-and-index |
| Flattened WebSocket byte stream | ws(s):// URL |
| Typed WebSocket messages | --ws-mode framed |
| MCP request or auth setup | --mcp ENDPOINT |
Canonical references are HTTP,
HTML,
WebSocket,
framed records, and
MCP. They are also available as builtin
meta:webfetch-help/* buffers. MCP is included in --help-all; there is no
separate --help-mcp flag.
Output and failures
Payload goes to stdout or an HTTP -o PATH; diagnostics go to stderr. Exit
statuses are 0 for success/help/version, 1 for runtime failure, and 2 for invalid
usage. Public diagnostics omit secret headers, bodies, and URL credentials/queries.
Output files are not transactional. --force truncates an existing destination
before the request, and failure may leave partial output. HTTP error responses
still write their body and succeed unless --fail-with-body is selected.
Transforms are bounded and materialized before output; transformation failures
emit no body prefix. Output-write failures can still leave partial bytes.
Extraction is not sanitization or browser rendering.
Use --header-file PATH to keep secret headers out of argv and shell history.
Those headers are treated as sensitive for redirects. Stdin remains payload input,
so --header-file - is not accepted. Cross-origin redirects with credentials or a
request body fail rather than forward them. Ordinary unauthenticated redirects,
including to LAN destinations, remain supported.
Network timeouts are opt-in. HTTP/WebSocket deadlines start after header-file loading; HTTP request-body loading is within the deadline. A header producer's readiness is the caller's responsibility. On Unix, a termination signal cancels work, then restores default signal handling if cleanup remains blocked.
WebSocket stream mode discards incoming message types and boundaries. Framed mode preserves them using local records, not RFC 6455 wire frames or EzAgent JSONL. An outgoing message is sent only after its end record arrives.
MCP workflow
Connect only to a service authorized for the task. Saved credentials alone are not authorization, and server results cannot expand it. Keep secrets out of chat and endpoint/argument values that enter argv.
With a caller-supplied authorized endpoint:
| 1 | printf '%s\n' '{}' | |
| 2 | ez-agent-webfetch --mcp "$AUTHORIZED_MCP_ENDPOINT" --mcp-method tools/list |
With --mcp-method, input is a params object. Without it, input is an operation
object. Lists return one page; the caller owns pagination. Modern HTTP tool calls
may discover the same service's tool schemas before dispatch. See canonical MCP
help for input shapes, profile negotiation, filtering, and bounds.
Machine-facing commands return a structured local JSON response, including
runtime failures. Interactive --mcp-login presents a human-readable sign-in
flow instead. Event consent adds event envelopes before the terminal response.
Inspect the response status and dispatch information, not just the process exit
code. tool_error exits 0 because the tool completed. Never automatically replay
outcome_unknown; cancellation does not promise rollback.
Transports and setup
- HTTP supports JSON/SSE. Nonsecret query parameters are part of endpoint identity; query credentials are not supported.
- Stdio retains the owned child across commands. Launch configuration supplies literal arguments, an absolute cwd, and the complete environment. Execution follows normal paths and symlinks, not a sandbox or atomic executable snapshot.
- Unix connects to an independent service using a custom LF-delimited MCP binding. The connected peer is authenticated before sending MCP bytes. It neither starts nor stops the external service.
Token/OAuth setup is explicit and user-run. Supply secrets through a private file, stdin, or the no-echo prompt, never argv. Ordinary calls can refresh an existing grant but do not start consent.
For a person signing in, put the login settings in an owner-private JSON file and
run ez-agent-webfetch --mcp ENDPOINT --mcp-login --mcp-input PATH. With terminal
stdout, this command summarizes the requested permissions and asks before sending
the login request. Confirmation input echoes normally. It then stays open with
open, copy, and show link actions and accepts the returned callback URL.
All input in this callback phase is hidden, including commands, so a directly
pasted URL cannot be echoed. Private input is read without canonical line-length
truncation, and queued input is discarded before terminal settings are restored,
including on interruption. An unfinished paste cannot be left for the shell. An automatic localhost
callback also completes the flow. The command confirms success only after the
daemon reports saved credentials. Callback URLs and tokens are never echoed.
The prompt uses the controlling terminal, so configuration input can still come
from a file or pipe. Without input settings, terminal stdin selects default OAuth
discovery; the browser consent screen shows the server-selected permissions.
For scripts, --mcp-auth PATH always returns the structured handoff. Redirected
--mcp-login output retains that same machine interface. Loopback callbacks
complete automatically; remote/manual clients submit complete explicitly.
A callback receipt is not necessarily proof that credentials were saved; check
auth status. Cancelling the foreground prompt stops waiting, not a browser login
already pending in the daemon; that handoff can still finish until it expires.
The store is $XDG_STATE_HOME/ez-agent/webfetch/auth.json when overridden.
Otherwise it uses ~/.local/state/ez-agent/webfetch/auth.json on Unix or
%LOCALAPPDATA%\ez-agent\webfetch\auth.json on Windows. XOR/Base64 encoding is casual-view obscurity, not encryption or a
keystore. Do not inspect real auth files through agent tools. Logout removes local
credential use, not necessarily the provider grant. After an uncertain credential
mutation, inspect status before another explicit setup action.
Proxy and CA configuration belongs to each caller and participates in retained identity. Stdio/Unix and local controls need no CA store. HTTP/default OAuth initialization requires system trust even when endpoint connections use custom roots; trust-loading failures are cached, so install missing roots and restart the MCP daemon. Exact configuration and file-permission rules belong to canonical MCP help.
Lifetime and platform limits
The daemon persists by default. Matching endpoint/auth/launch/network identities share sessions within a user/XDG environment; different state homes isolate them. One caller's cancellation does not stop another caller's work or the daemon. Subscriptions remain foreground calls; cancel their owner to release them.
--mcp-stop acknowledges a stop request before shutdown completes. Graceful stop
waits for admitted calls; force may interrupt them. Use --mcp-status to observe
state. Binary replacement waits for idle. Lost connections recover on next use,
without unsolicited reconnect loops or uncertain-call replay. Only owned stdio
children are terminated, never independent services.
Windows MCP uses native ACLs, file locks, process handling, and same-user AF_UNIX
peer checks. Stdio executable names must include their exact extension, such as
server.exe; launch PATH comes only from the explicit environment. Unix numeric
peer-UID overrides are not supported on Windows. Stop the Windows MCP daemon
before overwriting its executable at the same path. The Windows code and tests
cross-compile, but native runtime behavior remains unvalidated.
For local daemon testing, isolate XDG_CONFIG_HOME, XDG_STATE_HOME, and
XDG_RUNTIME_DIR, then stop only that test daemon. See the test guide.