# API and MCP playground

Pick any tool the sandbox serves, or write a query, and run it against the live sandbox from this page. Each answer shows its run id, its result digest and its rows, with code you can copy.

| Capability | Runtime | Status |
|---|---|---|
| Query the sample book and run all seven read-only tools with your workspace key | Sandbox | Live |
| Record Decisions and advance workspace time inside your isolated company enclave | Sandbox | Live |

<!-- portal:playground -->

## What you can run

The sandbox serves ten MCP tools inside your company's isolated enclave. Every company receives a private workspace key (`penv_...`) requested on `https://sandbox.precise.ai` (sign in on the sandbox home page or paste your key in the `Workspace key` drawer below). Seven tools run read-only queries and methods on the sample book; three write Decisions and advance time inside your own enclave.

| Tool | What it answers | Scope |
|-|-|-|
| `get_guide` | The guide to the sample book: its tables, measures, verbs, workflows and the two kinds of holdout | Workspace key (`precise:read`) |
| `get_book` | The book itself: its size, one order or campaign in full, and the record of scored Decisions | Workspace key (`precise:read`) |
| `query` | One read-only SQL query, or one structured join, over the pinned Parquet catalog | Workspace key (`precise:query`) |
| `run_analysis` | One Gateway method or workflow, on the book or on the method's own reference input. Each answer says which | Workspace key (`precise:run`) |
| `size_holdout` | The smallest held-back share and the shortest duration that can detect a lift | Workspace key (`precise:run`) |
| `get_calls` | The record of scored Decisions, or one Decision's five fields | Workspace key (`precise:read`) |
| `inspect_audit` | A verified run reopened by its `run_id`: its output, its digest and what rests on it | Workspace key (`precise:read`) |
| `make_call` | Records a Decision with its expected impact and range | Workspace key (`precise:record`) |
| `score_call` | Scores an open Decision once its outcome is in | Workspace key (`precise:record`) |
| `advance_time` | Makes time pass in a workspace, so delivery and outcomes arrive | Workspace key (`precise:record`) |

Any call without a valid workspace key answers HTTP 401 with the code `workspace_required`. That answer is shown here like any other, so you can see its exact fail-closed shape.

## What an answer carries

Every run on the Gateway returns two identifiers:

- `run_id` names the run. Pass it to `inspect_audit` to reopen the run. The playground fills it in for you after your first run.
- `result_digest` is a SHA-256 digest of the run's record. The same request text returns the same digest for the life of one Gateway process. Compare digests within one session, and compare rows across sessions.

A tool answer also starts with a plain sentence. `Measured:` states what the data shows. `Said:` states what Precise concludes from it or expects.

A query returns at most 200 rows. The [limits and errors](limits-and-errors.md) page has the limits and the error codes.

## Tool examples

These are the examples in the playground's menu. Each is the `arguments` object of a `tools/call` message.

### The guide's two kinds of holdout

```json sample get_guide
{"section": "holdouts"}
```

### The book at a glance

```json sample get_book
{}
```

### Five orders that carry a holdout

```json sample get_book
{"holdout": true, "limit": 5}
```

### One order in full

```json sample get_book
{"id": "ORD-012"}
```

### Spend and impressions by format

```json sample query
{"sql": "SELECT format, ROUND(SUM(media_spend_usd), 2) AS media_spend_usd, SUM(impressions) AS impressions FROM gold_daily_cube GROUP BY format ORDER BY media_spend_usd DESC"}
```

### List every method and workflow

```json sample run_analysis
{"list_contracts": true}
```

### Read one method's contract

```json sample run_analysis
{"describe": "power/holdout"}
```

### Check that a holdout ran clean

```json sample run_analysis
{"method": "comparison/holdout-integrity", "order_id": "ORD-012"}
```

### Split credit across four parts

```json sample run_analysis
{"method": "contribution/shapley"}
```

### Width of the next forecast range

```json sample run_analysis
{"method": "calibration/split-conformal-band"}
```

### Size a holdout the traffic can support

```json sample size_holdout
{"order_id": "ORD-012"}
```

