Metadata-Version: 2.4
Name: cartesia-mcp
Version: 1.0.0
Summary: The official Cartesia MCP server
Requires-Python: >=3.13
Description-Content-Type: text/markdown
Requires-Dist: cartesia[websockets]<6,>=5.1.0
Requires-Dist: httpx>=0.28.1
Requires-Dist: mcp[cli]<3,>=2
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: redis>=5.0.0
Requires-Dist: uvicorn>=0.34.0
Provides-Extra: hosted
Requires-Dist: ddtrace<5,>=4.8.2; extra == "hosted"

# Cartesia MCP Server

<!-- mcp-name: io.github.cartesia-ai/cartesia-mcp -->

[![PyPI version](https://img.shields.io/pypi/v/cartesia-mcp)](https://pypi.org/project/cartesia-mcp/)

The Cartesia MCP server exposes [Cartesia](https://cartesia.ai/) APIs over the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) so clients such as **Cursor**, **Claude Desktop**, and **OpenAI Agents** can list voices, run **TTS** and **STT**, manage pronunciation dictionaries, clone voices, and more—without one-off scripts.

**Documentation:** [Cartesia docs — MCP](https://docs.cartesia.ai/tools/ai/mcp)

## Setup

**Hosted (recommended)** — connect to `https://mcp.cartesia.ai/mcp` and sign in when prompted. A Cartesia MCP API key is created for your organization if one does not exist yet. You can also connect from [API Keys](https://play.cartesia.ai/keys) in the Playground.

**Cursor** — [Install Cartesia MCP](cursor://anysphere.cursor-deeplink/mcp/install?name=cartesia-mcp&config=eyJ1cmwiOiJodHRwczovL21jcC5jYXJ0ZXNpYS5haS9tY3AifQ==), then sign in to the Playground when your browser opens.

**Claude Code:**

```bash
claude mcp add --transport http --scope user cartesia-mcp https://mcp.cartesia.ai/mcp
```

Run `/mcp`, select **cartesia-mcp**, and sign in when prompted.

Or add to `.cursor/mcp.json` / your client’s MCP config:

```json
{
  "mcpServers": {
    "cartesia-mcp": {
      "url": "https://mcp.cartesia.ai/mcp"
    }
  }
}
```

### Local (`uvx`)

Run the published package on your machine with an API key. Requires **[uv](https://docs.astral.sh/uv/)** (Python 3.13+ is installed by `uvx`) and a **[Cartesia API key](https://play.cartesia.ai/keys)**. Optionally set an **[admin API key](https://play.cartesia.ai/keys)** (Keys → Admin) for `get_credit_usage` and `get_agent_usage`. Admin keys and standard keys are separate credentials; each only works on its own route class.

**CLI** — `npx add-mcp "uvx cartesia-mcp" --name cartesia --env 'CARTESIA_API_KEY=${CARTESIA_API_KEY}'`

**Cursor** — [Install local Cartesia MCP](cursor://anysphere.cursor-deeplink/mcp/install?name=cartesia&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyJjYXJ0ZXNpYS1tY3AiXX0=), then set `CARTESIA_API_KEY` in **Settings → MCP**.

**Claude Code** — `claude mcp add -e CARTESIA_API_KEY=<your-api-key> cartesia -- uvx cartesia-mcp`

```json
{
  "mcpServers": {
    "cartesia": {
      "command": "uvx",
      "args": ["cartesia-mcp"],
      "env": {
        "CARTESIA_API_KEY": "<your-api-key>"
      }
    }
  }
}
```

## Try it

Ask your agent things like:

- List all available Cartesia voices
- Convert text to audio with a chosen voice (speed, volume, emotion)
- Transcribe an audio file to text
- Create a pronunciation dictionary and use it in TTS
- Check credit usage for your account
- Localize an existing voice into another language
- List catalog accent IDs, then add British English to a cloned voice
- Create a voice agent that takes pizza orders, then give me a link to try it
- Why did my agent's last call end early?
- Add our returns policy to my support agent's knowledge base
- Score my agent's calls on whether it confirmed the appointment, then show last week's results
- Show Managed Agents usage by day for the last month

## Tools

Keep this table in sync with `@mcp.tool` registrations in `cartesia_mcp/server.py` and `cartesia_mcp/agents.py` (`tests/test_readme_tools.py` enforces that). Mirror the same tool names on [Cartesia docs — MCP](https://docs.cartesia.ai/tools/ai/mcp) when you ship a change.

| Tool | Description |
|------|-------------|
| `text_to_speech` | Convert text to audio; optional `output_path` (local server), speed, volume, emotion, and pronunciation dict. Default `save=true` returns `file_id` and a 24h `download_url`. |
| `speech_to_text` | Transcribe audio from `file_id` or a server `file_path` (`mode=batch` default, or `mode=stream`) |
| `list_voices` | List available voices (filter by language, search, gender, etc.) |
| `get_voice` | Fetch metadata for a voice by ID |
| `clone_voice` | Clone a voice from `file_id` or a server `file_path` |
| `update_voice` | Update a cloned voice's name or description |
| `delete_voice` | Delete a cloned voice |
| `localize_voice` | Adapt a voice to another language or dialect |
| `list_accents` | List catalog accent IDs and metadata (`british`, `standard-japanese`, …) |
| `list_models` | List Sonic and Ink ids for TTS and STT. Not a Managed Agent `model.id` |
| `list_agents` | List Managed Agents (search by name) |
| `get_agent` | Get an agent's current config and a Playground link to try it |
| `create_agent` | Create a Managed Agent from instructions, model, voice, and system tools; returns a Playground link |
| `update_agent` | Change an agent's name, description, or config (config changes publish a new version) |
| `delete_agent` | Permanently delete a Managed Agent |
| `list_agent_tools` | List webhook and client tools an agent can call |
| `get_agent_tool` | Get a tool's request schema (credentials are never returned) |
| `create_agent_tool` | Create a webhook or client tool, then `attach_agent_tool` |
| `attach_agent_tool` | Add one tool to an agent and keep the tools already attached |
| `detach_agent_tool` | Remove one tool from an agent and keep the others |
| `update_agent_tool` | Change a tool. Schema fields replace the stored value |
| `delete_agent_tool` | Delete a tool that no agent uses |
| `list_agent_models` | List Managed Agents LLM ids. Not Sonic or Ink ids from `list_models` |
| `list_agent_calls` | List a Managed Agent's calls with status, end reason, error, and config version |
| `get_agent_call` | Debug one call: outcome, variables, and turns with timing and tool calls (`detail=full` for raw JSON) |
| `get_agent_call_logs` | Runtime log lines for one call (read only; check first when a call fails) |
| `list_agent_versions` | List a Managed Agent's config versions |
| `get_agent_version` | Get the config a version (or a call's `agent_version_id`) ran with |
| `list_phone_numbers` | List phone numbers and the agent each routes inbound calls to (read only) |
| `get_phone_number` | Get one phone number, its assigned agent, and provider (read only) |
| `create_agent_calls` | Place real outbound calls with an agent (asks the user to confirm numbers first) |
| `cancel_agent_call` | Cancel an outbound call that has not connected |
| `delete_agent_call` | Permanently delete a call record |
| `list_call_batches` | List outbound call batches |
| `get_call_batch` | Get a batch's status, progress, and per-recipient results |
| `create_call_batch` | Start a batch that dials many recipients, now or scheduled (confirm first) |
| `cancel_call_batch` | Stop dialing a batch |
| `retry_call_batch` | Dial a batch's failed recipients again (confirm first) |
| `get_phone_provisioning_usage` | This month's phone number provisioning usage and remaining quota (read only) |
| `provision_phone_number` | Buy a Cartesia-managed phone number, unassigned until the user confirms it |
| `import_phone_number` | Link a number you own through a provider |
| `update_phone_number` | Change a number's label, inbound agent, or provider |
| `delete_phone_number` | Remove a phone number |
| `list_phone_providers` | List linked Twilio and SIP trunk providers (secrets never returned) |
| `get_phone_provider` | Get one provider |
| `create_twilio_provider` | Link a Twilio account |
| `update_phone_provider` | Change a Twilio or SIP trunk provider |
| `delete_phone_provider` | Unlink a provider |
| `list_knowledge_folders` | List knowledge base folders, their documents, and the agents that can search them |
| `get_knowledge_folder` | Get one folder |
| `create_knowledge_folder` | Create a folder |
| `update_knowledge_folder` | Rename or move a folder |
| `delete_knowledge_folder` | Delete a folder (`force` also deletes its contents) |
| `list_knowledge_documents` | List documents with status and size, without their text |
| `get_knowledge_document` | Get one document's text and processing status |
| `create_knowledge_documents` | Upload up to 100 documents from text, a `file_id`, or a local `file_path` |
| `attach_knowledge_folder` | Let an agent search one more folder and keep the folders already attached |
| `detach_knowledge_folder` | Stop an agent searching one folder, without deleting it |
| `attach_knowledge_document` | Let an agent search one more document and keep the documents already attached |
| `detach_knowledge_document` | Stop an agent searching one document, without deleting it |
| `update_knowledge_document` | Change a document's text, name, metadata, or folder |
| `delete_knowledge_document` | Delete a document |
| `retry_knowledge_document` | Reprocess a failed document |
| `list_event_webhooks` | List call event webhooks |
| `get_event_webhook` | Get one event webhook (secret never returned) |
| `create_event_webhook` | Create an event webhook, then set `config.event_webhook_id` |
| `update_event_webhook` | Change a webhook's URL, name, or secret |
| `delete_event_webhook` | Delete an event webhook |
| `list_agent_metrics` | List evaluation metrics |
| `get_agent_metric` | Get one metric and its scoring prompt |
| `create_agent_metric` | Create a metric that scores finished calls |
| `delete_agent_metric` | Delete a metric |
| `attach_agent_metric` | Score an agent's calls with a metric |
| `detach_agent_metric` | Stop scoring an agent's calls with a metric |
| `list_agent_metric_results` | List evaluation scores, filtered by agent, call, metric, or date |
| `export_agent_metric_results` | Export evaluation scores as CSV text |
| `add_voice_accents` | Add catalog accents to an instant voice clone (`british`, `parisian`, …) |
| `delete_voice_accent` | Remove a catalog accent from an instant voice clone |
| `list_pronunciation_dicts` | List pronunciation dictionaries |
| `create_pronunciation_dict` | Create a pronunciation dictionary |
| `get_pronunciation_dict` | Get a pronunciation dictionary by ID |
| `update_pronunciation_dict` | Update a pronunciation dictionary |
| `delete_pronunciation_dict` | Delete a pronunciation dictionary |
| `download_file` | Fetch a cloud file by ID (`download_url` + local copy) |
| `get_credit_usage` | Credit usage over time (`CARTESIA_ADMIN_API_KEY`) |
| `get_agent_usage` | Managed Agents cents, minutes, and calls over time (`CARTESIA_ADMIN_API_KEY`) |

See [`cartesia_mcp/server.py`](./cartesia_mcp/server.py) for parameters and return types.

## Prompts

| Prompt | Description |
| --- | --- |
| `generate_and_transcribe` | Synthesize text with a voice, then transcribe it back to verify |
| `clone_and_localize` | Clone a voice from a `file_id`, then localize it to another language |
| `create_voice_agent` | Build a Managed Agent from a plain-language description and share a Playground link |
| `debug_agent_call` | Find why an agent call went wrong and propose a config fix |

## Releases

Versions and PyPI publishes are driven by [Conventional Commits](https://www.conventionalcommits.org/) on `main` via release-please. Use PR titles like `feat: …` or `fix: …` (especially when squash merging). See [CONTRIBUTING.md](./CONTRIBUTING.md).

## Local development

Run your checkout in an MCP client instead of the published `uvx cartesia-mcp` package:

```sh
git clone https://github.com/cartesia-ai/cartesia-mcp.git
cd cartesia-mcp
uv sync --dev
```

Set `CARTESIA_API_KEY` (and optionally `CARTESIA_ADMIN_API_KEY`). Replace `/path/to/cartesia-mcp` below with your checkout path.

**Cursor** — add to `.cursor/mcp.json`:

```json
{
  "mcpServers": {
    "cartesia": {
      "command": "uv",
      "args": ["--directory", "/path/to/cartesia-mcp", "run", "cartesia-mcp"],
      "env": {
        "CARTESIA_API_KEY": "<your-api-key>"
      }
    }
  }
}
```

Restart Cursor or reload MCP servers, then confirm **cartesia** appears under **Settings → MCP**.

**Claude Code**:

```bash
claude mcp add -e CARTESIA_API_KEY=<your-api-key> cartesia -- uv --directory /path/to/cartesia-mcp run cartesia-mcp
```

In a Claude Code session, run `/mcp`, select **cartesia**, and verify tools load.

## Testing

Unit tests (no API keys):

```sh
uv sync --dev
uv run pytest
```

Smoke-test all tools (requires `CARTESIA_API_KEY`):

```sh
uv run python scripts/test_all_tools.py
```

The script creates temporary cloned/localized voices and pronunciation dictionaries, then deletes only those. It does not delete catalog or other existing resources.

## Advanced

### Output directory

On the **local** server, generated audio is written to the working directory by default. To choose a fixed folder, add `OUTPUT_DIRECTORY` to `env`:

```json
"env": {
  "CARTESIA_API_KEY": "<your-api-key>",
  "OUTPUT_DIRECTORY": "~/cartesia-output"
}
```

With the local server (`uvx` / stdio), `text_to_speech` also accepts `output_path` to write a specific file (for example an absolute path under your project). Relative paths resolve against the MCP process working directory (often not your project root), so prefer absolute paths. Hosted MCP (`mcp.cartesia.ai`) rejects `output_path` — use `file_id` / `download_url` there. Hosted `text_to_speech` with `save=true` (the default) does not keep a local `file_path`; temporary copies used for `download_file` / same-session inputs live under the system temp directory and are deleted after about an hour (`OUTPUT_FILE_TTL_SECONDS`). Hosted cleanup emits JSON logs (`mcp_output_cleanup` / `mcp_output_disk_warn`) and DogStatsD gauges (`mcp.output.bytes`, `mcp.output.files`); warn when the dir exceeds `OUTPUT_DIRECTORY_WARN_BYTES` (default 2GiB).

### Audio inputs (`file_id` or `file_path`)

`speech_to_text` and `clone_voice` take one of:

- **`file_id`** — a Cartesia cloud file from `text_to_speech` (`save=true`) or `download_file`. Use this on hosted MCP (`mcp.cartesia.ai`). The server downloads the bytes. A path on the agent machine will not be found.
- **`file_path`** — an absolute path on the machine running MCP that must exist. Use this with local `uvx`, or pass a `file_path` from `download_file` / `save=false` TTS in the same hosted session. On hosted MCP, only files the server wrote for the same API key are accepted; any other path (missing, client-local like `/Users/...`, written for another account, or elsewhere on the server) returns a validation error telling you to use `file_id`.

`download_url` is a 24-hour browser link. It is not an input to those tools.

For `speech_to_text`, use the default batch mode for common containers (mp3, flac, wav, etc.). Use `mode="stream"` for mono PCM WAV or raw PCM with `encoding` and `sample_rate`.

### Admin API key

Some tools call [management endpoints](https://docs.cartesia.ai/api-reference/usage/credits) that accept **admin** API keys only (`sk_car_admin_...`). Set `CARTESIA_ADMIN_API_KEY` in `env` alongside `CARTESIA_API_KEY`:

- `CARTESIA_API_KEY` — TTS, STT, voices, pronunciation dictionaries, etc.
- `CARTESIA_ADMIN_API_KEY` — optional; required for `get_credit_usage` and `get_agent_usage`. Admin keys do not work on generation routes, and standard keys do not work on admin routes.

Mint admin keys in the Playground under **Keys → Admin** (org admins only).

### Hosted sessions and rate limits

Hosted MCP keeps one live session per client on handshake-era protocol versions. After `initialize`, reuse the `mcp-session-id` response header on later requests. A `POST /mcp` without that header starts a new session and replaces the previous one for that client.

Requests with `MCP-Protocol-Version: 2026-07-28` do not open a session. They are not counted against the new-session limit below.

A session with no requests for 30 minutes is closed. Call `initialize` again to open a new one.

New sessions are limited to **5 per minute per access token** and **15 per minute per client IP**. Over the limit, the server returns HTTP 429:

```json
{
  "error": "too_many_requests",
  "error_description": "MCP session creation rate limit exceeded"
}
```

`Retry-After` is the window in seconds (60 for session creation). Wait and retry with the same session id when you still have one. A 429 is not an expired login — do not mark the connector failed or start a new OAuth flow.

### Hosted OAuth redirect URIs

Hosted MCP (`mcp.cartesia.ai`) accepts Dynamic Client Registration with a restricted redirect-URI policy:

- **Custom schemes** (desktop apps) — e.g. `cursor://…`, `vscode://…`
- **Loopback HTTP** — `http://localhost|127.0.0.1|::1` (any port/path)
- **Allowlisted HTTPS** — first-party callbacks for Claude, ChatGPT, Cursor web/Agents, VS Code Web, and Devin

To temporarily allow another exact HTTPS callback without a code change, set:

```text
MCP_OAUTH_EXTRA_HTTPS_REDIRECTS=partner.example|/mcp/oauth/callback
```

(comma-separated `host|/path` pairs). Prefer adding durable hosts in code for known products.

### API version

All tools send `Cartesia-Version` (default `2026-08-14`, the latest in [Cartesia docs](https://docs.cartesia.ai/use-the-api/api-conventions)). Override with `CARTESIA_VERSION` in `env` if you pin an older integration date.
