Class CassetteRegistry

java.lang.Object
org.mockserver.mock.CassetteRegistry

public class CassetteRegistry extends Object
Process-wide registry of known cassettes — fixture files of MockServer expectations recorded with record_llm_fixtures or loaded with load_expectations_from_file.

The dashboard's Cassettes tab keeps a per-browser list in localStorage; this registry is the server-side counterpart so cassettes are also discoverable across page reloads, across browsers, and from automation (e.g. the demo data loader). It holds only lightweight metadata — the cassette's file path, name, expectation count and how it was created — never the file contents themselves. State is held in a ConcurrentHashMap keyed by file path and is cleared on server reset (see HttpState.reset()).

Exposed over the control plane as GET/PUT/DELETE /mockserver/cassettes.

Registration policy (settled — do not re-open). A cassette enters this registry from exactly three places, and loading and recording register automatically:

  • the record_llm_fixtures MCP tool, when it writes a fixture file (origin "recorded");
  • the load_expectations_from_file MCP tool, when it loads a fixture file (origin "loaded");
  • an explicit PUT /mockserver/cassettes, to track a cassette produced some other way.
The two MCP tools each own the file path and expectation count at the point the file is written/loaded, so they call register(java.lang.String, java.lang.String, int, java.lang.String) directly rather than routing through a shared load/record method — there is no such method: recording writes bytes and loading reads them, and they converge only on this registry. A manual PUT is therefore not required after a load or a record. Every path upserts by file path (see register(java.lang.String, java.lang.String, int, java.lang.String)), so re-loading or re-recording the same file updates the existing entry in place rather than duplicating it.
  • Constructor Details

    • CassetteRegistry

      public CassetteRegistry(LongSupplier clock)
  • Method Details

    • getInstance

      public static CassetteRegistry getInstance()
    • register

      public CassetteRegistry.Entry register(String path, String filename, int expectationCount, String origin)
      Register (or update) a cassette, stamping its lastUsed with the current time. When a cassette with the same path already exists it is updated in place rather than duplicated. No-op if path is blank.
      Parameters:
      origin - how the cassette was created — "recorded" or "loaded"
      Returns:
      the stored entry, or null if path was blank
    • remove

      public boolean remove(String path)
      Remove a cassette by path. Returns true if one was removed.
    • list

      public List<CassetteRegistry.Entry> list()
      Snapshot of all registered cassettes, most-recently-used first.
    • reset

      public void reset()
      Clear all cassettes. Called on server reset and for test isolation.