Skip to content

Commit ea58563

Browse files
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/35442-mcp-app-docs-tools.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ An AI client connected over MCP (a user's own Claude, Cursor, …) can now answe
1313

1414
- **`search_package_docs({ terms, package? })`** finds the pages whose title, a heading or text contains one of the terms (case aside, in the page's base text or a translation). Pages that contain more of the terms come first, then pages where the terms sit higher (the sum of title 3, heading 2, text 1), then by title; at most 10, each with an excerpt, its manual and, where the page has one, its console address (`/_console/apps/<package>/docs/<book>/<page>`) to cite. The heading parse is line-based and linear.
1515
- **`read_package_doc({ name, package?, locale? })`** reads one page: its title, manual, Markdown content and, where the page has one, its console address (cut at 60,000 characters, and the answer says so).
16-
- **Who sees what.** Both tools read the `doc` items through the `/meta/doc` docs-audience gate (ADR-0046 §6.7) with the request's execution context as the caller: a page the caller may not read is neither found nor read, and answers as not found. On an OAuth grant that caller is the agent, so the docs audience is judged on the token's grant (its scope-derived permission sets), not on the person's own permission sets: a manual whose audience is a permission set the person holds stays hidden on that connection. Both tool descriptions say so. Both are read tools: they register for an API key, a session, or a token granted `data:read`. The runtime's HTTP bridge carries them where the protocol serves the `/meta` list read; the stdio bridge does not.
16+
- **Who sees what.** Both tools read the `doc` items through the `/meta/doc` docs-audience gate (ADR-0046 §6.7) with the request's execution context as the caller: a page the caller may not read is neither found nor read, and answers as not found. 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. Both are read tools: they register for an API key, a session, or a token granted `data:read`. The runtime's HTTP bridge carries them where the protocol serves the `/meta` list read; the stdio bridge does not.
1717
- **The answer order.** Where both tools register, the HTTP `initialize` instructions say: read the manuals first; answer a concept from the manual, and label a general explanation as one when no page covers it; for a process or rule, also read its real definition, which wins where the two differ; end with each page's title and url. The rule names a definition reader only where the connection lists one (`describe_metadata`, else `get_metadata_item`, both under `metadata:write`); without one it says to answer from the manual and state that the configured process was not checked. A host's own instructions and a configured `instructions` option are served unchanged.
1818

1919
The two names are the ones the cloud AI runtime already registers, so `MCP_DOOR_TOOL_NAMES` (`@objectstack/spec/system`) now lists them too; `PLATFORM_PROVIDED_TOOL_NAMES` is unchanged. No metadata key, value or default changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/mcp': patch
3+
'@objectstack/runtime': patch
4+
---
5+
6+
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.
7+
Metadata-protocol: none
8+
9+
fix(runtime): on an OAuth MCP connection, `search_package_docs` and `read_package_doc` judge a manual's permission-set audience by the delegating person's own permission sets
10+
11+
An OAuth token makes the request an agent acting on behalf of the person who consented (ADR-0090 D10). The two app-docs tools used to judge a manual whose audience is `{ permissionSet }` against the token's scope-derived permission sets, so a person who holds that set could not find or read the manual from their own AI client, while the Console showed it to them.
12+
13+
Now, on such a connection:
14+
15+
- The token's scope still decides whether the docs tools are reached at all (`data:read`). A token without it is served neither tool, whatever the person holds.
16+
- The audience reads the person's own permission sets, resolved by the same grant resolution a request uses, in the organization the request runs in: the one the token's consent bound, while the person's membership there is current. A person with no user row holds no set here. A person whose membership there has ended is read with no active organization, as their own session is, so no grant stored in an organization applies.
17+
- The token's own permission sets are never added to the person's: a manual whose audience is one of the token's scope sets stays closed unless the person holds it.
18+
- Manuals with the default audience answer as before. API keys, signed-in sessions and AI service accounts keep their own permission sets.
19+
20+
Both tool descriptions now say so: on an OAuth connection, the person's own permission sets decide, never more.

‎packages/mcp/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ analytics service serves its dataset executor), and `search_package_docs` /
180180
`readPackageDoc` (the runtime's HTTP bridge does where the protocol serves the
181181
`/meta` list read; it reads every page through the `/meta/doc` docs-audience
182182
gate as the caller, so a page the caller may not read is neither found nor
183-
read; on an OAuth grant the caller is the agent, judged on the token's grant
184-
rather than the person's own permission sets; the stdio bridge carries neither); a bridge without those seams
183+
read; on an OAuth connection whose grant reaches the docs tools, a
184+
permission-set audience is read against the delegating person's own permission
185+
sets, never wider; the stdio bridge carries neither); a bridge without those seams
185186
serves the rest and advertises nothing it cannot do.
186187

187188
OAuth scopes narrow the families at consent time: `data:read` covers

‎packages/mcp/src/mcp-http-tools.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ export interface McpDataBridge {
427427
* `input.terms`, ranked and capped at `opts.maxResults`. Runs AS the
428428
* principal: the host reads the docs through the ADR-0046 §6.7 docs-audience
429429
* gate, so a page the caller may not read is never searched. On an OAuth
430-
* grant the principal is the agent envelope, judged on the token's grant.
430+
* grant the audience is the delegating person's own permission sets.
431431
*
432432
* OPTIONAL: a host that cannot read docs for the caller omits both doc
433433
* members ({@link searchPackageDocs}, {@link readPackageDoc}) and neither
@@ -3315,10 +3315,10 @@ export function packageDocToolsServed(
33153315
* - **No second gate.** Neither tool judges what the caller may read: the
33163316
* host's members read the `doc` items through the `/meta/doc` docs-audience
33173317
* gate (ADR-0046 §6.7) as the principal, so a page the caller may not read
3318-
* is neither found nor read, and reads as not found. On an OAuth grant the
3319-
* principal is the agent envelope, so the docs audience is judged on the
3320-
* token's grant, not the person's own permission sets; both descriptions
3321-
* say so.
3318+
* is neither found nor read, and reads as not found. On an OAuth grant that
3319+
* reaches these tools (the gate above), the docs audience is the delegating
3320+
* person's own permission sets, never wider (ADR-0090 D10); both
3321+
* descriptions say so.
33223322
* - **The search is a substring match**, stated in the description: no
33233323
* server-side doc search exists, so the honest search is a term found in a
33243324
* page's title, a heading or its text (case aside). Pages that contain more
@@ -3348,7 +3348,7 @@ export function registerPackageDocTools(
33483348
+ 'aside. Pages that contain more of the terms come first, then pages where the terms sit higher (title, '
33493349
+ `then heading, then text), then by title; at most ${PACKAGE_DOC_SEARCH_MAX_RESULTS}, each with an excerpt `
33503350
+ 'and, where the page has one, the url to cite. Only pages this connection may read are searched; on an '
3351-
+ 'OAuth connection that is judged on the connection\'s grant, not on the person\'s own permission sets. '
3351+
+ 'OAuth connection, those the person\'s own permission sets open, never more. '
33523352
+ `Read a page with ${READ_PACKAGE_DOC_TOOL_NAME}.`,
33533353
inputSchema: strictToolInput(
33543354
{
@@ -3382,7 +3382,7 @@ export function registerPackageDocTools(
33823382
'Read one page of an installed app\'s manual by its name (the name search_package_docs answers): its '
33833383
+ 'title, its manual, its Markdown content and, where the page has one, its url to cite. Send package when '
33843384
+ 'two apps ship a page of that name. A page this connection may not read answers as not found; on an OAuth '
3385-
+ 'connection that is judged on the connection\'s grant, not on the person\'s own permission sets.',
3385+
+ 'connection, the person\'s own permission sets decide, never more.',
33863386
inputSchema: strictToolInput(
33873387
{
33883388
surface: `this ${READ_PACKAGE_DOC_TOOL_NAME} call`,

0 commit comments

Comments
 (0)