Agent-First HTTP
Persistent HTTP client for AI agents — one request, one JSON line.
Supported platforms: macOS, Linux, Windows.
Modes (single entrypoint):
--mode cli(default)--mode pipe--mode mcp--mode curl
The key contract for agents is protocol determinism: stdout is always structured JSON, and failures are always structured {"code":"error",...} events with stable error_code values. No human-only text parsing, no mixed output channels, no ad-hoc error shapes.
CLI Mode
The default mode — one request, one JSON response, exit:
# {"code":"response","status":200,"body":[...],"trace":{"duration_ms":120,...}}
# {"code":"response","status":201,"body":{"id":42},...}
# {"code":"response","status":200,...}
Structured error output examples:
Pipe Mode
For long-lived sessions with connection reuse, concurrent requests, and WebSocket — use afhttp --mode pipe:
output:
What just happened:
- One bash call — the heredoc sends all requests into one
afhttpprocess; afhttp exits when stdin closes - Auth set once per host —
host_defaultsapplies auth only to matching host; credentials do not leak to other domains - Three requests fired without waiting —
models,usage, andchatall in-flight simultaneously - Connection reuse is automatic — requests to the same host can reuse pooled connections without extra agent logic
- Out-of-order responses —
usagearrived beforechatfinished; the agent matches byid - Streaming inline —
chatdelivers events as they arrive, no buffering, no special setup - HTTP errors are data —
usagereturned 403; afhttp delivers it ascode: "response"withstatus: 403; the agent checksstatus, not exception types or text patterns
MCP Mode
afhttp --mode mcp runs as a Model Context Protocol server, letting AI tools like Claude Desktop make HTTP requests directly:
Claude can then call http_request and http_config tools. See docs/mcp.md for the full setup guide.
curl Compatibility
Use explicit curl mode. afhttp understands a subset of curl flags and returns structured JSON:
# {"code":"response","status":201,"body":{"id":42},...}
Install
macOS / Linux — Homebrew
Windows — Scoop
scoop bucket add cmnspore https://github.com/cmnspore/scoop-bucket
scoop install afhttp
Any platform — Cargo
Docs
- CLI Manual — CLI, MCP, and curl compat modes
- MCP Reference — MCP tool reference and Claude Desktop setup
- Protocol Reference — full field specification
- Testing Strategy — layered tests, coverage gate, regression policy
- Design — architecture and principles
License
MIT