Repository navigation
Commit ea58563
fix(runtime): read a delegated MCP token's docs audience against the person's own permission sets (#35888)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DDxdrYJq965rUfrZBso8FS3)_
Fixes #35584
Clause-②: yes — widening: on a delegated agent token whose scope reaches
the docs tools, a permission-set-gated package doc is now found and read
when the delegating person holds that set (ADR-0090 D10, ceiling ∩
delegator); nothing served today is refused, a non-holder and a token
without docs-tool access still see nothing. Seat runs a contract read
before ready; security#2 checks the head read-only before merge.
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:用户通过自己的 AI
助手授权登录后,助手能搜到、读到只给某个权限集看的应用手册——前提是本人持有这个权限集,且这次授权包含读数据的范围;其他人和其他手册不变。
- 为什么做:外部 AI 助手接入平台这条线上的遗留问题(应用手册查询的后续);本人在控制台能看的手册,在自己的助手里却搜不到。
- 出错会怎样:碰到的是通过授权登录使用 AI
助手查手册的人;最坏是该看的手册仍看不到,或权限集手册多给了不持有的人看;改动只在一处读权限的地方,可直接撤回。
- 要你做什么:无。
## What changes
On an OAuth MCP connection the request is an agent acting on behalf of
the person who consented (ADR-0090 D10). `search_package_docs` and
`read_package_doc` read every page through the `/meta/doc` docs-audience
gate; for a manual whose audience is `{ permissionSet }`, the gate asks
the security service for the caller's permission-set names. Until now
that caller was the agent envelope, whose sets are the token's
scope-derived ceiling, so a manual restricted to a set the person holds
was neither found nor read on that connection.
- `packages/runtime/src/domains/mcp-package-docs.ts`:
`packageDocsReadGate` takes the data engine. On a delegated agent
envelope (`principalKind: 'agent'` with `onBehalfOf.userId`), the
holdings the audience reads are the person's own:
`resolveUserAuthzGrants` in the request's organization (`tenantId`), the
grant resolution the open draft door uses, without that door's
`manage_metadata` admission. It fails closed the way the security
plugin's delegator resolution does: no `sys_user` row, no current
membership in the organization (`vetOrganizationClaim`), or a read that
throws leaves the person with no set, so permission-set audiences stay
closed. The envelope's ceiling sets are never read for the audience and
never unioned in. Holdings are resolved once per gate, and only when a
permission-set audience is in play. A non-delegated principal (session,
API key, AI service account) is unchanged.
- `packages/runtime/src/domains/mcp.ts`: the docs seam rides the bridge
only where the grant reaches the docs tools (no grant, or `data:read`).
`packageDocToolsServed` in `@objectstack/mcp` stays the authority on
listing; the runtime reads the same condition so a token that cannot
reach the tools never has the person's holdings read. The bridge call
site hands the gate this request's data engine.
- PR #35564's stated limit: the helper header (`mcp-package-docs.ts`) no
longer says the envelope's ceiling is the caller, and the test header
and the pin are rewritten to match. The pending #35442 changeset is
corrected (below).
- `packages/mcp/src/mcp-http-tools.ts`, text only (commit 3dae06c,
under the amended claim): the `registerPackageDocTools` docblock, the
`searchPackageDocs` bridge-member docblock and both tool descriptions
now say that on an OAuth connection whose grant reaches the docs tools,
the docs audience is the delegating person's own permission sets, never
wider. Each description is shorter than before (`tools/list` weight,
#34689): `search_package_docs` -25 bytes (100 to 75 for the changed
sentence), `read_package_doc` -29 bytes (93 to 64). No behaviour
changes; no test pins either string.
- Changeset `.changeset/35584-delegated-docs-audience.md`
(`@objectstack/mcp` and `@objectstack/runtime`, patch).
**DELIBERATE CORRECTION** of a pending release note:
`.changeset/35442-mcp-app-docs-tools.md` (unreleased). Its sentence
about OAuth grants now reads: "On an OAuth grant the request is an agent
acting for the person who consented, and a permission-set audience is
read against that person's own permission sets (ADR-0090 D10), never the
token's scope-derived sets." The dropped sentence ("Both tool
descriptions say so.") no longer holds. `check-empty-changeset` is red
on this by design; the dispatching seat's record confirms it.
**Pin flipped in place** (`mcp-package-docs.test.ts`): "on an OAuth
grant the caller is the agent: the page is neither found nor read though
the delegator holds the set" answered CLOSED for a holder; it is
replaced by "the holder of the set finds and reads the page", which
answers OPEN. Card #35584, maintainer ruling A.
## Ruling conditions
| Condition (ruling A) | Pin in
`packages/runtime/src/domains/mcp-package-docs.test.ts` |
|:--|:--|
| 1. The token's scope must still reach the docs tools. | `a token whose
scope does not reach the docs tools is carried no docs member, whatever
the person holds` (person holds the set; token `metadata:write` +
`actions:execute`; both members absent, scopes passed unchanged to the
MCP runtime) |
| 2. Delegator's own holdings by grant resolution; fails closed for a
missing person or one outside the organization; never a union; AI
service accounts keep their own sets. | `the holder of the set finds and
reads the page…`; `fails closed: a person with no user row, or with no
membership in the request's organization, holds no set`; `no union: a
manual whose audience is a set only the token's ceiling carries stays
closed`; `an AI service account keeps its own sets` |
| 3. Keep the non-holder control; a token that cannot reach the docs
tools finds and reads nothing. | `control: a person who does not hold
the set in the token's organization neither finds nor reads it` (new,
OAuth); the session pair `a page only a permission-set manual claims is
neither found nor read without the set` / `control: the holder…` kept;
the scope pin above |
| 4. security#2 does a read-only check of the head before merge. | Not a
code pin: security#2 checks this PR's head read-only before merge. |
Default-audience pages are unchanged: every OAuth pin asserts the
default page `crm_order_payment` is still found, including the
fail-closed and no-union cases.
## Clause-② reading
Widening only. Nothing served today is refused: the change opens
permission-set manuals to a delegated token whose person holds the set
and whose scope already reaches the tools. Every answer that was CLOSED
for a non-holder stays CLOSED, and a token without `data:read` was
already listed neither tool by the MCP runtime, so dropping the seam
from its bridge changes nothing it is served.
## Verification
- Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run
--maxWorkers=2 src/domains/mcp-package-docs.test.ts` — 18 tests pass.
- Files to read first, by risk: `mcp-package-docs.ts`
(`packageDocsReadGate`, `delegatorHoldingsCaller`), `mcp.ts` (the
`packageDocs` scope condition), the new describe block in the test.
<details><summary>Ablation (each leg mutated on disk through
scripts/ablation-replace.mjs, then restored; HEAD blob hashes
re-matched)</summary>
- A1 user-row check removed: red on `fails closed…` (1 failed / 17
passed).
- A2 membership vet removed: red on `fails closed…` (1 / 17).
- A3 delegated person not resolved (the old envelope behaviour): red on
`the holder…` and `no union…` (2 / 16).
- A4 union of the person's sets with the envelope's ceiling: red on `no
union…` (1 / 17).
- A5 scope condition removed in `mcp.ts`: red on `a token whose scope
does not reach the docs tools…` (1 / 17).
- After restore: `git diff HEAD` empty; `mcp-package-docs.ts` 2334108
and `mcp.ts` f101e59 equal their HEAD blobs.
</details>
<details><summary>Local runs at head 3dae06c (origin/main 8145424
merged in, then the mcp text commit)</summary>
- Closure build `pnpm --workspace-concurrency=2 --filter
'@objectstack/mcp^...' --filter '@objectstack/runtime^...' build`:
VERDICT command-exit 0.
- `vitest run src/domains/mcp-package-docs.test.ts` (runtime): 18 passed
(18). `vitest run` of the mcp doc-tool, tools-list weight and initialize
selection-rule files: 3 files, 26 passed (26).
- `pnpm --filter @objectstack/mcp test`: Test Files 82 passed (82),
Tests 1452 passed (1452). `pnpm --filter @objectstack/mcp typecheck` and
`pnpm --filter @objectstack/runtime typecheck`: VERDICT command-exit 0
(`check:test-typecheck: OK` for both).
- `dispatch-gates --commands` (68 families, change set vs merge base
8145424), exit codes captured before any pipe: 66 exit 0;
`check-empty-changeset --base origin/main` exit 1 (only
`.changeset/35442-mcp-app-docs-tools.md`, the DELIBERATE CORRECTION, red
by design); `check:dual-build-cjs-loads` exit 3 PREREQUISITE NOT MET
(needs a whole-repo build), NOT MEASURED. `--ran` reconciliation: 68
derived, 67 run, 1 NOT-MEASURED. After the changeset line for
`@objectstack/mcp` was added, the changeset, nul-byte, citation,
closing-keyword and affected-docs gates were re-run on the final head:
same answers.
- `overlap-check --branch=claude/area-a4C-35584`: exit 1, the only
overlap the bot's Version Packages PR #35129 on
`.changeset/35442-mcp-app-docs-tools.md`; `origin/main` merges cleanly.
- Full runtime suite not re-run this round (runtime code unchanged since
942869d); CI runs it.
</details>
<details><summary>Earlier local runs (head 942869d; code identical to
ea97649, the commit after which only a changeset changed)</summary>
- Closure build `pnpm --workspace-concurrency=2 --filter
'@objectstack/runtime^...' build`: VERDICT command-exit 0.
- `pnpm --filter @objectstack/runtime typecheck`: exit 0
(`check:test-typecheck: OK`).
- `pnpm --filter @objectstack/runtime test` (code tree ea97649): Test
Files 634 passed (634); Tests 11712 passed, 25 skipped (11737); VERDICT
command-exit 0.
- `dispatch-gates --commands` (68 families), each run with its exit code
captured: 65 exit 0; `check-empty-changeset --base origin/main` exit 1
(the DELIBERATE CORRECTION above, red by design); NOT MEASURED, exit 3
PREREQUISITE NOT MET: `check-plugin-teardown-shape --self-test` (shallow
clone cannot reach its pinned fixture commit) and
`check:dual-build-cjs-loads` (needs a whole-repo build). `--ran`
reconciliation: 68 derived, 66 run, 2 NOT-MEASURED, 0 UNRUN.
- `overlap-check --branch=claude/area-a4C-35584`: exit 1, the only
overlap being the bot's standing Version Packages PR (#35129), which
consumes `.changeset/35442-mcp-app-docs-tools.md`; it is regenerated
from `main`.
</details>
## Round 3 (seat S1/S2)
Head `183bed4d56`, text only, two files:
- **S1** `packages/mcp/README.md`: the bridge paragraph now says that on
an OAuth connection whose grant reaches the docs tools, a permission-set
audience is read against the delegating person's own permission sets,
never wider. A search of the head for the old sentence ("judged on the
token's grant", "caller is the agent", "person's own permission sets")
outside CHANGELOGs found no other stale copy.
- **S2** `.changeset/35584-delegated-docs-audience.md`, second bullet:
the organization sentences use the seat's wording verbatim (the
organization the request runs in: the one the token's consent bound,
while the membership there is current; no user row holds no set; an
ended membership is read with no active organization, so no grant stored
in an organization applies). No `Regen-provenance:` line is added to the
changeset: that line is a seat-posted thread pointer
(`scripts/pm/record-recognisers.mjs`), not changeset text.
- Nits: nit a (a second membership pin through `oauthEnvelope`) was
drafted but not verified before the handover stop, so it is not in this
head. Nit b was not done: `packageDocsReadGate` has no logger, so it
would take more than one line per arm. Nit c skipped, as the order says.
- Not re-run this round: the closure build was stopped for the handover,
so the runtime and mcp tests, typecheck and derived gates are NOT
MEASURED on this head. No code changed; CI runs them. `check-nul-bytes`:
OK. `overlap-check`: exit 1, the same Version Packages PR #35129 overlap
on `.changeset/35442-mcp-app-docs-tools.md` as before; `origin/main`
merges cleanly.
## Acceptance notes
- Holdings are resolved through `resolveUserAuthzGrants` directly in
`mcp-package-docs.ts` rather than via a helper shared with
`mcp-authoring.ts`: that file is outside this PR's claimed surface, and
its reader is admitted on `manage_metadata`, which the ruling says must
not apply here. The two readers now share the grant call, not the
admission.
- The scope condition (`data:read`, or no grant) is spelled once more in
the runtime beside `packageDocToolsServed`, as the draft door reads
`metadata:write` beside `grantsAuthoringTools`. If the MCP runtime's
docs family ever changes, both must move.
Session: https://claude.ai/code/session_016WV4d1k1GRsQbF3vCPKxhz
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- signed: repo:objectstack#4 · os-elon-musk ·
session_016WV4d1k1GRsQbF3vCPKxhz -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f555352 commit ea58563
7 files changed
Lines changed: 262 additions & 60 deletions
File tree
- .changeset
- packages
- mcp
- src
- runtime/src/domains
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 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 | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | | - | |
| 430 | + | |
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| |||
3315 | 3315 | | |
3316 | 3316 | | |
3317 | 3317 | | |
3318 | | - | |
3319 | | - | |
3320 | | - | |
3321 | | - | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
| 3321 | + | |
3322 | 3322 | | |
3323 | 3323 | | |
3324 | 3324 | | |
| |||
3348 | 3348 | | |
3349 | 3349 | | |
3350 | 3350 | | |
3351 | | - | |
| 3351 | + | |
3352 | 3352 | | |
3353 | 3353 | | |
3354 | 3354 | | |
| |||
3382 | 3382 | | |
3383 | 3383 | | |
3384 | 3384 | | |
3385 | | - | |
| 3385 | + | |
3386 | 3386 | | |
3387 | 3387 | | |
3388 | 3388 | | |
| |||
0 commit comments