SchemaSnapshot
Rasuvaeff\Yii3Mcp\Testing\SchemaSnapshot
Class — Rasuvaeff\Yii3Mcp — Source
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.
SchemaSnapshot::verify($tester, __DIR__ . '/mcp-schema.json');Methods
assert()
static assert(Testing\McpTester $tester, string $path): voidCompares 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()
static verify(Testing\McpTester $tester, string $path): voidStrict 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()
static record(Testing\McpTester $tester, string $path): voidDeliberately (re)writes the snapshot file from the currently served capability schemas.
capture()
static capture(Testing\McpTester $tester): arrayCaptures the currently served capability definitions, normalized for stable comparison (sections keyed, lists ordered by their identity key, objects with sorted keys).