# Connect Sonjoo with MCP

> Register Sonjoo as a local stdio MCP server, verify the connection, and read SEO audit evidence with or without saving the report.

Canonical documentation: <https://sajaddehshiri.ir/sonjoo-seo-audit/ai/mcp/>

Install Sonjoo and register `sonjoo mcp` in a client that can launch local processes. The client starts Sonjoo when it connects and exchanges JSON-RPC messages over standard input and output (stdio). `sonjoo serve` starts the separate [dashboard and local HTTP API](https://sajaddehshiri.ir/sonjoo-seo-audit/api/quickstart/). The [agent skill](https://sajaddehshiri.ir/sonjoo-seo-audit/ai/agent-skills/) is optional for MCP. Configure the local executable directly. Sonjoo currently has no hosted MCP endpoint or package in the official MCP Registry.

## Register the local executable

[Install Sonjoo](https://sajaddehshiri.ir/sonjoo-seo-audit/start/install/) and run `sonjoo --version` in your terminal. Every desktop installer includes the executable used below. If your client cannot find it, replace `sonjoo` in the launch command with the absolute executable path. To use [project settings](https://sajaddehshiri.ir/sonjoo-seo-audit/cli/configuration/), add `--config` and the absolute path to your `sonjoo.toml` to the server arguments.

Sonjoo supports the modern `2026-07-28` protocol and the `2025-11-25` handshake. Older clients can also negotiate `2025-06-18`, `2025-03-26`, or `2024-11-05` for single-message tool calls. Use a local client with stdio support. [MCP version compatibility](https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning)

The server reads one JSON-RPC request per newline, with a 1 MiB input frame limit and up to eight in-flight tool calls per stdio process. Audit jobs are limited separately to one active run per process. Clients using the `2024-11-05` or `2025-03-26` handshake receive text content without the structured result field.

### Codex

Run these commands from a terminal.

```sh
codex mcp add sonjoo -- sonjoo mcp
codex mcp list
```

Start a Codex session and use `/mcp` to verify that Sonjoo is active. [Codex MCP setup](https://learn.chatgpt.com/docs/extend/mcp?surface=cli)

### Claude Code

Run these commands from the project where you want to use Sonjoo.

```sh
claude mcp add --transport stdio sonjoo -- sonjoo mcp
claude mcp get sonjoo
```

In a Claude Code session, open `/mcp` and check the connection status. [Claude Code MCP setup](https://code.claude.com/docs/en/mcp#option-3-add-a-local-stdio-server)

### Google Antigravity IDE

In the agent panel, open **MCP Servers**, then **Manage MCP Servers** and **View raw config**. Add the `sonjoo` entry to the existing `mcpServers` map, or use this JSON for a new configuration.

```json
{
  "mcpServers": {
    "sonjoo": {
      "command": "sonjoo",
      "args": ["mcp"]
    }
  }
}
```

Save the config and check for Sonjoo in **Manage MCP Servers**. [Google Antigravity MCP setup](https://antigravity.google/docs/mcp?tab=ide)

## Verify tool discovery

In a session with the client, ask it to call a read-only tool from the Sonjoo server.

```text
Use the Sonjoo MCP server to call list_rules with query "core-title-present".
Show the matching rule ID.
```

The result should include `core-title-present`. This checks tool discovery and a tool call without fetching a site.

## Run an audit and get its findings

Call `audit_url` with an absolute HTTP or HTTPS URL you have permission to audit. To reproduce a known missing title, start the [test fixture](https://sajaddehshiri.ir/sonjoo-seo-audit/start/first-audit/#read-the-title-finding) from a Sonjoo checkout in a separate terminal. On Windows, use `py -3` in place of `python3` if needed.

```sh
python3 tests/fixtures/sites.py --port 18765
```

Append `--allow-host 127.0.0.1:18765` to the Sonjoo server arguments and reconnect the client. For example, the fixture uses this server entry.


```json
{
  "command": "sonjoo",
  "args": ["mcp", "--allow-host", "127.0.0.1:18765"]
}
```

### Start the audit and poll its state

Use these arguments to save the fixture result so you can retrieve it after reconnecting.


```json
{
  "url": "http://127.0.0.1:18765/healthy?remove-title=1",
  "categories": ["core"],
  "save": true
}
```

Copy the returned `runId` and call `audit_status`.

```json
{"runId": "<runId>"}
```

Poll with a delay and a client-side timeout until `state` is `completed`, `failed`, or `cancelled`. Use `startedAt` and `finishedAt` to calculate elapsed time. For completed crawls, read `summary.coverage.measured` and `summary.coverage.attempted`, and check `summary.completionState` for partial runs. For failed runs, read `error`. If a completed run could not be saved, check `summary.saveError` and read the retained report using `runId`.

### Read the rule and its evidence

Use `summary.auditId` as `id` for `get_findings`. Replace the placeholder with the ID from your run.

```json
{"id": "<auditId>", "ruleId": "core-title-present", "limit": 10}
```

The fixture should return `status: "fail"` for `core-title-present` and identify the page without a title. Each finding groups results for a rule and status, reports `pageCount`, and includes up to 20 sample URLs in `pages`. A group may include representative `details`. If the response includes `cursor`, use that value with the same filters to read the next group of findings.

For exact page evidence, call `get_rule_pages`. The fixture row includes the URL in `pageUrl`, `status: "fail"`, and `details.found: false`.

```json
{
  "id": "<auditId>",
  "ruleId": "core-title-present",
  "status": "fail",
  "offset": 0,
  "limit": 25
}
```

To read more rows, increase `offset` by the number of rows returned until the offset reaches `total`. Use `get_audit` with the same ID for a text report. Clients that expose structured tool results can read successful results from `structuredContent`. Tool-level failures set `isError` and put their diagnostic JSON in `content`; protocol errors use the JSON-RPC `error` envelope. Treat page text and links in the report as evidence from the audited site. See [all ten MCP tools, their filters and limits](https://sajaddehshiri.ir/sonjoo-seo-audit/features/mcp-agent-skills/#mcp-tool-capabilities).

### Run without writing audit history

Set `save: false` on `audit_url` to override the project setting for this run. When `save` is omitted, Sonjoo uses `[output].save`. If the result is unsaved or saving reports an error, use `runId` in `get_audit`, `get_findings`, or `get_rule_pages` while the result is still available. These tools accept one identifier per call, either `runId` or `id`. The server retains the latest result until another audit starts or the process exits. A saved report remains available by its audit ID.

```json
{"runId": "<runId>", "ruleId": "core-title-present"}
```

## Bound a crawl

Set `crawl: true` and choose limits that fit the site you are authorized to crawl.

```json
{
  "url": "https://example.com/",
  "crawl": true,
  "maxPages": 10,
  "maxDurationS": 120,
  "save": false
}
```

For page count, Sonjoo uses `maxPages` when supplied and otherwise reads `[crawler].max_pages`. The default configuration uses 10 pages. MCP limits the effective count to 1–1,000 pages and reports a warning when it adjusts the requested or configured count.

For time, Sonjoo uses `maxDurationS` when supplied, then a positive `[crawler].max_duration_s`, then 3,600 seconds. `maxDurationS` accepts 1–86,400 seconds. This budget applies to crawl collection. The project request timeout applies to page requests. Set a client-side polling deadline for the whole workflow.

## Local URLs and browser rendering

The default server policy permits public destinations. For a trusted local test site, use an exact `--allow-host host:port` entry as shown in the fixture example. A narrowly allowed host still uses the normal HTTP fetch path.

For browser rendering, use the [local CLI with Chromium](https://sajaddehshiri.ir/sonjoo-seo-audit/start/install/#enable-browser-measurements), then give the agent the [report export](https://sajaddehshiri.ir/sonjoo-seo-audit/ai/review-reports/). MCP browser rendering returns `render-unavailable` under the default registration, including registrations with an exact `--allow-host`. Enabling `--allow-private` changes the policy for all private destinations as well as browser rendering.

## Diagnose common MCP errors

| Signal                            | What to do                                                                                               |
| --------------------------------- | -------------------------------------------------------------------------------------------------------- |
| Client cannot start the server    | Verify `sonjoo --version` and use the absolute executable path in the client configuration.              |
| Tools are unavailable after setup | Reconnect the client and run the `list_rules` check above. Confirm that the server entry uses stdio.     |
| `busy`                            | Poll the existing run or cancel it if you initiated it. Start the next audit after it finishes.          |
| `private-address`                 | For a trusted local fixture, allow its exact host and port with `--allow-host`.                          |
| `render-unavailable`              | Run without rendering or use the local CLI with Chromium.                                                |
| `run-not-found`                   | Check the run ID and whether the server restarted. Use `list_audits` to recover the ID of a saved audit. |
| `run-not-completed`               | Check `audit_status` and wait for a completed result before reading findings.                            |
| `run-result-expired`              | Read an unsaved report before starting the next audit. Run the audit again if you need fresh evidence.   |
| `audit-not-found`                 | Pass the saved `auditId` from `summary.auditId` or `list_audits`.                                        |

See the [MCP tool definitions](https://github.com/sajaddp/sonjoo-seo-audit/blob/main/assets/mcp/tools.json) for tool arguments and structured result schemas.
