> ## Documentation Index
> Fetch the complete documentation index at: https://docs.igrisecurity.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Policy Playground

> Interactive tool for testing Igris policies and connection scenarios before deploying to production.

# Policy Playground

The **Policy Playground** is an interactive browser tool for testing Igris governance policies against real gateway traffic before deploying them in production.

**URL:** [https://playground.igrisecurity.com](https://playground.igrisecurity.com)

The playground creates real policies and connections in your Igris account via the management API, fires actual requests through the MCP and LLM gateways, classifies the outcome (allowed / denied / redacted / alerted / error), then lets you clean up everything it created.

***

## Before you start

You need:

* A running Igris API and an API key (`ig_...`). Create the key under **Settings → API Keys**.
* An LLM provider key, base URL, and model name. The playground requires them.
* The bundled MCP mock server, reachable from both your browser and your Igris API (see below).

> [!WARNING]
>
> The playground creates and changes real connections and policies in your organization. The API key's creator needs permission to manage them: `connections:read`, `connections:write`, `policies:read`, and `policies:write`. Owner, Admin, and Developer have these. An API key acts with its creator's current role. See [Roles and permissions](https://docs.igrisecurity.com/reference/permissions.md).

***

## Setup

On first launch, the playground opens a setup dialog. You cannot dismiss it until setup is complete.

| Field | Description |
| - | - |
| **API URL** | Base URL of your Igris API, for example `https://api.igrisecurity.com` or `http://localhost:3100` |
| **API Key** | An Igris API key (`ig_...`) |
| **LLM Provider API Key** | Your key for the upstream LLM provider. Sent to your Igris API to store on the `playground-llm` connection |
| **LLM Provider Base URL** | An OpenAI-compatible endpoint, for example `https://api.openai.com/v1`, `https://openrouter.ai/api/v1`, or `http://localhost:11434/v1` for Ollama |
| **LLM Model** | The model name sent in LLM scenarios (default `gpt-4o-mini`). Your provider must serve it |

Click **Test Connection**. The dialog runs four checks, and all four must pass before **Start Testing** appears:

| Check | What it does |
| - | - |
| **Igris API reachable** | Calls your API from the browser |
| **API key valid** | Verifies the key and shows the organization name |
| **MCP server running** | Calls `/health` on the MCP mock server |
| **LLM provider verified** | Creates or updates the `playground-llm` connection, then sends a one-token chat completion through the gateway |

Settings are stored in your browser's `localStorage`, including both keys. To edit them later, click **Settings** in the header. That dialog can be closed with the X button, a click outside it, or Escape.

### The MCP mock server

The playground ships its own mock MCP server with 28 tools across seven categories (file, database, code execution, network, destructive, system, and search), so MCP scenarios need no external server. It listens on port 3600 locally.

Its URL is set at build time with `NEXT_PUBLIC_MCP_URL` (default `http://localhost:3600`). Both your browser and your Igris API must be able to reach it. The browser calls `/health`, and your API forwards tool calls to `<MCP URL>/mcp`. That means it cannot be `localhost` if your API runs elsewhere. The hosted playground uses `https://mcp-playground.igrisecurity.com`.

### CORS

The playground calls your Igris API directly from the browser. The API's `CORS_ORIGIN` setting must include the playground's origin, for example `https://playground.igrisecurity.com` or `http://localhost:3500`. Otherwise the checks fail with the API shown as unreachable. If you run your own API, add the origin to `CORS_ORIGIN` and restart it.

### What setup creates

| Resource | Details |
| - | - |
| `playground-llm` connection | LLM connection using your key. Provider is `openai`, or `openai-compatible` when you set a base URL. Body retention is set to 7 days |
| `playground-mcp` connection | HTTP MCP connection to `<MCP URL>/mcp`, created on the first MCP scenario |
| Scenario policies | One policy per scenario, named `playground-...` |

***

## Scenario Categories

The playground has eleven categories in four groups. Select one in the left sidebar to see its scenarios.

| Group | Category | What it tests |
| - | - | - |
| **Content Guards** | **PII Detection** | Detection of personal data (email, phone, SSN, credit card, and others) in LLM prompts |
| | **Secrets Detection** | Detection of API keys, tokens, and private keys in prompts |
| | **Injection Detection** | Prompt injection phrases that try to override instructions |
| | **Guard Actions** | The `deny`, `alert`, and `redact` guard actions against the same PII payload |
| **Enforcement** | **Token Guards** | Limits on input and output tokens per request |
| | **Rate Limits** | Request, token, and dollar limits hit by rapid requests |
| | **Conditional Rules** | Rules that match on `X-Igris-User` and `X-Igris-Metadata-*` headers |
| | **Policy Actions** | Each action type: `allow`, `deny`, `alert`, `redact` |
| **Anomaly** | **MCP Anomaly** | Rate spike and destructive pattern signals from rapid MCP tool calls |
| | **LLM Anomaly** | Cost spike, token burn, response length, and error rate signals |
| **Sessions** | **Session Lifecycle** | MCP session create, suspend, resume, and inspect |

The sidebar shows the number of scenarios in each category.

***

## Running a Scenario

Click **Run** on a scenario card. The runner:

1. Creates (or reuses) the required connection with `POST /api/v1/connections`
2. Creates the scenario's policy with `POST /api/v1/policies`, or reuses a policy that already has the same name
3. Enables that policy and disables every other policy whose name starts with `playground-`, so only this scenario's policy is enforced
4. Fires the request or requests through the gateway
5. Classifies each response and shows the result

Step 3 matters: the gateway uses the first matching policy, so leftover playground policies would give wrong results. It also means the playground edits the `enabled` flag of your `playground-` policies.

Multi-request scenarios (rate limits, anomaly detection) show per-request status and a progress indicator. A result card links to **View on dashboard**. The link opens the Incidents page for denied and alert outcomes, but denials and alerts do not create incidents today, so look for them in the Audit Trail instead. The link assumes the dashboard runs on port 3200 next to an API on port 3100, so it is only reliable for local setups.

### Paired Pass-Through

Detector-based cards (PII, Secrets, Injection, and Guard Actions) fire **two requests under the same policy**:

1. A prompt containing the trigger content (an SSN, a secret, an injection phrase). The content guard acts on it according to the scenario.
2. A clean prompt with no trigger content. The same policy lets it through to the LLM.

The result card shows one row per request. The allowed row displays the **actual assistant reply** returned by the model (`choices[0].message.content`). This shows that one policy blocks unsafe traffic while letting safe traffic pass.

***

## Outcome Classification

The playground maps each gateway HTTP response to one of five outcomes:

| Outcome | Condition |
| - | - |
| **allowed** | 2xx response, body parses, and no `[REDACTED:` marker |
| **denied** | HTTP 403 or 429 |
| **redacted** | 2xx response whose body contains `[REDACTED:` anywhere |
| **alert** | 2xx response that passed through cleanly, where the scenario's expected outcome is `alert` |
| **error** | Any other status, or a 2xx response with a body that cannot be parsed |

> [!NOTE]
>
> The `alert` action forwards the request to upstream and logs the event, so the gateway response looks the same as `allow`. When a scenario expects `alert` and the request passes through cleanly, the playground reports `alert`. Confirm it in the Audit Trail, where the event shows the policy that matched, or through your `policy_deny` webhook. Alerts do not create incidents today. The playground cannot detect the alert from the response alone.

***

## Cleanup

The playground tracks every connection slug and policy ID it creates in `localStorage`.

Click **Clean Up Resources** at the bottom of the sidebar and confirm. It then:

* Deletes tracked policies with `DELETE /api/v1/policies/:id`
* Deletes tracked connections (`playground-llm` and `playground-mcp`) with `DELETE /api/v1/connections/:slug`
* Treats resources that are already gone (404) as deleted
* Keeps resources that fail to delete (auth error, network error) in tracking so a later cleanup can retry them

A message reports how many policies and connections were removed and lists any failures.

> [!WARNING]
>
> Cleanup removes policies and connections from your live Igris account, not just from the playground UI. If you renamed or reused a playground-created resource for real traffic, cleanup still deletes it.

***

## How It Works

The playground is a static Next.js site that talks directly to your Igris API from the browser. There is no playground backend. Every request uses the API key you entered in setup.

MCP scenarios send tool calls to `POST /v1/mcp/:slug`. LLM scenarios send chat completions to `POST /llm/:slug/v1/chat/completions`. The model field uses `@slug/model` syntax, and the playground substitutes the model name you configured at runtime.

### Running it locally

```bash theme={null}
cd tools/playground
bun install
bun run dev   # UI on :3500, MCP mock on :3600
```

Open `http://localhost:3500` and enter your API URL and keys. The API's `CORS_ORIGIN` must include `http://localhost:3500`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.