API Documentation
API Documentation
The Sonarly Model Context Protocol (MCP) server gives compatible AI agents schema-validated tools for accounts, audiences, prospects, prospecting jobs, signals, campaigns, content approvals, inbox conversations, scheduled replies, and account activity.
The current public package supports Codex CLI through the Sonarly plugin marketplace and Claude Code through a manual local configuration. Both clients run the same local STDIO server and send requests only to https://api.sonarly.io.
MCP tools can read and change Sonarly data. Create an API key with only the accounts and permissions the agent needs, review proposed writes according to your client approval policy, and revoke the key when it is no longer required.
You need:
sk_live_... format.Create the key under Settings > API Keys. Copy it immediately, because Sonarly shows the complete value only once. Start with read permissions and add write permissions only for workflows the agent must perform.
Keep the key in the environment of the process that launches the MCP client. Never put it in a repository, prompt, screenshot, tool argument, or shared shell history.
Add the official Sonarly marketplace and install the plugin:
codex plugin marketplace add sonarly-io/plugins --ref main
codex plugin add sonarly@sonarlyExpose the API key to the shell that starts Codex:
export SONARLY_API_KEY="sk_live_..."Start a new Codex task after installation. The installed plugin contains the complete server bundle and does not need the private Sonarly repository or pnpm.
Claude Code can run the same public STDIO bundle. Clone the public repository into a stable local directory:
git clone --depth 1 https://github.com/sonarly-io/plugins.git /absolute/path/to/sonarly-pluginsReplace /absolute/path/to/sonarly-plugins with the permanent local directory where you want to keep the checkout.
Set these values in the shell that starts Claude Code:
export SONARLY_API_KEY="sk_live_..."
export SONARLY_PLUGIN_ROOT="/absolute/path/to/sonarly-plugins/plugins/sonarly"Register the server at user scope. The single-quoted JSON deliberately keeps the environment-variable placeholders out of the saved command:
claude mcp add-json --scope user sonarly '{
"type": "stdio",
"command": "node",
"args": ["${SONARLY_PLUGIN_ROOT}/scripts/sonarly-mcp.mjs"],
"env": {
"NODE_ENV": "production",
"SONARLY_API_KEY": "${SONARLY_API_KEY}",
"SONARLY_API_BASE_URL": "https://api.sonarly.io",
"SONARLY_MCP_CONTRACT_PATH": "${SONARLY_PLUGIN_ROOT}/generated/tool-contracts.json"
}
}'Restart Claude Code after adding the server. The current release does not include a Claude Desktop .dxt extension; do not try to install the Codex plugin manifest as a desktop extension.
For Codex CLI:
codex plugin list
codex mcp get sonarlyFor Claude Code:
claude mcp listVerification should show a connected local STDIO server named sonarly. Do not run or share the output of claude mcp get sonarly: current Claude Code versions may print expanded environment values, including the API key. If discovery succeeds but a tool returns 401, confirm that the key is available to the process that launched the client and has not been revoked.
Start with a read-only discovery request:
Use the Sonarly MCP to list the account groups available to me. Do not make any changes. Tell me which Sonarly tool you used and where each returned identifier came from.The agent should begin with accounts.list. It must discover identifiers from tool results instead of guessing IDs.
The MCP exposes 40 tools across these workflow groups:
Use the endpoint reference for the underlying request and response contracts.
The current plugin is a local STDIO package that reads SONARLY_API_KEY while the agent is running. Codex Cloud secrets are available to setup scripts but are removed before the agent phase, so this API-key package is not currently supported in Codex Cloud.
Do not work around this by saving the key as a non-secret environment variable or committing it to a repository. Secure hosted support requires a remote MCP endpoint with delegated OAuth authentication and will be released separately.
Codex desktop can discover marketplace plugins, but Sonarly has not yet validated a secure desktop-native workflow for supplying this release's environment key. It is not a verified support surface for this release. The same boundary applies to hosted Claude connectors and public ChatGPT distribution. Claude Desktop one-click installation additionally requires a separately packaged and reviewed .dxt extension.
Update the Codex marketplace, then reinstall the plugin so Codex refreshes the cached bundle:
codex plugin marketplace upgrade sonarly
codex plugin remove sonarly@sonarly
codex plugin add sonarly@sonarlyRemove the Claude Code registration with:
claude mcp remove --scope user sonarlyPull the public repository before restarting Claude Code when you want to update its local bundle.
| Symptom | Check |
|---|---|
| Server does not start | Confirm Node.js 22+, the installed file paths, and that the bundle and generated contract file exist. |
| Server is missing | Start a new client task or session, then run the client-specific verification commands above. |
401 UNAUTHORIZED | Confirm SONARLY_API_KEY is available to the client process and the key is active. |
403 SCOPE_DENIED | Add only the missing permission or select an account the key can access. |
429 RATE_LIMIT_EXCEEDED | Wait for the documented reset window; retry only safe reads or identical idempotency-protected writes. |
Never include the API key, authorization header, customer data, or provider payloads in a support report.
UPSTREAM_SCHEMA_DRIFT |
| Stop the workflow and report the tool name and trace ID through Sonarly dashboard live chat. |
| An old tool list remains | Update or reinstall the client configuration, then start a new task or session. |