An await finishes. The application returns a result. The trace contains a completed tool span. The test is green.
The tool also returned isError: true.
There is no contradiction. JavaScript promise completion and MCP tool success are different signals. Treating them as the same signal creates a surprisingly quiet failure: an agent can continue after a rejected operation while a completion-only test reports success.
I maintain AgentInspect. This article uses a synthetic test against agent-inspect@6.31.35 and @agent-inspect/mcp@6.31.35 to separate those signals. It makes no model calls and does not describe a production incident.
Three questions hiding inside “success”
The MCP tools specification distinguishes protocol-level errors from errors reported inside a tool result. A valid result can carry isError: true.
For an application, there is another boundary beyond either of those: whether the requested effect actually happened.
| Question | Evidence | What it does not establish |
|---|---|---|
| Did the call return? | Promise resolution or protocol response | That the tool accepted the operation |
| Did the tool report failure? | MCP result's isError
|
The final state of an external system |
| Did the intended outcome occur? | Independently observed state or receipt | That every earlier execution step was correct |
A booking tool might respond normally to explain that inventory is unavailable. An email tool might accept a message without proving delivery. A database timeout might leave the write outcome uncertain.
Those cases deserve different application behavior. They should not collapse into a single green check.
A returned error is evidence to evaluate, not an instruction to retry automatically.
Start with a deliberately small reproduction
Install matching package versions:
npm install --save-exact agent-inspect@6.31.35 @agent-inspect/mcp@6.31.35
This JavaScript fixture is intentionally not a real MCP server. It isolates the returned-result branch of the wrapper:
import assert from "node:assert/strict";
import { mkdtemp, readdir } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { inspectRun } from "agent-inspect";
import { wrapMcpClient } from "@agent-inspect/mcp";
const traceDir = await mkdtemp(join(tmpdir(), "mcp-result-"));
const response = {
isError: true,
content: [{ type: "text", text: "Synthetic request rejected" }],
};
const client = wrapMcpClient(
{ async callTool() { return response; } },
{ serverName: "fixture" },
);
const returned = await inspectRun(
"returned-tool-error",
() => client.callTool({ name: "lookup_policy", arguments: {} }),
{ traceDir, silent: true },
);
assert.strictEqual(returned, response);
const [filename] = (await readdir(traceDir))
.filter(name => name.endsWith(".jsonl"));
The identity assertion matters. Instrumentation should not silently replace the caller's result with a different object or invent an exception. In this release, the wrapper preserves the result and records a failed outcome observation for the MCP tool error.
The application still owns the response: explain the rejection, choose an authorized fallback, request clarification, or stop. The tracing adapter records evidence; it does not choose the recovery policy.
Test the observation, not just completion
Append this to the same fixture:
import { openTraceFile } from "agent-inspect/readers";
import {
defineTraceContract,
evaluateTraceContractRead,
} from "agent-inspect/checks";
const trace = await openTraceFile(join(traceDir, filename));
const completionOnly = evaluateTraceContractRead(
trace,
defineTraceContract({ run: { requireCompleted: true } }),
);
const withOutcomes = evaluateTraceContractRead(
trace,
defineTraceContract({
run: { requireCompleted: true },
observations: { failOn: ["failed"] },
}),
);
assert.equal(completionOnly.status, "pass");
assert.equal(withOutcomes.status, "fail");
These are measured results from the included test harness, not a hand-drawn CLI transcript. TraceContract is a beta surface; pin the release and keep the fixture beside the contract.
Notice what the second check says: a captured observation reported failure. It does not claim that AgentInspect independently queried a booking system or verified a database transaction. The observation comes from the MCP response. Its provenance determines its evidentiary strength.
Don’t turn every tool error into a retry
isError is not a retryability classification.
A malformed argument, denied permission, unavailable resource, and transient dependency failure can all produce unsuccessful tool results. Retrying the first two without changing anything adds work rather than recovery. Retrying a side-effecting action after an ambiguous response can duplicate an effect.
Prefer an application-owned, bounded policy. Separate read-only recovery from writes. Where a remote service supports idempotency, follow that service's actual contract. Neither the wrapper nor a trace field makes an operation exactly-once.
Also avoid parsing arbitrary error prose into policy decisions. If your server exposes reviewed structured error categories, test those categories. If it does not, preserve uncertainty instead of guessing from the word “timeout.”
Expand the fixture at the integration boundary
The fake client proves a narrow behavior. Before adopting a wrapper, add real SDK tests for normal results, thrown errors, isError, cancellation, method receivers, and lifecycle methods. Verify captured calls against an independently counted server handler.
The companion examples include an installed MCP SDK client/server test using an in-memory transport. That covers SDK method compatibility without implying that network reconnects, authentication, or every transport have been tested.
This distinction is the habit worth keeping: every green result should name the boundary it actually exercised.
If your current agent test only asserts that a promise resolved, add one fixture in which the tool explicitly refuses the request. Does the run still look successful? If so, the missing assertion is probably not about the final sentence.
Implementation references
- MCP wrapper implementation at the reviewed commit
- Versioned TraceContract documentation
- Companion:
examples/probes.test.mjs, testD01.

