# AI Connector

Connect Claude, ChatGPT, Claude Code or another AI assistant to your OnCharge store, then ask it about your ad spend, sales and return on ad spend in plain English. The connector is an [MCP](https://modelcontextprotocol.io) server. It is read-only: the assistant can look at your ads and payments, but it can't change anything.

> Only an owner or admin of a store can connect an assistant. Each connection covers one store.

## Connect your assistant

The connector's address is:

```text
https://app.oncharge.io/api/mcp
```

It is also in the merchant portal under **Settings → AI Connector**.

**Claude (claude.ai or the desktop app).**

1. Open **Settings → Connectors** and press **Add custom connector**.
2. Name it OnCharge and paste the address.
3. Press **Add**, then **Connect**.
4. In the OnCharge window, sign in, pick the store and press **Allow**.

**ChatGPT.**

1. Open **Settings → Apps & Connectors → Advanced settings** and turn on **Developer mode**.
2. Press **Create**, paste the address and set authentication to **OAuth**.
3. Sign in to OnCharge, pick the store and press **Allow**.

**Claude Code.**

```bash
claude mcp add --transport http oncharge https://app.oncharge.io/api/mcp
```

Then type `/mcp`, choose **oncharge** and **Authenticate**.

**Other assistants.** Any MCP client that supports Streamable HTTP and OAuth 2.1 with dynamic client registration can connect the same way.

## What the assistant can see

| Tool | Needs | What it returns |
|---|---|---|
| `get_store` | either | The store, what the connection may see, and its linked ad accounts, pixels and catalogs. |
| `get_revenue` | Payments | Paid orders, gross revenue, refunds and net revenue per currency, with disputes opened. It can break these down by day, by ad channel or by `utm_campaign`. |
| `list_recent_orders` | Payments | The latest paid orders: amount, refunds, status and ad channel. |
| `get_ad_spend` | Ads | Spend, impressions, clicks, CTR and CPC per ad platform, with the conversions and ROAS the platforms report. It can break these down by day or by ad account. |
| `list_campaign_plans` | Ads | Google and TikTok campaigns OnCharge runs for the store, with their status and budget. |
| `get_true_roas` | Ads and Payments | Each platform's spend against the revenue OnCharge actually took from shoppers who clicked its ads, next to the ROAS the platform reports. |

- No shopper names, emails, phone numbers or addresses are ever sent to the assistant.
- No API keys or ad platform credentials are sent either.
- Money is in major units (`49.5` is $49.50) next to its currency. Currencies are never converted.

## True ROAS

Ad platforms count conversions their own way. Their totals can include view-through and modelled conversions, and orders that were refunded later.

`get_true_roas` uses the payments OnCharge processed instead. Each order is credited to the ad platform of the shopper's last recorded click:

- The click ID from the landing URL, if there is one: `fbclid`, `gclid`/`gbraid`/`wbraid` or `ttclid`.
- Otherwise, Meta's `_fbc` cookie.

The OnCharge tag or plugin records that click at checkout (see [Advertising](https://oncharge.io/docs/advertising)). Refunds are subtracted, and spend comes from the ad accounts connected in the portal.

Two caveats:
- Facebook also adds `fbclid` to clicks on unpaid posts, so some organic Facebook sales can count as Meta.
- Orders from storefronts without the OnCharge tag can't be credited to any platform.

## Try asking

- "What was my true ROAS on Meta last month, and how does it compare with what Meta reports?"
- "Which `utm_campaign` brought in the most revenue over the last 30 days?"
- "How much did I spend on ads this week, and how much did refunds cost me?"

## Disconnect

Go to **Settings → AI Connector** and press **Disconnect**. You can also remove the connector in your assistant, which revokes its tokens.

Access ends immediately in both cases. It also ends straight away for any connections made by someone you remove from your OnCharge account.

## For developers

The connector follows the [MCP authorization spec](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization). OnCharge is both the authorization server and the protected resource.

| | |
|---|---|
| MCP endpoint | `POST https://app.oncharge.io/api/mcp`. Streamable HTTP in stateless JSON mode; `GET` returns 405 because there is no server-sent event stream. |
| Protected resource metadata | `https://app.oncharge.io/.well-known/oauth-protected-resource/api/mcp` |
| Authorization server metadata | `https://app.oncharge.io/.well-known/oauth-authorization-server` |
| Client registration | `POST /api/oauth/register` ([RFC 7591](https://www.rfc-editor.org/rfc/rfc7591)). Public clients only (`token_endpoint_auth_method: none`). Redirect URIs must use `https`, loopback `http` or a private-use scheme. |
| Authorization | `/oauth/authorize`: authorization code with PKCE (`S256` only). `resource` must be the MCP endpoint. The response includes `iss` ([RFC 9207](https://www.rfc-editor.org/rfc/rfc9207)). |
| Token | `POST /api/oauth/token` with `authorization_code` or `refresh_token`. Access tokens last 1 hour. Refresh tokens last 60 days and rotate on every use; reusing one disconnects the app. |
| Revocation | `POST /api/oauth/revoke` ([RFC 7009](https://www.rfc-editor.org/rfc/rfc7009)). Revoking a refresh token disconnects the app. |
| Scopes | `ads:read` and `payments:read`. Both are granted when none are requested. |
