Skip to content

Commit 28a2f0f

Browse files
fix(mcp,runtime): describe_object serves readonly: true where a write never sets the value (#33150)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoSLDKWQ8v7cxY9uDGijfncD)_ Fixes #32530 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:MCP 的 `describe_object`(HTTP 与 stdio 两种传输)和 `objectstack://objects/{name}` 资源,现在对「写了也不会生效」的字段回答 `readonly: true`:自动编号(包括手写、没带 readonly 标记的字段)、公式字段、声明了 `expression` 的存储计算字段。HTTP 传输按字段的原始声明判断(调用者看不到表达式引用的字段时,表达式会被遮蔽,但仍回答 `readonly: true`,表达式本身不外露);stdio 与资源只拿得到遮蔽后的对象,这一情形的缺口已另立 #33156。工具说明同时写明:`readonly` 是 schema 的判断,不是调用者的字段编辑权限;`defaultValue` 可能是服务端解析的令牌(`NOW()`、`current_user`)或表达式对象,代理应省略该字段而不是照抄。 - 为什么改:之前只看字段上声明的 `readonly` 标记,代理会以为这些字段可写,写进去被引擎丢弃或覆盖,再猜再试。 - 风险与回滚:只放宽回答(多说了 `readonly: true`),不拒绝任何新输入;普通字段仍是 `false`、声明了只读的仍是 `true`(有对照用例)。回滚 = revert 本 PR,不涉及数据。 - 先看:`packages/runtime/src/domains/mcp.ts` 与 `packages/mcp/src/mcp-server-runtime.ts` 新增的 `writeNeverSetsField`(两处孪生实现);`packages/mcp/src/mcp-http-tools.ts` 的 `describe_object` 说明文字。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/mcp-object-schema-mask.test.ts -t 32530`,预期 4/4 通过(真实引擎 + 安全插件)。 - 需要你做的:无,席位落地。 ## What changes - **Item 1, both twins.** `describeServedObject` in `packages/runtime/src/domains/mcp.ts` (HTTP bridge) and in `packages/mcp/src/mcp-server-runtime.ts` (stdio bridge and the `objectstack://objects/{name}` resource) now serve `readonly` from `writeNeverSetsField(f)`, one small predicate per twin: the declared flag, OR a runtime-owned type (`RUNTIME_OWNED_FIELD_TYPES` from `@objectstack/spec/data`, today `autonumber`), OR a `formula` (`isVirtualSearchField`, the spec's one statement of the virtual set; the engine's write strip keys on the same type), OR a stored field declaring an `expression` (the spec's `expression` contract: "a client-sent value never stands"; truthy, the engine's own test in `planStoredExpressions`). No local type list. - **Round 2 (contract review S1): the HTTP twin judges on the declaration.** The caller's field mask deletes a readable field's `expression` when it names a field the caller cannot read, while the engine still computes the column. `describeObject` in `packages/runtime/src/domains/mcp.ts` now runs `readServedObject` and `servedToCaller` as two steps and calls `describeServedObject(def, declared)`: `readonly` comes from `writeNeverSetsField(declared.fields[k])`, and everything served is still built from the masked `def`, so the expression stays hidden. No new read: `declared` is the object the bridge already masks. The stdio twin and the objects resource hold only the masked object (`callerObjectView`), so there the expression case answers `true` only where the caller is shown the expression; the mcp twin's JSDoc and the changeset say so. - **The stored-expression arm is a bounded same-class fix.** The card names autonumber and formula; a non-formula field with an `expression` is the same defect (served `readonly: false`, the engine overwrites the sent value, measured below), on the same line, with the same gate family, and no other claim holds the function. Leaving it would keep the card's complaint for that field kind. - **Item 2: option (b).** The served view cannot answer the caller's edit verdict without a new read. Measured: the caller's object is `servedToCaller(def)` over `resolveObjectMasker` → `resolveObjectSchemaMaskPosture`, which asks the security service `getMetadataReadableFields` / `getReadableFields` and `canReadObject` only; the posture carries a `readable` set and nothing about edit. The edit verdict lives in `ISecurityService.getWritableFields(object, context)` (optional member, the write gate's complement). So the description now says `readonly` is the schema's, not the caller's edit permission, and that a write naming a read-only-for-you field is refused. What an edit verdict would need is in the acceptance notes. - **Item 3.** The `optionFieldsOf` JSDoc no longer says `describe_object` "serves what it served before"; the `describe_object` description gains the `defaultValue` sentence (token or expression object: omit the field, never copy the value) and the `readonly` wording above. - **Skills-docs: not owed.** `packages/mcp/src/skill-md.ts` names `describe_object` (fields: name, type, required) but restates neither `readonly` nor `defaultValue`, so it and its console mirror are untouched. ## Tests - `packages/runtime/src/domains/mcp-object-schema-mask.test.ts`, new top-level describe `[#32530]` on the file's existing real-layer harness (real `ObjectQL` over `SqlDriver`, real `SecurityPlugin`, the real `/mcp` entry): - precondition: the hand-written `autonumber` literal reaches the served object with no `readonly` flag; - `ticket_no` (autonumber), `total` (formula), `bare_formula` (formula, no expression), `doubled` (number + expression) are served `readonly: true`; CONTROL `title` and `qty` stay `false`, `frozen_note` (declared readonly) stays `true`; - through the same bridge's `create`, the engine stores none of the sent values: the autonumber is issued (`T-0001` shape), the formula reads `6`, the stored expression is `6`, the CONTROL field is stored; - the item-2 arm: `locked_note` (member may read, not edit) is served `readonly: false`, and `create` naming it is refused `PERMISSION_DENIED` / `403`; - round 2: `marked_up` is a stored expression over `hidden_cost`, which the member may not read. It is served `readonly: true`, and the served answer contains neither `hidden_cost` nor any `record.` text. Preconditions: the member's `/metadata/object` read serves `marked_up` with no `expression`, while `engine.getSchema` still carries it. - `packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts`: new top-level describe `[#32530]` pinning the same fields over stdio `describe_object` and over `buildObjectSchemaResource`; the existing `DECLARED_ANSWER` pin had `bonus_formula` at `readonly: false`, which encoded the defect, and now reads `true`. ## Acceptance notes - **What an edit verdict (item 2a) would need, measured.** HTTP bridge: one `security.getWritableFields(name, ec)` call per `describe_object`, feature-detected, beside the masker (the service is already resolved there). stdio bridge: `StdioDataBridgeDeps.security` is typed `ObjectSchemaMaskSecuritySurface`, which has no `getWritableFields`, so the dependency type and `callerObjectView` widen (`stdio-data-bridge.ts`, outside this card's surface). The objects resource: `buildObjectSchemaResource` reads an `McpObjectView` (`listObjects` / `getObject`) with no principal, so it cannot ask at all without a new seam. And the contract (`getWritableFields` JSDoc) requires a consumer without that member to state in its response that it narrowed by the read projection, so the answer would also gain a coverage key. Not filed: it is the card's own option (a), deliberately not taken. - **Out of scope, filed as #33156:** over stdio and on the `objectstack://objects/{name}` resource, a caller who cannot read a field that a stored expression names is served `readonly: false` for that field, while the HTTP door answers `true`. Those two readers hold only the masked object; the declaration is not reachable there without a second metadata read, and `stdio-data-bridge.ts` is outside this card's surface. - **`summary` is left `readonly: false`.** `COMPUTED_VALUE_TYPES` calls it server-computed, but the engine persists a caller-sent summary value (`stripComputedWriteFields` JSDoc: "a roll-up HAS a column, and a caller-supplied value is persisted"), so `readonly: true` would claim a drop that does not happen. Noted, not filed: the engine records the question as its own. - **The formula predicate is search-named.** `isVirtualSearchField` is the spec's only exported statement of "computed on read, no column"; the write strip in objectql keys on `type === 'formula'` literally and `isRuntimeOwnedField` lives in objectql, which `@objectstack/mcp` does not depend on. Both read the same set today. A write-named spec predicate would be its own spec change. - **Serial.** Edits stay on `describeServedObject` / `writeNeverSetsField`, the `optionFieldsOf` JSDoc and the `describe_object` description; no hunk touches `servedObjectDefinitionOf`, the `validate_expression` handler (#33134) or the connector narrowing (#31699). - **Ruling grep** (`ruling|Ruling-ref|maintainer|⛔`) on the touched surface: 69 hits across the three source files. The ones inside the edited regions are the `describeServedObject` JSDoc's "⛔ never its condition, pattern or transition table" (both twins, unchanged, honoured: no rule expression is served) and the new JSDoc's own "⛔ Not the caller's field edit permission". No ruling record governs `readonly`. The `mcp-http-tools.ts` hits sit outside the edited JSDoc and description. ## Verification Round 1 readings were taken at `819ea267` (base `932eab54`; `origin/main` merged once there, bringing only `packages/lint` changes). Round 2 readings were taken at head `92fba691`: the S1 fix `d05eae15`, the changeset narrowing, then `origin/main` merged a second time because #33144 landed on `packages/runtime/src/domains/mcp.ts` (no conflict). <details><summary>Round 2 (S1) at 92fba69</summary> - `mcp-object-schema-mask.test.ts` (runtime) — Tests 72 passed (72); `src/domains/mcp*` (runtime) — Test Files 5 passed (5), Tests 247 passed (247) - `pnpm --filter @objectstack/mcp test` — Test Files 63 passed (63), Tests 1106 passed (1106) - `pnpm --filter @objectstack/mcp --filter @objectstack/runtime typecheck` — `VERDICT command-exit 0` - Ablations, both red and both restored to the HEAD blob: `readonly: writeNeverSetsField(f)` back in place gives 1 failed (the new `marked_up` case); serving `declared.fields[k].expression` gives 1 failed (the same case, its no-expression assertion). - Derived gates re-derived at `92fba691`: the same 66 families, each run with stdin closed and its exit code recorded; `--ran` reconciles **66 accounted, 66 run, 0 NOT MEASURED**, every one exit 0 (`check:dual-build-cjs-loads` included this time, after the post-merge closure build). `pnpm lint` exit 0. </details> <details><summary>Measured at origin/main first (the premise holds)</summary> The new runtime pins over the unfixed twin (`4fee53be`, tests only on `932eab54`): **1 failed | 3 passed**. The failing case: `doubled`, `ticket_no` and `total` were served `readonly: false` (the `frozen_note` and plain-field controls matched). The three passing cases are the measurement of the engine and the gate: the autonumber literal carries no flag, the engine dropped or replaced every sent computed value, and the member's write naming `locked_note` was refused `PERMISSION_DENIED` / `403` while `describe_object` served it `readonly: false`. On the stdio side, `DECLARED_ANSWER` pinned `bonus_formula` at `readonly: false` on `main`. </details> <details><summary>Package tests and typecheck</summary> - `pnpm --filter @objectstack/mcp test` — Test Files 63 passed (63), Tests 1106 passed (1106) - `pnpm --filter @objectstack/runtime test` — Test Files 596 passed (596), Tests 10581 passed | 19 skipped (10600), `VERDICT command-exit 0` - `mcp-object-schema-mask.test.ts` (runtime) — Tests 71 passed (71) - `pnpm --filter @objectstack/mcp --filter @objectstack/runtime typecheck` — `VERDICT command-exit 0`; both run `tsc --noEmit && pnpm check:test-typecheck`, the second over `tsconfig.test.json`, which carries the test files </details> <details><summary>Ablations (12, all red, all restored)</summary> Every leg through `scripts/ablation-replace.mjs` (anchor x1 → x0, blob changed, restored blob == HEAD and `git diff HEAD` empty). The suites import the source, so no `dist/` leg. - Runtime twin, `-t 32530`: whole verdict back to `f?.readonly === true` → 1 failed; runtime-owned arm removed → 1 failed; formula arm removed → 1 failed; expression arm → `false` → 1 failed; declared arm removed → 1 failed; CONTROL (last arm → `true`) → 2 failed (the plain-field control and the item-2 `locked_note` case). - mcp twin, `stdio-data-bridge.object-schema-mask.test.ts`: whole verdict → 4 failed (the two new cases plus the two `DECLARED_ANSWER` cases); runtime-owned arm → 2 failed; formula arm → 2 failed; expression arm → 2 failed; declared arm → 3 failed; CONTROL → 5 failed. </details> <details><summary>Derived gates and lint</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at `819ea267`: 66 families, each run with stdin closed and its exit code recorded before any pipe. `--ran` reconciles **66 accounted, 65 run, 1 NOT MEASURED**: - `pnpm check:dual-build-cjs-loads` — exit 3, PREREQUISITE NOT MET: the scan needs `dist/` of packages outside this diff's closure. NOT MEASURED; CI runs it. All other 65 exit 0, `check:nul-bytes`, `check:cross-package-test-inputs`, `check:test-source-alias`, `check:doc-authoring` and `check:adr-0087-registration` among them. `node scripts/check-plugin-teardown-shape.mjs --self-test` first exited 3 (its pinned positive control was not in the shallow clone); after fetching `621a4876`, exit 0, 48 cases. `pnpm lint` — exit 0. No export was renamed or removed, so `check-platform-checklist.mjs` is not owed. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibzwtSQM5u87bBFCujF)_ <!-- signed: domain:server#7 · os-tesla · session_01L9qibzwtSQM5u87bBFCujF --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 47f6c93 commit 28a2f0f

7 files changed

Lines changed: 352 additions & 20 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/mcp': patch
3+
'@objectstack/runtime': patch
4+
---
5+
6+
fix(mcp,runtime): `describe_object` serves `readonly: true` where a write never sets the value
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
`describe_object` and the `objectstack://objects/{name}` resource served each field's `readonly` from the declared flag alone, so an agent was told it could write fields whose sent value the engine drops or replaces. Both transports now also answer `readonly: true` for a runtime-owned type (`autonumber`, including a hand-written field literal with no flag), for a `formula` field, and for a stored field that declares an `expression`. On the HTTP transport, `readonly` is judged on the field as declared, so a stored expression the caller is not shown (it names a field they cannot read) still answers `true`, and the expression itself stays hidden. Over stdio and on the resource, which hold only the object as the caller is served it, the expression case answers `true` where the caller is shown the expression. An ordinary field still answers `readonly: false`, and a declared `readonly` still answers `true`.
12+
13+
`readonly` is the schema's answer, not the caller's field edit permission: a field the caller may read but not edit still answers `readonly: false`, and a write naming it is refused as before. The tool description now says so, and it also says that a `defaultValue` may be a token the server resolves (`NOW()`, `current_user`) or an expression object, so an agent omits the field instead of copying the value.

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ export interface McpDataBridge {
179179
* `validate_expression` hands it to the shared validator as
180180
* `ExprSchemaHint.optionFields`, so the tool refuses the `label()` call the
181181
* object save door refuses, in the same words. It is a member of its own,
182-
* not a key on {@link describeObject}'s answer, so `describe_object` serves
183-
* what it served before.
182+
* not a key on {@link describeObject}'s answer: `describe_object` already
183+
* serves each field's `options`, and this list names the fields that carry
184+
* them without a second copy of the object.
184185
*
185186
* OPTIONAL, like {@link listObjectsDiagnosed}: a bridge that omits it gets
186187
* no `label()` target check, exactly as before (the validator's opt-in).
@@ -2401,8 +2402,12 @@ export function registerObjectTools(
24012402
{
24022403
description:
24032404
'Get the schema of a data object as you may read it, with what a write needs. Each field: name, type, label, '
2404-
+ 'required, readonly (a write to it is dropped), system (a platform-injected column), options (value + label; '
2405-
+ 'send the value) on a field that offers a fixed set, and defaultValue when an insert applies one. '
2405+
+ 'required, readonly (a write never sets it: declared read-only, or a value the platform computes, such as a '
2406+
+ 'formula, an autonumber or a field with an expression; leave it out of a write), system (a platform-injected '
2407+
+ 'column), options (value + label; send the value) on a field that offers a fixed set, and defaultValue when '
2408+
+ 'an insert applies one. A defaultValue may be a token the server resolves (NOW(), current_user) or an '
2409+
+ 'expression object: to get it, omit the field, never copy the value. readonly is the schema\'s, not your '
2410+
+ 'edit permission: a field you may read but not edit shows readonly false, and a write naming it is refused. '
24062411
+ 'validations: each active rule\'s name, type, message, severity, events and the fields it names (the '
24072412
+ 'message is what a refused write answers). Also the enabled features.',
24082413
inputSchema: strictToolInput(

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

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { z } from 'zod';
5959
// [#28715] The engine's own reading of "this field declares options" (its
6060
// `label()` map is built from it), never a second spelling here.
6161
import { declaresOptions } from '@objectstack/formula';
62+
import { RUNTIME_OWNED_FIELD_TYPES, isVirtualSearchField } from '@objectstack/spec/data';
6263

6364
/**
6465
* Configuration for the MCP Server Runtime.
@@ -104,6 +105,7 @@ interface ServedFieldDef {
104105
system?: boolean;
105106
options?: unknown[];
106107
defaultValue?: unknown;
108+
expression?: unknown;
107109
}
108110

109111
/**
@@ -113,10 +115,11 @@ interface ServedFieldDef {
113115
* that names a denied field anywhere, its message included) is not described.
114116
*
115117
* Per field: `required`, `readonly` and `system` (an auto-injected column such
116-
* as `created_at` is `readonly` and `system`), the allowed `options` as value +
117-
* label for a field that declares them (a picklist-bound field carries its
118-
* list's resolved options on the served object, {@link declaresOptions}), and
119-
* the `defaultValue` an INSERT applies. Per active validation rule: its name,
118+
* as `created_at` is `readonly` and `system`; [#32530] `readonly` is also true
119+
* where a write never sets the value, {@link writeNeverSetsField}), the allowed
120+
* `options` as value + label for a field that declares them (a picklist-bound
121+
* field carries its list's resolved options on the served object,
122+
* {@link declaresOptions}), and the `defaultValue` an INSERT applies. Per active validation rule: its name,
120123
* kind, message, severity, the write events it runs on, and the fields it names
121124
* — ⛔ never its condition, pattern or transition table: the rule's message is
122125
* what a refused write answers with, and its expression is server policy.
@@ -139,7 +142,7 @@ export function describeServedObject(def: ServedObjectDef): Record<string, unkno
139142
type: f?.type,
140143
label: f?.label ?? key,
141144
required: f?.required ?? false,
142-
readonly: f?.readonly === true,
145+
readonly: writeNeverSetsField(f),
143146
system: f?.system === true,
144147
...(declaresOptions(f) ? { options: describedOptions(f.options as unknown[]) } : {}),
145148
...(f?.defaultValue !== undefined ? { defaultValue: f.defaultValue } : {}),
@@ -149,6 +152,43 @@ export function describeServedObject(def: ServedObjectDef): Record<string, unkno
149152
};
150153
}
151154

155+
/**
156+
* [#32530] `readonly` as {@link describeServedObject} serves it: a caller's
157+
* write can never set this field's value. True for the declared flag, and for
158+
* a value the engine owns whatever the payload says:
159+
*
160+
* - a runtime-owned type (`RUNTIME_OWNED_FIELD_TYPES`, today `autonumber`):
161+
* the write path strips a caller's value even with no `readonly` flag, and a
162+
* hand-authored literal carries none (the field builder injects it);
163+
* - a `formula`, virtual — computed on read, no column (`isVirtualSearchField`,
164+
* the spec's one statement of that set): the write path strips it;
165+
* - a stored field declaring an `expression`: the engine computes it from the
166+
* row the write stores, so a client-sent value never stands (the spec's
167+
* `expression` contract).
168+
*
169+
* ⛔ Not the caller's field edit permission: a field the caller may read but
170+
* not edit is served the schema's answer, and the write naming it is refused
171+
* at the field-level write gate. The served object carries the read projection
172+
* only, and the `describe_object` description says so.
173+
*
174+
* ⚠️ Asked of the object as the caller is SERVED it, the only object this
175+
* package's two readers hand over: the caller's mask deletes a readable
176+
* field's `expression` when it names a field the caller cannot read, so for
177+
* that caller the expression arm does not hold and the field is served
178+
* `readonly: false` while the engine still computes it. The HTTP twin asks
179+
* the declared field instead (the bridge holds the declaration it masks).
180+
*
181+
* The twin is `writeNeverSetsField` in `packages/runtime/src/domains/mcp.ts`.
182+
*/
183+
function writeNeverSetsField(f: ServedFieldDef | undefined): boolean {
184+
if (!f) return false;
185+
if (f.readonly === true) return true;
186+
if (typeof f.type === 'string' && RUNTIME_OWNED_FIELD_TYPES.has(f.type)) return true;
187+
if (isVirtualSearchField(f)) return true;
188+
// Truthy, the engine's own test for a stored expression it plans.
189+
return Boolean(f.expression);
190+
}
191+
152192
/** A field's options as value + label: the stored value a write sends, and what a person reads. */
153193
function describedOptions(options: unknown[]): Array<{ value: unknown; label: unknown }> {
154194
return options

‎packages/mcp/src/mcp-validate-expression.option-labels.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
* Each bridge answers `optionFieldsOf(name)` from the object `describeObject`
2020
* reads, through `@objectstack/formula`'s `declaresOptions`, and the tool
2121
* hands that list to the validator on the `formula` site, the one site the
22-
* door judges it on. `describe_object` serves what it served before.
22+
* door judges it on. The list is a member of its own, not a key on
23+
* `describe_object`'s answer.
2324
*
2425
* Which predicate: measured on real kernels (`ObjectKernel` + `MetadataPlugin`
2526
* + `ObjectQLPlugin`, with and without an `environmentId`), the protocol's

‎packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
import { createStdioDataBridge } from './stdio-data-bridge.js';
4747
import { registerObjectTools } from './mcp-http-tools.js';
4848
import { MCPServerPlugin } from './plugin.js';
49-
import type { MCPServerRuntime } from './mcp-server-runtime.js';
49+
import { buildObjectSchemaResource, type MCPServerRuntime } from './mcp-server-runtime.js';
5050

5151
const OBJECT = FLS_CONTRACT_OBJECT.name;
5252
const account = () => JSON.parse(JSON.stringify(FLS_CONTRACT_OBJECT));
@@ -142,7 +142,8 @@ const DECLARED_ANSWER = {
142142
system: false,
143143
options: [{ value: 'band_a', label: 'Band A' }, { value: 'band_b', label: 'Band B' }],
144144
},
145-
{ name: 'bonus_formula', type: 'formula', label: 'Bonus', required: false, readonly: false, system: false },
145+
// [#32530] A formula is computed on read: a write to it never stands.
146+
{ name: 'bonus_formula', type: 'formula', label: 'Bonus', required: false, readonly: true, system: false },
146147
],
147148
validations: [
148149
{ name: 'graded_account_needs_name', type: 'script', message: 'A graded account needs a name.', fields: [] },
@@ -541,3 +542,62 @@ describe('[#32435] stdio describe_object serves what a write needs, as the calle
541542
expect(text).toBe((await describeAs(undefined)).text);
542543
});
543544
});
545+
546+
describe('[#32530] stdio describe_object and the objects resource serve readonly where a write never stands', () => {
547+
const TICKET = {
548+
name: 'ticket',
549+
label: 'Ticket',
550+
fields: {
551+
// CONTROL: an ordinary field, writable.
552+
title: { type: 'text', label: 'Title' },
553+
// CONTROL: a declared `readonly` stays true.
554+
frozen_note: { type: 'text', label: 'Frozen note', readonly: true },
555+
// A hand-authored runtime-owned literal: no `readonly` flag.
556+
ticket_no: { type: 'autonumber', label: 'Ticket No' },
557+
// Computed on read, no column.
558+
total: { type: 'formula', label: 'Total', expression: 'record.qty * 2' },
559+
// The write path strips a formula by its TYPE, an expression or not.
560+
bare_formula: { type: 'formula', label: 'Bare formula' },
561+
// A stored field the engine computes on every write.
562+
doubled: { type: 'number', label: 'Doubled', expression: 'record.qty * 2' },
563+
},
564+
};
565+
const EXPECTED = { title: false, frozen_note: true, ticket_no: true, total: true, bare_formula: true, doubled: true };
566+
const readonlyOf = (described: any) => Object.fromEntries(described.fields.map((f: any) => [f.name, f.readonly]));
567+
const metadataService = () => {
568+
const object = () => JSON.parse(JSON.stringify(TICKET));
569+
return {
570+
listObjects: vi.fn(async () => [object()]),
571+
getObject: vi.fn(async (name: string) => (name === TICKET.name ? object() : undefined)),
572+
} as unknown as IMetadataService;
573+
};
574+
575+
it('describe_object over stdio', async () => {
576+
const bridge = createStdioDataBridge({
577+
engine: {} as unknown as IDataEngine,
578+
metadataService: metadataService(),
579+
resolvePrincipal: async () => ({ userId: 'u_member' }) as unknown as ExecutionContext,
580+
});
581+
const server = new McpServer({ name: 'pin', version: '0' });
582+
registerObjectTools(server, bridge);
583+
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
584+
await server.connect(serverSide);
585+
const client = new Client({ name: 'pin', version: '0' });
586+
await client.connect(clientSide);
587+
try {
588+
const res = (await client.callTool({ name: 'describe_object', arguments: { objectName: TICKET.name } })) as {
589+
isError?: boolean;
590+
content: Array<{ text: string }>;
591+
};
592+
expect(res.isError === true).toBe(false);
593+
expect(readonlyOf(JSON.parse(res.content[0]!.text))).toEqual(EXPECTED);
594+
} finally {
595+
await client.close();
596+
}
597+
});
598+
599+
it('the objectstack://objects/{name} resource', async () => {
600+
const result = await buildObjectSchemaResource(metadataService(), TICKET.name);
601+
expect(readonlyOf(JSON.parse(result.contents[0]!.text))).toEqual(EXPECTED);
602+
});
603+
});

0 commit comments

Comments
 (0)