Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2f540bc
feat(mcp): open draft door registry with the three read tools
claude Nov 17, 2026
2e6afd6
test(mcp): pin the open draft door's admission cells and read tools; …
claude Nov 17, 2026
f86960e
test(runtime): the unknown-type pin's protocol double serves its live…
claude Nov 17, 2026
a40a48e
fix(runtime): the draft door's own argument refusals answer the stand…
claude Nov 17, 2026
eaa8716
test(runtime): the draft door's pins pay the metadata package's load …
claude Nov 18, 2026
504662e
chore(scripts): declare the open draft door's registry module among t…
claude Nov 18, 2026
2ef0ca8
fix(runtime): the open draft door's reads run the /meta read gates wi…
claude Nov 18, 2026
861c63e
feat(metadata-protocol): make the draft publish judgement public, rea…
claude Nov 18, 2026
87be085
fix(metadata-protocol): the stored-draft read names its environment r…
claude Nov 18, 2026
09f5249
chore(changeset): declare the public draft publish verdict
claude Nov 18, 2026
39ccc2a
Merge PR-a's fix head 2ef0ca896e into the draft door's write half
claude Nov 18, 2026
9350be6
feat(runtime): the open draft door saves and discards drafts, and ans…
claude Nov 18, 2026
aa96eb0
test(runtime,mcp): pin the draft writes, the verdicts and the app-crm…
claude Nov 18, 2026
1298f20
fix(runtime): the draft writes and the listed verdicts fold the type …
claude Nov 18, 2026
16c0ab9
test(runtime,mcp): the real envelope's locales and posture in the wri…
claude Nov 18, 2026
91c7ac4
chore(changeset): the open MCP server's draft writes, the listed verd…
claude Nov 18, 2026
bb39cca
fix(runtime): the draft door folds the type once at its boundary, so …
claude Nov 18, 2026
b7838f5
test(runtime): pin that an inherited member's name reaches the protoc…
claude Nov 18, 2026
7b83798
Merge PR-a's M1-b fix head b7838f512f into the draft door's write half
claude Nov 18, 2026
426f0f7
Merge origin/main into the draft door's write half
claude Nov 18, 2026
b39f0f8
chore(scripts): declare the draft door's tool-call refusal as how its…
claude Nov 18, 2026
ffb4f7b
test(runtime): pin that an inherited member's name as the write tools…
claude Nov 18, 2026
c1368f8
fix(runtime): the draft door's reads run the /meta type-level read ad…
claude Nov 18, 2026
c50358b
chore(changeset): the draft door's reads ask the /meta type-level rea…
claude Nov 18, 2026
1ea1733
Merge PR-a's type-level read admission head c50358b59c into the draft…
claude Nov 18, 2026
1294fe1
fix(runtime): the draft door's writes and verdicts ask the /meta type…
claude Nov 18, 2026
a94722f
docs(permissions): name the draft door's walled write verdict on the …
claude Nov 18, 2026
c2fa38c
Merge remote-tracking branch 'origin/main' into claude/issue-34766-mc…
claude Nov 18, 2026
328a3d9
Merge remote-tracking branch 'origin/main' into claude/issue-34766-mc…
claude Nov 18, 2026
c7294ea
Merge PR-a's head c2fa38c8b4 (main merged in) into the draft door's w…
claude Nov 18, 2026
7cbb425
fix(runtime,metadata-protocol): record the draft door's save among th…
claude Nov 18, 2026
8709c88
Merge origin/main (the read half squash-merged) into the draft door's…
claude Nov 18, 2026
50b2d84
fix(runtime,metadata-protocol): the draft list collects each package'…
claude Nov 18, 2026
2d6a722
Merge origin/main into the draft door's write half
claude Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/34766-mcp-draft-door-write-tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/runtime': patch
'@objectstack/mcp': patch
---

feat(runtime,mcp): the open MCP server saves and discards metadata drafts, and every save answers with what publishing the draft would say

