Skip to content

Commit 2d33205

Browse files
feat(mcp): the open draft door saves and discards drafts, and each save answers with its publish verdict (#35103)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> Fixes #34766 Claim on the card naming this branch: 6974854210 (PR-a #35059 merged as 78f3ab2; this PR carries the rest). _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_ The read half (#35059) is on `main`; this PR is the write half and completes the card. Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:开放 MCP 草稿门新增 `save_metadata_draft`、`delete_metadata_draft` 两个写工具;`list_drafts` 每条草稿附带发布裁决。metadata-protocol 的 `draftPublishJudgement` 改为公开方法,可直接读已存草稿。写入与裁决同 `/meta` 一样先过类型级读写准入。读工具一半已在 main 上,本 PR 只含写的一半。 - 为什么改:AI 通过 OAuth 写元数据时只落草稿,同一次回复里就能看到"发布会被拒在哪条规则、哪个路径、下一步怎么做",由人在 Studio 审核发布。 - 风险与回滚:新增写面但只写草稿,无发布工具、无 `force`;受令牌授权范围与用户元数据管理能力双重门禁、`/meta` 类型级准入和 walled 租户拒写约束。回滚即 revert 本 PR,读的一半不受影响。 - 先看:`packages/runtime/src/domains/mcp-authoring.ts`(save/delete 分支、`typeAdmission`、list_drafts 的逐条裁决,每个包的发布闭包每次调用只收集一次)、`packages/metadata-protocol/src/protocol-authoring-gate.ts`(无 body 时读已存草稿)、`packages/mcp/src/mcp-server-runtime.ts`(initialize 文案)。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run --project local --maxWorkers=2 src/domains/mcp-authoring.test.ts`,预期 37/37 通过,其中 done-when 用例返回 `flow-trigger-unroutable` 及其路径与 hint。 - 需要你做的:无,席位落地。 ## What changes - **D2, the public verdict.** `ObjectStackProtocolImplementation.draftPublishJudgement` is now public. The facade line stays at its ceiling: the change is in place, with a delta of 0 lines. With no `body`, the gate reads the stored draft at `type`/`name`/`packageId` (and `member` for a bundled type), and an absent draft answers `404 NO_DRAFT`. It is the same judgement the draft read and the publish gate run; there is no second routine. - **`save_metadata_draft({ type, name, item, package, ifMatch? })`** calls `saveMetaItem` with `mode: 'draft'`, `surface: 'mcp'` and `client.id` set to the token's OAuth client, plus `writeFace: 'meta-dispatch'`; `ifMatch` maps to `parentVersion`. The reply holds three parts: - `saved`: type, name, package, state and version. - `verdict`: `publishable`, plus `refusals` and `advisories`, each with rule, path, message, hint and severity. - `review`: the Studio routes `/studio/PKG/interfaces?changes=review` and `/studio/PKG/metadata/TYPE/NAME?review=1`. - If the judgement throws, the reply says `verdict: null` plus `verdictError`. The draft stays saved and the save is not reported as refused. - **D4.** A save with no `package` is refused `400 VALIDATION_ERROR`, naming the writable packages (capped at 20). `package` is deliberately left out of the JSON schema's `required` list: the SDK enforces `required`, so listing it there would make this named refusal unreachable. - **`delete_metadata_draft({ type, name, package? })`** calls `deleteMetaItem` with `state: 'draft'`. - **`list_drafts`.** Each draft carries its `verdict`, gated per item with the read half's item read gate. A draft the human may not read gets `verdict: null` plus `verdictWithheld`, so no finding derived from its body leaks. The list itself stays ungated, matching `/meta/_drafts`, and state `draft` keeps the overlaid `getMetaItems` read. - **One closure per package per `list_drafts` call (contract review S1).** A draft's publish closure, the package's other drafts that a package publish judges it against, depends on the package alone. `draftPublishJudgement` takes an optional `packageClosures` map: `list_drafts` hands one map to every judgement of the call, so each package's closure is collected once, on its first draft. A call without the map collects per call, as before; the save's judgement passes none. The loop's comment states why each per-draft read remains. The strict draft read is the item gate's own read, and like every `/meta` draft read it folds a verdict into `_diagnostics`. The judgement reads the row as stored, which the served copy is not, and returns each finding whole, with its `hint`. Per package of N drafts, closure collections go from 2N to N + 1. - **Gates.** The same D1 gate covers every tool. Both writes then ask the `/meta` type-level write admission (`metaTypeWriteRefusal`, the save as `PUT`, the discard as `DELETE`) with the human as the caller, and then `walledCatalogWriteVerdict` with the envelope's tenancy posture, before anything is written: a metadata type the caller may not write is refused 403, a walled tenant is refused 403, and a platform admin is admitted. A failed posture read answers 503 and nothing is written. The authoring admission alone does not cover a type whose own write door requires more. - **Verdicts and the type-level read admission.** A verdict is a read of the stored draft's body, so the save's verdict and each listed draft's verdict are told only where `metaTypeReadRefusal` admits the human; elsewhere the reply carries `verdict: null` and `verdictWithheld`. The reads keep the read half's rule as landed on `main`: both read tools ask the same admission before any read, now through the one helper the writes share. - **Type fold.** `type` is folded to its canonical singular before any gate, verdict, refusal or write, through the read half's one module helper `canonicalTypeOf`, as landed on `main`; there is no second copy, and `list_drafts`' per-draft fold goes through the same helper. - **`initialize`.** When the authoring tools are listed, the open server's default instructions add one paragraph: these tools save drafts only, and a person publishes them in Studio. The paragraph is absent when the tools are not served. - **Refusals carry their findings.** A coded protocol refusal keeps its code, status and message and now also relays the thrown `issues[]`: the save states the `meta-dispatch` face, which trims a spec-validation refusal's message to a headline because that face declares a structured channel, so the findings travel beside it. - **Registry-question producers.** The save is recorded in `REGISTRY_QUESTION_PRODUCERS` (`packages/metadata-protocol/src/registry-question.ts`), by face: `meta-dispatch` and always `mode: 'draft'`, so the body-only question. The face set's note now says `meta-dispatch` is stated at a second door. The runtime repo tier's producer census (`metadata-registry-question-producers.test.ts`) reads that ledger. - **`check:system-context-census`.** `openWriter` reads the envelope's `isSystem` for the walled verdict, so row 55b of `content/docs/permissions/system-context.mdx` now lists the draft save and discard among its doors and names `openWriter`; the generated site register was rewritten by `--write`. - **`check:durability-log-level`.** The tool switch's outer catch guards `saveMetaItem` and returns `refusalFromThrown` on its only path, an `isError` tool result carrying the error envelope. That hands the failure to the caller, so the site is declared in `FAILURE_PROPAGATION_SITES` (`packages/runtime/src/domains/mcp-authoring.ts::execute`, callee `refusalFromThrown`, `via: 'return'`), the remedy the gate's own text and AGENTS.md name for this shape; no log was added. ## Tests At `50b2d84512` (the S1 fix round; tree `98ddc83bd2`, which the runs below measured): - Runtime `src/domains/mcp-authoring.test.ts`: 37/37. The new pin: three flow drafts in one package, real protocol, real SQL store. One `list_drafts` makes N + 1 closure collections (spy on `collectBatchPendingDeclarations`): one per strict draft read and one shared by the door's judgements. Each listed verdict equals the same draft judged alone. - metadata-protocol `protocol.draft-publish-verdict.test.ts`: 62/62. The new pin: one map for a pass of three judgements collects once, and the answers equal three calls without the map, which collect three times. - mcp full suite: 71 files, 1269/1269. - Typecheck exits 0 for metadata-protocol, runtime (with `check:test-typecheck`) and mcp. <details><summary>S1 ablations</summary> Both ran through `scripts/ablation-replace.mjs` under the verify lock. Each anchor went 1 -> 0, and each restore read the blob equal to HEAD's with `git diff HEAD` empty. - Runtime: a fresh map per draft (`gatedDraftVerdict(protocol, draft, new Map())`) gives collections 6, where the pin expects 4: 1 failed. The runtime module is imported from `src/`. - metadata-protocol: removing the map's `set`, so nothing is shared, gives collections 3, where the pin expects 1: 1 failed. The suite imports `./protocol.js` from `src/`. </details> Earlier rounds, at `8709c889fe` (the merge of `origin/main` at `99a0e4fbfc`, which carries the read half's squash `78f3ab2aa3`): - Runtime `src/domains/mcp-authoring.test.ts`: 36/36. This includes the done-when end-to-end test on the app-crm shape, run against a real SqlDriver (better-sqlite3) store with `crm_opportunity`: - An unnamed save is refused 400, naming the authored package. - The save answers `flow-trigger-unroutable` with its path and hint. - `list_drafts` lists the draft with the same verdict. - The delete empties the list. - Runtime repo tier `src/metadata-registry-question-producers.test.ts`: 3/3. - metadata-protocol `protocol.draft-publish-verdict.test.ts`, `sys-metadata-repository.draft-drain.test.ts` (it reads the durability script), `protocol.invalid-metadata-422-face-inventory.test.ts` and `protocol.destructive-409-face-inventory.test.ts`: 4 files, 132/132. - mcp full suite: 71 files, 1269/1269. - Typecheck exits 0 for runtime, mcp and metadata-protocol. - Pins this half adds: - On the real protocol, a save the schema refuses answers `422 INVALID_METADATA` with its structured findings beside the headline, and writes nothing. - A type the caller may not write is refused on the save and the discard before anything is written; a holder of the type's capability writes it. - A save of a type the caller may not read lands, and its verdict is withheld rather than read. - `list_drafts` withholds the verdict of a draft whose type the caller may not read, without reading its body. - On the real protocol, an inherited member's name as `type` (`constructor`, `toString`), which the fold keeps as sent, is refused on save and discard and leaves no draft. <details><summary>Ablations</summary> Each ran through `scripts/ablation-replace.mjs` under the verify lock. The suite imports the module relatively from `src/`, so no `dist/` is on the subject's path. Every restore read the blob equal to HEAD's, with `git diff HEAD` empty. At `8709c889fe`, re-run after the merge (restored blob == HEAD `647fb95516d8`): - Dropping the one fold (`canonicalTypeOf` returns the type as sent): anchor 1 -> 0; 3 failed / 33 passed — the read half's plural-fold pin, its folded-type pin and this half's save/verdict/discard fold pin. - Dropping the type-level read admission (`typeAdmission` admits every read): anchor 1 -> 0; 3 failed / 33 passed — the read half's type-admission pin, the save-verdict pin and the `list_drafts` pin. Recorded earlier, at `1294fe181c` (restored blob == HEAD `04e3fe15e4fc`) and `7cbb4252a9` (restored blob == HEAD `647fb95516d8`); no file they mutate has moved since `7cbb4252a9`: - Dropping `verdict` from the save reply: 2 failed / 33 passed (the save-shape pin and the done-when pin). - Dropping the package requirement: 2 failed / 33 passed (the D4 pin and the done-when pin). - Dropping the type-level write admission: 1 failed / 34 passed (the write-admission pin). - At `7cbb4252a9`, dropping the relayed `issues`: 1 failed / 35 passed (the structured-findings pin). </details> ## Acceptance notes - **An inherited member's name as `type`.** `save_metadata_draft` and `delete_metadata_draft` with `type: "constructor"` write nothing, but the protocol answers them as faults, not as an unknown type: the save fails inside the protocol with an error that names the metadata store as unreadable, and the discard with a TypeError in the spelling module's own fold. The door keeps the agent's string, so this is the protocol's fold (`canonicalMetaUrlType` reading a plain object), the shape the read half recorded. The pin above asserts the refusal and the absent draft, and does not pin the status. - #34979 shares `protocol-authoring-gate.ts` and merges cleanly; the seat accepted it as a clean neighbour. - Optional, not folded (L1-c N2 on #35059): for type `object`, `/meta`'s `listMetaItems` reads `getMetaItemsForExecution` while the door reads `getMetaItems`. The verdict is the same and only the cost differs; these tools do not add that member. - `clientSpecVersion` is deliberately not accepted. It is #34774's contract, and accepting it here would make it an inert parameter. ## Verification At `50b2d84512` (tree `98ddc83bd2`): - `dispatch-gates --commands` derived 125 families (14 paths vs merge base `99a0e4fbf`). Each one ran with its exit code captured before any pipe. 123 exited 0 on the first pass. `check:skill-examples` and `check:dual-build-cjs-loads` exited 3, a prerequisite failure: some packages were not built. Both exited 0 after `turbo run build --filter='./packages/**'` (81/81 tasks). `dispatch-gates --ran` with the exit codes recorded: "125 derived, 125 run, 0 NOT-MEASURED, 0 UNRUN", a derived zero. - `check-governed-merges --branch HEAD`: NOT governed, 1175 changed lines (+1115 / -60) over 14 files. - `overlap-check --branch=HEAD`: VERDICT clean against `origin/main` `910306b632` and #34817. - `check-nul-bytes`: exit 0. No exported symbol is renamed or removed. Earlier rounds: - Merged `origin/main` at `99a0e4fbfc` into `7cbb4252a9`, as `8709c889fe`. The read half's squash gave an add/add conflict on `packages/runtime/src/domains/mcp-authoring.ts` and its test, and a content conflict on `packages/mcp/src/skill-md-surface-guard.test.ts`. This branch had merged the read half's final head `c2fa38c8b4`, whose blobs equal `main`'s for all seven of that half's files, so each conflicted path takes this branch's side: `main`'s landed content plus this half only. - How the delta was checked: `git diff --name-only origin/main...HEAD` and the two-dot form name the same 14 files, and none of the read half's four other files (its changeset, the design note, `mcp.ts`, `check-route-envelope.mjs`). Per file, the patch `origin/main..HEAD` is byte-identical to this half's own patch before the merge: `78f3ab2aa3..7cbb425` for the three conflicted files, and merge base `aef42cba4e..7cbb425` for the other eleven. The read half's changeset is `main`'s, unchanged and out of the diff; this half carries only its own two. - `overlap-check --branch=HEAD`: VERDICT clean against `origin/main` `99a0e4fbfc`, #35156 (shares `packages/mcp/src/initialize-selection-rule-34686.test.ts` and `packages/mcp/src/mcp-server-runtime.ts`) and #34817 (shares `content/docs/permissions/system-context.mdx`). - `check-governed-merges --branch HEAD`: NOT governed, 1088 changed lines (+1032 / -56) over 14 files, under 3000. `dispatch-gates --tier` exit 0. - `dispatch-gates --commands` derived 125 families (14 paths vs merge base `99a0e4fbf`); each ran with its exit captured before any pipe. 123 exited 0 on the first pass; `check:skill-examples` and `check:dual-build-cjs-loads` exited 3 (prerequisite: unbuilt packages), and both exited 0 after a workspace build (`pnpm build`, 120/120 tasks). `dispatch-gates --ran`: "125 derived, 125 run, 0 NOT-MEASURED, 0 UNRUN", a derived zero. `check-platform-checklist --changed-from origin/main`: 0 anchors lost. `check-nul-bytes` exit 0. Every family CI runs is read from this PR's check-runs. --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbWDsbbJizuYnDwBxT8)_ <!-- signed: repo:objectstack#1 · os-warren · session_01JQwxbWDsbbJizuYnDwBxT8 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1caee8c commit 2d33205

14 files changed

Lines changed: 1115 additions & 60 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/runtime': patch
3+
'@objectstack/mcp': patch
4+
---
5+
6+
feat(runtime,mcp): the open MCP server saves and discards metadata drafts, and every save answers with what publishing the draft would say
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
The open draft door on a self-hosted runtime gains its write half. It is served to the same OAuth clients as the read tools: the token carries `metadata:write` and its user holds `manage_metadata`.
12+
13+
- `save_metadata_draft({ type, name, item, package, ifMatch? })` saves `item` as a pending draft in `package`, recorded as an MCP save by the token's OAuth client. The reply carries `saved` (type, name, package, state, version), `verdict` and `review`. `verdict` is what publishing the stored draft would say: `publishable`, `refusals` (the issues a publish would refuse the draft on) and `advisories`, each with `rule`, `path`, `message`, `hint` and `severity`. `review` holds the Console routes where a person reviews and publishes the draft in Studio. `ifMatch` is the version the save expects to replace; a stale one is refused as the `/meta` draft save refuses it.
14+
- A save that names no `package` is refused `400 VALIDATION_ERROR`, and nothing is saved. The refusal names the writable packages in that environment.
15+
- `delete_metadata_draft({ type, name, package? })` discards a pending draft. The published version, if any, is left as it is.
16+
- `list_drafts` now gives each draft its `verdict`. A draft the user may not read (for example a dashboard whose `requiredPermissions` they lack) is listed with `verdict: null` and the reason it was withheld.
17+
18+
A plural type spelling (`dashboards`) is folded to its singular before any gate, verdict or write, as the `/meta` doors fold it. Both writes ask the type-level write admission every `/meta` write asks, so a metadata type the user may not write is refused `403 PERMISSION_DENIED` and nothing is written; a verdict, on a save or a listed draft, is withheld for a type the user may not read. A tenant whose catalog is walled refuses both writes `403 PERMISSION_DENIED`, as the `/meta` write path does; a platform admin is admitted. Nothing on this server publishes: there is no publish tool and no `force`.
19+
20+
When the authoring tools are listed, the open server's default `initialize` instructions add one paragraph saying that they save drafts only and that a person publishes in Studio. The paragraph is absent when the tools are not served, and a host's own instructions replace the default text as before.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
feat(metadata-protocol): the draft publish verdict is a public protocol method, and it reads the stored draft itself
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
`ObjectStackProtocolImplementation.draftPublishJudgement` is now public. It answers what publishing a stored draft would say, without publishing it: `refusals`, the issues the publish would refuse the draft on, and `advisories`, the findings a publish that passes still returns. Each issue keeps every member the publish's `422 INVALID_METADATA` carries: `rule`, `path`, `where`, `message`, `hint` (the next step) and `severity`. The draft read's `_diagnostics` folds the same verdict but drops the `hint`.
11+
12+
A caller that holds no stored row may omit `body`: the method then reads the stored draft at `type`, `name` and `packageId` (`null` for the draft bound to no package), and `member` for a bundled type, and judges the bytes as stored. An address that holds no draft is refused `404 NO_DRAFT`, as the strict draft read refuses it. It runs the same judgement the draft read and the publish gate run; nothing about either changes.
13+
14+
A caller that judges several drafts in one pass may hand one `packageClosures` map (an empty `Map`) to every call of the pass. The package's other drafts, which a package publish judges each draft against, are then collected once per package instead of once per call. The answers are the same; without the map, each call collects them as before.

‎content/docs/permissions/system-context.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ One of the largest consumers of the flag;
210210
| 54 | Package REST route capability gate bypassed | rest | Get: a marketplace publish over REST (`POST /packages/publish`, the one route the REST registrar mounts since #14503) without `manage_metadata`; the package read cohort (`studio.access` / `setup.access`) is enforced by the dispatcher `/packages` domain's own read gate, where the reads are served | `refusePackageRequest` |
211211
| 55 | Package domain capability gates bypassed | runtime | Get: package management and package-inventory reads without the capability | `requireManageMetadata`, `requireReadCapability` |
212212
| 56 | Activation write / authoring refusals do not fire | runtime | Get: activation artifacts writable and authorable without the activation-authoring capability | `refuseUngrantedActivationWrite`, `refuseUngrantedActivationAuthoring` |
213-
| 55b | Walled environment-metadata refusal does not fire | metadata-core, rest, runtime | Get: under `isolated` / `group`, a write of the environment's metadata, of any type, at the `/meta` write doors (save, reset, publish, rollback) and `POST /meta/_migrate-stored` on both transports, at every `/packages` write door (create, the manifest `PATCH`, enable, disable, publish, `publish-drafts`, `discard-drafts`, `revert`, `rollback`, `commits/:commitId/revert`, `duplicate`, `adopt-orphans`, delete), at the `/automation` definition writes (create, update, delete, clone), at the permission-set clone door, at the import of a remote table as an object (the REST import route and the MCP `import_object` tool), and at the refresh of a federated datasource's cached catalog. Every other caller below the platform-operator rung is refused `403` there (ADR-0131 D3, D12 items 7–8, D11), because one organization's write would change what every organization resolves. The seeders, the package door and migrations write the environment's metadata this way. Under `single` the refusal is inert for every caller | `walledCatalogWriteVerdict`, `walledCatalogRefusal`, `refuseWalledCatalogPackageWrite`, `refuseWalledFlowDefinitionWrite`, `registerExternalDatasourceRoutes`, `federationService` |
213+
| 55b | Walled environment-metadata refusal does not fire | metadata-core, rest, runtime | Get: under `isolated` / `group`, a write of the environment's metadata, of any type, at the `/meta` write doors (save, reset, publish, rollback) and `POST /meta/_migrate-stored` on both transports, at every `/packages` write door (create, the manifest `PATCH`, enable, disable, publish, `publish-drafts`, `discard-drafts`, `revert`, `rollback`, `commits/:commitId/revert`, `duplicate`, `adopt-orphans`, delete), at the `/automation` definition writes (create, update, delete, clone), at the permission-set clone door, at the import of a remote table as an object (the REST import route and the MCP `import_object` tool), at the open MCP server's draft save and discard (`save_metadata_draft`, `delete_metadata_draft`), and at the refresh of a federated datasource's cached catalog. Every other caller below the platform-operator rung is refused `403` there (ADR-0131 D3, D12 items 7–8, D11), because one organization's write would change what every organization resolves. The seeders, the package door and migrations write the environment's metadata this way. Under `single` the refusal is inert for every caller | `walledCatalogWriteVerdict`, `walledCatalogRefusal`, `refuseWalledCatalogPackageWrite`, `refuseWalledFlowDefinitionWrite`, `registerExternalDatasourceRoutes`, `federationService`, `openWriter` |
214214
| 57 | Automation run-state read, flow-authoring write, the paused-run caller gate (screen read and resume), the two operator run-lifecycle writes, and the elevated self-triggered start, the AI-service-account elevated start and the start-record check at every door that starts a flow by name all pass | runtime | Get: run state, flow writes, a paused run's screen and its resume with no grant and without being the run's starter — and cancelling or restoring a suspension without the platform-operator rung. The screen read and the resume ask one predicate, so this is one bypass for both. The lifecycle bypass is the in-process owner's door: plugin-approvals' revise-window recall (ADR-0044) cancels on behalf of a decision it already authorized and recorded. And starting a flow declared `runAs: 'system'` whose type is self-triggered (`autolaunched`, `record_change`, `schedule`) through any door that starts a flow by name — the trigger route, an action of `type: 'flow'` (REST `/actions` and the MCP `run_action` bridge) and a declared endpoint of `type: 'flow'` — which every other caller, the guest principal included, is refused `403 PERMISSION_DENIED` (the maintainer's rulings, letters B and A) — and starting, through the same doors, a flow whose `requiredPermissions` the caller does not hold (ruling record 6377848497, letter A) — and starting, through the same doors, a flow declared `runAs: 'system'` as an AI service account (an agent acting for itself, with no `onBehalfOf`) where the action's `ai.exposed: true` opt-in is not in hand, which that account is refused `403 PERMISSION_DENIED` (ADR-0151 Non-goals, ruling record 6812617393, letter C; a trigger route and a declared endpoint carry no opt-in, so there it is always refused, and the refusal names the action door that admits it). And starting, through the same doors, a flow on a record key the caller's own scope does not deliver, which every other caller is refused with the action door's `404 RECORD_NOT_FOUND` before the run exists (and `400 VALIDATION_FAILED` for a key that is not one id, or for an elevated start that names no object). The three doors ask one check, so this is one bypass for all of them, and it is the in-process caller's, such as a job: inbound HTTP never carries the flag | `mayReadRunState`, `refuseUngrantedFlowWrite`, `isRunStarterOrRunStateReader`, `refuseUngrantedRunLifecycleWrite`, `flowStartRefusal`, `refuseUnreadableFlowStartRecords` |
215215
| 57b | Connector credential door's capability and posture gates pass | runtime | Get: listing, setting and clearing the environment's stored connector credentials (`/automation/connectors/credential-refs`) without `manage_metadata`, and under the `group` / `isolated` postures, where the door refuses every other caller `403 PERMISSION_DENIED` naming the posture, the platform operator included, because the store is environment-level. The bypass is the in-process caller's: inbound HTTP never carries the flag. Get nothing more about the value: no answer of this door carries it | `refuseUngrantedConnectorCredentialAccess`, `refuseWalledConnectorCredentialAccess` |
216216
| 57c | Connector connection door's capability gate passes | runtime | Get: reading, beginning, completing (the OAuth callback) and revoking an organization's connection of an `oauth2` `authorization_code` connector instance (`/automation/connectors/:name/connection`, `/automation/connectors/oauth/callback`, ADR-0143 D5) without `manage_metadata`. No posture refuses it: a connection belongs to its organization. The bypass is the in-process caller's: inbound HTTP never carries the flag. Get nothing more: no answer of this door carries a token, and the callback's `state` is still bound to the user and organization that began the connect | `refuseUngrantedConnectorConnectionAccess` |
@@ -675,6 +675,7 @@ and CI refuses one that differs from what the tree produces.
675675
| `packages/runtime/src/domains/automation.ts#refuseWalledConnectorCredentialAccess` | 1 | 57b |
676676
| `packages/runtime/src/domains/automation.ts#refuseWalledFlowDefinitionWrite` | 1 | 55b |
677677
| `packages/runtime/src/domains/i18n.ts#handleI18nRequest` | 1 | 52 |
678+
| `packages/runtime/src/domains/mcp-authoring.ts#openWriter` | 1 | 55b |
678679
| `packages/runtime/src/domains/mcp.ts#federationService` | 1 | 55b |
679680
| `packages/runtime/src/domains/mcp.ts#handleMcpRequest` | 1 | 53 |
680681
| `packages/runtime/src/domains/mcp.ts#membershipReachRefusal` | 1 | 62b |

‎packages/mcp/src/initialize-selection-rule-34686.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,33 @@ describe('[#34686] initialize instructions — host and configured texts are lef
204204
});
205205
});
206206

