# Roofpeace agent API

Roofpeace is a roofing business operating backend. Muse and other agents use
HTTPS JSON endpoints at `https://roofpeace.com/api/v1`; no browser login, UI
automation, signup, or email approval is needed by an agent.

**MCP server:** `https://roofpeace.com/api/mcp` (streamable HTTP). Clients that
support OAuth, such as Muse, Claude and ChatGPT, connect with no key: a company
owner or admin signs in and approves. See [MCP server](#mcp-server) below.

## Start

1. A company owner or admin visits `/settings/agent-access`, opens "API keys for
   developers", names the key, chooses view only or view and change, then creates
   it. Admins' keys work while they remain an admin. The company must already have
   an active plan or trial; activation happens at `/onboarding/billing`.
2. The person who made it places the one-time `rp_live_...` key in the agent's
   secret store. Never put it in chat, URLs, source files, logs or research attachments.
3. Read `/api/v1/openapi.json`. Send `Authorization: Bearer <stored key>`.
4. Call `GET /me`. Verify `org_id`, company name, `scopes`, `expires_at`, and
   `access_active`. Stop on a company mismatch. `GET /me` remains available
   for a valid key even when company billing has expired.
5. Perform only actions within the granted scopes and the person's task.

The agent needs ordinary HTTP access and secure secret storage, not a Roofpeace
SDK, browser session or Muse-specific plugin. Use one key per agent so attribution
and revocation remain independent.

## Free roofing estimate PDF (no key)

`POST https://roofpeace.com/api/estimate-template` needs no account or key. Use the
contractor's own prices; Roofpeace supplies none and does not save the estimate
(one waiting to be emailed is kept until it is sent, at most a day).
Without `send_to` the response is the PDF. With `send_to` it returns 202 JSON and
emails that address a link; the PDF is sent once they tap "Send my estimate" (the
link lasts a day). The confirmed address and company name are kept as a sales lead.
Only send to someone who asked for it, and tell them about the follow-up.

```bash
curl -X POST https://roofpeace.com/api/estimate-template \
  -H "Content-Type: application/json" \
  -o roofing-estimate.pdf \
  -d '{"company":"Mesa Roofing","customer":"Pat Lee","address":"123 Main St",
       "lines":[{"description":"Install architectural shingles","quantity":24,
                 "unit":"square","price":425,"waste":10}],
       "tax_percent":8.25,"deposit_percent":50,"terms":"Net 15."}'
```

- `lines` (required, up to 100): `description`, `quantity`, `price`, optional `waste`
  percent, and `unit`: `square`, `linear ft`, `sheet`, `each` (default) or `load`.
- Optional: `details`, `phone`, `email`, `tax_percent`, `deposit_percent`, `terms`,
  `date`, `send_to`, and `logo` as a PNG or JPEG data URL.
- Limits: 30 requests an hour per connection. Emails: 5 an hour per connection and 3
  a day per address. Errors return JSON with `detail`: 422 for bad input, 429 with
  `Retry-After` when limited, and 502 if an email fails to send. An address that
  unsubscribed or complained gets 422.

## Permissions and operations

All paths below are relative to `/api/v1`.

<!-- generated:permissions -->
| Permission | Operations |
|---|---|
| `jobs:read` | GET `/jobs`; GET `/jobs/{job_id}` |
| `jobs:write` | POST `/jobs`; PATCH `/jobs/{job_id}`; PATCH `/jobs/{job_id}/state` |
| `research:write` | POST `/research` |
| `workspace:read` | GET `/service-areas`; GET `/buildings`; GET `/buildings/{building_id}`; GET `/strikes`; GET `/strikes/{strike_id}` |
| `workspace:write` | POST `/service-areas` |
| `crm:read` | GET `/crm/pipeline`; GET `/crm/buildings/{building_id}/summary`; GET `/crm/inquiries/{inquiry_id}/summary` |
| `crm:write` | POST `/crm/buildings/{building_id}/notes`; PATCH `/crm/buildings/{building_id}/stage`; POST `/crm/inquiries/{inquiry_id}/notes`; POST `/crm/buildings/{building_id}/tasks`; POST `/crm/inquiries/{inquiry_id}/tasks` |
| `marketing:read` | GET `/marketing/ads`; GET `/marketing/leads`; GET `/marketing/learning`; GET `/marketing/feedback`; GET `/marketing/feedback/{id}` |
| `marketing:draft` | POST `/marketing/ads/{ad_id}/revisions`; PATCH `/marketing/ad-revisions/{revision_id}`; POST `/marketing/ad-revisions/{revision_id}/comments` |
<!-- /generated:permissions -->

New keys default to read-only workspace/CRM/marketing/jobs access.
Writes must be selected explicitly. Existing keys retain their existing scopes.
Internal founder keys are separate, read-only, and cannot be issued by customers.

## Directory profiles

Directory ownership is separate from company membership. An agent needs the
explicit `directory:write` permission and a currently verified, unbanned delegated
Roofpeace account. Verification is checked on every request. Existing keys do not
receive this permission automatically. An approved claim is required for edits to
each individual business; company access alone never grants directory ownership.

Use `GET /api/directory?slug=overture-UUID` to read your claim and approved fields.
Use `POST /api/directory` with a JSON body and the same bearer key:

- Claim: `{ "action": "claim", "slug": "overture-UUID", "id": "UUID", "evidence": "Your role and evidence (20-3000 characters)" }`.
- Edit: `{ "action": "edit", "slug": "overture-UUID", "id": "UUID", "revision": 0, "fields": { "business_name": "Name", "phone": "", "website": "", "business_type": "unknown", "description": "", "service_areas": "" } }`.

Reuse the body `id` for retries. Read the current revision before submitting an
edit. A 409 means the listing changed or another change is awaiting review.
Business types are `unknown`, `residential`, `commercial`, `both`, `supplier`,
and `manufacturer`. Claims and edits enter a private review queue. Agents cannot
approve claims, publish edits, classify businesses, or resolve reports. New contact
links remain hidden until a verified human reviewer corroborates them. The public
search and business profiles remain available without an account.

## MCP server

Roofpeace also serves the Model Context Protocol at `https://roofpeace.com/api/mcp`
(streamable HTTP, stateless). MCP clients that support OAuth, such as Muse, connect
without a key: the server's 401 points to
`/.well-known/oauth-protected-resource/api/mcp`, and a company owner or admin signs
in and chooses view-only or view-and-update access. Someone who runs more than one
company picks which one. Clients register dynamically, use PKCE and send
`resource=https://roofpeace.com/api/mcp`. Owners and admins disconnect the agent at
`/settings/agent-access`. Other clients can use a key made there:

```sh
claude mcp add --transport http roofpeace https://roofpeace.com/api/mcp \
  --header "Authorization: Bearer $ROOFPEACE_AGENT_KEY"
```

Only tools allowed by the key's scopes are listed. Tool calls are recorded like
API requests. Write tools take an `idempotency_key`; reuse it when retrying.

<!-- generated:mcp-tools -->
| Tool | Scope | Purpose |
|---|---|---|
| `get_workspace` | any | Company and permissions |
| `list_jobs` | `workspace:read` | List jobs |
| `get_job` | `workspace:read` | Get a job |
| `list_invoices` | `workspace:read` | List a job's invoices |
| `list_supplements` | `workspace:read` | List a job's supplements |
| `get_quote` | `workspace:read` | Get a job's quote |
| `list_tasks` | `workspace:read` | List open tasks |
| `list_team` | `workspace:read` | List the team |
| `add_job_note` | `crm:write` | Add a note to a job |
| `add_job_task` | `crm:write` | Add a task to a job |
| `set_job_stage` | `crm:write` | Move a job to a stage |
| `update_job_details` | `crm:write` | Correct a job's address or customer |
| `set_job_main_contact` | `crm:write` | Choose a job's main contact |
| `add_person_to_job` | `crm:write` | Put someone on a job |
| `set_agreement_status` | `crm:write` | Set a job's agreement status |
| `search_workspace` | `workspace:read` | Search everything |
| `set_claim_decision` | `crm:write` | Set what the carrier decided on a claim |
| `ask_for_reinspection` | `crm:write` | Ask the carrier for a re-inspection |
| `set_work_type` | `crm:write` | Make a job insurance or retail |
| `find_contacts` | `workspace:read` | Find contacts |
| `get_contact` | `workspace:read` | Get a contact |
| `add_contact` | `crm:write` | Add a contact |
| `get_money` | `workspace:read` | Money owed to the company |
| `get_schedule` | `workspace:read` | Production schedule |
| `list_paperwork` | `workspace:read` | Supplier paperwork waiting |
| `list_licenses` | `workspace:read` | Licenses and insurance |
| `start_license_renewal` | `crm:write` | Track a license or policy renewal |
| `record_license_renewal` | `crm:write` | Record a renewed license or policy |
| `get_today` | `crm:read` | Today's calls and follow-ups |
| `get_lead` | `crm:read` | One website lead |
| `list_storm_alerts` | `workspace:read` | Recent storm alerts |
| `get_door_list` | `workspace:read` | Ranked, routed door list for a storm alert |
| `search_properties` | `workspace:read` | Search ranked properties |
| `get_property` | `workspace:read` | Property detail |
| `get_roof_code` | `workspace:read` | Roof insulation code |
| `record_door_outcome` | `crm:write` | Record a door outcome |
| `add_follow_up_task` | `crm:write` | Add a follow-up task |
| `check_coverage` | any | Check coverage |
| `get_website_copy` | `marketing:website` | Read website copy |
| `edit_website_copy` | `marketing:website` | Edit website copy |
| `submit_research` | `research:write` | Submit sourced research |
<!-- /generated:mcp-tools -->

Read tools accept `detail: "concise" | "detailed"`; concise is the default.

## Return research

POST `/research` with `Content-Type: application/json` and a unique
`Idempotency-Key` header:

```json
{
  "observation": "The source describes a repeated manual handoff.",
  "source": "Interview or publication title",
  "received_on": "2026-09-22",
  "evidence_url": "https://example.com/source",
  "hypothesis": "Sharing the job record might reduce repeated entry.",
  "proposed_change": "Ask the team to validate this with a real job."
}
```

`observation`, `source`, `received_on`, and HTTP(S) `evidence_url` are required.
Separate observed facts from hypotheses. No server fetch of that URL occurs.
Findings are attributed to the agent and saved as `new`/`pending` in Marketing
research. Agents cannot declare a reviewed outcome, overwrite human research,
or qualify leads. Read them back through `/marketing/feedback` when granted
`marketing:read`. To correct a finding, submit a new observation referencing it.

## Reliable writes

Every mutation requires a stable `Idempotency-Key` (1–100 characters). Retry the
same method, path, key and JSON payload after a transport error; successful
retries return the original result with `Idempotent-Replay: true`. Reusing the
key with different data returns 409. Honor `Retry-After` for in-progress writes.
Never change the idempotency key just to bypass an ambiguous failure.

POST `/jobs` accepts `title`, `source` (`property` or `inquiry`) and the matching
`building_id` or `inquiry_id`; optional `assigned_operator_user_id` must be a
company member. PATCH `/jobs/{id}` edits title/assignment; PATCH `/jobs/{id}/state` accepts
`{ "state": "active" }` and enforces allowed transitions.
Read current records before editing and use returned IDs rather than inventing
people, measurements, prices, conversations or completion claims.

For notes use `{ "body": "..." }`. For tasks use `title`, optional `details`,
`due_at`, and a verified `assigned_operator_user_id`. Omission leaves the task
unassigned. Neither action sends a message.

## Errors, renewal and revocation

- 401: missing, expired or revoked key. Stop; ask the person who made it for a replacement.
- 403: insufficient scope, disabled agent or changed ownership. Do not bypass it
  with browser cookies or owner credentials.
- 402: inactive company. Give the owner `/onboarding/billing`; do not purchase
  a subscription or repeatedly retry work.
- 404: unavailable/foreign record or unsupported endpoint.
- 409: conflicting/replayed mutation or invalid transition; inspect before retrying.
- 422: invalid inputs; correct the reported fields.
- 429: honor `Retry-After` where returned and back off.

Owners can rotate or revoke at `/settings/agent-access`. Rotation invalidates all previous
keys for that agent and issues a 90-day replacement. Initial expiry is 1–365 days
(default 90). Lost keys cannot be recovered; rotate. Revocation rejects subsequent
requests; it does not undo work already committed or cancel an in-flight request.
A revoked agent stays disabled; create a new explicit grant to restore access.

No agent endpoint manages keys, billing, teammates, provider connections, signing
approval/sends, or ad publication. Research submission does not approve or publish
anything. Agents must not use UI automation to bypass these boundaries.

Legacy `/enrollments`, status/claim and email-approval routes return 410. They no
longer send email, create companies or issue keys. Already-issued credentials
continue to work until expired, rotated or revoked.