### Size a holdout the traffic cannot support

```json sample size_holdout
{"order_id": "ORD-067"}
```

### The record of scored Decisions

```json sample get_calls
{"limit": 5}
```

## Sample queries

One read-only `SELECT` per run. The ten tables are `orders`, `line_items`, `deals`, `segments`, `tests`, `invoices`, `gold_daily_cube`, `outcomes`, `wins` and `bid_sample`. The playground lists each table's columns.

### Spend and impressions by format

```sql sample
SELECT format,
       ROUND(SUM(media_spend_usd), 2) AS media_spend_usd,
       SUM(impressions) AS impressions
FROM gold_daily_cube
GROUP BY format
ORDER BY media_spend_usd DESC
```

### Each deal against the open auction on the same seller

```sql sample
WITH deal AS (
  SELECT deal_id, seller_id, format, SUM(impressions) AS impressions, SUM(media_spend_usd) AS media_usd, SUM(allocated_segment_fees_usd) AS data_fees_usd
  FROM gold_daily_cube WHERE deal_id <> 'DEAL-OPEN-000' GROUP BY deal_id, seller_id, format
), open_line AS (
  SELECT seller_id, format, SUM(impressions) AS impressions, SUM(media_spend_usd) AS media_usd, SUM(allocated_segment_fees_usd) AS data_fees_usd
  FROM gold_daily_cube WHERE deal_id = 'DEAL-OPEN-000' GROUP BY seller_id, format
)
SELECT d.deal_id, d.seller_id, d.format, d.impressions,
  ROUND(1000.0 * (d.media_usd + d.data_fees_usd) / d.impressions, 4) AS all_in_cpm,
  ROUND(1000.0 * (o.media_usd + o.data_fees_usd) / o.impressions, 4) AS open_all_in_cpm,
  ROUND(d.media_usd + d.data_fees_usd - d.impressions * (o.media_usd + o.data_fees_usd) / o.impressions, 2) AS paid_above_open_usd
FROM deal d LEFT JOIN open_line o ON o.seller_id = d.seller_id AND o.format = d.format
ORDER BY d.deal_id
```

### Data fees by segment vendor

```sql sample
SELECT l.segment_vendor,
       ROUND(SUM(g.allocated_segment_fees_usd), 2) AS data_fees_usd,
       ROUND(SUM(g.avoidable_segment_fees_usd), 2) AS avoidable_usd
FROM gold_daily_cube g
JOIN line_items l ON l.line_item_id = g.line_item_id
GROUP BY l.segment_vendor
ORDER BY data_fees_usd DESC
```

### The planned tests

```sql sample
SELECT test_id, order_id, assignment_unit, split_method, allocation_treatment, planned_lift_pp, enrolled_cap_per_arm
FROM tests
ORDER BY order_id
LIMIT 10
```

### One holdout, arm by arm

```sql sample
SELECT holdout_arm, SUM(eligible_units) AS eligible_units, SUM(purchases) AS purchases
FROM outcomes
WHERE order_id = 'ORD-012'
GROUP BY holdout_arm
ORDER BY holdout_arm
```

### Wins by bid tier

```sql sample
SELECT bid_bucket, COUNT(*) AS bids, SUM(CASE WHEN won THEN 1 ELSE 0 END) AS wins
FROM bid_sample
GROUP BY bid_bucket
ORDER BY bid_bucket
```

## The same from a terminal

The playground sends two kinds of request, and both are open.

| Request | Address | Guide |
|-|-|-|
| An MCP `tools/call` message | `POST https://sandbox.precise.ai/api/mcp` | [MCP and A2A](../workspaces/platform-and-agents/mcp-and-a2a.md) |
| A governed query | `POST https://sandbox.precise.ai/api/sql/run` | [REST API quickstart](../workspaces/platform-and-agents/rest-api-quickstart.md) |

The DuckDB tab of a query builds a script that reads the same public Parquet files the sandbox reads, at `https://sandbox.precise.ai/data/parquet/<table>.parquet`. Run it in the `duckdb` shell to check a result on your own machine. The scripts were checked with DuckDB 1.5.5.