207+
describe('[#34766] initialize instructions — the drafts line follows the authoring tools', () => {
208+
const DRAFTS = 'They save drafts only';
209+
const ONE_TOOL = { getAll: () => [{ name: 'save_metadata_draft', description: 'Save a draft.' }], execute: async () => ({}) as never };
210+
211+
it('a metadata:write request whose host registry lists a tool is told authoring lands as drafts a person publishes', async () => {
212+
const runtime = new MCPServerRuntime({ name: 't', version: '1.0.0' });
213+
const text = await instructionsOf(runtime, makeBridge(), {
214+
grantedScopes: [MCP_OAUTH_SCOPE_DATA_READ, MCP_OAUTH_SCOPE_METADATA_WRITE],
215+
authoring: { registry: ONE_TOOL as never },
216+
});
217+
expect(text).toContain(DRAFTS);
218+
// The rest of the open text is still there.
219+
expect(carriesRule(text)).toBe(true);
220+
expect(text).toContain('@objectstack/skills');
221+
});
222+
223+
it('no drafts line where no authoring tool registers: an empty registry, a grant without metadata:write, no injection', async () => {
224+
const runtime = new MCPServerRuntime({ name: 't', version: '1.0.0' });
225+
const cases: Opts[] = [
226+
{ grantedScopes: [MCP_OAUTH_SCOPE_METADATA_WRITE], authoring: {} },
227+
{ grantedScopes: [MCP_OAUTH_SCOPE_DATA_READ], authoring: { registry: ONE_TOOL as never } },
228+
{},
229+
];
230+
for (const o of cases) expect(await instructionsOf(runtime, makeBridge(), o), JSON.stringify(o)).not.toContain(DRAFTS);
231+
});
232+
});
233+
207234
/**
208235
* [#34919] The rule tells the client to follow `list_datasets`' `nextStep`
209236
* and cite `query_dataset`'s `sourceLine`, and names the precedence among

‎packages/mcp/src/mcp-server-runtime.authoring-scope.test.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ import type {
5757
ToolRegistry,
5858
} from './types.js';
5959

60+
/** [#34766] The paragraph the open server's default text adds where authoring tools register. */
61+
const AUTHORING_DRAFTS_PARAGRAPH_START = 'This connection also lists authoring tools';
62+
63+
/** The text with that one paragraph taken out (the paragraphs are joined by a blank line). */
64+
function withoutDraftsParagraph(text: unknown): unknown {
65+
if (typeof text !== 'string') return text;
66+
return text.split('\n\n').filter((part) => !part.startsWith(AUTHORING_DRAFTS_PARAGRAPH_START)).join('\n\n');
67+
}
68+
6069
// ---------------------------------------------------------------------------
6170
// Fixtures
6271
// ---------------------------------------------------------------------------
@@ -686,10 +695,12 @@ describe('[#31022] per-request instructions on the authoring injection — answe
686695
).toBe(defaultText);
687696
});
688697

