#411·OfficeCLI

MCP: an operation that applied nothing reports `isError:false` to the agent (the CLI says `success:false`, exit 2) — while the same intent via `batch` reports `isError:true`

Author: argszeroCreated Sep 20, 2026Updated Sep 21, 2026

Summary

The MCP surface decides whether a call failed from the process exit code alone:

csharp
bool appliedWithCaveats = r.Exit == 2 && stdout.Length > 0;   // McpServer.cs:485
bool isError = r.Exit != 0 && !appliedWithCaveats;            // McpServer.cs:486

A one-shot set in which no property was applied exits 2 and writes {"success": false, "message": "No properties applied to …"} to stdout — so it is classified as "applied with caveats" and reported to the agent as not an error. The same intent expressed as a batch item exits 1 and is reported as an error. The MCP text is the JSON envelope, so the contradiction is visible inside a single tool result.

Measured on the released binary 1.0.151; source read at origin/main dced0d74.

Environment

  • officecli 1.0.151 (macOS arm64), driven through the officecli mcp stdio server (raw JSON-RPC: initialize → notifications/initialized → tools/call, tool name officecli)
  • Fixture: create t.xlsx && set t.xlsx /Sheet1/A1 --prop value=1 && close t.xlsx; each arm runs on a byte-identical copy of it

The mismatch

Every arm below is the same command run twice: once as a CLI process (rc + envelope), once through MCP (isError).

arm CLI exit envelope success MCP isError verdict agrees with CLI?
set t.xlsx /Sheet1/A1 --prop bogusprop=1 --json 2 false false ✗
set t.xlsx /Sheet1/A1 --prop colr=red --json (typo) 2 false false ✗
set t.xlsx /Sheet1/A1 --prop bogus1=1 --prop bogus2=2 --json 2 false false ✗
set t.docx /body/p[1]/r[1] --prop bogusprop=1 --json 2 false false ✗
set t.xlsx /Sheet1/A1 --prop bogusprop=1 (text mode) 2 — false ✗
the same intent as a batch item 1 false true ✓
control: --prop value=5 --prop bogusprop=1 (applied with caveats) 2 true false ✓
control: latex caveat (\boguscmd{x}) 2 true false ✓
control: unknown sheet 1 false true ✓

In text mode the failure is spelled out on stdout — No properties applied to /Sheet1/A1 — and MCP still reports isError:false; in JSON mode the payload MCP forwards verbatim contains "success": false.

One input family therefore reaches the wire with three different verdicts (exit 0 in batch, 1 in batch when nothing applied, 2 one-shot), and the MCP layer then guesses which one means "not an error".

Root cause

McpServer.cs:470-476 states the intended rule in the author's own words:

Only a genuine failure raises: exit 1 (e.g. path not found, nothing applied), or exit 2 with no stdout … An exit-2 add/set with a populated stdout is the CLI's "applied with caveats" path — the element was added (envelope success:true) and only an unsupported property was dropped; surfacing that as a hard error makes agents re-issue an op that already landed.

  • "nothing applied" is exactly the measured shape, and it does not raise: set maps it to exit 2 with a populated stdout.
  • The same file says the verdict must not be read out of the prose: McpServer.cs:492-494 — "The pass/fail bit rides on isError, not on the text — exactly like a terminal user reading stdout plus the exit code." The measurements above invert that: the text says failure, the bit says fine.
  • appliedWithCaveats collapses two different CLI outcomes into one bucket. "Some props applied, some dropped" (envelope success:true) and "no prop applied" (envelope success:false) are both exit == 2 && stdout.Length > 0.
  • The envelope is already in hand: RunCliRaw (McpServer.cs:449-459) captures (exit, stdout, stderr) through Console redirection, and SurfaceCliResult already parses nothing out of it.

