# MCP server

> Connect an AI agent to Relvo over the Model Context Protocol

Source: https://app.relvoerp.com/docs/product/guides/mcp/

Relvo exposes a **Model Context Protocol** server, so an AI agent — Claude Code, your own SDK-based agent, anything that speaks MCP — can investigate invoices, customers, contracts, usage, payments, bank movements and reports, and work your operations task queue, without you writing an API client for it.

MCP is built for an agent asking questions. To feed a dashboard, a BI tool or a scheduled script, use the REST API instead: see [Reading data for dashboards](https://app.relvoerp.com/docs/product/guides/mcp.md#reading-data-for-dashboards-use-rest-not-mcp).

The boundary is deliberate and worth stating first:

- **Financial records are read-only by default.** No tool edits, voids or sends an invoice, a credit note or any other fiscal document, and none of them moves money. Issuing an invoice is possible only through the prepared-issuance workflow. Relvo enables it separately for each organization, and it needs `invoices:write` plus an explicit issuer permission.
- **The task queue is writable.** An agent can create tasks and move them through their state machine — assign, start, complete, cancel — in the same queue your team works in the Relvo dashboard.
- **Proposal decisions require human approval attested by the connected app.** The `operations:write` scope also permits approve/reject calls. Relvo checks the named operator's membership and role, but cannot independently prove a human clicked an approval button.

## Connect with an API token

```bash
claude mcp add --transport http relvo \
  https://app.relvoerp.com/api/mcp/ \
  --header "Authorization: Bearer rk_live_xxxxxxxxxxxxxxxxxxxx"
```

| | |
|---|---|
| URL | `https://app.relvoerp.com/api/mcp/` — **with the trailing slash** |
| Transport | Streamable HTTP |
| Auth | API token in `Authorization: Bearer <your Relvo API token>` |
| Organization | Carried by the token. There is no organization parameter or header on this surface |

Configure the trailing slash. The bare path `/api/mcp` answers a `307` redirect to `/api/mcp/`; most clients follow it, but some drop the `Authorization` header when they do, which then looks like an auth failure rather than a URL mistake.

## Get an API token

Mint an API token in the Relvo dashboard under **Developer Zone** (OWNER or ADMIN members only), exactly as described in [Authentication](https://app.relvoerp.com/docs/product/guides/authentication.md). The plaintext token is shown once, at creation.

Issue the **narrowest scope that does the job**. `full_access` is issuable and would hand a model every machine endpoint Relvo has — it is the wrong credential for an MCP client, always.

`operations:write` implies `operations:read`; `invoices:read` implies nothing else. For an agent that only investigates, a single `full_read` key covers every reviewed read tool and grants no writes. An agent that must also work the queue needs a second connection with an `operations:write` token, so each connection's blast radius stays legible.

## Connect with OAuth

Relvo also supports OAuth 2.1 for remote MCP clients that cannot accept a static
API token. Point the client to the MCP URL below; it discovers the authorization
server and takes the user through the Relvo consent flow.

| | |
|---|---|
| MCP URL | `https://app.relvoerp.com/api/mcp/` |
| Protected-resource discovery | `https://app.relvoerp.com/.well-known/oauth-protected-resource` |
| Authorization-server metadata | `https://app.relvoerp.com/.well-known/oauth-authorization-server` |
| Issuer | `https://app.relvoerp.com` |
| OAuth scopes | The `scopes_supported` list in the metadata above: the business `:read` scopes, plus `invoices:write`, `billing:write`, `contracts:write` and `operations:write`. Add `offline_access` for persistent access |

If your connector offers **Dynamic Client Registration**, select it and enter
the MCP URL. Relvo advertises `https://app.relvoerp.com/oauth/register`, where
the connector registers its own callback and receives a generated client ID.
You do not need an API key, client secret, or manually supplied client ID.
Then sign in to Relvo, choose your organization, and approve the requested scopes.
Self-registered client names are marked **Unverified:** on the consent screen.

Connectors may request any of the business scopes listed in `scopes_supported`; request only the ones the agent needs. For persistent
access, they register the `refresh_token` grant and request `offline_access`.
Access tokens last ten minutes; refresh tokens rotate and each successor lasts
30 days, so working refresh keeps the connection active without repeated login.

Manual OAuth configuration remains supported for clients without dynamic
registration. Relvo must register that client's exact callback first; use the
client ID supplied for that connector, not another connector's ID. Client scope
ceilings and organization consent still apply; OAuth never grants `full_access`.

## What the agent can do

Tools are grouped by the scope they require. Relvo turns tool families on per organization, so the authoritative list for your connection is what `tools/list` returns. Beyond the tables below, read families cover customers (`customers:read`), contracts (`contracts:read`), catalog and prices (`catalog:read`), taxes (`taxes:read`), FX (`fx:read`), billing schedules (`billing:read`), usage (`usage_events:read`), payment methods (`payment_methods:read`), banking (`banking:read`), reconciliation and unmatched cash (`reconciliation:read`) and reports (`reports:read`).

### `invoices:read`

| Tool | Answers |
|---|---|
| `relvo_invoices_search` | find invoices by text and by lifecycle / fiscal / payment / delivery status and issue-date range |
| `relvo_invoice_get` | one invoice in full |
| `relvo_invoice_check_open_readiness` | why a draft cannot be opened yet — findings, missing FX rates |
| `relvo_invoice_payment_status` | what has been paid against one invoice |

### `operations:read`

| Tool | Answers |
|---|---|
| `relvo_task_search` | find tasks by text, status, kind, priority, assignee, due date |
| `relvo_task_get` | one task, including its action proposals |

### `operations:write` — also grants operations reads

| Tool | Effect | Destructive |
|---|---|---|
| `relvo_task_create` | opens a new task, optionally carrying action proposals | no |
| `relvo_task_assign` | gives a task to a member, **by email** | no |
| `relvo_task_start` | OPEN → IN_PROGRESS | no |
| `relvo_task_complete` | OPEN / IN_PROGRESS → COMPLETED | yes |
| `relvo_task_cancel` | → CANCELLED | yes |
| `relvo_task_proposal_approve` | records the app-attested human approval and starts separate execution | yes |
| `relvo_task_proposal_reject` | records rejection with a required reason | yes |

Assignment is by email address and never by user id. No tool on this server returns a user, organization or membership id — resolving the email server-side, against the caller's own organization, is the only shape that cannot be used to probe for user ids belonging to another tenant.

## Reading data for dashboards: use REST, not MCP

An MCP tool answers one question for one agent turn. Its pages hold at most 50 records, and a model reads every page before it answers. Reading a whole ledger that way takes hours. A dashboard, a BI export or a nightly script should call the [REST API](https://app.relvoerp.com/docs) directly:

1. Issue a key with the [`full_read`](https://app.relvoerp.com/docs/product/guides/authentication.md#read-only-keys-full_read) scope. It reads everything a dashboard needs and can write nothing.
2. Page every list with `?limit=200` and follow `next_cursor` until it is `null`.
3. Stay inside the [rate limits](https://app.relvoerp.com/docs/product/guides/authentication.md#rate-limits): 600 requests per minute per key, about 120,000 records a minute at 200 per page.

```bash
curl "https://app.relvoerp.com/api/v1/public/invoices?limit=200" \
  -H "Authorization: Bearer rk_live_xxxxxxxxxxxxxxxxxxxx"
```

| Dashboard data | REST resource | Scope |
|---|---|---|
| Invoices | `GET /invoices` | `invoices:read` |
| Usage | `GET /usage-events` | `usage_events:read` |
| Customers | `GET /customers` | `customers:read` |
| Contracts | `GET /contracts` | `contracts:read` |
| MRR and receivables | `GET /reports/mrr`, `GET /reports/receivables-aging/customers` | `reports:read` |
| Payments | `GET /payments` | `payments:read` |
| Unmatched receipts (*pagos sin identificar*) | `GET /reconciliation/unmatched-receipts`, `/by-counterparty`, `/totals` | `reconciliation:read` |

Every path is relative to `https://app.relvoerp.com/api/v1/public`. `full_read` covers every scope in the table. Keep MCP for what it is good at: an agent investigating why one invoice, customer or payment looks wrong.

## Retries are replays, not duplicates

MCP has no `Idempotency-Key` header, so Relvo derives one for you from the tool name, the organization and the validated arguments — the same guarantee as [Idempotency](https://app.relvoerp.com/docs/product/guides/idempotency.md) on the REST API, without the bookkeeping. An agent that retries `relvo_task_create` with identical arguments gets **the same task back**, not a second task.

When you genuinely mean "again" — the same daily task, a second time — pass a different `request_marker` on the write tool. Without it, a repeat is a replay, which is the safe default.

## Client compatibility

The same MCP endpoint supports two credential types: a static API token for
header-capable clients, and OAuth 2.1 for remote connectors. Do not copy an API
token into a client that supports OAuth; use the consent flow instead.

| Client | Works | How |
|---|---|---|
| Claude Code | ✅ | the `claude mcp add` command above |
| Your own agent, any MCP SDK | ✅ | Streamable HTTP plus the `Authorization` header |
| `mcp-remote` and similar proxies | ✅ | pass the header through; useful for stdio-only hosts |
| Claude remote connectors (claude.ai, Desktop, and mobile) | ✅ | OAuth 2.1 discovery and consent |
| ChatGPT custom MCP app (web) | ✅ | OAuth discovery, PKCE, and `offline_access` provide persistent read-only access when the registered client permits it |
| ChatGPT mobile | ❌ | ChatGPT custom MCP apps are currently web-only |

OAuth access tokens are short-lived. Request `offline_access` only for a client
registered to allow it; Relvo then issues rotating refresh tokens. It is a
persistence capability, not a data permission, and the consent screen still
names the business scopes the client requests.

## When something fails

Tool failures come back as **tool errors** — an error flag plus a `{code, message, retryable}` body — rather than protocol errors, so the agent can read the message and act on it.

| Code | Cause |
|---|---|
| `mcp.unauthenticated` | no valid API token or OAuth access token on the request — including a browser session reaching the endpoint, which is rejected on purpose |
| `mcp.forbidden` | the token's scope does not cover that tool. The tool never ran |
| `mcp.invalid_arguments` | the arguments failed validation |
| `mcp.not_found` | the id does not exist **in your organization**. A record belonging to another tenant is indistinguishable from a missing one, deliberately |
| `mcp.conflict` | a state guard or a concurrent edit — for example completing a task someone else already cancelled. `retryable` tells you which: reload with `relvo_task_get` and decide |
| `mcp.unavailable` | a genuine server-side problem. This is the only one worth retrying blindly |

A `307` followed by a `401` is not an auth problem — it is the missing trailing slash, and a client that dropped the header on the redirect.
