Skip to content

SchemaSnapshot

Rasuvaeff\Yii3Mcp\Testing\SchemaSnapshot

ClassRasuvaeff\Yii3McpSource

Contract canary for MCP capability schemas: snapshots every served tool, resource, resource template and prompt definition into a committed JSON file and fails when the served set drifts — a changed method signature silently changes the generated inputSchema and breaks agents mid-flight, so drift must be an explicit, reviewed act.

Three modes:

  • verify() — for CI: a missing snapshot is an error, so a deleted or never-committed file cannot yield a green build.
  • assert() — migration-friendly: a missing snapshot is generated on first run, then compared like verify().
  • record() — deliberately (re)writes the snapshot.

Setting the MCP_SNAPSHOT_RECORD environment variable to any value except ''/'0' switches assert()/verify() into record mode — the explicit regeneration path (MCP_SNAPSHOT_RECORD=1 vendor/bin/testo); CI must not set it.

php
SchemaSnapshot::verify($tester, __DIR__ . '/mcp-schema.json');

Methods

assert()

php
static assert(Testing\McpTester $tester, string $path): void

Compares the served capability schemas against the snapshot file. A missing file is generated (first run passes); a mismatch throws with a per-section summary of the drift. Prefer verify() in CI, where a missing snapshot must be an error.

verify()

php
static verify(Testing\McpTester $tester, string $path): void

Strict form of assert() for CI: a missing snapshot file is an error instead of being silently generated, so a lost or never-committed snapshot cannot produce a green build.

record()

php
static record(Testing\McpTester $tester, string $path): void

Deliberately (re)writes the snapshot file from the currently served capability schemas.

capture()

php
static capture(Testing\McpTester $tester): array

Captures the currently served capability definitions, normalized for stable comparison (sections keyed, lists ordered by their identity key, objects with sorted keys).