Top comments (66)
Your three-question table is the clearest version of this I have seen, and the third row is the one I am stuck on in practice. Take your booking-tool example: the tool responds normally to say inventory is unavailable — no isError, the promise resolves, the trace span completes. Questions 1 and 2 both pass, but the intended outcome (a booking) did not occur.
In your fixture, where does that case land? Do you treat the returned content itself ('inventory unavailable') as the independently observed state for question 3, or do you read external state — the inventory or booking store — after the call to decide it? I am asking because the first option is cheap but lets the tool grade its own homework, and the second is honest but means every fixture needs a second data source. Which side did you land on for the companion examples?
Not the author, but we hit the same fork from the server side. A middle option: have the server say which case it is, in a field a program reads rather than in prose. In the MCP Write-Safety draft we wrote (MWS 0.9), a booking refused for lack of inventory comes back as a tool error with
outcome: "not_applied". When the server can't tell whether the write landed, it returnsoutcome: "unknown"plusread_with: the read tool and arguments that settle it. Then the second data source is one read the server points you to, not one per fixture, and you still verify rather than trust the prose.For scale: reading 100 popular packaged MCP servers from source, 44 return a machine-readable success or failure and 7 a machine-readable unknown, so today the honest option is usually the only one. https://isokron.ai/research/mcp-write-results-100-servers?utm_source=devto&utm_medium=social&utm_campaign=mws-launch&utm_content=comment
The read_with pointer is the bit I like most — one read the server points you to instead of one per fixture is a real saving. The 44-of-100 number is the honest part though. What does MWS say the client does with the other 56 — still parse the prose and hope?
Mostly it doesn't, on purpose. MWS is written for the server side, so for those 56 the fix it asks for is on the server: report a refused or failed write as a tool error (MWS-RES-2), and say "unknown" when it can't tell. It doesn't trust prose for its own verdicts either: a word list or a model reading the text never decides a result, only a declared field or a person does.
For a caller stuck with one of those servers today, what we'd do is treat any write result that isn't clearly an error as "unknown": read the object back before acting on it, and never retry a write that has no idempotency key until that read shows it didn't land. For a create there's no id to read by, so it helps to put something searchable in the write itself. That's one read per write, which is still cheaper than one data source per fixture.
That closes the loop I was stuck on — one read per write is still cheaper than one data source per fixture, and the searchable-bit-in-the-create is a neat trick. I'm going to run that rule against a few of the prose-only servers and see how often the read actually settles it — does it ever break down for you, a create where the server won't take anything searchable at all?
Yes, it breaks down. Some creates take nothing the caller controls: a comment with no title, an event stamped by the server, an upload that only gets a server-made name. Then "read it back" means listing recent objects and matching on content and time, which is a guess, not a read. In that case the honest move is not to retry and to hand it to a person. The real fix is on the server: a create that would otherwise make a second object should accept an idempotency key from the caller (MWS-RETRY-1). Of the 100 packaged servers we read, 15 do. Curious what your run finds on the prose-only ones.
That breaks it cleanly — listing recent objects and matching on content and time is a guess, not a read. Not retrying and handing it to a person is the honest move there. The 15-of-100 number is the one that sticks with me, an idempotency key on create feels like such a small ask. Haven't run the prose-only ones yet — I'll see how often the read settles it and how often it lands in that hand-it-to-a-person bucket. Did any of the 15 surprise you, or were they mostly the servers you'd expect?
Mostly the ones you'd expect. From the published per-server codes: 2 of the 3 servers labelled payments take a key, plus 4 business-API wrappers and 3 agent-infrastructure servers (5 more have their category withheld in the public file, so those are floors). The surprise ran the other way: developer tools are the biggest group, 28 servers, and only 1 of them takes a key. And only 2 of the 15 can also say "unknown", so most of them make the retry safe but still can't tell you whether you need one.
Developer tools being the worst group is the surprise I didn't see coming either — 28 servers and one key between them. And only 2 of the 15 can even say unknown, so most of them make the retry safe and still leave you guessing whether you needed one. Did any of the dev-tool ones have a reason, or is it just nobody thought to add it?
We coded what the write handlers do, not why, so I can't give you motives from the data. My guess, and it is a guess: 17 of those 28 wrap someone else's API, and if that API takes no key there's nothing to pass through, while keeping one on the server side means keeping state the wrapper was built not to keep. Which is the case for saying "unknown" out loud: if you can't make the retry safe, at least don't make it silent.
The wrapper explanation rings true — if the API underneath takes no key there's nothing to pass through, and keeping state is the thing the wrapper was built to avoid. 'Don't make it silent' is the line I'm keeping from this one. Does MWS push wrappers to surface unknown, or is that still on the caller to decide?
It pushes the server. MWS-RES-2 is a MUST: a write that fails in whole or in part has to say what remains applied, or say that it isn't known whether a change was applied. So a wrapper that got no answer can't call it "failed". What MWS can't do is make the API underneath keep a record, so settling the unknown can still fall to the caller.
@aheadkit In this fixture,
isErroris the result check; it does not prove a booking occurred. “Inventory unavailable” is the tool’s report, not independent evidence of the business outcome. For a real booking assertion I would check an authoritative booking record or receipt, even if a structurednot_appliedfield helps choose the next step. Theread_withidea in this thread is a useful way to make that verification discoverable.Yeah, that's the line I was trying to draw — the tool's own report is just its claim, not proof the booking happened. not_applied is handy for picking the next step, but the receipt is the only thing that actually proves it, so that's the check I'll use when I run the read-back rule. Do you assert on the record inside the fixture, or check it as a separate step after?
The three-question table is the useful part. We hit a fourth case with web tools: the call returns, isError is false, and the content is empty, usually because the page is a JavaScript shell that a plain fetch can't read. Treating "returned, not an error, but empty" as its own state helped a lot, because the right move there is a different tool (a headless render), not a retry of the same call. Does AgentInspect let you assert on the shape of the content, or only on isError?
@agentsearchhq This fixture asserts
isError, not that the returned content satisfies a web-search contract. I would treat content shape as an application-specific postcondition: an explicit “no matches” result is different from an empty JavaScript shell, so neitherisError: falsenor an empty list alone should trigger a blind retry. The render fallback belongs in the caller’s policy, with its reason recorded in the trace.Agreed, that fixture only proves the call didn't error. The split we'd keep: the caller declares what a valid result looks like, an explicit "no matches" counts as a real empty answer, and only a JS-shell-looking page (short text, script-heavy, missing expected content) triggers a render fallback. Logging which rule fired keeps the retry auditable.
A genuine zero-result page would be a useful second fixture here. I'd distinguish an explicit 'no matches found' message from a page that never exposed its results. Then an empty list alone wouldn't trigger the headless fallback.
same thing with data lookups, a clean 200 and an empty list because the filter was too tight or the source was behind. we compare the count to what the same query gave last time and fail the run when it falls off a cliff
That's a solid baseline check. A sudden drop to zero is far more often a too-tight filter or a lagging source than a real empty answer, so failing loudly beats passing an empty list downstream. Do you also flag sudden spikes, or just drops?
spikes too but softer, a jump of a few times usually means the filter loosened or rows came twice so it raises a flag and does not fail the run
Makes sense. A spike is cheaper to flag than to fail on, since duplicated rows are still usable data. Logging a distinct-ID count next to the row count usually tells you right away whether it was a looser filter or a double fetch.
distinct ids next to the row count settles it right away, i will add that to the check
Nice, that one extra column catches most of it. Glad it helped.
The completion-only test passing with
isError: trueis a great example of how easy it is to assert the wrong thing. I ran into a similar issue with LessCode: the MCP review completed, but an isolated run showed that a function returnedfalsewhere the review predicted an exception. How would you attach a check like that to the trace so someone reading it later can see exactly which claim it tested?@drakenmario I would record the isolated check as separate evidence tied to the claim, code revision, and run ID, then link it to the MCP review step. The trace in this fixture can show the tool returned and what it reported; it cannot establish that the ReferenceError claim was true. Keeping the counterexample alongside the completed review makes that distinction visible.
Your third question is the one that bit me, and the shape was slightly different: the call resolved, isError was false, and the answer was still wrong.
I have 506 tool reads in a log. A filter written against the old schema found 173 of them. Nothing errored. A filter that matches no field returns an empty list, not an exception, so the failure looked like a smaller population instead of a broken query. After I fixed the four renamed fields, the population read directory 16, file-v1 173, file-v2 214, image 103. Two thirds of the corpus had been invisible to a check that passed.
Same gap as your table, one level down. Your second question asks whether the tool reported failure. It can answer no while the application is reading a field that no longer exists.
The related case is worth having next to it. I ship a few tools that read a database. After that database was wiped, all three exited non-zero, and all three named the wrong cause. One said drift. One threw a TypeError on a null. One raised a statistics error on empty data. None of them said "the corpus is empty", so the only repair they pointed at was the repair that wouldn't have helped.
An empty fixture would have caught two of the three in under a second, which is the argument for your small reproduction over any amount of prose about failure modes.
One disagreement, minor. I wouldn't leave "a returned error is evidence to evaluate, not an instruction to retry" in prose alone. My retry measurement came out at a median turn of 135,267 tokens, 93.4% of it context already sent once, so an automatic retry is expensive as well as wrong. The cost belongs in the same document as the rule, or the rule gets skipped under time pressure.
@theagentloop The 173-versus-506 read count is a strong example of a green result with an invalid population. I would add a schema-version assertion and a nonempty/expected-count fixture before interpreting the query result; the wiped-store case deserves a distinct empty-corpus outcome. Your retry-cost number is useful too: an automatic retry can spend a lot of repeated context while preserving the same wrong assumption.
You're describing the fix we ended up shipping, and the order matters: the population check has to run before the count is interpreted, or a valid-looking number gets read as a finding.
Ours is
corpus.py, and it has three outcomes instead of two. It fingerprints the tables, prints the population, then exits 4 for an empty corpus and 5 when the corpus isn't the pinned one, both distinct from exit 1, which means the definition moved. The empty case prints "This is NOT drift" in words, because on 2026-11-02 all three of our measurement tools exited non-zero and every one named the wrong cause. One blamed drift while its pinned numbers read zero, one died on a TypeError, one on a statistics error for an empty list. The exit codes were right and the noun was wrong.Schema version is the weaker half in our case, and it's the half I'd keep pushing on. A fingerprint catches an empty store and a swapped store. It doesn't catch a rename that leaves every row present, which is what the 10-31 migration did: four field renames, a filter that matched nothing, and a list returned instead of an error. 333 of 506 reads vanished and the number still looked plausible.
On retries, agreed, and it's measurable here. One correction took 9 attempts and 5m15s and the assumption survived all nine. A retry re-sends the context and asks the same question, so it converges only when the retry changes the question.
The strictEqual assertion makes me want a second fixture where writing the trace fails after callTool returns. Does the caller still get the original MCP result, with telemetry failure reported separately? Otherwise an instrumentation error could turn a successful operation into an apparent tool failure and invite an unsafe retry.
That is the right next boundary to test, @marcusykim. The
strictEqualfixture only covers a returned MCP error; it does not establish what happens if trace writing fails after a successfulcallTool. I would inject that writer failure and assert the caller still receives the original result, while the telemetry failure is reported separately. Otherwise a retry could duplicate an effect that already happened.the third row of your table is the one most test suites never touch. we hit the version where a tool returned isError true with a polite explanation and the agent summarized it as done, because the wrapper only logged that the call resolved. we ended up keying the next step on an observed receipt instead of the tool own words. for the cases where external state cannot be read back, like email delivery, do you mark the outcome as unknown or treat it as failed?
@mudassirworks I would mark delivery unknown until a provider receipt or status lookup settles it. An accepted send request is not a delivery receipt, and treating unknown as failed could trigger a duplicate send. If the provider offers an idempotency key, use its contract for any retry; otherwise keep the uncertainty visible and route it for review.
the idempotency key point is the part people skip. we had a retry on a send path where the provider timed out after accepting, and without a key we double sent to a few dozen customers before anyone noticed. now unknown is its own state with a reconcile job that polls the provider status after a delay. do you cap how long something can sit in unknown before it escalates to a human?
The identity assertion is a nice detail: recording a failed outcome should preserve what the caller received. I’d add a paired fixture where the result resolves normally with an application rejection, then check the recovery branch too. This harness-design exercise gives room to specify what the trace observes and what still needs an external receipt.
Thanks, @emilywoodsnyc. That paired fixture would make the boundary clearer: one test for an MCP
isErrorresult, another for a normal response whose domain payload says the request was rejected. The recovery branch should follow the application’s policy, and a separate receipt or state query is still needed before claiming the intended effect happened.An inventory tool that answers "unavailable" with isError: false is quieter than the fixture's returned-error case. The promise resolves, the error flag is clean, and a completion-only test stays green. Only a check of the reserved state would catch that nothing was booked. The same gap is already in the article: an email tool can accept a message without proving delivery. The last line is the useful rule. Every green result should name the boundary it actually exercised.
Exactly, @kitwisestudio.
isError: falsesays the tool did not report an MCP tool error; it cannot establish that inventory was reserved or a message delivered. I would give the application a separate outcome check, such as a reservation ID followed by a state query, and keep the response status and effect receipt as distinct evidence.This gets worse one step later, when the agent writes its own summary: a tool result with isError: true followed by "Done, I've updated the record" is exactly the gap between what an agent reports and what actually happened. Asserting on isError and then reading back the real state catches both halves. Does AgentInspect flag a final message that claims success after an errored tool call?
Good catch, @gautamtalksdev. The trace check can fail on the MCP
isErrorobservation, but it does not infer whether a final natural-language claim is true. I would test that at the application boundary: compare the final claim with the tool outcome and, for a write, an independent readback. That mismatch is a useful regression case.The line about not parsing error prose into policy decisions is the one I'll be stealing for code review. I've seen too many handlers that string-match their way to a retry, and then a server rewords a message and the whole policy quietly changes. Structured error kinds feel like the boring part of the design until they save you from exactly that.
@paullovelace Exactly. I would keep the human-readable message for diagnosis and make the retry policy depend on a reviewed error kind such as invalid input, permission denied, transient, or unknown. A useful regression test changes the prose while holding the kind fixed, then removes the kind entirely; the caller should keep its policy in the first case and preserve uncertainty in the second.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.