From 4fee53be07ab664e2f58598712a326852cc32446 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 19:27:37 +0000 Subject: [PATCH 1/6] test(mcp,runtime): pin describe_object readonly for fields a write never sets Claude-Session: https://claude.ai/code/session_01L9qibzwtSQM5u87bBFCujF Co-Authored-By: Claude --- ...dio-data-bridge.object-schema-mask.test.ts | 62 ++++++++- .../domains/mcp-object-schema-mask.test.ts | 130 ++++++++++++++++++ 2 files changed, 190 insertions(+), 2 deletions(-) diff --git a/packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts b/packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts index 94e11999eae..30b896c7092 100644 --- a/packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts +++ b/packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts @@ -46,7 +46,7 @@ import { import { createStdioDataBridge } from './stdio-data-bridge.js'; import { registerObjectTools } from './mcp-http-tools.js'; import { MCPServerPlugin } from './plugin.js'; -import type { MCPServerRuntime } from './mcp-server-runtime.js'; +import { buildObjectSchemaResource, type MCPServerRuntime } from './mcp-server-runtime.js'; const OBJECT = FLS_CONTRACT_OBJECT.name; const account = () => JSON.parse(JSON.stringify(FLS_CONTRACT_OBJECT)); @@ -142,7 +142,8 @@ const DECLARED_ANSWER = { system: false, options: [{ value: 'band_a', label: 'Band A' }, { value: 'band_b', label: 'Band B' }], }, - { name: 'bonus_formula', type: 'formula', label: 'Bonus', required: false, readonly: false, system: false }, + // [#32530] A formula is computed on read: a write to it never stands. + { name: 'bonus_formula', type: 'formula', label: 'Bonus', required: false, readonly: true, system: false }, ], validations: [ { name: 'graded_account_needs_name', type: 'script', message: 'A graded account needs a name.', fields: [] }, @@ -541,3 +542,60 @@ describe('[#32435] stdio describe_object serves what a write needs, as the calle expect(text).toBe((await describeAs(undefined)).text); }); }); + +describe('[#32530] stdio describe_object and the objects resource serve readonly where a write never stands', () => { + const TICKET = { + name: 'ticket', + label: 'Ticket', + fields: { + // CONTROL: an ordinary field, writable. + title: { type: 'text', label: 'Title' }, + // CONTROL: a declared `readonly` stays true. + frozen_note: { type: 'text', label: 'Frozen note', readonly: true }, + // A hand-authored runtime-owned literal: no `readonly` flag. + ticket_no: { type: 'autonumber', label: 'Ticket No' }, + // Computed on read, no column. + total: { type: 'formula', label: 'Total', expression: 'record.qty * 2' }, + // A stored field the engine computes on every write. + doubled: { type: 'number', label: 'Doubled', expression: 'record.qty * 2' }, + }, + }; + const EXPECTED = { title: false, frozen_note: true, ticket_no: true, total: true, doubled: true }; + const readonlyOf = (described: any) => Object.fromEntries(described.fields.map((f: any) => [f.name, f.readonly])); + const metadataService = () => { + const object = () => JSON.parse(JSON.stringify(TICKET)); + return { + listObjects: vi.fn(async () => [object()]), + getObject: vi.fn(async (name: string) => (name === TICKET.name ? object() : undefined)), + } as unknown as IMetadataService; + }; + + it('describe_object over stdio', async () => { + const bridge = createStdioDataBridge({ + engine: {} as unknown as IDataEngine, + metadataService: metadataService(), + resolvePrincipal: async () => ({ userId: 'u_member' }) as unknown as ExecutionContext, + }); + const server = new McpServer({ name: 'pin', version: '0' }); + registerObjectTools(server, bridge); + const [clientSide, serverSide] = InMemoryTransport.createLinkedPair(); + await server.connect(serverSide); + const client = new Client({ name: 'pin', version: '0' }); + await client.connect(clientSide); + try { + const res = (await client.callTool({ name: 'describe_object', arguments: { objectName: TICKET.name } })) as { + isError?: boolean; + content: Array<{ text: string }>; + }; + expect(res.isError === true).toBe(false); + expect(readonlyOf(JSON.parse(res.content[0]!.text))).toEqual(EXPECTED); + } finally { + await client.close(); + } + }); + + it('the objectstack://objects/{name} resource', async () => { + const result = await buildObjectSchemaResource(metadataService(), TICKET.name); + expect(readonlyOf(JSON.parse(result.contents[0]!.text))).toEqual(EXPECTED); + }); +}); diff --git a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts index 026d2c76300..e5b9423d2c9 100644 --- a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts +++ b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts @@ -1512,3 +1512,133 @@ describe('[#32435] describe_object serves what a write needs, as the caller is s expect(text).toBe(JSON.stringify(await unsecured.bridge.describeObject(OBJ))); }); }); + +describe('[#32530] describe_object serves readonly where a write never stands — the real engine and security layer', () => { + const OBJ = 'mcp_write_ticket'; + let engine: ObjectQL; + let services: Record; + + /** Denied the edit of `locked_note` (it may still read it); every other field is open. */ + const MEMBER = { userId: 'usr_ticket_member', positions: [] as string[], permissions: ['mcp_ticket_member'], systemPermissions: [] as string[] }; + + beforeAll(async () => { + engine = new ObjectQL(); + const driver = new SqlDriver({ client: 'better-sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true } as any); + const storeObjects = [SysMetadataObject, SysMetadataHistoryObject, SysMetadataAuditObject] as any[]; + await driver.initObjects(storeObjects); + engine.registerDriver(driver as any, true); + await engine.init(); + for (const o of storeObjects) engine.registry.registerObject(o, '@objectstack/platform-objects'); + engine.registerApp({ + id: 'com.objectstack.qa.mcp-describe-computed', + name: 'MCP describe computed fields', + version: '1.0.0', + type: 'plugin', + scope: 'system', + objects: [{ + name: OBJ, + label: 'Ticket', + sharingModel: 'public_read_write', + fields: { + // CONTROL: an ordinary field, writable. + title: { name: 'title', type: 'text', label: 'Title' }, + qty: { name: 'qty', type: 'number', label: 'Qty' }, + // CONTROL: a declared `readonly` stays true. + frozen_note: { name: 'frozen_note', type: 'text', label: 'Frozen note', readonly: true }, + // A hand-authored runtime-owned literal: no `readonly` flag (the builder injects one; a literal does not). + ticket_no: { name: 'ticket_no', type: 'autonumber', label: 'Ticket No', autonumberFormat: 'T-{0000}' }, + // Computed on read, no column. + total: { name: 'total', type: 'formula', label: 'Total', expression: 'record.qty * 2' }, + // A stored field the engine computes on every write. + doubled: { name: 'doubled', type: 'number', label: 'Doubled', expression: 'record.qty * 2' }, + // Readable, not editable, for the member: the schema says writable. + locked_note: { name: 'locked_note', type: 'text', label: 'Locked note' }, + }, + }], + } as never); + await engine.syncSchemas(); + const all = { allowRead: true, allowCreate: true, allowEdit: true, allowDelete: true }; + const sets = [ + PermissionSetSchema.parse({ + name: 'mcp_ticket_member', label: 'Member', objects: { '*': all }, + fields: { [`${OBJ}.locked_note`]: { readable: true, editable: false } }, + }), + PermissionSetSchema.parse({ name: 'mcp_ticket_staff', label: 'Staff', objects: { '*': all } }), + ]; + const pluginServices: Record = { + manifest: { register: vi.fn() }, + objectql: engine, + metadata: { + get: async (type: string, name: string) => + (type === 'permission' ? sets.find((s: any) => s?.name === name) : engine.getSchema(name)) ?? null, + list: async () => sets, + }, + }; + const ctx = { + logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }, + registerService: vi.fn((name: string, service: unknown) => { pluginServices[name] = service; }), + getService: (name: string) => { + if (!(name in pluginServices)) throw new Error(`service not registered: ${name}`); + return pluginServices[name]; + }, + }; + const plugin = new SecurityPlugin({ fallbackPermissionSet: 'mcp_ticket_staff' }); + await plugin.init(ctx as never); + await plugin.start(ctx as never); + expect(pluginServices.security, 'precondition: the security plugin registered its service').toBeDefined(); + vi.spyOn((engine as unknown as { logger: { warn: () => void } }).logger, 'warn').mockImplementation(() => undefined); + services = { + protocol: new ObjectStackProtocolImplementation(engine as any), + security: pluginServices.security, + objectql: engine, + }; + vi.spyOn(console, 'warn').mockImplementation(() => undefined); + }, 60_000); + + afterAll(async () => { + vi.restoreAllMocks(); + try { await engine?.destroy(); } catch { /* noop */ } + }); + + const readonlyOf = (described: any) => + Object.fromEntries(described.fields.map((f: any) => [f.name, f.readonly])); + const rowOf = async (id: string): Promise => engine.findOne(OBJ, { where: { id }, context: { isSystem: true } }); + + it('precondition: the autonumber literal reaches the served object WITHOUT a readonly flag', async () => { + expect((engine.getSchema(OBJ) as any).fields.ticket_no.readonly).not.toBe(true); + expect((engine.getSchema(OBJ) as any).fields.total.readonly).not.toBe(true); + }); + + it('autonumber, formula and a stored expression are served readonly: true; CONTROL a plain field stays false and a declared readonly stays true', async () => { + const { bridge } = await bridgeFor(kernelOver(services), MEMBER); + const served = readonlyOf(await bridge.describeObject(OBJ)); + expect(served).toMatchObject({ + title: false, + qty: false, + frozen_note: true, + ticket_no: true, + total: true, + doubled: true, + }); + }); + + it('…and the engine, through the same bridge, never stores what a caller sends to any of them', async () => { + const { bridge } = await bridgeFor(kernelOver(services), MEMBER); + const created: any = await bridge.create(OBJ, { title: 'Pump', qty: 3, ticket_no: 'FORGED-1', total: 999, doubled: 999 }); + const id = String(created?.id ?? created?.record?.id); + const row = await rowOf(id); + expect(row.title, 'CONTROL: the writable field is stored').toBe('Pump'); + expect(row.ticket_no).not.toBe('FORGED-1'); + expect(row.total).not.toBe(999); + expect(row.doubled).toBe(6); + }); + + it('a field the caller may read but not edit is served the SCHEMA\'s readonly (false), and the write naming it is refused', async () => { + const { bridge } = await bridgeFor(kernelOver(services), MEMBER); + const described: any = await bridge.describeObject(OBJ); + expect(readonlyOf(described).locked_note).toBe(false); + const refused = await rejectionOf(() => bridge.create(OBJ, { title: 'Valve', locked_note: 'x' })); + expect(refused, 'the field-level write gate refuses the field the member may not edit').toBeDefined(); + expect(typeof refused.code).toBe('string'); + }); +}); From 1ad809aac78f278ac28a61a56c088f4066d19781 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 19:33:54 +0000 Subject: [PATCH 2/6] fix(mcp,runtime): describe_object serves readonly where a write never sets the value A runtime-owned type, a formula and a stored field declaring an expression are served readonly: true, beside the declared flag. The describe_object description says readonly is the schema's, not the caller's edit permission, and that a defaultValue may be a token or an expression the server resolves. Claude-Session: https://claude.ai/code/session_01L9qibzwtSQM5u87bBFCujF Co-Authored-By: Claude --- packages/mcp/src/mcp-http-tools.ts | 13 ++++-- packages/mcp/src/mcp-server-runtime.ts | 43 ++++++++++++++++--- .../domains/mcp-object-schema-mask.test.ts | 2 +- packages/runtime/src/domains/mcp.ts | 42 +++++++++++++++--- 4 files changed, 85 insertions(+), 15 deletions(-) diff --git a/packages/mcp/src/mcp-http-tools.ts b/packages/mcp/src/mcp-http-tools.ts index 777a202873a..e627be1ad62 100644 --- a/packages/mcp/src/mcp-http-tools.ts +++ b/packages/mcp/src/mcp-http-tools.ts @@ -152,8 +152,9 @@ export interface McpDataBridge { * `validate_expression` hands it to the shared validator as * `ExprSchemaHint.optionFields`, so the tool refuses the `label()` call the * object save door refuses, in the same words. It is a member of its own, - * not a key on {@link describeObject}'s answer, so `describe_object` serves - * what it served before. + * not a key on {@link describeObject}'s answer: `describe_object` already + * serves each field's `options`, and this list names the fields that carry + * them without a second copy of the object. * * OPTIONAL, like {@link listObjectsDiagnosed}: a bridge that omits it gets * no `label()` target check, exactly as before (the validator's opt-in). @@ -2250,8 +2251,12 @@ export function registerObjectTools( { description: 'Get the schema of a data object as you may read it, with what a write needs. Each field: name, type, label, ' - + 'required, readonly (a write to it is dropped), system (a platform-injected column), options (value + label; ' - + 'send the value) on a field that offers a fixed set, and defaultValue when an insert applies one. ' + + 'required, readonly (a write never sets it: declared read-only, or a value the platform computes, such as a ' + + 'formula, an autonumber or a field with an expression; leave it out of a write), system (a platform-injected ' + + 'column), options (value + label; send the value) on a field that offers a fixed set, and defaultValue when ' + + 'an insert applies one. A defaultValue may be a token the server resolves (NOW(), current_user) or an ' + + 'expression object: to get it, omit the field, never copy the value. readonly is the schema\'s, not your ' + + 'edit permission: a field you may read but not edit shows readonly false, and a write naming it is refused. ' + 'validations: each active rule\'s name, type, message, severity, events and the fields it names (the ' + 'message is what a refused write answers). Also the enabled features.', inputSchema: strictToolInput( diff --git a/packages/mcp/src/mcp-server-runtime.ts b/packages/mcp/src/mcp-server-runtime.ts index b7289e18819..a04d5f003f1 100644 --- a/packages/mcp/src/mcp-server-runtime.ts +++ b/packages/mcp/src/mcp-server-runtime.ts @@ -59,6 +59,7 @@ import { z } from 'zod'; // [#28715] The engine's own reading of "this field declares options" (its // `label()` map is built from it), never a second spelling here. import { declaresOptions } from '@objectstack/formula'; +import { RUNTIME_OWNED_FIELD_TYPES, isVirtualSearchField } from '@objectstack/spec/data'; /** * Configuration for the MCP Server Runtime. @@ -104,6 +105,7 @@ interface ServedFieldDef { system?: boolean; options?: unknown[]; defaultValue?: unknown; + expression?: unknown; } /** @@ -113,10 +115,11 @@ interface ServedFieldDef { * that names a denied field anywhere, its message included) is not described. * * Per field: `required`, `readonly` and `system` (an auto-injected column such - * as `created_at` is `readonly` and `system`), the allowed `options` as value + - * label for a field that declares them (a picklist-bound field carries its - * list's resolved options on the served object, {@link declaresOptions}), and - * the `defaultValue` an INSERT applies. Per active validation rule: its name, + * as `created_at` is `readonly` and `system`; [#32530] `readonly` is also true + * where a write never sets the value, {@link writeNeverSetsField}), the allowed + * `options` as value + label for a field that declares them (a picklist-bound + * field carries its list's resolved options on the served object, + * {@link declaresOptions}), and the `defaultValue` an INSERT applies. Per active validation rule: its name, * kind, message, severity, the write events it runs on, and the fields it names * — ⛔ never its condition, pattern or transition table: the rule's message is * what a refused write answers with, and its expression is server policy. @@ -139,7 +142,7 @@ export function describeServedObject(def: ServedObjectDef): Record { return options diff --git a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts index e5b9423d2c9..16099b90b17 100644 --- a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts +++ b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts @@ -1519,7 +1519,7 @@ describe('[#32530] describe_object serves readonly where a write never stands let services: Record; /** Denied the edit of `locked_note` (it may still read it); every other field is open. */ - const MEMBER = { userId: 'usr_ticket_member', positions: [] as string[], permissions: ['mcp_ticket_member'], systemPermissions: [] as string[] }; + const MEMBER = { userId: 'usr_ticket_member', organizationId: 'org_ticket', tenantId: 'org_ticket', positions: [] as string[], permissions: ['mcp_ticket_member'], systemPermissions: [] as string[] }; beforeAll(async () => { engine = new ObjectQL(); diff --git a/packages/runtime/src/domains/mcp.ts b/packages/runtime/src/domains/mcp.ts index 0ab4d2977d6..4d923bbb1c4 100644 --- a/packages/runtime/src/domains/mcp.ts +++ b/packages/runtime/src/domains/mcp.ts @@ -34,6 +34,7 @@ import { readDispatchedBody } from '../deferred-request-body.js'; // [#28715] The engine's own reading of "this field declares options" (its // `label()` map is built from it), never a second spelling here. import { declaresOptions } from '@objectstack/formula'; +import { RUNTIME_OWNED_FIELD_TYPES, isVirtualSearchField } from '@objectstack/spec/data'; // [#15705] The resume door's one refusal table, shared with // `POST /automation/:name/runs/:runId/resume` so the two doors answer one // engine result identically. @@ -596,10 +597,11 @@ async function warnIfSkillListIncomplete( * that names a denied field anywhere, its message included) is not described. * * Per field: `required`, `readonly` and `system` (an auto-injected column such - * as `created_at` is `readonly` and `system`), the allowed `options` as value + - * label for a field that declares them (a picklist-bound field carries its - * list's resolved options on the served object, `declaresOptions`), and the - * `defaultValue` an INSERT applies. Per active validation rule: its name, kind, + * as `created_at` is `readonly` and `system`; [#32530] `readonly` is also true + * where a write never sets the value, {@link writeNeverSetsField}), the allowed + * `options` as value + label for a field that declares them (a picklist-bound + * field carries its list's resolved options on the served object, + * `declaresOptions`), and the `defaultValue` an INSERT applies. Per active validation rule: its name, kind, * message, severity, the write events it runs on, and the fields it names — * ⛔ never its condition, pattern or transition table: the rule's message is * what a refused write answers with, and its expression is server policy. @@ -619,7 +621,7 @@ function describeServedObject(def: any): Record { type: f?.type, label: f?.label ?? k, required: f?.required ?? false, - readonly: f?.readonly === true, + readonly: writeNeverSetsField(f), system: f?.system === true, ...(declaresOptions(f) ? { options: describedOptions(f.options) } : {}), ...(f?.defaultValue !== undefined ? { defaultValue: f.defaultValue } : {}), @@ -629,6 +631,36 @@ function describeServedObject(def: any): Record { }; } +/** + * [#32530] `readonly` as {@link describeServedObject} serves it: a caller's + * write can never set this field's value. True for the declared flag, and for + * a value the engine owns whatever the payload says: + * + * - a runtime-owned type (`RUNTIME_OWNED_FIELD_TYPES`, today `autonumber`): + * the write path strips a caller's value even with no `readonly` flag, and a + * hand-authored literal carries none (the field builder injects it); + * - a `formula`, virtual — computed on read, no column (`isVirtualSearchField`, + * the spec's one statement of that set): the write path strips it; + * - a stored field declaring an `expression`: the engine computes it from the + * row the write stores, so a client-sent value never stands (the spec's + * `expression` contract). + * + * ⛔ Not the caller's field edit permission: a field the caller may read but + * not edit is served the schema's answer, and the write naming it is refused + * at the field-level write gate. The served object carries the read projection + * only ({@link servedToCaller}), and the `describe_object` description says so. + * + * The twin is `writeNeverSetsField` in `packages/mcp/src/mcp-server-runtime.ts`. + */ +function writeNeverSetsField(f: any): boolean { + if (!f || typeof f !== 'object') return false; + if (f.readonly === true) return true; + if (typeof f.type === 'string' && RUNTIME_OWNED_FIELD_TYPES.has(f.type)) return true; + if (isVirtualSearchField(f)) return true; + // Truthy, the engine's own test for a stored expression it plans. + return Boolean(f.expression); +} + /** A field's options as value + label: the stored value a write sends, and what a person reads. */ function describedOptions(options: unknown[]): Array<{ value: unknown; label: unknown }> { return options From 8ff1e438378db261ba60743792752a27fc9106ee Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 19:35:19 +0000 Subject: [PATCH 3/6] test(runtime): assert the edit-denied write refusal envelope; add the changeset Claude-Session: https://claude.ai/code/session_01L9qibzwtSQM5u87bBFCujF Co-Authored-By: Claude --- .../32530-describe-object-readonly-computed.md | 13 +++++++++++++ .../src/domains/mcp-object-schema-mask.test.ts | 11 +++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 .changeset/32530-describe-object-readonly-computed.md diff --git a/.changeset/32530-describe-object-readonly-computed.md b/.changeset/32530-describe-object-readonly-computed.md new file mode 100644 index 00000000000..337389f60c4 --- /dev/null +++ b/.changeset/32530-describe-object-readonly-computed.md @@ -0,0 +1,13 @@ +--- +'@objectstack/mcp': patch +'@objectstack/runtime': patch +--- + +fix(mcp,runtime): `describe_object` serves `readonly: true` where a write never sets the value + +Clause-②: yes (widening) +Metadata-protocol: none + +`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`. An ordinary field still answers `readonly: false`, and a declared `readonly` still answers `true`. + +`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. diff --git a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts index 16099b90b17..5afe0feb581 100644 --- a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts +++ b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts @@ -1628,17 +1628,20 @@ describe('[#32530] describe_object serves readonly where a write never stands const id = String(created?.id ?? created?.record?.id); const row = await rowOf(id); expect(row.title, 'CONTROL: the writable field is stored').toBe('Pump'); - expect(row.ticket_no).not.toBe('FORGED-1'); - expect(row.total).not.toBe(999); + expect(row.ticket_no, 'the engine issues the number').toMatch(/^T-\d{4}$/); + expect(row.total, 'computed on read').toBe(6); expect(row.doubled).toBe(6); }); + // Item 2 is answered by the description, not by `readonly`: the served object + // carries the caller's READ projection only, so an edit verdict would be a new + // security read on every describe (see `writeNeverSetsField`). it('a field the caller may read but not edit is served the SCHEMA\'s readonly (false), and the write naming it is refused', async () => { const { bridge } = await bridgeFor(kernelOver(services), MEMBER); const described: any = await bridge.describeObject(OBJ); expect(readonlyOf(described).locked_note).toBe(false); const refused = await rejectionOf(() => bridge.create(OBJ, { title: 'Valve', locked_note: 'x' })); - expect(refused, 'the field-level write gate refuses the field the member may not edit').toBeDefined(); - expect(typeof refused.code).toBe('string'); + // The field-level write gate refuses the field the member may not edit. + expect({ code: refused?.code, status: refused?.status }).toEqual({ code: 'PERMISSION_DENIED', status: 403 }); }); }); From ab0fe87fe7a859e2e1cf81edb8df78c41a3257ef Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 19:36:32 +0000 Subject: [PATCH 4/6] test(mcp,runtime): pin the formula arm by type alone Claude-Session: https://claude.ai/code/session_01L9qibzwtSQM5u87bBFCujF Co-Authored-By: Claude --- packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts | 4 +++- packages/runtime/src/domains/mcp-object-schema-mask.test.ts | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts b/packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts index 30b896c7092..b6c00889952 100644 --- a/packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts +++ b/packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts @@ -556,11 +556,13 @@ describe('[#32530] stdio describe_object and the objects resource serve readonly ticket_no: { type: 'autonumber', label: 'Ticket No' }, // Computed on read, no column. total: { type: 'formula', label: 'Total', expression: 'record.qty * 2' }, + // The write path strips a formula by its TYPE, an expression or not. + bare_formula: { type: 'formula', label: 'Bare formula' }, // A stored field the engine computes on every write. doubled: { type: 'number', label: 'Doubled', expression: 'record.qty * 2' }, }, }; - const EXPECTED = { title: false, frozen_note: true, ticket_no: true, total: true, doubled: true }; + const EXPECTED = { title: false, frozen_note: true, ticket_no: true, total: true, bare_formula: true, doubled: true }; const readonlyOf = (described: any) => Object.fromEntries(described.fields.map((f: any) => [f.name, f.readonly])); const metadataService = () => { const object = () => JSON.parse(JSON.stringify(TICKET)); diff --git a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts index 5afe0feb581..8ba010d8fa9 100644 --- a/packages/runtime/src/domains/mcp-object-schema-mask.test.ts +++ b/packages/runtime/src/domains/mcp-object-schema-mask.test.ts @@ -1549,6 +1549,8 @@ describe('[#32530] describe_object serves readonly where a write never stands ticket_no: { name: 'ticket_no', type: 'autonumber', label: 'Ticket No', autonumberFormat: 'T-{0000}' }, // Computed on read, no column. total: { name: 'total', type: 'formula', label: 'Total', expression: 'record.qty * 2' }, + // The write path strips a formula by its TYPE, an expression or not. + bare_formula: { name: 'bare_formula', type: 'formula', label: 'Bare formula' }, // A stored field the engine computes on every write. doubled: { name: 'doubled', type: 'number', label: 'Doubled', expression: 'record.qty * 2' }, // Readable, not editable, for the member: the schema says writable. @@ -1618,6 +1620,7 @@ describe('[#32530] describe_object serves readonly where a write never stands frozen_note: true, ticket_no: true, total: true, + bare_formula: true, doubled: true, }); }); From 56546bd55bce3ce6d69c7bfe0b05a55385935056 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 20:33:01 +0000 Subject: [PATCH 5/6] fix(runtime): judge describe_object readonly on the declared field, not the masked one The caller's field mask deletes a readable field's expression when it names a field the caller cannot read; the engine still computes that field. The HTTP bridge now reads only the boolean from the declaration it masks and keeps serving the masked definition. Claude-Session: https://claude.ai/code/session_01L9qibzwtSQM5u87bBFCujF Co-Authored-By: Claude --- packages/mcp/src/mcp-server-runtime.ts | 7 +++++ ...-validate-expression.option-labels.test.ts | 3 +- .../domains/mcp-object-schema-mask.test.ts | 31 +++++++++++++++++-- packages/runtime/src/domains/mcp.ts | 28 ++++++++++++++--- 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/packages/mcp/src/mcp-server-runtime.ts b/packages/mcp/src/mcp-server-runtime.ts index a04d5f003f1..23c79165575 100644 --- a/packages/mcp/src/mcp-server-runtime.ts +++ b/packages/mcp/src/mcp-server-runtime.ts @@ -171,6 +171,13 @@ export function describeServedObject(def: ServedObjectDef): Record; - /** Denied the edit of `locked_note` (it may still read it); every other field is open. */ + /** Denied the edit of `locked_note` (it may still read it) and any access to `hidden_cost`; every other field is open. */ const MEMBER = { userId: 'usr_ticket_member', organizationId: 'org_ticket', tenantId: 'org_ticket', positions: [] as string[], permissions: ['mcp_ticket_member'], systemPermissions: [] as string[] }; beforeAll(async () => { @@ -1555,6 +1555,10 @@ describe('[#32530] describe_object serves readonly where a write never stands doubled: { name: 'doubled', type: 'number', label: 'Doubled', expression: 'record.qty * 2' }, // Readable, not editable, for the member: the schema says writable. locked_note: { name: 'locked_note', type: 'text', label: 'Locked note' }, + // Not readable for the member, and a stored expression over it: the + // member's mask deletes `marked_up.expression`, the engine still computes it. + hidden_cost: { name: 'hidden_cost', type: 'number', label: 'Hidden cost' }, + marked_up: { name: 'marked_up', type: 'number', label: 'Marked up', expression: 'record.hidden_cost * 2' }, }, }], } as never); @@ -1563,7 +1567,10 @@ describe('[#32530] describe_object serves readonly where a write never stands const sets = [ PermissionSetSchema.parse({ name: 'mcp_ticket_member', label: 'Member', objects: { '*': all }, - fields: { [`${OBJ}.locked_note`]: { readable: true, editable: false } }, + fields: { + [`${OBJ}.locked_note`]: { readable: true, editable: false }, + [`${OBJ}.hidden_cost`]: { readable: false, editable: false }, + }, }), PermissionSetSchema.parse({ name: 'mcp_ticket_staff', label: 'Staff', objects: { '*': all } }), ]; @@ -1647,4 +1654,24 @@ describe('[#32530] describe_object serves readonly where a write never stands // The field-level write gate refuses the field the member may not edit. expect({ code: refused?.code, status: refused?.status }).toEqual({ code: 'PERMISSION_DENIED', status: 403 }); }); + + it('a stored expression over a field the caller cannot read is still served readonly: true, and neither the expression nor that field is served', async () => { + const { bridge } = await bridgeFor(kernelOver(services), MEMBER); + const described: any = await bridge.describeObject(OBJ); + expect(readonlyOf(described).marked_up).toBe(true); + const text = JSON.stringify(described); + expect(described.fields.map((f: any) => f.name)).not.toContain('hidden_cost'); + expect(text).not.toContain('hidden_cost'); + expect(text).not.toContain('record.'); + // Precondition: the member's served object is the masked one: the + // expression the declaration carries is not in it. + const { dispatcher } = await bridgeFor(kernelOver(services), MEMBER); + const meta = await dispatcher.handleMetadata(`/object/${OBJ}`, { + request: {}, environmentId: undefined, executionContext: { ...MEMBER }, + } as any, 'GET'); + const servedField = meta.response?.body?.data?.item?.fields?.marked_up ?? meta.response?.body?.data?.fields?.marked_up; + expect(servedField, 'precondition: the member is served the field').toBeDefined(); + expect(servedField.expression, 'precondition: the mask deleted the expression').toBeUndefined(); + expect((engine.getSchema(OBJ) as any).fields.marked_up.expression, 'the declaration still carries it').toBeDefined(); + }); }); diff --git a/packages/runtime/src/domains/mcp.ts b/packages/runtime/src/domains/mcp.ts index 4d923bbb1c4..d05eae15b9e 100644 --- a/packages/runtime/src/domains/mcp.ts +++ b/packages/runtime/src/domains/mcp.ts @@ -606,13 +606,17 @@ async function warnIfSkillListIncomplete( * ⛔ never its condition, pattern or transition table: the rule's message is * what a refused write answers with, and its expression is server policy. * + * `declared` is the object `def` was projected from (the caller's mask + * applied to it gives `def`): `readonly` is judged on it, + * {@link writeNeverSetsField}. Nothing else is read from it. + * * The twin is `describeServedObject` in `packages/mcp/src/mcp-server-runtime.ts`, * which the stdio bridge and the `objectstack://objects/{name}` resource serve * (this package does not depend on `@objectstack/mcp`): the transports answer * one shape, and the `describe_object` description (`mcp-http-tools.ts`) * states it. */ -function describeServedObject(def: any): Record { +function describeServedObject(def: any, declared: any): Record { return { name: def.name, label: def.label ?? def.name, @@ -621,7 +625,12 @@ function describeServedObject(def: any): Record { type: f?.type, label: f?.label ?? k, required: f?.required ?? false, - readonly: writeNeverSetsField(f), + // [#32530] Judged on the DECLARED field, never the served one: the + // caller's mask deletes a readable field's `expression` when it + // names a field they cannot read, and the engine still computes the + // field. Only the boolean is read there; the served definition, + // without that expression, is what the answer is built from. + readonly: writeNeverSetsField(declared?.fields?.[k]), system: f?.system === true, ...(declaresOptions(f) ? { options: describedOptions(f.options) } : {}), ...(f?.defaultValue !== undefined ? { defaultValue: f.defaultValue } : {}), @@ -650,7 +659,13 @@ function describeServedObject(def: any): Record { * at the field-level write gate. The served object carries the read projection * only ({@link servedToCaller}), and the `describe_object` description says so. * - * The twin is `writeNeverSetsField` in `packages/mcp/src/mcp-server-runtime.ts`. + * Asked of the DECLARED field ({@link describeServedObject}'s `declared`), + * because the caller's mask deletes an `expression` that names a field the + * caller cannot read, while the engine still computes the column from it. + * + * The twin is `writeNeverSetsField` in `packages/mcp/src/mcp-server-runtime.ts`, + * which has only the masked object to ask: there the expression arm holds where + * the caller is served the expression. */ function writeNeverSetsField(f: any): boolean { if (!f || typeof f !== 'object') return false; @@ -962,10 +977,13 @@ export function buildMcpBridge( // object among them) is "not found" here too. // [ADR-0106 D1/D5] …as this caller is served it ({@link readObjectForCaller}). describeObject: async (name: string) => { - const def: any = await readObjectForCaller(name); + // {@link readObjectForCaller}'s two steps, kept apart so the + // declaration it masks is in hand ([#32530] `readonly`). + const declared: any = await readServedObject(name); + const def: any = declared ? await servedToCaller(declared) : declared; if (!def) return null; // [#32435] …each field and rule carrying what a write needs. - return describeServedObject(def); + return describeServedObject(def, declared); }, // [#28715] The fields `validate_expression` judges a `label()` call // against, from the object `describeObject` reads: the served object, From 48fff48ae38e95d40225e091d3c21c08e6634162 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 20:34:02 +0000 Subject: [PATCH 6/6] docs(changeset): say where the stored-expression readonly arm holds on each transport Claude-Session: https://claude.ai/code/session_01L9qibzwtSQM5u87bBFCujF Co-Authored-By: Claude --- .changeset/32530-describe-object-readonly-computed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/32530-describe-object-readonly-computed.md b/.changeset/32530-describe-object-readonly-computed.md index 337389f60c4..406ac2c3161 100644 --- a/.changeset/32530-describe-object-readonly-computed.md +++ b/.changeset/32530-describe-object-readonly-computed.md @@ -8,6 +8,6 @@ fix(mcp,runtime): `describe_object` serves `readonly: true` where a write never Clause-②: yes (widening) Metadata-protocol: none -`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`. An ordinary field still answers `readonly: false`, and a declared `readonly` still answers `true`. +`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`. `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.