Skip to content

fix(mcp): the refusal-reasons relay withholds only the security gate's own refusal - #37537

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-37512-mcp-refusal-relay-reach
Nov 26, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-37512-mcp-refusal-relay-reach

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Sales · project thread

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 security(mcp): run_action renders a thrown refusal's details verbatim, while the runtime dispatcher withholds a PermissionDeniedError's details (ruling on #7450): whether a raw permission refusal reaches it is unmeasured #23529 / The runtime dispatcher serialises a PermissionDeniedError's details to the client, so positions / permissionSets reach the browser on the /data transport #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 MCP:一次拒绝带多条原因时,把 details.refusals 逐条转给智能体(接 #36877) #37416 cases keep their old double unchanged.
Package suite, typecheck, ablations (head 4682eb8)
  • 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 0754deea 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.

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 MCP:一次拒绝带多条原因时,把 details.refusals 逐条转给智能体(接 #36877) #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

Derived gates (67), on 4682eb8

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.ai/code/session_01L6bhgVUz5oS8fMgmncxU96

@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

3 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 12 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 98cc0e45b8e3c0c7fe5a9da4ff157ede05768fd9 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from c32e51ce498f8f5764ae3d1b772aabc0b26064d0 — the merge of head 4682eb84568febbca9a4db4e2ce6b3347345d6c3 into base 98cc0e45b8e3c0c7fe5a9da4ff157ede05768fd9, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin c32e51ce498f8f5764ae3d1b772aabc0b26064d0 && git checkout c32e51ce498f8f5764ae3d1b772aabc0b26064d0
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 98cc0e45b8e3c0c7fe5a9da4ff157ede05768fd9 4682eb84568febbca9a4db4e2ce6b3347345d6c3 && git checkout -B drift-repro 98cc0e45b8e3c0c7fe5a9da4ff157ede05768fd9 && git merge --no-ff 4682eb84568febbca9a4db4e2ce6b3347345d6c3

node scripts/docs-audit/affected-docs.mjs --json 98cc0e45b8e3c0c7fe5a9da4ff157ede05768fd9

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

席位核对 — ACCEPT · head 4682eb8 · area s2-ai · 2026-11-26T11:54Z

L1 checklist

  • Shape and relation: l1-face.mjs --pr 37537 CLEAN (13 items). Fixes #37512 is right: every Expected bullet of the card is delivered — S1 decided (narrow the guard to the gate's own PERMISSION_DENIED, i.e. no declaredCode) and pinned on all five write/action tools plus a gate-shaped control; S2 pinned on run_action / resume_run with the jsdoc reason corrected; S3 declared out of reach with a reason and a >500-character pin (premise corrected in the body, measured); N1–N3 covered. No other card carries a closing keyword.
  • Scope: 3 files, all on the card (mcp-http-tools.ts, its test, one changeset). @objectstack/mcp is published and carries a patch changeset.
  • Changeset read sentence by sentence against the diff: the demotion sentence, the withholding sentence (only a PERMISSION_DENIED with no declaredCode is withheld — matches the guard at withRefusalReasonsRelay), the REST-parity sentence (matches the body's parity case on mapDataError / actionsDoorAnswerOf), the new lead text (matches REFUSAL_REASONS_RELAY_LEAD) and the delete_records sentence (matches the new rowRefusalOf jsdoc). All true.
  • Gates at this head (pr-state): 37 success · 16 expected skip · 0 failed · 0 pending; Lint & Repo Gates and TypeScript Type Check success. mergeable_state clean. landing-k K = 2.
  • Assertions: the refusal cases assert code, declaredCode and status on content[0] and the absence of details; three ablations (S1 guard, S2 5xx arm, S1 on /actions) each turn exactly their cases red and restore to a HEAD-equal blob.

Seat's own read of the security edge (no contract face is hit — Clause-②: no, no narrowing declaration, no packages/spec/src/**, no governed path per check-governed-merges.mjs — so no second agent is started, contract-review.md):

  • The gate's own refusal keeps both withholdings: no relay block (literal PERMISSION_DENIED, no declaredCode) and no details (errorResultFromThrown arm unchanged in what it serves).
  • refusalReasonsRelayText reads only the thrown value's declared refusal lines and its userMessage (declaredRefusalLines, declaredUserMessage), never details, so positions / permissionSets reach the relay on no path.
  • An app throwing the literal PERMISSION_DENIED code with a list is still withheld (stricter than REST /data). The newly relayed text is app-authored refusal reasons the REST doors already serve the same caller. No widening of what any caller may read.

Deviations recorded: a local re-run of the two-minute check from this seat's older checkout is NOT MEASURED (the tree predates the test file's harness); the CI check-runs at this head are the reading.

Tier: S (not governed, 267 lines). Landing: ready + auto-merge by this stroke.


Generated by Claude Code

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 26, 2026 11:55
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 1af67b2 Nov 26, 2026
54 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-37512-mcp-refusal-relay-reach branch November 26, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp: settle the refusal-relay guard reach (403-declared app codes), pin its 5xx arm, and relay delete_records per-row refusals

2 participants