689-
it('a metadata:write request whose injection carries no instructions gets the default', async () => {
698+
it('a metadata:write request whose injection carries no instructions gets the default, plus the drafts line its tools earn', async () => {
690699
const defaultText = await instructionsAtInitialize(runtime, { grantedScopes: [MCP_OAUTH_SCOPE_DATA_READ] });
691700
const subject = await instructionsAtInitialize(runtime, { grantedScopes: [MCP_OAUTH_SCOPE_METADATA_WRITE], registry });
692-
expect(subject).toBe(defaultText);
701+
// [#34766] The one paragraph a request that registers authoring tools adds.
702+
expect(subject).toContain(AUTHORING_DRAFTS_PARAGRAPH_START);
703+
expect(withoutDraftsParagraph(subject)).toBe(defaultText);
693704
});
694705

695706
it('a runtime configured with instructions keeps them for every request the injection does not reach', async () => {
@@ -810,7 +821,7 @@ describe('[#32766] data-only instructions on the authoring injection — the com
810821
await instructionsAtInitialize(runtime, { grantedScopes: [MCP_OAUTH_SCOPE_DATA_READ], registry, dataOnlyInstructions: ' \n ' }),
811822
).toBe(defaultText);
812823
expect(
813-
await instructionsAtInitialize(runtime, { grantedScopes: [MCP_OAUTH_SCOPE_METADATA_WRITE], registry, instructions: '' }),
824+
withoutDraftsParagraph(await instructionsAtInitialize(runtime, { grantedScopes: [MCP_OAUTH_SCOPE_METADATA_WRITE], registry, instructions: '' })),
814825
).toBe(defaultText);
815826
});
816827

‎packages/mcp/src/mcp-server-runtime.ts‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,29 @@ const DATASET_SELECTION_RULE =
18371837
+ 'which reports the first of several_measures, one_measure, candidates_only, no_measure when words differ. Cite '
18381838
+ 'query_dataset\'s sourceLine as the answer\'s source.';
18391839

1840+
/**
1841+
* [#34766] What a request that registers host-injected authoring tools is told
1842+
* about them, in one sentence true of every such registry: authoring lands as
1843+
* drafts that a person reviews and publishes (the authoring section of the
1844+
* served skill says the same, `skill-md.ts`). What each tool answers — the
1845+
* open draft door's save answers with the publish verdict — is the tool's own
1846+
* description. Sent only where the authoring family registers tools
1847+
* ({@link authoringToolsServed}).
1848+
*/
1849+
const AUTHORING_DRAFTS_LINE =
1850+
'This connection also lists authoring tools, which change the app\'s metadata. They save drafts only: nothing '
1851+
+ 'they write is published until a person reviews and publishes it in Studio. Read each tool\'s reply before '
1852+
+ 'the next step; a refused authoring call means you may not author that here.';
1853+
1854+
/**
1855+
* [#34766] Does this request register host-injected authoring tools? The gate
1856+
* `registerAuthoringTools` reads (`grantsAuthoringTools`) and a registry that
1857+
* lists at least one tool for this caller.
1858+
*/
1859+
function authoringToolsServed(authoring: McpAuthoringInjection | undefined, grantedScopes: readonly string[] | undefined): boolean {
1860+
return authoring !== undefined && grantsAuthoringTools(grantedScopes) && authoring.registry.getAll().length > 0;
1861+
}
1862+
18401863
/**
18411864
* [#34686] The published skills package an open server points a client to
18421865
* (#34659 ruling D5 = A), at the version to install: this package's own
@@ -1862,13 +1885,19 @@ function skillsInstallLine(version: string | undefined): string | undefined {
18621885
/**
18631886
* [#34686] The open server's own `initialize` text for one HTTP request: the
18641887
* default sentence, the selection rule when this request's grant registers
1865-
* both dataset tools, and the skills install line. Read only when neither the
1888+
* both dataset tools, [#34766] the drafts line when it registers authoring
1889+
* tools, and the skills install line. Read only when neither the
18661890
* host (`hostInstructions`) nor the runtime's configured `instructions`
18671891
* answers: both are whole texts their author owns, and the configured one is
18681892
* the same string for every grant, so nothing is appended to either.
18691893
*/
1870-
function openServerInstructions(datasetRule: boolean): string {
1871-
return [DEFAULT_HTTP_INSTRUCTIONS, datasetRule ? DATASET_SELECTION_RULE : undefined, skillsInstallLine(PACKAGE_VERSION)]
1894+
function openServerInstructions(datasetRule: boolean, authoringServed = false): string {
1895+
return [
1896+
DEFAULT_HTTP_INSTRUCTIONS,
1897+
datasetRule ? DATASET_SELECTION_RULE : undefined,
1898+
authoringServed ? AUTHORING_DRAFTS_LINE : undefined,
1899+
skillsInstallLine(PACKAGE_VERSION),
1900+
]
18721901
.filter((part): part is string => part !== undefined)
18731902
.join('\n\n');
18741903
}
@@ -2821,7 +2850,10 @@ export class MCPServerRuntime {
28212850
instructions:
28222851
hostInstructions(opts.authoring, opts.toolOptions?.grantedScopes) ??
28232852
this.config.instructions ??
2824-
openServerInstructions(datasetToolsServed(opts.bridge, opts.toolOptions)),
2853+
openServerInstructions(
2854+
datasetToolsServed(opts.bridge, opts.toolOptions),
2855+
authoringToolsServed(opts.authoring, opts.toolOptions?.grantedScopes),
2856+
),
28252857
},
28262858
);
28272859

0 commit comments

Comments
 (0)