> ## Documentation Index
> Fetch the complete documentation index at: https://docs.newlead.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP server

> Connect an AI assistant to NewLead with the Model Context Protocol: the URL, sign-in, permissions, tools and limits.

NewLead runs a remote [Model Context Protocol](https://modelcontextprotocol.io) server. An assistant that supports MCP, such as Claude or ChatGPT, can use it in two ways:

* to read your leads, conversations, calls, figures and balance, and what needs attention;
* if you allow it, to write to leads, call them and update them, and to mark leads and alerts as handled.

It works on the same data and rules as the [API](https://docs.newlead.ai/index.md), and it needs no API key.

```text theme={null}
https://mcp.newlead.ai/mcp
```

To connect Claude or ChatGPT step by step, see [Connect NewLead to Claude or ChatGPT](https://docs.newlead.ai/guide/getting-started/connect-claude-chatgpt.md).

## Connection

* **Transport:** Streamable HTTP, without sessions. Every tool call says which subaccount it acts on, so nothing depends on an earlier call.
* **Sign-in:** OAuth 2.1 with the person's NewLead account, as a public client with no secret.
  * A client registers itself with dynamic client registration (RFC 7591), or with a client ID metadata document.
  * It must use PKCE with `S256` and send `resource=https://mcp.newlead.ai/mcp` (RFC 8707).
  * Redirect URIs must be `https`, or `http` on a loopback address, written exactly as the URL resolves: no credentials (`user@host`), fragment, backslash, whitespace or `..` segments. The same goes for the URL of a client ID metadata document.
* **Discovery:** a request without a valid token returns `401` with a `WWW-Authenticate` header pointing to `https://mcp.newlead.ai/.well-known/oauth-protected-resource/mcp`, which names the authorization server. Its metadata is at `https://mcp.newlead.ai/.well-known/oauth-authorization-server`.
* **Tokens:** an access token lasts one hour and a refresh token 30 days. Each refresh returns a new refresh token; reusing an old one more than a minute after it was replaced ends the connection.
* **What a connection reaches:** every subaccount the person can open in the dashboard, with their role there. A subaccount, agent or lead they can't see returns `resource_not_found`, the same as one that does not exist. A paused subaccount can be read but not changed, except that `resolve_alert` still closes its alerts, as in the dashboard.

## Permissions

> [!WARNING]
>
> Whatever the assistant reads, such as conversations, phone numbers and call transcripts, is sent to Anthropic or OpenAI under the account of the agency that holds them. What a lead writes is read by the assistant too, so a message can try to steer it. Leave **Act** unticked if you don't need it, and review each action before you approve it.

| Permission | What it allows |
| - | - |
| `mcp:read` | Read leads, messages, calls, agents, properties, metrics, the balance, the leads that need attention and the alerts. Always granted. An agent's setup, metrics, the balance, attention and alerts also depend on the role: see [Roles](#roles), [Metrics and balance](#metrics-and-balance) and [Attention and alerts](#attention-and-alerts). |
| `mcp:act` | Send messages, templates and files, place calls, opt leads out or back in, pause or resume the AI, create or update leads, mark leads as contacted and resolve alerts. The person can untick **Act** on the consent screen. |

* A connection without `mcp:act` doesn't list the tools that act. Calling one returns a JSON-RPC error (`-32602`, tool not found), not a tool result. To use them, connect again and leave **Act** ticked.
* Acting also needs a role that can do the same in the dashboard. See [Roles](#roles).
* To change the permissions, revoke the connection in **Settings › Connected apps** and connect again. If the client asks only to read, **Act** doesn't appear.
* With `mcp:admin` (**Administer**) it can also create and set up text and voice agents: see the tools marked Administer in [Tools](#tools). It can't delete agents or leads, connect WhatsApp, Lead Ads, Instagram, email, a calendar or a phone number, manage billing or top up a wallet. Those stay in the dashboard: `get_connect_link` returns the link to the right panel.

### Roles

A tool that acts checks the person's role in the subaccount, with the same rule as the dashboard:

| Tools | Who can use them |
| - | - |
| `create_lead`, `update_lead`, `set_do_not_contact`, `pause_ai`, `resume_ai`, `send_message`, `send_template`, `send_media`, `mark_attended`, `undo_attended` | Any role that can open the subaccount |
| `place_call` | Every role except **Subaccount Manager** and **Subaccount User**, the same roles that can't set up agents |
| `resolve_alert` | Every role except **Subaccount Manager** and **Subaccount User**, the same roles that see alerts in the dashboard |

A role that can't use a tool gets `role_forbidden`. So does a role that calls `get_metrics`, `get_balance`, `list_attention` or `list_alerts` for something it doesn't see in the dashboard. [Team and roles](https://docs.newlead.ai/guide/getting-started/team-and-roles.md) describes each role.

`get_agent` returns an agent's lead fields, qualification questions and templates only to the roles that set up agents in the dashboard. Every role except **Subaccount Manager** and **Subaccount User** sees them; the rest get the agent alone, with a `note` that says why. `list_agents` returns the same to every role, without any agent's setup.

## Tools

Every tool takes a required `subaccount_id`, except `whoami` and `list_subaccounts`. In `get_balance` it is optional.

| Tool | What it does | Permission |
| - | - | - |
| `whoami` | The person who connected (`user`), their `organizations`, the granted `scopes` and the app (`client`) | Read |
| `list_subaccounts` | The subaccounts the person can open, with `search` by name | Read |
| `list_agents` | The text and voice agents of a subaccount | Read |
| `get_agent` | A text agent, with its lead fields, qualification questions and templates for the roles that set up agents | Read |
| `get_agent_config` | Everything that can be edited on a text or voice agent, with its full instructions (and greeting) and their current `version_ids`, for the roles that set up agents | Read |
| `list_instruction_versions` | The saved versions of an agent's instructions or greeting, or one version with its text | Read |
| `get_connect_link` | The dashboard link where the person connects a channel to an agent: WhatsApp, Instagram, Meta Lead Ads, email, Google Calendar, the webchat or a phone number | Read |
| `search_leads` | Search and filter leads, as [`GET /v1/leads`](https://docs.newlead.ai/api-reference/leads/list-leads) | Read |
| `get_lead` | A lead, with whether it was opted out and why | Read |
| `list_messages` | A lead's messages, with links to their attachments | Read |
| `list_calls` | Calls, with a link to the recording and `transcript_ready`, without the transcript | Read |
| `get_call` | A call, with its transcript and a link to the recording | Read |
| `list_properties` | The property catalog | Read |
| `get_metrics` | The figures of a period, as [`GET /v1/metrics`](https://docs.newlead.ai/api-reference/metrics/get-metrics) | Read |
| `get_balance` | The wallet balance of a subaccount or of the agency | Read |
| `list_attention` | The leads in the dashboard's three queues, with the reason each one waits | Read |
| `list_alerts` | The open alerts of the subaccount's agents | Read |
| `create_lead` | Create a lead | Act |
| `update_lead` | Change a lead's name, status and variables | Act |
| `set_do_not_contact` | Opt a person out, or back in, with a reason | Act |
| `pause_ai`, `resume_ai` | Pause or resume the AI for a lead | Act |
| `send_message` | Send a text message to a lead | Act |
| `send_template` | Send a WhatsApp template to a lead | Act |
| `send_media` | Send an image, a document, an audio or a video to a lead | Act |
| `place_call` | Have a voice agent call a lead | Act |
| `mark_attended`, `undo_attended` | Mark a lead as contacted, as **Already contacted** in the dashboard, or undo it | Act |
| `resolve_alert` | Mark an alert as resolved | Act |
| `create_text_agent`, `update_text_agent`, `set_qualification`, `set_business_hours`, `set_follow_ups`, `set_finish_conversation`, `set_platform_skill`, `set_notification_recipients`, `set_webchat`, `create_template`, `set_template_roles`, `set_agent_active`, `test_text_agent`, `create_voice_agent`, `update_voice_agent`, `restore_instruction_version` | Set up text and voice agents | Administer |
| `set_lead_fields` | Replace the lead fields of a text or voice agent: the data the AI gathers from each lead and the tags the team filters by | Administer |

The tools carry hints that help the assistant decide when to ask before running one:

* the tools that only read are marked `readOnlyHint`;
* `set_do_not_contact`, `undo_attended`, `resolve_alert` and `set_agent_active` are marked `destructiveHint`;
* `send_message`, `send_template`, `send_media`, `place_call` and `set_template_roles` are marked `destructiveHint` and `openWorldHint`, because they reach a person outside NewLead: assigning the first-contact template sends it by WhatsApp to up to 100 of the agent's email leads that were waiting for a first message, as the dashboard does;
* `create_template` and `set_platform_skill` are marked `openWorldHint`, because they send templates to Meta for review: a new template, or the WhatsApp notification templates when WhatsApp notifications are switched on.

`create_lead` needs a text agent and a phone number, and updates the lead if that agent already has one with that phone.

On WhatsApp, outside the 24-hour window `send_message` goes out as the agent's reopening template. On Instagram, or if the agent has no approved reopening template, it fails with `messaging_window_closed`.

To send or call a phone number with no lead, create the lead first with `create_lead`. That way every message goes through the person's opt-out and the agent's rules.

## Results

* Each successful result carries its object in `structuredContent`: the same as the API's, or one that only the MCP server has, such as `subaccount`, `agency_balance`, `attention_lead`, `attended_mark` and `alert`. Its `content` has two text blocks: a short summary, and the same object as JSON for clients that don't read `structuredContent`.
* Lists take `limit` (1 to 50, 20 by default) and `cursor`, and return `next_cursor`. The exception is `list_agents`, which returns every agent at once.
* A failed call returns a result with `isError: true` and `structuredContent.error`, with the code, type and message of the [API error](https://docs.newlead.ai/errors.md), such as `lead_do_not_contact` or `messaging_window_closed`. Two codes belong to the MCP server and aren't in the API catalog, both `permission_error`: `insufficient_scope` and `role_forbidden`. Messages name tools and arguments, such as `send_message` or `idempotency_key`, not API routes or headers. Its `content` is one text block, `code: message`, followed by `Retry after N s.` when the error carries `retry_after_sec`. There is no `request_id` and no HTTP status.
* Arguments that don't match a tool's schema never reach the tool: a malformed id, a `limit` above 50, a phone that isn't E.164 or, in the tools that act, an argument the tool doesn't have. That result has `isError: true` and only a text message, with no `structuredContent` and no code. Calling a tool that doesn't exist returns a JSON-RPC error (`-32602`), not a result.
* The tools that send or call accept an optional `idempotency_key`, which works like [`Idempotency-Key`](https://docs.newlead.ai/idempotency): the same key with the same arguments returns the first result instead of sending again. A key is valid for 24 hours, per person, client and subaccount. The same key with other arguments returns `idempotency_key_reused`. Always pass one.
* The role is checked before the key, and `place_call` also checks first whether the AI is paused for the lead or the lead opted out. So a retry can return `role_forbidden`, `lead_ai_paused` or `lead_do_not_contact` instead of the stored result.
* If the key can't be checked, nothing is sent or called and the result is `provider_unavailable`: retry with the same key. The API does this only for calls, and processes messages [without the protection](https://docs.newlead.ai/idempotency.md#when-the-key-cannot-be-checked).
* What a person handles from the MCP server is handled in the dashboard too. A message, template or file that `send_message`, `send_template` or `send_media` sends counts as **Already contacted** when the lead required contact or had never written, the same as a message written by hand in the dashboard: the lead leaves the queues, its team notices and lead alerts close, and its history says it was handled from an AI assistant. As with a message written by hand, the conversation shows the message and no separate line. A send that fails or returns `send_outcome_unknown` doesn't count, and neither does a send through the API, where an integration sends and not a person. See [Attention and alerts](#attention-and-alerts).
* If a send or a call returns `send_outcome_unknown`, don't send or call again. It may have gone through: check `list_messages`, or `list_calls` for a call. The same key keeps returning that result.
* The links to attachments (`list_messages`) and recordings (`list_calls`, `get_call`) are signed and valid for one hour. Anyone who has the link can open the file until it expires, so treat it like the conversation itself.

## Metrics and balance

`get_metrics` returns the same object as [`GET /v1/metrics`](https://docs.newlead.ai/api-reference/metrics/get-metrics):

* the leads that came in during the period and how far each one got, as in **Analysis**;
* the median time to the agent's first contact;
* new leads by channel, billable conversations, calls and call minutes.

The days are calendar days in Europe/Madrid. A period lasts at most 92 days; without `from` and `to`, it covers the last 7.

The figures are not live. The leads and the median are cached for 5 minutes. The other counts are rebuilt every 5 minutes and can be cached for 1 more.

A **Subaccount User** can't read metrics, as in the dashboard: `get_metrics` returns `role_forbidden`.

With `subaccount_id`, `get_balance` returns the same object as [`GET /v1/balance`](https://docs.newlead.ai/api-reference/account/get-the-wallet-balance). When the agency pays the subaccount's usage, `mode` is `manual` and `wallet` is `null`. The agency roles and the client's **Subaccount Owner** and **Subaccount Admin** can read it. A **Subaccount Manager** or **Subaccount User** gets `role_forbidden`.

Without `subaccount_id`, it returns the wallet of your agency, which only the **Owner** and **Agency Admins** can see. Anyone else gets `role_forbidden`. `wallet` is `null` when the agency doesn't pay from a prepaid wallet.

```json theme={null}
{
  "object": "agency_balance",
  "organization": { "id": "00000000-0000-4000-8000-000000000001", "name": "Your agency" },
  "wallet": {
    "available_eur": "120.50",
    "courtesy_margin_limit_eur": "20.00",
    "courtesy_margin_used_eur": "0.00",
    "spendable_eur": "140.50",
    "frozen": false,
    "auto_top_up": true
  }
}
```

## Attention and alerts

`list_attention` returns the leads of the dashboard's three queues, each with its `queue` and `reason`:

* `no_contact`: it never got a first message, with the reason, such as `no_phone` or `delivery_rejected` (with Meta's reason in `failure`);
* `waiting`: the agent asked for a person, with its notice in `detail`, or the lead wrote again after opting out (`dnc_return`);
* `no_reply`: it got the first message and never replied, with the follow-ups sent in `detail`.

`no_contact` and `no_reply` look at the leads that came in during `period`, `last_30d` by default as in the dashboard. `waiting` has no period. Each queue lists all its leads, newest first, where the dashboard shows only the first ones of each group. A **Subaccount User** can't see the queues, as in the dashboard, and gets `role_forbidden`.

Sending a lead a message takes it off the queues, except a `dnc_return` lead, who opted out, and a `no_phone` lead, who has no number to write to. Those leave only with `mark_attended`.

`mark_attended` does what **Already contacted** does in the dashboard: the lead leaves the queues, its open team notices close, its lead alerts (`first_contact_failed` and `lead_dnc_return`) are resolved and it no longer requires contact. It returns an `attended_mark`; `undo_attended` with its `id` as `mark_id` leaves everything as it was, unless someone marked the lead again since. The lead's history in the dashboard shows who marked it and that it was from an AI assistant.

`list_alerts` returns the open alerts at the top of the subaccount's dashboard, newest first, such as a WhatsApp to reconnect or a calendar that lost access. Each one says which `action` fixes it and whether it `closes_by_itself` once fixed. The alerts of a single lead aren't there: they're in `list_attention` and close with `mark_attended`. `resolve_alert` marks one as resolved, and it can't be reopened.

The agency roles see the alerts of the subaccount, and its **Subaccount Owner** and **Subaccount Admin** see those of its agents. A **Subaccount Manager** or **Subaccount User** gets `role_forbidden`. If alerts aren't enabled for the account, both tools return `feature_disabled`. Resolving an alert sends nothing to anyone, so `resolve_alert` also works in a paused subaccount or with an inactive subscription, as in the dashboard.

## Limits

* 60 tool calls per minute per connection (one person with one app), not per token. Over it, `rate_limit_exceeded`. Unlike the API, the MCP server sends no `RateLimit-*` headers.
* `place_call` places at most 5 calls per minute per connection. Over it, `rate_limit_exceeded` too.
* `test_text_agent` sends at most 10 test messages per minute per connection, because each reply spends from the wallet. Over it, `rate_limit_exceeded` too.
* Files sent with `send_media` come from a public `https` URL, up to 25 MB, and follow the [API's limits](https://docs.newlead.ai/messages-and-calls.md#send-an-image-or-a-document).

## Revoke a connection

Each person sees their connections in **Settings › Connected apps**, with the app, its permissions and when it was last used, and can use **Revoke access** there. The connection stops working at once. Removing someone from an organization revokes their connections only when they have no other organization left. If they still have one, their connections keep working there and stop seeing the organization that removed them at once. Changing or resetting a password revokes all of that person's connections too, so they have to connect each app again. It also closes their dashboard sessions, except the one where they changed it from their profile. If closing the sessions fails on our side, the password changes anyway and some sessions may stay open; changing it again closes them.

## Add it from the command line

In Claude Code:

```bash theme={null}
claude mcp add --transport http newlead https://mcp.newlead.ai/mcp
```

## Test it with MCP Inspector

**1. Start the Inspector**

Run `npx @modelcontextprotocol/inspector`. It opens in your browser.

**2. Connect**

Choose **Streamable HTTP**, paste `https://mcp.newlead.ai/mcp` and select **Connect**. Sign in to NewLead and allow access.

**3. Try a tool**

Open **Tools**, select **List Tools**, and run `whoami`.

## Related

* [Connect NewLead to Claude or ChatGPT](https://docs.newlead.ai/guide/getting-started/connect-claude-chatgpt.md)
* [Errors](https://docs.newlead.ai/errors.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.