# Coding Agents

> Build ClutchCall apps with AI assistance — Claude Code, Cursor, Codex, and friends.

The ClutchCall SDK is built to work well with AI coding agents. We ship
three things designed specifically for them:

1. A documentation surface that LLMs can read directly (no HTML scraping).
2. A native MCP server they can call as a tool.
3. A CLI (`clutchcall`) that scaffolds projects with agent-ready
   `AGENTS.md` files baked in.

If you're using Claude Code, Cursor, Codex CLI, or any other coding agent,
point it at the resources below before asking it to write ClutchCall code.

## MCP server

Available at:

```
https://docs.clutchcall.dev/api/mcp
```

Streamable HTTP transport (POST JSON-RPC). Three tools:

| Tool          | Args                       | Returns                                                |
|---------------|----------------------------|--------------------------------------------------------|
| `list_pages`  | (none)                     | Navigation-grouped slug index of every docs page.      |
| `search_docs` | `query`, `limit?` (≤25)    | Ranked matches with title, description, and snippet.   |
| `get_page`    | `slug` (e.g. `rpc/method-ids`) | Full Markdown body of the page.                    |

### Wiring into Claude Code, Cursor, etc.

**Claude Code (.mcp.json):**
```json
{
  "mcpServers": {
    "clutchcall-docs": {
      "url": "https://docs.clutchcall.dev/api/mcp"
    }
  }
}
```

**Cursor (.cursor/mcp.json):**
```json
{
  "mcpServers": {
    "clutchcall-docs": {
      "url": "https://docs.clutchcall.dev/api/mcp"
    }
  }
}
```

**Codex CLI (codex.toml):**
```bash
[mcp_servers.clutchcall-docs]
url = "https://docs.clutchcall.dev/api/mcp"
```

Once configured, your agent will see `list_pages`, `search_docs`, and
`get_page` as callable tools alongside its built-in toolbox.

### Smoke test

```bash
curl -X POST https://docs.clutchcall.dev/api/mcp \
  -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
```

## Plain-text documentation

For agents that don't speak MCP (or for use as a static prompt-context
drop-in), every page is also published as plain Markdown:

| URL                                              | What it is                                                  |
|--------------------------------------------------|-------------------------------------------------------------|
| `https://docs.clutchcall.dev/llms.txt`            | Short, navigation-grouped index. Triage starts here.        |
| `https://docs.clutchcall.dev/llms-full.txt`       | Every page concatenated, page-marked. Whole-corpus context. |
| `https://docs.clutchcall.dev/<slug>.md`           | Per-page Markdown mirror (e.g. `/rpc/method-ids.md`).        |
| `https://docs.clutchcall.dev/search-index.json`   | Searchable JSON corpus (powers the MCP `search_docs` tool). |

