Testing the Protocol Layers

The Tools layer has solid coverage and the suite is green, and then the mobile app breaks because an endpoint now answers 200 where it used to answer 201. Nothing in the business logic changed. Protocol layers fail in their own way, at the seam between an outside convention and an inside function, so they need a different kind of test from the code underneath.

Test the translation, not the rule

LVD's protocol layers are adapters. Their job is to turn external semantics, such as HTTP verbs, status codes and content blocks, into calls on internal tools, and to turn the answers back. The book therefore says the main concern when testing them is contract compliance: does the adapter translate correctly between the outside protocol and the internal tool interface?

That framing says what to leave out. Business rules were verified in Layer 4, where the handlers live. Repeating them in an endpoint test means two places to change when a rule moves. As a rough smell test, if a REST test needs to know how a fee is calculated, some logic has probably leaked into the adapter.

Contract tests for REST

For an endpoint, a contract test checks that the route behaves as its documentation promises. A creation endpoint typically needs three cases: a valid request returns 201 with the new identifier in the body, a request without credentials returns 401, and a malformed body returns 400.

describe("POST /api/v1/reservations", () => {
  it("returns 401 without a token", async () => {
    const res = await request(app).post("/api/v1/reservations").send(validBody);
    expect(res.status).toBe(401);
  });

  it("returns 400 when seats is not a list", async () => {
    const res = await request(app)
      .post("/api/v1/reservations")
      .set("Authorization", `Bearer ${token}`)
      .send({ seats: "A1" });
    expect(res.status).toBe(400);
  });
});

Both tests are about the boundary. One proves the authentication step runs before anything else, and the other proves a bad payload is stopped by schema validation and mapped to the right status. Neither says anything about seating rules.

Contract tests for MCP

MCP tools get the same treatment, adapted to their response format. The tests verify the structure of the content that comes back and confirm the underlying tool handler was invoked properly. A successful call returns an array of content blocks whose text includes the expected summary, and carries no error flag. A call with missing parameters comes back with the error flag set to true.

const ok = await mcpClient.callTool("get-reservation", { reservationId });
expect(ok.content[0].type).toBe("text");
expect(ok.isError).toBeUndefined();

const bad = await mcpClient.callTool("get-reservation", {});
expect(bad.isError).toBe(true);

The second assertion matters more than it looks. The error flag is how an agent learns that a call failed, so a regression there would quietly turn failures into answers.

One test through both doors

Contract tests look at one adapter at a time. The book completes the picture with an end-to-end test that uses real or realistic infrastructure and exercises the full middleware chain. The sequence is short:

  1. Start a test server with a database and authentication enabled.
  2. Authenticate a test user and obtain a token.
  3. Create a record through the REST API and check for a 201.
  4. Fetch the same record through an MCP tool call.
  5. Assert that the MCP content mentions the identifier from step 3 and that the status matches.

What this proves is the architecture itself. A record created through the REST layer (L5) is visible through the MCP layer (L6), which confirms that both protocol layers delegate to the same underlying tool handlers. If either adapter had grown its own copy of the logic, the two views would eventually disagree, and this test is the one most likely to notice.

The takeaway

Test adapters as adapters. Check status codes, content shapes and the error flag, and leave the business rules to the tools. Add one end-to-end test that crosses both protocol layers to confirm they still share the same tools. The wider testing strategy for every layer is in layer-specific testing for protocols, skills, agents and UI, and the tests one layer down are covered in testing tools. For the adapters under test, see REST at Layer 5 and the MCP layer.

What the book covers

  • Full contract-test listings for a REST endpoint
  • MCP tool response validation including the error flag
  • The pseudocode for an end-to-end test that spans both protocol layers
  • Exercises on multi-protocol adapter design and on protocol-layer volatility measurement