Clause-②: yes (widening)
Metadata-protocol: none

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`.

- `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.
- A save that names no `package` is refused `400 VALIDATION_ERROR`, and nothing is saved. The refusal names the writable packages in that environment.
- `delete_metadata_draft({ type, name, package? })` discards a pending draft. The published version, if any, is left as it is.
- `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.

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`.

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.
14 changes: 14 additions & 0 deletions .changeset/34766-mcp-draft-door-write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/metadata-protocol': patch
---

feat(metadata-protocol): the draft publish verdict is a public protocol method, and it reads the stored draft itself

Clause-②: yes (widening)
Metadata-protocol: none

`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`.

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.

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.
3 changes: 2 additions & 1 deletion content/docs/permissions/system-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ One of the largest consumers of the flag;
| 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` |
| 55 | Package domain capability gates bypassed | runtime | Get: package management and package-inventory reads without the capability | `requireManageMetadata`, `requireReadCapability` |
| 56 | Activation write / authoring refusals do not fire | runtime | Get: activation artifacts writable and authorable without the activation-authoring capability | `refuseUngrantedActivationWrite`, `refuseUngrantedActivationAuthoring` |
| 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` |
| 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` |
| 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` |
| 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` |
| 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` |
Expand Down Expand Up @@ -675,6 +675,7 @@ and CI refuses one that differs from what the tree produces.
| `packages/runtime/src/domains/automation.ts#refuseWalledConnectorCredentialAccess` | 1 | 57b |
| `packages/runtime/src/domains/automation.ts#refuseWalledFlowDefinitionWrite` | 1 | 55b |
| `packages/runtime/src/domains/i18n.ts#handleI18nRequest` | 1 | 52 |
| `packages/runtime/src/domains/mcp-authoring.ts#openWriter` | 1 | 55b |
| `packages/runtime/src/domains/mcp.ts#federationService` | 1 | 55b |
| `packages/runtime/src/domains/mcp.ts#handleMcpRequest` | 1 | 53 |
| `packages/runtime/src/domains/mcp.ts#membershipReachRefusal` | 1 | 62b |
Expand Down
27 changes: 27 additions & 0 deletions packages/mcp/src/initialize-selection-rule-34686.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,33 @@ describe('[#34686] initialize instructions — host and configured texts are lef
});
});

describe('[#34766] initialize instructions — the drafts line follows the authoring tools', () => {
const DRAFTS = 'They save drafts only';
const ONE_TOOL = { getAll: () => [{ name: 'save_metadata_draft', description: 'Save a draft.' }], execute: async () => ({}) as never };

it('a metadata:write request whose host registry lists a tool is told authoring lands as drafts a person publishes', async () => {
const runtime = new MCPServerRuntime({ name: 't', version: '1.0.0' });
const text = await instructionsOf(runtime, makeBridge(), {
grantedScopes: [MCP_OAUTH_SCOPE_DATA_READ, MCP_OAUTH_SCOPE_METADATA_WRITE],
authoring: { registry: ONE_TOOL as never },
});
expect(text).toContain(DRAFTS);
// The rest of the open text is still there.
expect(carriesRule(text)).toBe(true);
expect(text).toContain('@objectstack/skills');
});

it('no drafts line where no authoring tool registers: an empty registry, a grant without metadata:write, no injection', async () => {
const runtime = new MCPServerRuntime({ name: 't', version: '1.0.0' });
const cases: Opts[] = [
{ grantedScopes: [MCP_OAUTH_SCOPE_METADATA_WRITE], authoring: {} },
{ grantedScopes: [MCP_OAUTH_SCOPE_DATA_READ], authoring: { registry: ONE_TOOL as never } },
{},
];
for (const o of cases) expect(await instructionsOf(runtime, makeBridge(), o), JSON.stringify(o)).not.toContain(DRAFTS);
});
});

/**
* [#34919] The rule tells the client to follow `list_datasets`' `nextStep`
* and cite `query_dataset`'s `sourceLine`, and names the precedence among
Expand Down
17 changes: 14 additions & 3 deletions packages/mcp/src/mcp-server-runtime.authoring-scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ import type {
ToolRegistry,
} from './types.js';

/** [#34766] The paragraph the open server's default text adds where authoring tools register. */
const AUTHORING_DRAFTS_PARAGRAPH_START = 'This connection also lists authoring tools';

