> For the complete documentation index, see [llms.txt](https://herd-security.gitbook.io/herd-security-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://herd-security.gitbook.io/herd-security-docs/api-documentation/mcp-server.md). Agents can also search and read this documentation through its [MCP server](https://herd-security.gitbook.io/herd-security-docs/~gitbook/mcp).

# MCP Server

Connect Claude, Cursor, or any MCP client to Herd: OAuth sign-in with your normal Herd login, read-only reporting tools, optional AI Insights totals, and draft-training creation that never publishes o

Herd supports the Model Context Protocol (MCP), so an AI assistant you already work in (Claude, Cursor, Claude Code, or any other MCP client) can read your organization's training, compliance, and phishing-simulation reporting and create draft trainings without leaving that tool. Apart from the AI Insights tools below, it is the same tool set HerdAI uses in the web chat, exposed over a standard interface.

{% hint style="info" %}
If you're not a developer, [Connect Your AI Assistant to Herd](https://herd-security.gitbook.io/herd-security-docs/ai/herdai/connect-your-ai-assistant.md) walks through setup in Claude Desktop, Cursor, and Claude Code.
{% endhint %}

{% hint style="info" %}
The connection is read plus draft create-and-edit only. Nothing reachable over MCP can publish a training, assign anything, launch a campaign, or send a message to a learner. Those actions stay in Herd, behind the same review and approval steps as always.
{% endhint %}

## Endpoint

```
https://api.herdsecurity.io/mcp
```

The transport is Streamable HTTP: the client sends JSON-RPC 2.0 messages with `POST` and Herd answers as JSON or as server-sent events, depending on the client's `Accept` header. A `GET /mcp` with `Accept: text/event-stream` opens a server-to-client stream, on which Herd sends `notifications/tools/list_changed` when a change to your permissions changes the tools you can use; without that header, `GET` returns `405`. Most clients need only the URL and discover the rest automatically.

## Connecting a client

Herd is the OAuth 2.0 authorization server for its MCP endpoint, with PKCE and dynamic client registration, so no client secret or pre-registration is needed. A client that supports remote MCP servers with OAuth runs this flow on its own:

1. The client fetches the discovery documents at `/.well-known/oauth-protected-resource` and `/.well-known/oauth-authorization-server` on the API origin.
2. It registers itself at `POST /mcp/oauth/register` and receives a `client_id`. Registration is open by design. A client record is only an identity, and every token still needs a person to approve it.
3. It opens `GET /mcp/oauth/authorize` in your browser (PKCE `S256` is required).
4. You sign in to Herd the way you always do: your organization's own login, including SSO if that's how your organization signs in.
5. Herd shows a consent screen naming the client and listing what it will be able to do. Click **Allow connection** to approve, or **Cancel**. Approving binds the connection to you and to your organization.
6. The browser returns to the client with a one-time code, which the client exchanges at `POST /mcp/oauth/token` for an access token and a refresh token.

Once connected, the client calls tools on your behalf. Every call is scoped to your organization and filtered by your own Herd permissions: a tool you couldn't use in HerdAI isn't offered over MCP either.

{% hint style="warning" %}
Only approve connections you started yourself. The consent screen shows where Herd will send the credentials: a loopback address for an app running on your computer (Claude Code, and current versions of Cursor), a private-use scheme such as `cursor://` for an app installed on your computer, or a server on the internet (Claude Desktop and claude.ai connect through `claude.ai`). For a server on the internet the screen shows a warning, and you should cancel unless you recognise that address. Anyone can register a client under any name, so the name alone is not proof of who is asking.
{% endhint %}

### Scopes

| Scope                   | What it allows                                                                                                                                                                 |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `herd:read`             | Read your organization's training, compliance, and phishing-simulation reporting                                                                                               |
| `herd:training:draft`   | Create and edit draft trainings. It cannot publish or assign anything                                                                                                          |
| `herd:ai_insights:read` | Read your organization's AI Insights totals and counts (AI tools in use, findings counts, agent oversight). Never prompt or response text, and never any one person's activity |

A client that asks for no scopes gets `herd:read` and `herd:training:draft`. `herd:ai_insights:read` is never granted by default, and Herd's OAuth discovery lists only the two default scopes, so a client that takes its scopes from discovery does not ask for it. The consent screen offers it as an **unticked** choice, and a client that names it in its request lists it on the screen for you to approve. A connection approved before this scope existed does not gain it; reconnect and tick it if you want it.

### Token lifetimes

* Access tokens last 1 hour; the client refreshes them silently with its refresh token.
* Refresh tokens rotate on every use and expire 30 days after the connection was last used, so an idle connection lapses on its own. Reconnect through the same flow to continue.
* A pending consent request stays open for 10 minutes; after that, start the connection again from the client.

MCP tokens are separate from [API keys](https://herd-security.gitbook.io/herd-security-docs/api-documentation/authentication.md). They don't authenticate against `/api/v1`, and an API key doesn't authenticate against `/mcp`.

## What the client can do

The tools are a curated subset of HerdAI's, so an MCP client and the in-app assistant answer the same question the same way.

**Read tools** (`herd:read`):

* General-purpose data access: `query_data`, `aggregate_data`, plus `list_tables`, `get_table_schema`, and `get_sample_data` to explore what's available. These run against an allowlist of Herd tables, always scoped to your organization, and are how you answer questions like "all the phishing failures from last week" or "who completed which trainings this month".
* Training and track completion: `list_trainings`, `search_trainings`, `search_tracks`, `get_training`, `get_training_completers`, `get_incomplete_assignments`, `get_training_assignment_status_breakdown`, `get_training_effectiveness`, `get_training_impact`, `get_user_training_status`.
* Compliance and policies: `get_compliance_metrics`, `list_policies`.
* Organization-level reporting: `get_organization_summary`, `get_user_engagement`, `get_user_completion_rankings`, `get_team_analysis`, `get_risk_assessment`, `get_metric_definitions`.
* People and groups: `search_users`, `list_groups`.
* Phishing results: `get_phishing_results`, `list_phishing_campaigns`, `get_campaign_recipients`.
* Nudge completion: `get_nudge_completion` reports completion of standalone nudges, such as an external LMS course. It is available when Nudges is enabled for your organization.

**Draft tools** (`herd:training:draft`):

* `preview_training` generates a training and saves it as a draft. It appears under **Trainings → Drafts** in Herd, where you can edit it, **Add to Library**, or discard it, exactly like a draft created in the web chat. Submitting for review happens on the library training in Herd, not over MCP.
* `update_training_draft` edits a draft in place (its title, description, tags, the wait-for-reply setting, or removing a step) without regenerating it. It requires the `draftId` of the draft to edit.

**AI Insights tools** (`herd:ai_insights:read`): seven read-only tools that return totals and counts and nothing that identifies a person or what they typed. They are separate from HerdAI's own AI Insights tools, which return more (such as the people with the most findings), so they are not the same answers word for word.

Each one needs the **View AI governance** permission and the AI Insights plan feature it sits behind in the app: the first four need AI Insights (the AI Coach feature), the last three need Agent Oversight. A tool you lack either for is not offered. `get_ai_findings_counts` counts the newest 500 findings in the period and says when there were more.

| Tool                      | What it returns                                                                                                                                                                                                                                                      | Left out                                                 |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| `get_ai_tools_in_use`     | How many AI tools and agents Herd has seen, the name and vendor of the five most recent, and people who used AI this week and last week                                                                                                                              | Every other agent detail, and anyone's name              |
| `get_ai_findings_counts`  | AI policy findings over a period (30 days by default, up to 90) counted by policy, severity and triage status, plus how many were stopped before sending                                                                                                             | The matched text, the reason, who triggered it           |
| `get_ai_team_leaderboard` | Each team's rank, name, average score and scored members, only if an admin has switched the team leaderboard on                                                                                                                                                      | The individual leaderboard, conversation scores and text |
| `get_claude_code_usage`   | The last 30 days of Claude Code cost, sessions, commits, pull requests, tokens and the number of active users or API keys. With fewer than 5 active users or API keys, the totals and the count are all withheld, and only the fact that there was usage is returned | Which users, and each one's usage                        |
| `get_unowned_agents`      | How many agents Herd has seen, how many have no owner, and the name and last-seen time of up to 25 of them                                                                                                                                                           | Owners, sessions, people                                 |
| `get_agent_rule_activity` | Each agent rule's name, severity and mode, and how many tool calls it stopped, would have stopped or added context to                                                                                                                                                | Messages, sessions, people                               |
| `get_agent_hook_coverage` | Per surface, sessions seen, sessions checked by the hook, and the gap                                                                                                                                                                                                | Individual sessions and people                           |

These tools apply a floor of 5. A count of people under 5 (weekly active AI users, Claude Code active users, people without the hook) is reported as withheld rather than as a number, and a team with fewer than 5 scored members is left off the leaderboard and counted. This is stricter than the app in two places: the team leaderboard page shows small teams, and HerdAI reports the weekly active count whatever it is. The AI Insights tables are not reachable through `query_data` either.

Ask your client for the tool list (`tools/list`) to see the descriptions and parameters. For the training, reporting and draft tools they're identical to HerdAI's own tool definitions and update together.

## Typical uses

* Draft a training in the editor where you already have your other MCP connections (Slack, Drive, Confluence), pulling in context from those sources, then push the result into Herd as a draft for review.
* Run an assistant over your own repositories or data lake, mine patterns, and turn what it finds into a draft training.
* Pull reporting into a notebook or an internal agent: "everyone who failed a simulation last week", "trainings completed this quarter by department".

## Limits

MCP calls go through the same permission checks and organization scoping as HerdAI. Draft-training generation counts against your per-user hourly AI-generation quota, the same one Herd's in-app AI generation uses, so a client that has used it up is told how long to wait and gets no second allowance.

`preview_training` without a `draftId` always creates a new draft and never changes an existing one. To refine a draft, pass the `draftId` returned by an earlier call and it is revised in place; every `preview_training` result returns that id. `update_training_draft` and adding steps both require a `draftId` over MCP and are refused without one, since there is no implicit draft to edit or append to.

Each connected client still gets one durable Herd conversation per user, so drafts accumulate under **Trainings → Drafts** rather than replacing each other.
