Repository navigation
Commit 1af67b2
fix(mcp): the refusal-reasons relay withholds only the security gate's own refusal (#37537)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu3zQ2AqeghSGpv6Q7VEPDyQ)_
Fixes #37512
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:智能体通过 MCP
遇到应用自己按“无权限”声明的多原因拒绝时,现在也能完整拿到每条原因再转告用户;平台安全检查本身的拒绝仍然什么都不多给。
- 为什么做:这是上一轮“多原因拒绝完整转告智能体”审核留下的跟进项;同一个调用者走 REST 接口早已拿到这些原因,MCP 却少给了。
- 出错会怎样:只影响应用声明为“无权限”的多原因拒绝,智能体多看到一段原因文字;安全检查的内部授权信息在任何路径上都不读取,可以直接撤回。
- 要你做什么:无。
## What changes
`packages/mcp/src/mcp-http-tools.ts` only, plus the tests and one
changeset.
- **S1, the guard's reach (narrowed to the gate's own refusal).**
`withRefusalReasonsRelay` now withholds the relay block on a served
`PERMISSION_DENIED` with no `declaredCode`: the security gate's own
refusal. A listed refusal an app's catalogue declared at `403` under its
own code is served as `PERMISSION_DENIED` with that code in
`declaredCode` (the doors' demotion of an unregistered code) and now
gets the block. `errorResultFromThrown`'s `PERMISSION_DENIED` arm now
passes through the same function, so `run_action` / `resume_run` reach
it too; that arm still serves no `details` (the #23529 / #7450
withholding is unchanged). The relay reads only `refusals` and
`userMessage`, never `details`, so the gate's `positions` /
`permissionSets` reach it on no path.
- **Parity, measured, not argued.** For the same 403 app-code throw,
both REST doors' own readers serve the same caller every relayed line as
`details.refusals`: `mapDataError` (what the `/data` routes answer with)
and `actionsDoorAnswerOf` (what `/actions` answers with, its
`userMessage` uncut, closing line included). The dispatcher's
withholding arm keys on `isPermissionDeniedError`, which reads `false`
for that throw (scratch probe against `plugin-security`'s source:
app-at-403 `false`, gate-shaped `true`). So MCP serves nothing REST does
not serve the same caller. MCP stays stricter than REST in two places,
both left alone: the gate's own literal `PERMISSION_DENIED` carrying a
list (REST `/data` would attach it), and `details` on `run_action` for
the demoted 403.
- **S2, the 5xx arm.** Pinned (a listed throw at 503 on `run_action` and
`resume_run`, the only renderers that reach the relay on a fault; on the
record tools a declared 5xx never reaches the envelope path). The jsdoc
reason is corrected: the doors do still serve `userMessage` on a
declared 5xx; the block is withheld because a refusal catalogue declares
only a 4xx (`declaredRefusalEntrySchema`), so a listed throw at a 5xx is
no catalogue refusal.
- **S3, `delete_records` per-row refusals: declared needless, with a
pin.** Measured: the per-row group's `reason` is NOT cut. The catalogue
throws a coded `SandboxError` whose caller sentence (`innerMessage`) is
the same text as `userMessage` (`hook-refusal-catalogue.ts`, both set to
`answer.message`), and `rowRefusalOf` reads a coded throw's own
sentence, never the door's 500-character cut. So each group already
names every line whole, in order, closing line last. No relay block is
added, so the grouping shape is untouched; `rowRefusalOf`'s jsdoc says
why, and a pin holds a list over 500 characters.
- **N3.** `REFUSAL_REASONS_RELAY_LEAD` now reads `Tell the user every
line below, whole and in this order, in place of userMessage:` (true on
both doors; `/actions` never cuts).
## Tests
`packages/mcp/src/mcp-refusal-reasons.test.ts` (the card's harness file;
new top-level `describe` blocks), 17 new cases, all through the real
HTTP `/mcp` transport:
- S1: on each of the five write/action tools, a listed 403 app-code
refusal answers two blocks, `content[0]` is `{ code: PERMISSION_DENIED,
declaredCode, status: 403 }` with no `details`, `content[1]` is the
relay. Parity case: `mapDataError` and `actionsDoorAnswerOf` on the same
throw serve `details.refusals` equal to the lines. Control: a
gate-shaped throw (`PermissionDeniedError`, literal code,
`details.positions` / `permissionSets`) answers one block on every tool,
no `declaredCode`, and none of its details' text.
- S2: a listed throw at 503 on `run_action` and `resume_run` answers one
block, status 503, no `details`.
- N1: `query_records`, `aggregate_records`, `get_record`,
`get_record_context` and the `delete_records` outer catch each answer
the relay, `content[0]` equal to the same throw without a list;
`query_records` with an unknown field keeps `notRecorded` /
`ifNotRecorded` beside the envelope and the relay after it.
- N2: a `FLOW_FAILED` throw that is also listed answers three blocks in
order: envelope, flow sentence, relay.
- S3: `delete_records` over two rows refused by a six-line list (over
500 characters): one group, `reason` equal to the whole text, its lines
the listed lines then the closing line; one content block.
- The double gained an `asCatalogue` option (caller sentence =
`userMessage`, the catalogue's real shape); the #37416 cases keep their
old double unchanged.
<details><summary>Package suite, typecheck, ablations (head
4682eb8)</summary>
- `pnpm --filter @objectstack/mcp typecheck && pnpm --filter
@objectstack/mcp exec vitest run --maxWorkers=2`, under the verify lock:
`VERDICT command-exit 0`; Test Files 86 passed (86), Tests 1557 passed
(1557) (1540 on main + 17); `check:test-typecheck: OK`.
- Ablation S1 (`node scripts/ablation-replace.mjs`, anchor
`PERMISSION_DENIED && served.declaredCode === undefined)` to the bare
code check; blob 0754dee to 5fe5f300): 5 failed / 26 passed, the five
per-tool 403 cases. Restored: blob equals HEAD, `git diff HEAD` empty.
(A first attempt with a replacement that already occurred in the file
was refused by the tool before any run: counted 5 to 5; re-run with a
distinct marker.)
- Ablation S2 (the `isServerFault` guard deleted; blob to fa47a2ee): 2
failed / 29 passed, the two 503 cases. Restored, `git diff HEAD` empty.
- Ablation S1 on `/actions` (the `PERMISSION_DENIED` arm back to
`codedErrorResult(envelope)`; blob to 4f91d8a8): 2 failed / 29 passed,
the `run_action` / `resume_run` 403 cases. Restored, `git diff HEAD`
empty.
- The tests import `src/` relatively, so no rebuild was needed for the
ablations.
</details>
## Acceptance notes
- Premise corrections, measured: S2's "a catalogue entry may declare a
5xx status" does not hold at authoring (`declaredRefusalEntrySchema`
takes 400 to 499; the hook and action schema tests refuse 500 / 503);
the arm is defence for a hand-built listed throw. S3's "keeps the cut
sentence" does not hold for the catalogue's throw (see What changes); it
held only for the #37416 test double, whose caller sentence is the bare
code.
- Not changed: `run_action` / `resume_run` still serve no `details` on
any `PERMISSION_DENIED`, including the demoted 403, while REST
`/actions` serves its `details.refusals`. The relay block now carries
those lines, so nothing an agent needs is missing; widening `details`
there is outside this card.
- L2: the diff narrows a permission-keyed withholding guard, so
`Security-touching` reads yes for the reviewer; no exposure found (the
relay reads no `details`).
## Verification
<details><summary>Derived gates (67), on 4682eb8</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` (3 paths vs merge base 54ea3c8): 67
derived; 66 exit 0. One NOT MEASURED: `pnpm check:dual-build-cjs-loads`
exit 3 (PREREQUISITE NOT MET: needs the whole workspace built; CI Build
Core runs it).
- `--ran` reconciliation with exit codes recorded: 67 accounted, 66 run,
1 NOT-MEASURED (derived from the recorded exit 3), 0 UNRUN.
- `node scripts/pm/overlap-check.mjs`: clean against origin/main and
#37436.
</details>
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 31 passed.
Read first: `withRefusalReasonsRelay` (the narrowed guard and its
jsdoc), the `PERMISSION_DENIED` arm of `errorResultFromThrown`, and the
parity case in the test file.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgVUz5oS8fMgmncxU96
<!-- signed: repo:objectstack#2 · os-sales ·
session_01L6bhgVUz5oS8fMgmncxU96 -->
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5dbcc02 commit 1af67b2
3 files changed
Lines changed: 251 additions & 16 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 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1374 | 1374 | | |
1375 | 1375 | | |
1376 | 1376 | | |
1377 | | - | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
1378 | 1382 | | |
1379 | 1383 | | |
1380 | 1384 | | |
| |||
1397 | 1401 | | |
1398 | 1402 | | |
1399 | 1403 | | |
1400 | | - | |
| 1404 | + | |
1401 | 1405 | | |
1402 | 1406 | | |
1403 | 1407 | | |
| |||
1432 | 1436 | | |
1433 | 1437 | | |
1434 | 1438 | | |
1435 | | - | |
1436 | | - | |
1437 | | - | |
1438 | | - | |
1439 | | - | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
1440 | 1457 | | |
1441 | 1458 | | |
1442 | 1459 | | |
1443 | 1460 | | |
1444 | | - | |
| 1461 | + | |
1445 | 1462 | | |
1446 | | - | |
| 1463 | + | |
1447 | 1464 | | |
1448 | 1465 | | |
1449 | 1466 | | |
| |||
2392 | 2409 | | |
2393 | 2410 | | |
2394 | 2411 | | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
2395 | 2419 | | |
2396 | 2420 | | |
2397 | 2421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
35 | 51 | | |
36 | 52 | | |
37 | 53 | | |
38 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
39 | 59 | | |
40 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
41 | 66 | | |
42 | 67 | | |
43 | 68 | | |
| |||
72 | 97 | | |
73 | 98 | | |
74 | 99 | | |
75 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
76 | 112 | | |
77 | 113 | | |
78 | 114 | | |
79 | 115 | | |
80 | | - | |
| 116 | + | |
81 | 117 | | |
82 | 118 | | |
83 | 119 | | |
| 120 | + | |
84 | 121 | | |
85 | 122 | | |
86 | | - | |
| 123 | + | |
87 | 124 | | |
88 | 125 | | |
89 | 126 | | |
| |||
109 | 146 | | |
110 | 147 | | |
111 | 148 | | |
112 | | - | |
| 149 | + | |
113 | 150 | | |
114 | 151 | | |
115 | 152 | | |
| |||
123 | 160 | | |
124 | 161 | | |
125 | 162 | | |
126 | | - | |
127 | | - | |
| 163 | + | |
| 164 | + | |
128 | 165 | | |
129 | 166 | | |
130 | 167 | | |
| |||
214 | 251 | | |
215 | 252 | | |
216 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
0 commit comments