The format follows the [llms.txt convention](https://llmstxt.org/) — drop
the URL into any LLM's context window and it knows what to do with it.

## CLI: `clutch`

The `clutch` CLI does what the MCP server does, plus runs telephony
operations against the live control-plane API after `clutch auth login`.

**Docs (no auth)**:

```bash
clutch docs overview                          # navigation index
clutch docs search "originate trunk"          # full-text search
clutch docs get-page rpc/method-ids           # one page as Markdown
```

**Auth**:

```bash
clutch auth login                             # browser OAuth → portal
clutch auth whoami                            # current identity + active org
```

**Trunks + calls** (after auth):

```bash
clutch trunks list                            # tabular view
clutch trunks show <id>                       # one trunk in detail
clutch dial +15551234567 --trunk <your-trunk-id> \
    --app AI_BIDIRECTIONAL_STREAM --app-args my-agent-id
clutch dial --list-apps                       # all 13 DialplanAction values
clutch hangup <call_sid>
```

> **WARNING:**
> `clutch dial` defaults `--app` to `AI_BIDIRECTIONAL_STREAM` (=6). If you
>   don't pass `--app-args <agent_id>` the runtime has no agent to bridge
>   and the call lands in silence. For raw audio piping without an AI
>   agent, use `--app ANSWER` (=5).

**Mid-call control verbs** (each calls `ExecuteDialplan` server-side):

```bash
clutch transfer <call_sid> +15551234567       # RFC 3515 SIP REFER
clutch mute     <call_sid>                    # gateway-side TX silence
clutch mute     <call_sid> --wire             # also send recvonly re-INVITE
clutch unmute   <call_sid>
clutch hold     <call_sid>
clutch unhold   <call_sid>
clutch send-dtmf <call_sid> 5 --mode rfc2833 --duration-ms 200
```

Override targets via env: `CLUTCH_BASE_URL` (portal), `CLUTCH_DOCS_BASE` (docs site).

## Scaffolding agent-ready projects

`clutchcall init <lang> <name>` drops a working starter into your
working directory:

```bash
clutchcall init go      my-voice-agent
clutchcall init python  my-py-agent
clutchcall init typescript browser-demo
```

Each starter includes:

- A working dial / event-handling sample (`main.clutchcall` /
  `main.py` / `src/index.ts`) that compiles against the ClutchCall SDK.
- An **`AGENTS.md`** file tuned for that language. This is the file that
  agents read first when they enter the project — it captures the
  language-specific traps an agent will otherwise re-discover the hard way
  (e.g. "Emscripten corrupts byte arrays passed as `std::string`; use
  `typed_memory_view` instead").
- A `.clutchcall.json` project manifest with a pinned schema version
  for `clutchcall migrate`.

## Best practices for AI-assisted development

These mirror what works for any rapidly-evolving SDK; we mention them
because the ClutchCall wire format and method-ID table change between
minor releases.

1. **Browse before searching.** Have your agent fetch `/llms.txt` first so
   it knows what exists. Search excerpts are noisier than full pages.
2. **Fetch full pages, not excerpts.** Use `get_page` (MCP) or
   `get-page` (CLI) when you need authoritative answers. The grouped index
   is for navigation; the page itself is for code.
3. **Never hand-edit serde structs.** The Python, TypeScript, Go, Rust,
   Java, and .NET bindings are auto-generated by
   `clutchcall/tools/apirpc_compiler/generate_bridges.py`. If your
   agent wants to add an RPC field, it should update the upstream schema
   and regenerate, not patch the binding by hand.
4. **Run `clutchcall migrate` after bumping the SDK.** Surfaces
   schema drift before runtime does.

## Agent Skills

The [ClutchCall Agent Skills](https://github.com/clutchcall/agent-skills)
repository ships Anthropic-format Skills — opinionated, end-to-end recipes
that load into your coding agent's context when intent matches. Drop the
repo into `.claude/skills/` (Claude Code) or `.cursor/skills/` (Cursor) and
the agent gains task-specific knowledge for these workflows:

**Generic recipes**
- `clutchcall-pstn-dial` — outbound PSTN dialing (auth, originate,
  audio frames, hangup).
- `clutchcall-ai-bridge` — wire a live call to OpenAI Realtime /
  Anthropic / Gemini Live with barge-in.
- `clutchcall-call-events` — `CallEvent` stream consumption,
  reconnection, Q.850 cause handling.
- `clutchcall-inbound-routing` — `SetInboundRouting` →
  `AnswerIncomingCall`, IVR menus, queueing.
- `clutchcall-sip-trunk` — register a carrier (Twilio, Telnyx,
  Bandwidth, Plivo), caller-ID rules, codecs.
- `clutchcall-bulk-campaign` — `OriginateBulk` with CSV input,
  pacing, abort + resume.
- `clutchcall-recording` — per-call recording, stereo, retrieval,
  transcription.
- `clutchcall-tool-calling` — LLM tool / function calling: the
  built-in implicit telephony toolset (transfer / hold / DTMF /
  disconnect / supervisor), custom server-side tools, and client-side
  tool calls via OpenAI Realtime.
- `clutchcall-rag-integration` — pgvector / Pinecone / Weaviate
  retrieval as a tool call with latency budgets and barge-in safety.
- `clutchcall-crm-enrichment` — pre-call enrichment (Salesforce
  / HubSpot lookup → system prompt overrides) vs. in-call tool lookup.

**Vendor bridges**
- `clutchcall-vendor-browser-webrtc` — capture mic in the browser,
  send PCMU over WebTransport.
- `clutchcall-vendor-livekit` — bridge PSTN into a LiveKit room.
- `clutchcall-vendor-daily` — bridge PSTN into a Daily room
  (Pipecat-friendly).
- `clutchcall-vendor-chime` — Amazon Chime SDK Meetings or Voice
  Connector.
- `clutchcall-vendor-twilio` — bridge from existing Twilio Media
  Streams (TwiML `<Stream>`) into ClutchCall.
- `clutchcall-vendor-vapi` — bridge a Vapi.ai voice agent over
  Vapi's WebSocket transport.

Each skill is self-contained: prereqs checklist, working Python/TypeScript
code, "verify it works" snippet, common gotchas, and pointers back to the
docs MCP for deeper reference.
