# FastMesh DataFuel Agent Skill Handbook (`datafuel.fastmesh.dev`)

> Executable integration manual for autonomous agents, MCP clients, and backend pipelines calling `https://datafuel.fastmesh.dev` (local `http://127.0.0.1:9050`) via REST, JSON-RPC 2.0 `/mcp`, or the local Register-Anything `ra_proxy_request` zero-secret adapter.

## Operational Guarantees (Read Before Calling)
1. **Zero Secret Leakage (`reveal=False`):** Never pass raw upstream API keys, cookies, passwords, OTPs, or personal emails in requests. Upstream credentials stay sealed inside the local Register-Anything proxy daemon (`http://127.0.0.1:18793/api/proxy/<proxy_domain>`), and all responses are scrubbed in memory.
2. **Zero CAPTCHA & Payment Bypass:** Any Turnstile, reCAPTCHA, hCaptcha, GeeTest, or credit-card gate (such as card-gated prompts on `brave_search` or `whoisxml`) immediately transitions to `PARKED_WITH_FALLBACK` or `PARKED_SILENTLY` (`retry_allowed: false`, `bypass_attempted: false`) and fails over to a card-free provider.
3. **Hard `>= 120s/domain` Cooldown Lock:** Harvest probes per domain are throttled in SQLite WAL to prevent abusive bursts.
4. **SSRF `422` Unbilled Guard:** Private RFC1918 networks, loopback (`127.0.0.1`/`::1`), link-local, cloud metadata (`169.254.169.254`), and non-`http(s)` schemes are rejected with HTTP `422` and `billed_micros: 0`.
5. **Anti-Fake-200 & `$0` on Miss:** HTML error shells, bot walls, and empty result lists never poison the `7d-30d` `ArchiveCache` and always settle at `0` micro-USD.

---

## 1. REST Quickstart (`https://datafuel.fastmesh.dev`)

### A. Inspect Redacted Pool Telemetry (`$0`, No Auth Required)
```bash
curl -sS https://datafuel.fastmesh.dev/v1/datafuel/pool
```
Returns catalog counts (`18` providers across `5` families: `16` core + `2` card-free fallbacks `ipgeolocation` and `rdap_bootstrap`), vault hydration counts (`3` stored / `15` not stored via `reveal=False`), cooldown windows, and remaining monthly/daily free quotas with zero secret fields.

### B. Generate a Cooldown-Safe Harvest Plan (`$0`)
```bash
curl -sS -X POST https://datafuel.fastmesh.dev/v1/datafuel/plan-harvest \
  -H "Content-Type: application/json" \
  -d '{
    "families": ["web_search", "clean_scrape", "domain_enrichment"],
    "exclude_card_required": true,
    "dry_run": true
  }'
```

### C. Unified Web Search (`5,000` micro-USD = `$0.005`/verified hit; `$0` on miss)
Waterfall order: `tavily -> exa -> serper -> brave_search` (`7d-14d` archive cache).
```bash
curl -sS -X POST https://datafuel.fastmesh.dev/v1/datafuel/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "zero-secret web search MCP adapter",
    "downstream_engine": "rank",
    "tenant_id": "tenant-demo",
    "max_cost_micros": 10000,
    "providers": ["tavily", "exa", "serper"]
  }'
```

### D. SSRF-Guarded Clean Markdown Scrape (`10,000` micro-USD = `$0.010`/verified hit; `$0` on miss or `422`)
Waterfall order: `jina -> firecrawl -> apify_free -> browserless` (`7d-21d` archive cache).
```bash
curl -sS -X POST https://datafuel.fastmesh.dev/v1/datafuel/scrape \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://docs.python.org/3/library/sqlite3.html",
    "downstream_engine": "scrape",
    "tenant_id": "tenant-demo"
  }'
```
Probing `http://169.254.169.254/latest/meta-data/` or `http://127.0.0.1:9050/health` returns HTTP `422` with `billed_micros: 0`.

### E. Domain, Network/WHOIS, or Serverless Enrichment (`6,000`–`12,000` micro-USD/verified hit; `$0` on miss)
- `domain_enrichment` (`12,000` micro-USD, `14d-30d` cache): `brandfetch -> abstractapi -> hunter`
- `network_geo_whois` (`6,000` micro-USD, `14d-30d` cache): `ipinfo -> rdap_bootstrap -> ipgeolocation -> whoisxml`
- `serverless_infra` (`8,000` micro-USD, `7d-30d` cache): `upstash -> neon -> resend`

```bash
curl -sS -X POST https://datafuel.fastmesh.dev/v1/datafuel/enrich \
  -H "Content-Type: application/json" \
  -d '{
    "family": "network_geo_whois",
    "target": "fastmesh.dev",
    "downstream_engine": "verify",
    "tenant_id": "tenant-demo"
  }'
```

