Repository navigation
Commit 66919b6
fix(runtime,mcp): list_actions marks an organization action the caller's membership role does not reach (#33194)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoSLDKWQ8v7cxY9uDGijfncD)_
Fixes #32163
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:普通成员的 AI 通过 MCP `list_actions` 看到的 15
个组织类身份动作(邀请成员、移除成员、改组织、管团队等)仍然列出,但每行带上 `unavailable`
标记,写明需要哪种组织角色(如"需要组织 owner、admin 或 delegated admin")。owner、admin(邀请类还有
delegated admin)看到的列表不变。
- 为什么改:这些动作成员一执行就被组织端点 403 拒绝,AI 却以为能用,白白规划、浪费轮次。按裁决 E「列出并标记,不隐藏」处理。
- 风险与回滚:只多一个标记;谁能执行完全不变(两个执行门都不读这个标记,实测 main 与本分支执行结果逐一相同)。删 SSO 提供方、删
OAuth 应用、建组织这 3 个按记录所有者或部署形态判定的动作不标记。回滚即还原本 PR。
- 先看:`packages/runtime/src/domains/mcp.ts` 的 `membershipReachRefusal` 与
`listActions` 里 `refusal`
那一行的顺序;`packages/runtime/src/platform-admin-action-gate.test.ts` 末尾新
describe。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
src/platform-admin-action-gate.test.ts`,预期 16 passed。
- 需要你做的:无,席位落地。
## What changes
- **The mark.** `listActions` (`packages/runtime/src/domains/mcp.ts`)
asks a new module function, `membershipReachRefusal(action, objectName,
ec)`, after the two existing refusals: `confirmation ??
apiForwardCredentialRefusal(...) ?? membershipReachRefusal(...)`. That
is the order `run_action` meets them: the confirmation gate in the
admission sequence, the forward's credential table before the target is
called, and the organization endpoint last.
- **Where the reach comes from.** The function reads the action's
declared `target`. When it is an organization endpoint under the auth
base path (`/api/v1/auth/organization/...`), the grades that reach it
are the union of the grades of every `MEMBERSHIP_REACH` row naming that
endpoint (`@objectstack/spec/identity`, the table plugin-auth's
`membership-reach-table.test.ts` pins equal to the vendor doors).
`/organization/update-member-role` is two rows, so its reach is their
union. No local list, and no new stored key: the reach is derived from
what survives on the served action (its `target`), so ruling A's key is
not needed.
- **Whose grades.** The caller's `positions` in the organization the
listing reads, by the names `mapMembershipRole` projects the grades to
(`org_owner`, `org_admin`, `delegated_admin`). That is the reading the
actions' `requiresMembershipReach` sugar is lowered to. Only an envelope
that carries its own positions is judged: the system context, a
delegated agent (its envelope carries the agent ceiling, `positions:
[]`, not the person's grades) and an envelope with no `positions` array
are left unmarked.
- **The mark's shape.** `unavailable: { code: 'PERMISSION_DENIED',
reason }`. The code is the one `run_action` answered for a member on
every set-A/B action measured on a booted showcase (below). The reason
names the action, the roles that reach it and the endpoint, and says who
can run it: "Action 'invite_user' on 'sys_member' needs an organization
owner, admin or delegated admin: its endpoint
(/organization/invite-member) refuses every other membership role, and
your role in this organization is none of those. Ask a person who holds
one of those roles to run it."
- **Nothing hidden, no run change.** Every action stays listed. Neither
run door reads the mark: `run_action` and `POST /actions` forward the
call to the endpoint exactly as before, and the endpoint stays the
authority (a call naming another organization is judged there).
- **System-context page.** Row 62b on
`content/docs/permissions/system-context.mdx` owns the mark's
system-context skip (an elevation read the census counts), and the
generated site register names `mcp.ts#membershipReachRefusal`.
- **Published page.** `content/docs/ai/actions-as-tools.mdx`: the
`list_actions` row names the three codes a listed action can carry
(`UNAUTHENTICATED`, `ACTION_CONFIRMATION_REQUIRED`, and
`PERMISSION_DENIED` for the membership grade), and the intro and "What
gets exposed" sentences no longer say every listed action can be run.
- **Wording.** `McpActionSummary.unavailable`'s JSDoc and the
`list_actions` tool description (`packages/mcp/src/mcp-http-tools.ts`)
name the membership-role case and its code, and the description no
longer promises that every returned action can be run ("that the
caller's permissions allow are returned"; "cannot be run by you as you
are connected (your credential, or your role in this organization)").
The served skill (`packages/mcp/src/skill-md.ts`) no longer says "only
those … you are permitted to run" and says what `unavailable` means. Its
Console mirror
(`ui/apps/console/src/pages/developer/objectstack-skill.ts`) carries the
same bytes, as its two drift pins require.
**Not marked (sets C and D, listed and refused at their door as
today):** `sys_sso_provider.delete_sso_provider` and
`sys_oauth_application.delete_oauth_application` (judged on record
ownership), and `sys_organization.create_organization` (judged on the
deployment's tenancy posture; measured on the showcase: `403
ORGANIZATION_CREATION_DISABLED`). No reach row names their endpoints, so
the function answers `undefined` for them.
## Tests
New top-level `describe('[ruling E] list_actions marks an organization
action the caller's membership role does not reach')` in
`packages/runtime/src/platform-admin-action-gate.test.ts`, the
identity-action harness: the REAL identity declarations
(`@objectstack/platform-objects/identity`) through the production
`McpActionBridge`, with the forward target faked as the endpoints answer
a refused role.
1. Premise: every pinned action is AI-exposed, `api`-typed, and declares
no capability gate.
2. A plain member (`positions: ['org_member', 'everyone']`) is listed
every set-A and set-B action, each marked `PERMISSION_DENIED`, the
reason naming "owner or admin" (set A) or "owner, admin or delegated
admin" and `/organization/invite-member` (set B).
3. Owner and admin get no mark on any of the 15; delegated_admin gets
none on set B and keeps it on set A.
4. CONTROL: the set-C and set-D actions are listed unmarked, for the
member and the admin.
5. CONTROL: a delegated agent and the system context are left unmarked.
6. CONTROL: `run_action` unchanged. For each of the 15, the member's
call is forwarded (the fake endpoint is called once, so no door refused
first) and refused with the endpoint's `PERMISSION_DENIED` / 403 and its
sentence; the admin's call is forwarded once and served. Green at `main`
too.
Red at `main` (test file at this branch,
`packages/runtime/src/domains/mcp.ts` restored from `28a2f0f5`): 2
failed / 14 passed (cases 2 and 3: no mark). Green here: 16 / 16.
<details><summary>Ablations (each through
<code>scripts/ablation-replace.mjs</code>, anchor 1 → 0, restored to the
HEAD blob, <code>git diff HEAD</code> empty after each; the suite
imports <code>./http-dispatcher.js</code> from <code>src</code>, so no
<code>dist/</code> sits between mutation and run)</summary>
| Mutation | Red |
| --- | --- |
| A: the caller's grades never reach (`if (false) return undefined;`) |
case 3 |
| B: the mark not asked in `listActions` (`?? undefined`) | cases 2 and
3 |
| C: a delegated agent and the system context judged too | case 5 |
| D: reach from every row, not the rows naming the endpoint | cases 2, 3
and 4 |
| E: hide instead of mark (`if (!served \|\|
membershipReachRefusal(...)) continue;`) | cases 2, 3 (and the run
control at the first test revision) |
</details>
<details><summary>Live measurement on a booted showcase (temporary
dogfood file, not committed; MCP over the session bearer of a signed-up
plain member and of the administrator)</summary>
At `origin/main` `28a2f0f5`: the member is listed 34 `sys_*` actions,
all 18 of sets A–D among them, none marked; the administrator 44. As the
member, `run_action` answers `403 PERMISSION_DENIED` with the endpoint's
own sentence on 14 of the 15 set-A/B actions ("You are not allowed to
invite users to this organization", "… to delete this member", "… to
update this organization", "… to create teams in this organization", …).
`cancel_invitation` answered `400 VALIDATION_ERROR` "Member not found":
the only invitation row the fixture holds belongs to another
organization, so the endpoint stops before its role check. Set C/D:
`create_organization` `403 ORGANIZATION_CREATION_DISABLED`; the two
deletes `404` (no such provider or client in the fixture).
At this branch (`d4df05f4`, after the rebuild): the member is listed the
same 34, the 15 set-A/B rows marked `PERMISSION_DENIED` and nothing
else; the administrator the same 44, none marked. Every member
`run_action` answer is identical to `main`'s, code, status and sentence.
Records: `measure-main-28a2f0f5.json` and `measure-head-d4df05f4.json`
in the seat's `out/32163/`.
</details>
## Acceptance notes
- **Surface.** Ruling grep (`ruling|Ruling-ref|maintainer|⛔`) over the
edited files: `mcp.ts` 17 hits, `mcp-http-tools.ts` 39, `skill-md.ts` 1,
none in or governing `listActions`, the `unavailable` JSDoc or the
`list_actions` description and skill lines; the one adjacent is the
`run_action` listed-check ("maintainer's ruling on the card: no
bypass"), which this change does not touch.
- **What the mark reads is the courtesy reading, not the door's.** It
reads `positions`, as the lowered `visible` predicate does. Two edges
where it can differ from the endpoint, both in the safe direction for
running (the mark never stops a run): a position granted directly
through `sys_user_position` under a grade name (no mark, the endpoint
still refuses, as today); a `sys_member` row outside its ADR-0091
validity window (no position, so marked, while the vendor may still
admit). With no active organization, every membership's grades count, so
a caller who is an admin anywhere is not marked.
- **The code.** `PERMISSION_DENIED` is a constant beside the function,
typed as the registered vocabulary. It is what `run_action` answered for
a member on the showcase; the reason is this listing's own sentence, not
the endpoint's (each endpoint words its refusal differently, and the
table does not carry them).
- **REST `/actions` listing** is not changed: the ruling scopes the mark
to MCP `list_actions`.
## Verification
<details><summary>Package suites, typecheck, lint (at `056f314d`; later
commits are docs-only)</summary>
After the last merge of `main` (`056f314d`), on a fresh install and a
full build (declarations included) of the `@objectstack/runtime...`,
`@objectstack/mcp...` and `@objectstack/service-storage...` closures:
| Run | Result |
| --- | --- |
| `pnpm --filter @objectstack/runtime exec vitest run` | 601 files,
11956 passed, 19 skipped |
| `pnpm --filter @objectstack/mcp exec vitest run` | 64 files, 1145
passed |
| `pnpm --dir ui exec vitest run
apps/console/src/pages/developer/objectstack-skill.test.ts` | 13 passed
|
| `pnpm --filter @objectstack/runtime --filter @objectstack/mcp
typecheck` | exit 0 |
| `pnpm lint` | exit 0 |
`3de7508e` (system-context row) and `f91b2a1d` (actions-as-tools page)
add only docs on top of `056f314d`; the package suites were not rerun
for them.
</details>
<details><summary>Derived gates (dispatch-gates --commands; reconciled
with --ran)</summary>
`dispatch-gates --ran` at `f91b2a1d`: **100 derived, 100 run, 0 NOT
MEASURED, 0 unrun.** Record: `gates-ran-f91b2a1d.list` in the seat's
`out/32163/`. The docs-family gates (31, `check:role-word` and
`check:system-context-census` among them) were rerun at `f91b2a1d`; the
rest were run at `3de7508e`, which differs from it by one docs page.
- `node scripts/check-plugin-teardown-shape.mjs --self-test` first
exited 3: its positive control is pinned to commit `621a4876`, which the
shallow clone did not hold. After `git fetch --depth=1 origin 621a487…`
it passes (48 cases).
- `pnpm check:system-context-census` was red at the first gate run: the
mark's system-context skip is an elevation read no row owned. Fixed in
`3de7508e` with row 62b on `content/docs/permissions/system-context.mdx`
and the regenerated register; green after.
- `pnpm check:role-word` was red on the first wording of that row
("membership role"); the row now says "membership grade". Green after.
- The docs edit added 31 docs-family gates to the derivation; all were
run at the new tree.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibvdpdhupF2wQf2NUU8)_
<!-- signed: domain:server#7 · os-tesla ·
session_01L9qibvdpdhupF2wQf2NUU8 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 30e364e commit 66919b6
8 files changed
Lines changed: 312 additions & 23 deletions
File tree
- .changeset
- content/docs
- ai
- permissions
- packages
- mcp/src
- runtime/src
- domains
- ui/apps/console/src/pages/developer
| 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 | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | | - | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | | - | |
| 105 | + | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
| |||
674 | 675 | | |
675 | 676 | | |
676 | 677 | | |
| 678 | + | |
677 | 679 | | |
678 | 680 | | |
679 | 681 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
387 | 390 | | |
388 | | - | |
389 | | - | |
390 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
391 | 395 | | |
392 | 396 | | |
393 | 397 | | |
| |||
3217 | 3221 | | |
3218 | 3222 | | |
3219 | 3223 | | |
3220 | | - | |
| 3224 | + | |
3221 | 3225 | | |
3222 | 3226 | | |
3223 | | - | |
3224 | | - | |
3225 | | - | |
| 3227 | + | |
| 3228 | + | |
| 3229 | + | |
3226 | 3230 | | |
3227 | 3231 | | |
3228 | 3232 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
465 | | - | |
| 465 | + | |
466 | 466 | | |
467 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
468 | 471 | | |
469 | 472 | | |
470 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
| |||
55 | 62 | | |
56 | 63 | | |
57 | 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 | + | |
58 | 126 | | |
59 | 127 | | |
60 | 128 | | |
| |||
1224 | 1292 | | |
1225 | 1293 | | |
1226 | 1294 | | |
1227 | | - | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
1228 | 1303 | | |
1229 | 1304 | | |
1230 | 1305 | | |
| |||
0 commit comments