Repository navigation
Commit b0505c0
feat(mcp): a refusal with several declared reasons names every line to the agent (#37497)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgFiXLbrG7d8JVydkmtSf4Bt)_
Fixes #37416
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:智能体通过 MCP
新建、修改、删除记录或运行动作时,如果一次拒绝带了多条原因,它现在能完整拿到每一条原因和最后的总结句,再转告用户;只有一条原因的拒绝和以前一样。
- 为什么做:接上「一次拒绝可以带多条已翻译原因」那张卡;数据入口把给用户的那句话截在 500 字,原因多时智能体只看到被截断的一段。
- 出错会怎样:只影响带多条原因的拒绝,智能体多看到一段文字;原来的错误内容一个字不变,可以直接撤回。
- 要你做什么:无。
## What changes
- `packages/mcp/src/mcp-http-tools.ts`: a refusal thrown as a declared
`reasons` list now gets a second text block, the
`flowFailureRelaySentence` pattern (card ruling): `content[0]` stays the
door's envelope byte for byte, and `content[1]` is a fixed lead
(`REFUSAL_REASONS_RELAY_LEAD`) followed by every listed line, whole and
in the order thrown, then the closing line.
- Wired into the two renderers that serve a door's `userMessage`:
`errorResultFromThrown` (`run_action`, `resume_run`; the `/actions`
answer) and `dataDoorErrorResult` (the record data tools; the `/data`
answer, whose `userMessage` is cut at 500).
- The lines are read through `declaredRefusalLines`
(`@objectstack/types`), the one recogniser every door uses for
`details.refusals` (imported, not hand-spelled). The closing line is not
on the list (the #36877 changeset says so). It is read as the part of
the error's own unbounded `userMessage` (`declaredUserMessage`) after
the listed lines. If that text does not begin with the lines, no closing
line is invented and the block carries the lines alone.
- Withheld, so these answers are unchanged: a `PERMISSION_DENIED` answer
(the #7450 rule; `run_action` already returned before this point, and
the data tools now ask the same question), an answer with no
`userMessage`, a fault (5xx), and any throw the shared recogniser does
not read (a single-reason refusal among them).
- `packages/mcp/src/stdio-data-bridge.ts` is untouched. It only
implements the bridge and renders no tool result. The stdio server's
tools are rendered by the same `mcp-http-tools.ts` functions, so the
relay applies to both transports with no stdio edit.
## Tests
`packages/mcp/src/mcp-refusal-reasons.test.ts` (new, named for the
card): 14 cases through the real HTTP `/mcp` transport
(`MCPServerRuntime.handleHttpRequest`), with a bridge double that throws
the shape the runtime's catalogue throws (`SandboxError` with `code`,
`status`, `userMessage`, `refusals`).
- For each of `run_action`, `resume_run`, `create_record`,
`update_record` and `delete_record`: two lines plus the closing line
ride as `content[1]`, and `content[0]` equals the answer to the same
throw without `refusals`. A single-reason refusal answers one block, as
today.
- A six-line list on `create_record` whose joined text exceeds 500
characters: the envelope's `userMessage` is cut (at most 500 characters,
closing line missing), and the relay names every line whole with the
closing line last.
- Controls: `PERMISSION_DENIED` carrying a list gets no relay on all
five tools; four malformed lists get none; a `userMessage` that does not
begin with the lines gets the lines and no invented closing line.
<details><summary>Package suite, typecheck, ablations</summary>
- `pnpm --filter @objectstack/mcp typecheck && pnpm --filter
@objectstack/mcp exec vitest run --maxWorkers=2` on `ef53eb6617`, under
the verify lock: `VERDICT command-exit 0`; Test Files 86 passed (86),
Tests 1540 passed (1540); `check:test-typecheck: OK` (the new file
compiles under `tsconfig.test.json` and has no debt entry).
- Ablation 1 (`node scripts/ablation-replace.mjs`): `const text =
refusalReasonsRelayText(err);` replaced by an always-undefined value
(anchor 1 → 0, blob a311814 → 335b2247). Result: 7 failed / 7 passed,
namely the five per-tool relay cases, the 500-cut case and the
no-invented-closing case. Restored: blob equals HEAD, `git diff HEAD`
empty.
- Ablation 2: the `PERMISSION_DENIED` guard removed (blob a311814 →
172d9385). Result: 1 failed / 13 passed, the #7450 control, failing at
`create_record` (`run_action` already returns earlier). Restored: blob
equals HEAD, `git diff HEAD` empty.
- The tests import `src/` through relative paths, so no rebuild was
needed for either ablation.
</details>
## Acceptance notes
- H3 measured: the closing line is not carried in `details`. The #36877
changeset states that `details.refusals` holds only the listed lines and
that the closing line exists only as the last line of `userMessage`. MCP
holds the thrown value in process, so it reads the unbounded
`userMessage` that the `/data` door would later cut. The closing line is
that text minus the listed-lines prefix. This relies on the composition
the catalogue documents (lines joined by a line break, then the code's
own `message`), and the control pins the case where the composition does
not match.
- On `run_action` / `resume_run`, the `/actions` door does not cut
`userMessage`, so the envelope already held every line. The block is
added there too so that every tool answers a listed refusal one way. The
envelope is unchanged on both doors. `details.refusals` is not added to
either envelope: `errorResultFromThrown` serves only a thrown `details`,
and the data tools withhold `details` by design (`errorResultWithCode`).
- Not covered: `delete_records` groups refused rows by the thrown
message (`rowRefusalOf`) and reads neither `userMessage` nor `details`.
The record resource and the metadata tools render no `userMessage`
relay. None of these is changed here.
- The tests are in a new file, as the dispatch order asked. The closest
existing file (`mcp-action-refusal-details.test.ts`) builds its own
local harness and is not a shared harness file.
## Verification
- Derived gate list (`node scripts/pm/dispatch-gates.mjs --commands
--repo objectstack-ai/objectstack`, change set of 3 paths against merge
base `eaa9e5447`): 67 derived, run on `ef53eb6617`. 66 exit 0. One NOT
MEASURED: `pnpm check:dual-build-cjs-loads` exit 3 (PREREQUISITE NOT
MET: it needs the whole workspace built; CI Build Core runs it). `--ran`
reconciliation: 67 accounted, 66 run, 1 NOT-MEASURED.
- CI check-runs are the authority for every family.
Two-minute check: `pnpm --filter @objectstack/mcp exec vitest run
--maxWorkers=2 src/mcp-refusal-reasons.test.ts`. Expect 14 passed.
Read first: `packages/mcp/src/mcp-http-tools.ts`, specifically
`withRefusalReasonsRelay` and `refusalReasonsRelayText` (the
closing-line read) and the `dataDoorErrorResult` hunk.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZmwqAVSYHM1nQUDTq)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent dd1ffcc commit b0505c0
3 files changed
Lines changed: 306 additions & 3 deletions
File tree
- .changeset
- packages/mcp/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
1384 | 1384 | | |
1385 | 1385 | | |
1386 | 1386 | | |
1387 | | - | |
| 1387 | + | |
1388 | 1388 | | |
1389 | 1389 | | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
1390 | 1464 | | |
1391 | 1465 | | |
1392 | 1466 | | |
| |||
1678 | 1752 | | |
1679 | 1753 | | |
1680 | 1754 | | |
1681 | | - | |
| 1755 | + | |
| 1756 | + | |
1682 | 1757 | | |
1683 | 1758 | | |
1684 | 1759 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
0 commit comments