---

## 2. Remote MCP JSON-RPC 2.0 Integration (`POST /mcp`)

Connect any MCP client to `https://datafuel.fastmesh.dev/mcp` (or `http://127.0.0.1:9050/mcp` locally).

### Step 1: Initialize Session
```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2024-11-05",
    "clientInfo": { "name": "agent-client", "version": "1.0.0" }
  }
}
```

### Step 2: List All 5 DataFuel Tools (`$0`)
```json
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/list",
  "params": {}
}
```
Exposed tools:
- `datafuel_pool_status` (`$0`)
- `datafuel_plan_harvest` (`$0`)
- `datafuel_search` (`5,000` micro-USD verified / `$0` miss)
- `datafuel_scrape` (`10,000` micro-USD verified / `$0` miss or SSRF `422`)
- `datafuel_enrich` (`6,000`–`12,000` micro-USD verified / `$0` miss)

### Step 3: Invoke a Tool (`tools/call`)
```json
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "datafuel_search",
    "arguments": {
      "query": "RDAP public domain registration JSON",
      "downstream_engine": "verify",
      "tenant_id": "agent-ops",
      "max_cost_micros": 10000
    }
  }
}
```

---

## 3. Register-Anything Zero-Secret Proxy Pattern (`ra_proxy_request`)

When running locally alongside the shared Register-Anything daemon (`http://127.0.0.1:18793`), DataFuel **never** calls `ra_resolve_credential(..., reveal=True)`. Follow the exact two-step zero-secret contract:

1. **Check Vault Presence Without Secret Reveal:**
   ```python
   # MCP tool call (read-only metadata check)
   ra_resolve_credential(domain="app.tavily.com", reveal=False)
   # Returns vault_status ("stored" | "not_stored") with zero secret bytes
   ```
2. **Execute Authenticated Upstream Call Through the Local Proxy:**
   ```python
   # MCP tool call — daemon injects Authorization header in memory
   ra_proxy_request(
       domain="api.tavily.com",
       method="POST",
       path="/search",
       json_body={"query": "fastmesh datafuel", "search_depth": "basic", "max_results": 5}
   )
   ```
3. **Direct Local Daemon HTTP Proxy (Bypassing System Proxies via `NO_PROXY`):**
   - Endpoint: `POST http://127.0.0.1:18793/api/proxy/<proxy_domain>`
   - Auth: Local daemon token read in memory from `~/.causal-store-v2/.register_anything_api_token` (`Authorization: Bearer $RA_LOCAL_TOKEN`)
   - Python stdlib rule: Always build opener with `urllib.request.ProxyHandler({})` so localhost traffic never detours through an external HTTP proxy.
   - Redaction rule: Scrub every response body and error trace before returning or logging.

---

## 4. Downstream FastMesh Engine Adaptation (`downstream_engine`)

Pass `"downstream_engine"` in `/v1/datafuel/search`, `/v1/datafuel/scrape`, `/v1/datafuel/enrich`, or MCP `tools/call` to receive a ready-to-ingest `downstream_payload` shaped for:
- `scrape` (`scrape.fastmesh.dev`) — clean markdown body, title, canonical URL, anti-fake-200 verdict
- `batch` (`batch.fastmesh.dev`) — normalized waterfall row with cache hit metadata and micro-USD receipt
- `rank` (`rank.fastmesh.dev`) — ranked SERP URLs, citation snippets, and brand presence markers
- `lead` (`lead.fastmesh.dev`) — company firmographics, logo/brand kit, verified domain contacts, ASN context
- `harvest` (`harvest.fastmesh.dev`) — clean markdown feed items ready for structured extraction
- `verify` (`verify.fastmesh.dev`) — RDAP/WHOIS registration facts, IP geolocation/ASN, email check signals

---

## 5. Prepaid Billing & Local CLI Verification

- **Prepaid Credit Packs (Creem):** Starter `$19` (`19,000,000` micro-USD), Pro `$79` (`90,000,000` micro-USD, `+14%` bonus), Scale `$249` (`325,000,000` micro-USD, `+30.5%` bonus). Credits never expire; no recurring subscription required.
- **Same-Tenant Cache Recheck Discount:** Verified repeat calls by the same `tenant_id` within the `7d-30d` `ArchiveCache` window bill at `10%` of base hit price (`0` upstream credits spent).
- **Local CLI / Causal Bazaar Hand (`run_hand.py`):**
  ```bash
  python3 run_hand.py self-test
  python3 run_hand.py pool
  python3 -m src.server --host 127.0.0.1 --port 9050
  ```

Support: `support@fastmesh.dev` | Operations: `ops@fastmesh.dev`