/** The text with that one paragraph taken out (the paragraphs are joined by a blank line). */
function withoutDraftsParagraph(text: unknown): unknown {
if (typeof text !== 'string') return text;
return text.split('\n\n').filter((part) => !part.startsWith(AUTHORING_DRAFTS_PARAGRAPH_START)).join('\n\n');
}

// ---------------------------------------------------------------------------
// Fixtures
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -686,10 +695,12 @@ describe('[#31022] per-request instructions on the authoring injection — answe
).toBe(defaultText);
});

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

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

Expand Down
40 changes: 36 additions & 4 deletions packages/mcp/src/mcp-server-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,29 @@ const DATASET_SELECTION_RULE =
+ 'which reports the first of several_measures, one_measure, candidates_only, no_measure when words differ. Cite '
+ 'query_dataset\'s sourceLine as the answer\'s source.';

/**
* [#34766] What a request that registers host-injected authoring tools is told
* about them, in one sentence true of every such registry: authoring lands as
* drafts that a person reviews and publishes (the authoring section of the
* served skill says the same, `skill-md.ts`). What each tool answers — the
* open draft door's save answers with the publish verdict — is the tool's own
* description. Sent only where the authoring family registers tools
* ({@link authoringToolsServed}).
*/
const AUTHORING_DRAFTS_LINE =
'This connection also lists authoring tools, which change the app\'s metadata. They save drafts only: nothing '
+ 'they write is published until a person reviews and publishes it in Studio. Read each tool\'s reply before '
+ 'the next step; a refused authoring call means you may not author that here.';

/**
* [#34766] Does this request register host-injected authoring tools? The gate
* `registerAuthoringTools` reads (`grantsAuthoringTools`) and a registry that
* lists at least one tool for this caller.
*/
function authoringToolsServed(authoring: McpAuthoringInjection | undefined, grantedScopes: readonly string[] | undefined): boolean {
return authoring !== undefined && grantsAuthoringTools(grantedScopes) && authoring.registry.getAll().length > 0;
}

/**
* [#34686] The published skills package an open server points a client to
* (#34659 ruling D5 = A), at the version to install: this package's own
Expand All @@ -1862,13 +1885,19 @@ function skillsInstallLine(version: string | undefined): string | undefined {
/**
* [#34686] The open server's own `initialize` text for one HTTP request: the
* default sentence, the selection rule when this request's grant registers
* both dataset tools, and the skills install line. Read only when neither the
* both dataset tools, [#34766] the drafts line when it registers authoring
* tools, and the skills install line. Read only when neither the
* host (`hostInstructions`) nor the runtime's configured `instructions`
* answers: both are whole texts their author owns, and the configured one is
* the same string for every grant, so nothing is appended to either.
*/
function openServerInstructions(datasetRule: boolean): string {
return [DEFAULT_HTTP_INSTRUCTIONS, datasetRule ? DATASET_SELECTION_RULE : undefined, skillsInstallLine(PACKAGE_VERSION)]
function openServerInstructions(datasetRule: boolean, authoringServed = false): string {
return [
DEFAULT_HTTP_INSTRUCTIONS,
datasetRule ? DATASET_SELECTION_RULE : undefined,
authoringServed ? AUTHORING_DRAFTS_LINE : undefined,
skillsInstallLine(PACKAGE_VERSION),
]
.filter((part): part is string => part !== undefined)
.join('\n\n');
}
Expand Down Expand Up @@ -2821,7 +2850,10 @@ export class MCPServerRuntime {
instructions:
hostInstructions(opts.authoring, opts.toolOptions?.grantedScopes) ??
this.config.instructions ??
openServerInstructions(datasetToolsServed(opts.bridge, opts.toolOptions)),
openServerInstructions(
datasetToolsServed(opts.bridge, opts.toolOptions),
authoringToolsServed(opts.authoring, opts.toolOptions?.grantedScopes),
),
},
);

Expand Down
Loading
Loading