Skip to content

Commit 4771d66

Browse files
feat(mcp): list_objects and describe_object return the authored object and field description (#34814)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_ repo:objectstack#3 · os-support-ai · session_01WGufzg1NmbJpZhtiWQkTir Fixes #34721 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:MCP 的 `list_objects` 与 `describe_object` 现在把作者写在对象和字段上的 `description` 一并返回(只在写了时出现),HTTP 与 stdio 两条通道同形。 - 为什么改:问数回退到对象工具时,客户端靠读工具返回来挑对象和字段;作者写的说明(如「金额,不含税」)原先拿不到,只能猜。维护者已定不加 synonyms,本卡即其替代。 - 风险与回滚:只增不减,未写说明的对象/字段输出逐字节不变;按调用者字段权限读取,读不到的字段连同其说明一起不出现。体积:app-crm 上 `describe_object` 每个对象约 +1.1 KB,其中约 1.0 KB 来自平台注入的 8 个系统列的说明。回滚即 revert 本 PR。 - 先看:`packages/runtime/src/domains/mcp.ts`(HTTP 通道的 `describeServedObject` 与 `listObjectSummaries`)、`packages/mcp/src/mcp-server-runtime.ts`(stdio 孪生与 `authoredDescription`)、`packages/mcp/src/mcp-http-tools.ts`(两条工具描述)。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run src/domains/mcp-object-descriptions-34721.test.ts`,预期 4 passed:可读字段带说明,被拒字段及其说明都不出现。 - 需要你做的:无,席位落地。 ## What changes - `describe_object` adds `description` to the object and to each field, and `list_objects` adds it to each object, when the definition as the caller is served it carries a non-blank string there. Otherwise the key is absent, so an object or field with no description is answered exactly as before. The key is the existing `description` of `ObjectSchema` and `FieldSchema`; no metadata key is added. - Both transports answer the same shape: the HTTP bridge (`packages/runtime/src/domains/mcp.ts`, `describeServedObject` and `listObjectSummaries`) and the stdio bridge (`packages/mcp/src/mcp-server-runtime.ts` `describeServedObject`, `packages/mcp/src/stdio-data-bridge.ts` `listObjects`). Each package carries one helper, `authoredDescription`, the two named as twins. - The two tool descriptions name the key. `McpObjectSummary` (exported) gains an optional `description` member. - Field-level security: the text is read off the object the caller is served (ADR-0106 D5), so a field the caller cannot read is removed whole, its description with it. The ADR-0106 projection keeps `description` as prose on the object and on readable fields (`packages/metadata-core/src/object-schema-fls-references.ts`, `description: keep`): the same authored text the `/meta` object door serves the same caller when the request names no locale. With a request locale `/meta` translates object and field labels and descriptions; the MCP object tools do not localize labels or descriptions, and this PR leaves that as it was. ## Tests - `packages/runtime/src/domains/mcp-object-descriptions-34721.test.ts` (HTTP bridge, real `SecurityPlugin` on a real `ObjectQL` over SQLite, bridge built by the real `/mcp` entry): a member denied one field is returned the object description and a readable field's description, and neither the denied field nor its description text; the unrestricted control is returned that field's description; a field with no description or a blank one, and an object with none, carry no `description` key; `list_objects` returns the object description and no key on an object without one. - `packages/mcp/src/stdio-data-bridge.object-descriptions-34721.test.ts` (stdio bridge behind the real tools over an in-memory MCP client, security from the shared ADR-0106 double): the same four cases. - Ablation, once per transport, after committing the fix (via `scripts/ablation-replace.mjs`, which proves the mutation landed and restores to the HEAD blob): deleting the field line `...authoredDescription(f),` turns 2 of 4 tests red on each transport (the readable-field and control cases); restore read back with `git diff HEAD` empty. Both suites import the source under test by relative path, so no build sits between the mutation and the run. ## Acceptance notes - Byte cost, measured on `examples/app-crm` (admin, HTTP MCP, tool text bytes, before on `f02f4f63`, after on this branch): `list_objects` 691 to 1193 (+502, all 7 objects carry a description). `describe_object`: `crm_account` 2738 to 3849, `crm_activity` 3791 to 4935, `crm_contact` 2455 to 3558, `crm_lead` 5351 to 6474, `crm_opportunity` 5310 to 6413, about +1.1 KB each. Of that, about 1.05 KB per object is the descriptions of the 8 platform-injected columns (`organization_id`, `created_at`, `created_by`, `updated_at`, `updated_by`, `owner_id`, `owning_business_unit_id`, `queue`), the same text on every object; for example `crm_account` would be 2803 without them. No hand-authored app-crm field carries a description today. Whether to serve descriptions on `system: true` fields is left to the seat; this PR follows the ruling (each field's existing description). - A readable field's or the object's description is free text the ADR-0106 projection does not scan for denied field names (it treats `description` as prose); the same fields' text is already served to the same caller by the `/meta` object door, so no new exposure. - The reading is on the card: comment 6945187409. ## Verification <details><summary>Live reading on app-crm, before and after</summary> Before (`f02f4f63`): `list_objects` objects keyed `name, label, fieldCount`; `describe_object crm_account` field keys `name, type, label, required, readonly, system`; zero `description` keys in either. The same caller's `GET /api/v1/meta/object/crm_account` serves the object description and descriptions on 9 fields. After (this branch, rebuilt): `list_objects` 7 of 7 objects with `description`; `describe_object crm_account` object description present, 8 of 12 fields with one, e.g. `{"name":"owner_id","type":"lookup","label":"Owner","description":"Record owner (auto-stamped to the creating user on insert; reassignable). Drives owner-scoped views, reports and notifications.","required":false,"readonly":false,"system":true}`. </details> <details><summary>Package tests and typecheck</summary> Run at `c204778e`. The final head `fbc4d13d` differs only by one module-top import in the new runtime test; at `fbc4d13d` that file and `pnpm --filter @objectstack/runtime typecheck` were rerun green. - `pnpm --filter @objectstack/mcp test`: Test Files 67 passed (67), Tests 1230 passed (1230). - `pnpm --filter @objectstack/runtime test`: Test Files 612 passed (612), Tests 11342 passed, 19 skipped (11361). - `pnpm --filter @objectstack/mcp typecheck`, `pnpm --filter @objectstack/runtime typecheck`: exit 0 (the lock's VERDICT command-exit 0). - New runtime test file rerun after the last commit: Tests 4 passed (4). </details> <details><summary>Derived gate families (dispatch-gates --commands)</summary> Full set run at `c204778e`; the reruns named below at the final head `fbc4d13d`. 69 derived, 68 exit 0, 1 NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs --self-test` exit 3, reason: shallow clone, its positive-control commit is unreachable here; CI runs it. `pnpm check:test-source-alias` first exited 1 on the new runtime test (the dispatcher reach loads `@objectstack/metadata` lazily); fixed with a module-top import as the sibling suite does, rerun exit 0. After that last commit, `check:cross-package-test-inputs`, `check:nul-bytes`, `check:undeclared-dep-imports`, `check:tier-file-adoption`, `check:issue-citations` rerun, exit 0. `dispatch-gates --ran`: 69 accounted, 68 run, 1 NOT-MEASURED (derived from the recorded exit 3). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzg1NmbJpZhtiWQkTir)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzg1NmbJpZhtiWQkTir --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d656d62 commit 4771d66

7 files changed

Lines changed: 423 additions & 3 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/mcp': patch
3+
'@objectstack/runtime': patch
4+
---
5+
6+
feat(mcp): `list_objects` and `describe_object` return the description an author wrote on an object and on its fields
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
An MCP client that picks an object and its fields by reading the object tools now reads the text the author wrote for them. `list_objects` adds `description` to each object, and `describe_object` adds it to the object and to each field. The key is present only where the definition carries a non-blank `description`, so an object or field without one is answered exactly as before. Both transports (HTTP and stdio) answer the same shape, and the two tool descriptions name the new key.
12+
13+
The text is the existing `description` key of the object and field schemas; no metadata key is added. It is read off the object as the caller is served it, so a field the caller cannot read is left out with its description, as it already was, and the caller is served the same authored text the `/meta` object door serves them when the request names no locale. With a request locale `/meta` translates object and field labels and descriptions; the MCP object tools do not localize labels or descriptions, and this change leaves that as it was.
14+
15+
`McpObjectSummary` gains an optional `description` member.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ import { actionConfirmationElicitorFor, type McpActionCallDoor } from './action-
130130
export interface McpObjectSummary {
131131
name: string;
132132
label?: string;
133+
/**
134+
* [#34721] The object's authored `description`, present only where one is
135+
* authored: what a client reads to pick the object for a question.
136+
*/
137+
description?: string;
133138
fieldCount?: number;
134139
}
135140

@@ -2564,7 +2569,8 @@ export function registerObjectTools(
25642569
note('list_objects'),
25652570
{
25662571
description:
2567-
'List the data objects (tables) available in this app. Returns each object\'s name, label and field count.',
2572+
'List the data objects (tables) available in this app. Returns each object\'s name, label, description '
2573+
+ '(where the author wrote one) and field count.',
25682574
inputSchema: strictToolInput({ surface: 'this list_objects call' }, {}),
25692575
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
25702576
},
@@ -2622,7 +2628,8 @@ export function registerObjectTools(
26222628
note('describe_object'),
26232629
{
26242630
description:
2625-
'Get the schema of a data object as you may read it, with what a write needs. Each field: name, type, label, '
2631+
'Get the schema of a data object as you may read it, with what a write needs: its name, label and description '
2632+
+ '(where the author wrote one). Each field: name, type, label, description (where written), '
26262633
+ 'required, readonly (a write never sets it: declared read-only, or a value the platform computes, such as a '
26272634
+ 'formula, an autonumber or a field with an expression; leave it out of a write), system (a platform-injected '
26282635
+ 'column), options (value + label; send the value) on a field that offers a fixed set, and defaultValue when '

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ interface ObjectDef {
9292
export interface ServedObjectDef {
9393
name: string;
9494
label?: string;
95+
description?: string;
9596
fields?: Record<string, ServedFieldDef>;
9697
validations?: unknown[];
9798
enable?: Record<string, unknown>;
@@ -101,6 +102,7 @@ export interface ServedObjectDef {
101102
interface ServedFieldDef {
102103
type?: string;
103104
label?: string;
105+
description?: string;
104106
required?: boolean;
105107
readonly?: boolean;
106108
system?: boolean;
@@ -120,7 +122,11 @@ interface ServedFieldDef {
120122
* where a write never sets the value, {@link writeNeverSetsField}), the allowed
121123
* `options` as value + label for a field that declares them (a picklist-bound
122124
* field carries its list's resolved options on the served object,
123-
* {@link declaresOptions}), and the `defaultValue` an INSERT applies. Per active validation rule: its name,
125+
* {@link declaresOptions}), and the `defaultValue` an INSERT applies.
126+
* [#34721] The object's and each field's authored `description`, where one is
127+
* authored ({@link authoredDescription}): the text a client reads to pick an
128+
* object and its fields, read off the same served object, so a field the
129+
* caller cannot read takes its description with it. Per active validation rule: its name,
124130
* kind, message, severity, the write events it runs on, and the fields it names
125131
* — ⛔ never its condition, pattern or transition table: the rule's message is
126132
* what a refused write answers with, and its expression is server policy.
@@ -148,10 +154,12 @@ export function describeServedObject(def: ServedObjectDef, declared: ServedObjec
148154
return {
149155
name: def.name,
150156
label: def.label ?? def.name,
157+
...authoredDescription(def),
151158
fields: Object.entries(def.fields ?? {}).filter(([key]) => key !== SEARCH_COMPANION_FIELD).map(([key, f]) => ({
152159
name: key,
153160
type: f?.type,
154161
label: f?.label ?? key,
162+
...authoredDescription(f),
155163
required: f?.required ?? false,
156164
// Judged on the DECLARED field, never the served one: the caller's mask
157165
// deletes a readable field's `expression` when it names a field they
@@ -168,6 +176,23 @@ export function describeServedObject(def: ServedObjectDef, declared: ServedObjec
168176
};
169177
}
170178

179+
/**
180+
* [#34721] An object's or a field's `description` as `list_objects` and
181+
* `describe_object` serve it: `{ description }` when the definition, as the
182+
* caller is served it, carries a non-blank string there, and nothing
183+
* otherwise, so an answer for a definition that authors none keeps the shape
184+
* it always had. The existing key only: the spec declares it on the object
185+
* and on the field (`ObjectSchema`, `FieldSchema`), and the ADR-0106
186+
* projection keeps it as prose on everything the caller may read, which is
187+
* what the `/meta` object door serves the same caller.
188+
*
189+
* The HTTP twin is `authoredDescription` in `packages/runtime/src/domains/mcp.ts`.
190+
*/
191+
export function authoredDescription(def: { description?: unknown } | undefined): { description?: string } {
192+
const text = def?.description;
193+
return typeof text === 'string' && text.trim() !== '' ? { description: text } : {};
194+
}
195+
171196
/**
172197
* [#32530] `readonly` as {@link describeServedObject} serves it: a caller's
173198
* write can never set this field's value. True for the declared flag, and for
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#34721] The stdio transport's `list_objects` and `describe_object` answer
5+
* the object's and each field's AUTHORED `description`, read off the object
6+
* as the principal is served it (ADR-0106 D5): a field the principal cannot
7+
* read is withheld with its description, and a definition that authors none
8+
* keeps the shape it always had (no `description` key). Driven through the
9+
* real tools (`registerObjectTools`) over the stdio bridge, with a security
10+
* service built by the shared ADR-0106 double (`securityDoubleFor`).
11+
*
12+
* The HTTP twin is `packages/runtime/src/domains/mcp-object-descriptions-34721.test.ts`.
13+
*/
14+
15+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
16+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
17+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
18+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
19+
import type { ExecutionContext } from '@objectstack/spec/kernel';
20+
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
21+
import { securityDoubleFor } from '@objectstack/metadata-core/testing';
22+
import { OBJECT_SCHEMA_MASK_DISABLE_ENV } from '@objectstack/metadata-core';
23+
import { createStdioDataBridge } from './stdio-data-bridge.js';
24+
import { registerObjectTools } from './mcp-http-tools.js';
25+
26+
const OBJ = 'deal';
27+
const PLAIN = 'plain';
28+
const DENIED = 'secret_margin';
29+
const OBJECT_TEXT = 'A sales deal, from first call to signed order.';
30+
const AMOUNT_TEXT = 'Amount, tax excluded.';
31+
const DENIED_TEXT = 'Internal margin after rebates.';
32+
33+
const deal = () => ({
34+
name: OBJ,
35+
label: 'Deal',
36+
description: OBJECT_TEXT,
37+
fields: {
38+
id: { name: 'id', type: 'text', label: 'ID' },
39+
subject: { name: 'subject', type: 'text', label: 'Subject' },
40+
amount: { name: 'amount', type: 'currency', label: 'Amount', description: AMOUNT_TEXT },
41+
blank_note: { name: 'blank_note', type: 'text', label: 'Note', description: ' ' },
42+
[DENIED]: { name: DENIED, type: 'currency', label: 'Margin', description: DENIED_TEXT },
43+
},
44+
});
45+
const plain = () => ({ name: PLAIN, label: 'Plain', fields: { id: { name: 'id', type: 'text' }, title: { name: 'title', type: 'text' } } });
46+
47+
/** The real tools over the stdio bridge, the principal reading `readable` (every field when omitted). */
48+
async function connect(readable?: readonly string[]) {
49+
const security = readable
50+
? securityDoubleFor({
51+
id: 'restricted-caller/34721',
52+
why: 'a principal denied one field',
53+
context: { userId: 'u_member', systemPermissions: [] },
54+
readable: [...readable],
55+
expect: { kind: 'unmasked' },
56+
} as never)
57+
: undefined;
58+
const defs = () => [deal(), plain()];
59+
const bridge = createStdioDataBridge({
60+
engine: {} as unknown as IDataEngine,
61+
metadataService: {
62+
listObjects: vi.fn(async () => defs()),
63+
getObject: vi.fn(async (name: string) => defs().find((d) => d.name === name)),
64+
} as unknown as IMetadataService,
65+
resolvePrincipal: async () => ({ userId: 'u_member', systemPermissions: [] }) as unknown as ExecutionContext,
66+
...(security ? { security: () => security } : {}),
67+
});
68+
const server = new McpServer({ name: 'pin', version: '0' });
69+
registerObjectTools(server, bridge);
70+
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
71+
await server.connect(serverSide);
72+
const client = new Client({ name: 'pin', version: '0' });
73+
await client.connect(clientSide);
74+
const call = async (name: string, args: Record<string, unknown>): Promise<{ text: string; json: any; isError: boolean }> => {
75+
const res = (await client.callTool({ name, arguments: args })) as { isError?: boolean; content: Array<{ text: string }> };
76+
const text = res.content[0]!.text;
77+
return { text, json: JSON.parse(text), isError: res.isError === true };
78+
};
79+
return { call, close: () => client.close() };
80+
}
81+
82+
const prevMask = process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV];
83+
beforeEach(() => { delete process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV]; });
84+
afterEach(() => {
85+
if (prevMask === undefined) delete process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV];
86+
else process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV] = prevMask;
87+
});
88+
89+
/** Every field but the denied one (the double answers one readable set for every object). */
90+
const MEMBER_READS = ['id', 'subject', 'amount', 'blank_note', 'title'] as const;
91+
92+
const field = (described: any, name: string) => described.fields.find((f: any) => f.name === name);
93+
94+
describe('[#34721] stdio list_objects and describe_object serve the authored descriptions, as the principal is served the object', () => {
95+
it('describe_object: a readable field\'s description is returned, a field the principal cannot read is withheld with its description', async () => {
96+
const session = await connect(MEMBER_READS);
97+
try {
98+
const described = await session.call('describe_object', { objectName: OBJ });
99+
expect(described.isError).toBe(false);
100+
expect(described.json.description).toBe(OBJECT_TEXT);
101+
expect(field(described.json, 'amount')).toMatchObject({ name: 'amount', label: 'Amount', description: AMOUNT_TEXT });
102+
expect(field(described.json, DENIED)).toBeUndefined();
103+
expect(described.text).not.toContain(DENIED_TEXT);
104+
} finally {
105+
await session.close();
106+
}
107+
});
108+
109+
it('CONTROL — a principal who may read every field is returned that field\'s description', async () => {
110+
const session = await connect();
111+
try {
112+
const described = await session.call('describe_object', { objectName: OBJ });
113+
expect(field(described.json, DENIED)).toMatchObject({ name: DENIED, description: DENIED_TEXT });
114+
} finally {
115+
await session.close();
116+
}
117+
});
118+
119+
it('describe_object: a field or object that authors no description (or a blank one) carries no description key', async () => {
120+
const session = await connect(MEMBER_READS);
121+
try {
122+
const described = (await session.call('describe_object', { objectName: OBJ })).json;
123+
expect('description' in field(described, 'subject')).toBe(false);
124+
expect('description' in field(described, 'blank_note')).toBe(false);
125+
expect('description' in (await session.call('describe_object', { objectName: PLAIN })).json).toBe(false);
126+
} finally {
127+
await session.close();
128+
}
129+
});
130+
131+
it('list_objects: each object\'s authored description, and no key on an object that authors none', async () => {
132+
const session = await connect(MEMBER_READS);
133+
try {
134+
const listed = (await session.call('list_objects', {})).json;
135+
const found = (name: string) => listed.objects.find((o: any) => o.name === name);
136+
expect(found(OBJ)).toEqual({ name: OBJ, label: 'Deal', description: OBJECT_TEXT, fieldCount: 4 });
137+
expect(found(PLAIN)).toEqual({ name: PLAIN, label: 'Plain', fieldCount: 2 });
138+
} finally {
139+
await session.close();
140+
}
141+
});
142+
});

‎packages/mcp/src/stdio-data-bridge.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ import { declaresOptions } from '@objectstack/formula';
149149
import type { McpDataBridge, McpObjectSummary } from './mcp-http-tools.js';
150150
import type { ListDatasetsOutput, QueryDatasetOutput } from '@objectstack/spec/ai';
151151
import {
152+
authoredDescription,
152153
describeServedObject,
153154
metaItemsArray,
154155
readObjectWithDeclaration,
@@ -285,6 +286,7 @@ export type StoredHashDigest = (plain: string) => Promise<string>;
285286
interface ObjectDef {
286287
name: string;
287288
label?: string;
289+
description?: string;
288290
fields?: Record<string, { type?: string; label?: string; required?: boolean }>;
289291
enable?: Record<string, unknown>;
290292
}
@@ -1164,9 +1166,11 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
11641166
// [#25138] The protocol's merged listing ({@link readMergedObjects}),
11651167
// [ADR-0106] as the principal is served it, so `fieldCount` counts the
11661168
// fields that exist for them ({@link callerObjectView}).
1169+
// [#34721] …and the object's authored `description`, as the HTTP twin serves it.
11671170
return ((await servedView.listObjects()) as ObjectDef[]).map((o) => ({
11681171
name: o.name,
11691172
label: o.label ?? o.name,
1173+
...authoredDescription(o),
11701174
fieldCount: o.fields ? Object.keys(o.fields).length : undefined,
11711175
}));
11721176
},

0 commit comments

Comments
 (0)