# MCP discovery history

**Last updated:** 2026-11-17T19:28:00-03:00 (UTC-3)

A console-managed MCP server ([MCP execution](/docs/features/mcp-execution/)) is executable only through tools an administrator approved from a recorded snapshot of its tool list. Every test and every detected drift already appends a snapshot. Discovery history makes that sequence reviewable: each snapshot names how and from which parent it was recorded, any two snapshots can be compared tool by tool, every approval becomes an immutable grant revision, and a grant change must name the approved snapshot the reviewer compared against.

| Flag | Default | What it turns on |
| --- | --- | --- |
| `mcp_discovery_history` | `false` | The three history routes, the reviewed-base check on approvals and grant revisions; an operator control; requires `mcp_connect` |

The flag adds no network call: history is read from PostgreSQL, and a server is contacted only by the existing **Test** action or by a call that detects drift. Boot (YAML) servers have their own read-only history behind `mcp_boot_discovery_history`; see [Boot (YAML) servers](#boot-yaml-servers).

## Snapshot provenance

Every new snapshot records:

| Field | Meaning |
| --- | --- |
| `source` | `test` (an administrator's Test), `drift` (a call saw an approved tool change), `import` (a new OpenAPI document), `scheduled` (a [scheduled check](/docs/features/mcp-scheduled-health/) saw the tools differ from the approved snapshot), `legacy` (recorded before migration 151) |
| `parent_id` | The server's previous snapshot, absent for the first |
| `request_id` | The request that discovered it |

A snapshot equal to the latest one is not appended again, as before. Snapshots are recorded whether or not the flag is on; the flag controls reading them and the review rules.

## Diff

`GET /api/v1/admin/mcp/managed-servers/{id}/snapshots/diff?from=&to=` compares two snapshots of the same server. `from` defaults to the approved snapshot (for a never-approved server every tool is `added`), `to` to the latest snapshot.

| Change | Meaning |
| --- | --- |
| `added` | A tool that was not in `from` |
| `removed` | A tool that is no longer listed |
| `schema_changed` | The input schema hash differs |
| `support_changed` | The tool moved in or out of the validated JSON Schema profile |
| `description_changed` | Only the description differs |

`affected_approvals` lists the currently approved tools that would not run against `to`: missing, outside the validated profile, or with a schema other than the approved hash. They stay quarantined until a new approval.

```json
{
  "from": 7,
  "to": 9,
  "unchanged": 3,
  "changes": [
    {"name": "lookup", "change": "schema_changed", "before_schema_sha256": "a1…", "after_schema_sha256": "b2…"},
    {"name": "admin_reset", "change": "added", "after_schema_sha256": "c3…"}
  ],
  "affected_approvals": ["lookup"]
}
```

## Explicit review before grant changes

With the flag on, an approval (`POST /api/v1/admin/mcp/managed-servers/{id}/approve`) of a server that already has an approved snapshot must carry `base_snapshot_id` equal to that approved snapshot. Without it, or with any other value, the gateway answers `409 mcp_review_required` and changes nothing. The check runs in the same transaction as the approval, so two reviewers who saw different approved states cannot both apply their grants; the existing `version` compare-and-set and per-tool schema hashes still apply. A first approval needs no base (and must not send one). While the flag is off `base_snapshot_id` is ignored. The console requests the diff for exactly the approved and latest snapshots on screen and approves that latest snapshot.

Each approval then appends a grant revision (`reason: approve`): a number per server ID, the approved snapshot, the reviewed base, the approvals before and after (tool, schema hash, teams), the actor, notes and request ID. When approvals are dropped outside an approval, the history records it too, as long as the server already has one: `reset` when an endpoint, auth or OpenAPI origin change returns the server to draft, `delete` when it is deleted; their `approvals` are empty. Revisions are never edited and remain readable after the server is deleted. A reused server ID continues the same numbering; `server_created_at` tells the incarnations apart and the `delete` revision closes the previous one. Approval never changes network trust: egress for a managed server is still limited to its own origin by the boot policy.

## Routes

All require the `mcp_connect:read` console permission (admin and viewer roles).

| Route | Returns |
| --- | --- |
| `GET /api/v1/admin/mcp/managed-servers/{id}/snapshots?before=&limit=` | Snapshots newest first (`limit` 1-100, default 20) with provenance, tool and unsupported counts and `approved` |
| `GET /api/v1/admin/mcp/managed-servers/{id}/snapshots/diff?from=&to=` | The diff above |
| `GET /api/v1/admin/mcp/managed-servers/{id}/grant-revisions?limit=` | Grant revisions newest first |

## Console

**MCP servers → Review** shows, above the per-tool grants, the changes since the approved snapshot, the snapshot lineage and the grant revisions. **Approve** sends the approved snapshot as the reviewed base.

## Boot (YAML) servers

| Flag | Default | What it turns on |
| --- | --- | --- |
| `mcp_boot_discovery_history` | `false` | Snapshots of boot servers and their two read-only routes; an operator control; requires `mcp_health_checks` |

A boot server's trust and grants are reviewed in YAML, so its history is evidence only: nothing in it approves, quarantines or changes a grant. With the flag on, every successful health check of a boot server with execution trust, the manual **Check health** (source `test`) or a [scheduled check](/docs/features/mcp-scheduled-health/) (source `scheduled`), appends a snapshot when the listed tools differ from the latest one of that server and endpoint. Each snapshot keeps the tool name, the input schema hash, whether it is outside the validated profile, and the SHA-256 of the first 300 characters of its description; the description itself is upstream text and is not kept. It also records `parent_id`, `request_id`, `endpoint_url` and the negotiated `protocol_version`. At most 200 snapshots are kept per server; older ones are deleted as new ones arrive. Two replicas checking at once never append the same snapshot twice. Checks are the only writers; the flag adds no network call.

| Route | Returns |
| --- | --- |
| `GET /api/v1/admin/mcp/boot-servers/{id}/snapshots?before=&limit=` | Snapshots newest first (`limit` 1-100, default 20) with `source`, `parent_id`, `request_id`, `endpoint_url`, `protocol_version`, tool and unsupported counts; `trust: "boot"` |
| `GET /api/v1/admin/mcp/boot-servers/{id}/snapshots/diff?from=&to=` | The diff above between `from` (default: the parent of `to`) and `to` (default: the latest), plus `missing_grants`: YAML grants the `to` snapshot does not offer in the validated profile |

Both need the `mcp:read` console permission and answer 404 for an ID that is not a boot server with execution trust. In the console, **MCP registry → Discovery history** on a trusted server's card loads the latest snapshots and the latest diff when opened; it offers no action.

```json
{"from": 7, "to": 9, "unchanged": 2,
 "changes": [{"name": "lookup", "change": "schema_changed", "before_schema_sha256": "a1…", "after_schema_sha256": "b2…"}],
 "missing_grants": ["retired"]}
```

## Upgrade

Migration 151 adds `source` (default `legacy`), `parent_id` and `request_id` to `gateway_mcp_tool_snapshots` and creates `gateway_mcp_grant_revisions`. Existing snapshots and approvals are unchanged. Upgrade every replica before turning the flag on: an older replica approves without the reviewed-base check. Migration 190 creates `gateway_mcp_boot_snapshots` for `mcp_boot_discovery_history`; an older binary rejects that flag name in YAML and ignores the table.