Why this is a defect rather than a design choice

  • The rule the code comment states is violated by the code, in the one example the comment picks.
  • The CLI's own verdict for this input is unambiguous and stable across modes: success:false, No properties applied to /Sheet1/A1, plus a warnings[{code:"unsupported_property"}] block. batch already models the same intent as a failure (success:false, exit 1).
  • This surface is the one agents use. The tool description tells them "Add --json to get/query/validate/view-issues for structured output", and its delivery gate says "any failure = fix and re-check, do NOT deliver". Learning the true verdict here requires parsing a JSON document out of a text content block while the protocol's own error channel reports success — and an agent that trusts isError concludes the edit landed.
  • The input is not exotic: set --prop colr=red is the typo case from #405, and bogusprop=1 is the shape the maintainer swept there and reported as exit 2 with success:false one-shot / resident.

Sibling precedent (same class, once already fixed)

#350 (reported by another user) was "docx: batch drops the dangling-style warning (stdout, --json, MCP)" — a per-surface propagation gap for a caveat. It was fixed by community PR #355 → ad07f8b4 "fix(batch): preserve per-item warnings", which wired Word's LastAddWarnings into the per-item warnings (now CommandBuilder.Batch.cs:98-117). So this repo treats "the verdict/caveat does not reach every surface" as a defect class, and the propagation machinery exists. This report is a different member of that class: not a missing warning, but an inverted failure verdict on the MCP surface.

(A comment on the closed #405 covers yet another member of the family — the warnings channel that is still unfed for a dropped property and the exit code that follows it. The two share one root: exit 2 is overloaded.)

Reproduction

CLI side:

bash
officecli create t.xlsx && officecli set t.xlsx /Sheet1/A1 --prop value=1 && officecli close t.xlsx

officecli set t.xlsx /Sheet1/A1 --prop bogusprop=1 --json; echo "exit=$?"
# exit=2, stdout: {"success": false, "message": "No properties applied to /Sheet1/A1", "warnings": [{"code":"unsupported_property", ...}]}

officecli set t.xlsx /Sheet1/A1 --prop bogusprop=1; echo "exit=$?"
# exit=2, stdout: No properties applied to /Sheet1/A1
#         stderr: UNSUPPORTED props: bogusprop (valid cell props: value, formula, ...)

MCP side — the same argv through officecli mcp (newline-delimited JSON-RPC on stdin):

json
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1"}}}
{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"officecli","arguments":{"command":["set","t.xlsx","/Sheet1/A1","--prop","bogusprop=1","--json"]}}}

Reply: result.isError == false, result.content[0].text = the {"success": false, …} envelope above.

For comparison, the same intent as a batch item:

bash
officecli batch t.xlsx --commands '[{"command":"set","path":"/Sheet1/A1","props":{"bogusprop":"1"}}]' --json; echo "exit=$?"
# exit=1, {"success": false, …}

→ through MCP, result.isError == true.

Each arm was re-run three times; readings identical.

Fix directions

Minimal (covers the five JSON arms): make the MCP verdict envelope-aware — narrow the caveat test to exit 2 + non-empty stdout + parsed envelope success == true, and keep today's heuristic only when stdout is not JSON carrying a boolean success:

csharp
bool appliedWithCaveats = r.Exit == 2 && stdout.Length > 0 && EnvelopeSaysSuccess(stdout);

success is present on the envelopes of get / view / query / set / add / batch / validate (spot-checked), so the fallback applies only to genuinely unstructured output.

Structural (covers text mode too, and the wire disagreement): give "nothing applied" one verdict on every surface. Today it is exit 2 one-shot, exit 1 in batch, so no exit-code heuristic can be right for both modes. Since exit 2 is documented as "applied with caveats", nothing-applied belongs in the failure class (that is also what batch already does) — after which appliedWithCaveats becomes sound for text mode as well.

Either way, these must keep working:

  • caveat shapes (exit 2, success:true) stay isError:false;
  • genuine failures (exit 1) stay isError:true;
  • text keeps surfacing the CLI output verbatim, since scripts parse the JSON out of it.

Notes

  • No patch attached: this machine has no .NET SDK, so the fix above is text-verified only. Every reading in this report is measured on the released 1.0.151 binary.
  • MCP was driven through the raw stdio JSON-RPC path, not through a client library, so a client that re-derives the verdict from the text payload would mask the problem rather than fix it.
  • Not measured: other MCP clients, and MCP batch against a live resident.