# Unspar for agents

Your AI tool can ask Unspar to research and write an article while you chat with it. Developers can do the same from a terminal or from their own code. All of them work in the same projects and spend the same credits as the web app.

Web version: https://www.unspar.com/docs/agents/

An agent is an AI tool that does work for you, like Claude Code or Cursor. Once you connect Unspar, you can ask the agent for an article right in its chat. The agent picks the right project and checks the price. Unspar writes the article, the agent shows you the text, and if you're happy with it, it can publish it too.

You don't need an AI tool to do this, though. The unspar CLI runs in your terminal, and the REST API works with your own code. All three use your [projects](https://app.unspar.com/projects), your templates, and your [credits](https://app.unspar.com/credits). Credits are how you pay in Unspar, and an article started by an agent costs the same as one you start in the web app.

Agent access is part of every plan, including the free one.

## Which way in should I use?

Unspar gives you three ways to connect. MCP (the Model Context Protocol) is a standard way for AI tools to talk to outside services. Unspar offers a hosted MCP server, plus a local one that comes with the CLI.

| Way in                                                              | What it is                                                                                                | Use it when                                                                                |
| ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| [Hosted MCP server](https://www.unspar.com/docs/mcp/)                                     | The address `https://app.unspar.com/mcp`. You approve the connection in your browser. Nothing to install. | You use Claude Code or Codex and want to ask for articles in the chat.                     |
| [CLI](https://www.unspar.com/docs/cli/) with its [local MCP server](https://www.unspar.com/docs/cli/local-mcp/) | The `unspar` program on your computer. Your AI tool starts it with `unspar mcp serve`.                    | You use another AI tool, like Cursor or Claude Desktop, or you want your agent to publish. |
| [REST API](https://www.unspar.com/docs/api/)                                              | Requests to `https://app.unspar.com/api/v1` with an API key.                                              | You want your own code or a server script to talk to Unspar.                               |

Each option covers a slightly different set of jobs. Here are the main differences.

| Job                             | Hosted MCP | Local MCP | CLI                  | REST API |
| ------------------------------- | ---------- | --------- | -------------------- | -------- |
| Write an article                | Yes        | Yes       | Yes                  | Yes      |
| Price estimate before writing   | Yes        | No        | Through `unspar api` | Yes      |
| Find ideas                      | Yes        | No        | Through `unspar api` | Yes      |
| Publish to an outlet            | No         | Yes       | Yes                  | Yes      |
| Change a project's site context | Yes        | No        | Yes                  | Yes      |

An outlet is a site you've connected to Unspar, such as your WordPress blog. See [Set up your AI tool](https://www.unspar.com/docs/mcp/setup/) for the exact steps for each tool.

## What can an agent do?

An agent works with the same things you see in the web app. It can:

- check the price of an article and start it;
- read the finished article and ask for changes;
- restore the text from before a change;
- cancel an article that is still running, or retry one that failed;
- start an idea run and turn a good idea into an article;
- publish to one of your [outlets](https://app.unspar.com/outlets), now or on a schedule;
- check your credit balance and spending history.

Unspar doesn't read your repository or your commits. If you want an article about a new feature, the agent sends a description of what the feature does along with the request. Both the hosted MCP server and the REST API accept this as additional context for a single article.

Some jobs still need the web app at [app.unspar.com](https://app.unspar.com/dashboard):

- refreshing an article you already have;
- working with posts that are already on your site;
- approving images;
- creating [many articles at once](https://app.unspar.com/articles/batch-create) from a list.

## Who can give an agent access?

Access always belongs to a team. Only the team owner and members with the **Administrator** role can grant it. [Teams](https://www.unspar.com/docs/guides/teams/) explains the roles.

There are two kinds of access. Your code and the CLI use an API key, which is a long secret that acts like a password for a single program. An AI tool using the hosted MCP server gets an MCP connection that you approve in your browser. Either way, you choose what the agent is allowed to do and which projects it can reach. [API keys and connections](https://www.unspar.com/docs/agents/access/) explains how to set this up.

## How do I keep control of credits and publishing?

Writing articles spends credits, and publishing sends an article straight to your site. Unspar has built-in checks for both, plus one setting you should check before letting an agent write.

| Way in               | What happens before it spends credits or publishes                                                      |
| -------------------- | ------------------------------------------------------------------------------------------------------- |
| CLI article commands | They ask for confirmation first. Without a terminal, they stop with an error unless you pass `--force`. |
| `unspar api post`    | It never asks. Running it counts as confirmation.                                                       |
| Local MCP server     | It never asks. Only your AI tool's own prompt before a tool call will stop it.                          |
| Hosted MCP server    | The agent can ask for a free price estimate first. It can't publish at all.                             |

Tell your agent to pass `--force` only after you've approved that specific article or publication. The skill file below teaches it this rule.

If the agent runs the create command twice, Unspar writes two articles and charges for both. While an article is in progress, the agent should check its status instead of starting it again. If a CLI create call loses its response and needs a retry, the agent should pass the same `--idempotency-key` on both runs.

A project can also publish finished articles automatically. This happens when **Auto-publish completed articles** is on and **Require human review before auto-publish** is off. With those settings, any article started through the CLI or the local server goes live on your site as soon as it finishes. Articles started through the hosted server never auto-publish. Check both settings on the project's **Edit** page before an agent writes there. [Scheduling and auto-publish](https://www.unspar.com/docs/guides/auto-publish/) explains how they work.

## Teach your agent the rules

An agent produces better articles when it knows how Unspar works. The main rule is that the brief should only describe the topic. Audience details go into the project's [site context](https://www.unspar.com/docs/guides/projects-and-site-context/) once, the [template](https://www.unspar.com/docs/guides/choosing-a-template/) controls the article's structure, and the project's [visual identity](https://www.unspar.com/docs/guides/images/) sets the look of its images, so a brief should never describe image styles.

Unspar gives you these rules in two forms.

| Form                    | What it has                                                                                                    | When the agent reads it                                          |
| ----------------------- | -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| Skill file (`SKILL.md`) | The rules, the steps from writing to publishing, which actions spend credits, and when to use `--force`.       | Claude Code and Codex load it when your request is about Unspar. |
| Short guide             | The template rule, the image rule, and six steps for writing an article. It doesn't cover publishing or edits. | At the start of every session, from `CLAUDE.md` or `AGENTS.md`.  |

Neither form connects the agent to Unspar. Set up the [MCP server](https://www.unspar.com/docs/mcp/setup/) or the [CLI](https://www.unspar.com/docs/cli/) for that.

### Install the skill file

The skill file lives at `https://app.unspar.com/skills/unspar/SKILL.md`. For Claude Code, run this in your project folder:

```sh
mkdir -p .claude/skills/unspar && curl -fsSL https://app.unspar.com/skills/unspar/SKILL.md -o .claude/skills/unspar/SKILL.md
```

Codex reads skills from `.agents/skills` instead:

```sh
mkdir -p .agents/skills/unspar && curl -fsSL https://app.unspar.com/skills/unspar/SKILL.md -o .agents/skills/unspar/SKILL.md
```

To use the skill across all your projects, save it to `~/.claude/skills/unspar` or `~/.agents/skills/unspar` instead. If you use both tools, each one needs its own copy. Run the same command again later to update to a newer version. If Claude Code doesn't pick up the new file in an open session, run `/reload-skills`.

### Add the short guide

The short guide comes with the CLI. This command writes it into a file in the current folder:

```sh
unspar agent-guide --write CLAUDE.md
```

Claude Code reads `CLAUDE.md`, while Codex and most other tools read `AGENTS.md` (use `--write AGENTS.md` for those). If the file already exists, the guide is added at the end between two marker lines, and running the command again updates only that section. To preview the guide first, run `unspar agent-guide` without `--write`.

The file must be in the folder where you run the command. For instructions that apply in all projects, change into that folder first:

```sh
cd ~/.claude && unspar agent-guide --write CLAUDE.md
```

For Codex, the folder is `~/.codex` and the file is `AGENTS.md`.

If you ask for an article now and then, the skill file is enough. If the repository is about your content, like your blog, add the guide too.

## Files an agent can read

These files help an agent that reads documentation or API contracts by itself.

| File                                                           | What it has                                                        |
| -------------------------------------------------------------- | ------------------------------------------------------------------ |
| [/llms.txt](https://www.unspar.com/llms.txt)                                         | A list of all pages of these docs.                                 |
| [/llms-full.txt](https://www.unspar.com/llms-full.txt)                               | All pages of these docs in one file.                               |
| [OpenAPI document](https://app.unspar.com/api/v1/openapi.yaml) | The REST API in a format tools can read.                           |
| [Operation map](https://app.unspar.com/api/v1/operations)      | Each API operation with the permission it needs.                   |
| [app.unspar.com/llms.txt](https://app.unspar.com/llms.txt)     | What is turned on in the app right now, and the list of MCP tools. |
| [Skill file](https://app.unspar.com/skills/unspar/SKILL.md)    | The rules for agents, as described above.                          |

Every docs page is also available in Markdown. Replace the trailing slash in its URL with `.md`, like `/docs/agents.md`.

## For AI agents

Check the key and pick the project. Get the estimate and show the price to the person. Create the article only after they agree, then show them the text and stop again. Publish only when they say so, to an outlet from unspar outlets list. Publishing runs in the background, so check the status afterwards. Without a terminal, create and publish need --force. Replace the <...> placeholders with the IDs that the earlier commands return.

```sh
unspar whoami
unspar projects list
unspar templates recommend --topic "How to choose a domain name" --project <project-id>
unspar api post /articles/estimate --field project=<project-id> --field "brief=How to choose a domain name"
unspar articles create --project <project-id> --brief "How to choose a domain name" --force --wait
unspar articles content <article-id> --output article.md
unspar outlets list
unspar articles publish <article-id> --outlet <outlet-id> --force
unspar articles status <article-id>
```
