Repository navigation
Commit 2d33205
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
File tree
- .changeset
- content/docs/permissions
- packages
- mcp/src
- metadata-protocol/src
- runtime/src/domains
- scripts
| 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 | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| |||
675 | 675 | | |
676 | 676 | | |
677 | 677 | | |
| 678 | + | |
678 | 679 | | |
679 | 680 | | |
680 | 681 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
207 | 234 | | |
208 | 235 | | |
209 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
60 | 69 | | |
61 | 70 | | |
62 | 71 | | |
| |||
686 | 695 | | |
687 | 696 | | |
688 | 697 | | |
689 | | - | |
| 698 | + | |
690 | 699 | | |
691 | 700 | | |
692 | | - | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
693 | 704 | | |
694 | 705 | | |
695 | 706 | | |
| |||
810 | 821 | | |
811 | 822 | | |
812 | 823 | | |
813 | | - | |
| 824 | + | |
814 | 825 | | |
815 | 826 | | |
816 | 827 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1837 | 1837 | | |
1838 | 1838 | | |
1839 | 1839 | | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
1840 | 1863 | | |
1841 | 1864 | | |
1842 | 1865 | | |
| |||
1862 | 1885 | | |
1863 | 1886 | | |
1864 | 1887 | | |
1865 | | - | |
| 1888 | + | |
| 1889 | + | |
1866 | 1890 | | |
1867 | 1891 | | |
1868 | 1892 | | |
1869 | 1893 | | |
1870 | | - | |
1871 | | - | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
1872 | 1901 | | |
1873 | 1902 | | |
1874 | 1903 | | |
| |||
2821 | 2850 | | |
2822 | 2851 | | |
2823 | 2852 | | |
2824 | | - | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
2825 | 2857 | | |
2826 | 2858 | | |
2827 | 2859 | | |
| |||
0 commit comments