diff --git a/.changeset/34721-mcp-object-descriptions.md b/.changeset/34721-mcp-object-descriptions.md new file mode 100644 index 00000000000..609d44d738a --- /dev/null +++ b/.changeset/34721-mcp-object-descriptions.md @@ -0,0 +1,15 @@ +--- +'@objectstack/mcp': patch +'@objectstack/runtime': patch +--- + +feat(mcp): `list_objects` and `describe_object` return the description an author wrote on an object and on its fields + +Clause-②: yes (widening) +Metadata-protocol: none + +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. + +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. + +`McpObjectSummary` gains an optional `description` member. diff --git a/packages/mcp/src/mcp-http-tools.ts b/packages/mcp/src/mcp-http-tools.ts index 1cc59f6af81..c5a23cad18d 100644 --- a/packages/mcp/src/mcp-http-tools.ts +++ b/packages/mcp/src/mcp-http-tools.ts @@ -130,6 +130,11 @@ import { actionConfirmationElicitorFor, type McpActionCallDoor } from './action- export interface McpObjectSummary { name: string; label?: string; + /** + * [#34721] The object's authored `description`, present only where one is + * authored: what a client reads to pick the object for a question. + */ + description?: string; fieldCount?: number; } @@ -2524,7 +2529,8 @@ export function registerObjectTools( note('list_objects'), { description: - 'List the data objects (tables) available in this app. Returns each object\'s name, label and field count.', + 'List the data objects (tables) available in this app. Returns each object\'s name, label, description ' + + '(where the author wrote one) and field count.', inputSchema: strictToolInput({ surface: 'this list_objects call' }, {}), annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }, }, @@ -2582,7 +2588,8 @@ export function registerObjectTools( note('describe_object'), { description: - 'Get the schema of a data object as you may read it, with what a write needs. Each field: name, type, label, ' + 'Get the schema of a data object as you may read it, with what a write needs: its name, label and description ' + + '(where the author wrote one). Each field: name, type, label, description (where written), ' + '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 ' diff --git a/packages/mcp/src/mcp-server-runtime.ts b/packages/mcp/src/mcp-server-runtime.ts index 9dbcf68fc24..3d0363b8b6e 100644 --- a/packages/mcp/src/mcp-server-runtime.ts +++ b/packages/mcp/src/mcp-server-runtime.ts @@ -92,6 +92,7 @@ interface ObjectDef { export interface ServedObjectDef { name: string; label?: string; + description?: string; fields?: Record; validations?: unknown[]; enable?: Record; @@ -101,6 +102,7 @@ export interface ServedObjectDef { interface ServedFieldDef { type?: string; label?: string; + description?: string; required?: boolean; readonly?: boolean; system?: boolean; @@ -120,7 +122,11 @@ interface ServedFieldDef { * 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, + * {@link declaresOptions}), and the `defaultValue` an INSERT applies. + * [#34721] The object's and each field's authored `description`, where one is + * authored ({@link authoredDescription}): the text a client reads to pick an + * object and its fields, read off the same served object, so a field the + * caller cannot read takes its description with it. 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. @@ -148,10 +154,12 @@ export function describeServedObject(def: ServedObjectDef, declared: ServedObjec return { name: def.name, label: def.label ?? def.name, + ...authoredDescription(def), fields: Object.entries(def.fields ?? {}).filter(([key]) => key !== SEARCH_COMPANION_FIELD).map(([key, f]) => ({ name: key, type: f?.type, label: f?.label ?? key, + ...authoredDescription(f), required: f?.required ?? false, // 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 @@ -168,6 +176,23 @@ export function describeServedObject(def: ServedObjectDef, declared: ServedObjec }; } +/** + * [#34721] An object's or a field's `description` as `list_objects` and + * `describe_object` serve it: `{ description }` when the definition, as the + * caller is served it, carries a non-blank string there, and nothing + * otherwise, so an answer for a definition that authors none keeps the shape + * it always had. The existing key only: the spec declares it on the object + * and on the field (`ObjectSchema`, `FieldSchema`), and the ADR-0106 + * projection keeps it as prose on everything the caller may read, which is + * what the `/meta` object door serves the same caller. + * + * The HTTP twin is `authoredDescription` in `packages/runtime/src/domains/mcp.ts`. + */ +export function authoredDescription(def: { description?: unknown } | undefined): { description?: string } { + const text = def?.description; + return typeof text === 'string' && text.trim() !== '' ? { description: text } : {}; +} + /** * [#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 diff --git a/packages/mcp/src/stdio-data-bridge.object-descriptions-34721.test.ts b/packages/mcp/src/stdio-data-bridge.object-descriptions-34721.test.ts new file mode 100644 index 00000000000..81a5f5a1432 --- /dev/null +++ b/packages/mcp/src/stdio-data-bridge.object-descriptions-34721.test.ts @@ -0,0 +1,142 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#34721] The stdio transport's `list_objects` and `describe_object` answer + * the object's and each field's AUTHORED `description`, read off the object + * as the principal is served it (ADR-0106 D5): a field the principal cannot + * read is withheld with its description, and a definition that authors none + * keeps the shape it always had (no `description` key). Driven through the + * real tools (`registerObjectTools`) over the stdio bridge, with a security + * service built by the shared ADR-0106 double (`securityDoubleFor`). + * + * The HTTP twin is `packages/runtime/src/domains/mcp-object-descriptions-34721.test.ts`. + */ + +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; +import { Client } from '@modelcontextprotocol/sdk/client/index.js'; +import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js'; +import type { ExecutionContext } from '@objectstack/spec/kernel'; +import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts'; +import { securityDoubleFor } from '@objectstack/metadata-core/testing'; +import { OBJECT_SCHEMA_MASK_DISABLE_ENV } from '@objectstack/metadata-core'; +import { createStdioDataBridge } from './stdio-data-bridge.js'; +import { registerObjectTools } from './mcp-http-tools.js'; + +const OBJ = 'deal'; +const PLAIN = 'plain'; +const DENIED = 'secret_margin'; +const OBJECT_TEXT = 'A sales deal, from first call to signed order.'; +const AMOUNT_TEXT = 'Amount, tax excluded.'; +const DENIED_TEXT = 'Internal margin after rebates.'; + +const deal = () => ({ + name: OBJ, + label: 'Deal', + description: OBJECT_TEXT, + fields: { + id: { name: 'id', type: 'text', label: 'ID' }, + subject: { name: 'subject', type: 'text', label: 'Subject' }, + amount: { name: 'amount', type: 'currency', label: 'Amount', description: AMOUNT_TEXT }, + blank_note: { name: 'blank_note', type: 'text', label: 'Note', description: ' ' }, + [DENIED]: { name: DENIED, type: 'currency', label: 'Margin', description: DENIED_TEXT }, + }, +}); +const plain = () => ({ name: PLAIN, label: 'Plain', fields: { id: { name: 'id', type: 'text' }, title: { name: 'title', type: 'text' } } }); + +/** The real tools over the stdio bridge, the principal reading `readable` (every field when omitted). */ +async function connect(readable?: readonly string[]) { + const security = readable + ? securityDoubleFor({ + id: 'restricted-caller/34721', + why: 'a principal denied one field', + context: { userId: 'u_member', systemPermissions: [] }, + readable: [...readable], + expect: { kind: 'unmasked' }, + } as never) + : undefined; + const defs = () => [deal(), plain()]; + const bridge = createStdioDataBridge({ + engine: {} as unknown as IDataEngine, + metadataService: { + listObjects: vi.fn(async () => defs()), + getObject: vi.fn(async (name: string) => defs().find((d) => d.name === name)), + } as unknown as IMetadataService, + resolvePrincipal: async () => ({ userId: 'u_member', systemPermissions: [] }) as unknown as ExecutionContext, + ...(security ? { security: () => security } : {}), + }); + 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); + const call = async (name: string, args: Record): Promise<{ text: string; json: any; isError: boolean }> => { + const res = (await client.callTool({ name, arguments: args })) as { isError?: boolean; content: Array<{ text: string }> }; + const text = res.content[0]!.text; + return { text, json: JSON.parse(text), isError: res.isError === true }; + }; + return { call, close: () => client.close() }; +} + +const prevMask = process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV]; +beforeEach(() => { delete process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV]; }); +afterEach(() => { + if (prevMask === undefined) delete process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV]; + else process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV] = prevMask; +}); + +/** Every field but the denied one (the double answers one readable set for every object). */ +const MEMBER_READS = ['id', 'subject', 'amount', 'blank_note', 'title'] as const; + +const field = (described: any, name: string) => described.fields.find((f: any) => f.name === name); + +describe('[#34721] stdio list_objects and describe_object serve the authored descriptions, as the principal is served the object', () => { + it('describe_object: a readable field\'s description is returned, a field the principal cannot read is withheld with its description', async () => { + const session = await connect(MEMBER_READS); + try { + const described = await session.call('describe_object', { objectName: OBJ }); + expect(described.isError).toBe(false); + expect(described.json.description).toBe(OBJECT_TEXT); + expect(field(described.json, 'amount')).toMatchObject({ name: 'amount', label: 'Amount', description: AMOUNT_TEXT }); + expect(field(described.json, DENIED)).toBeUndefined(); + expect(described.text).not.toContain(DENIED_TEXT); + } finally { + await session.close(); + } + }); + + it('CONTROL — a principal who may read every field is returned that field\'s description', async () => { + const session = await connect(); + try { + const described = await session.call('describe_object', { objectName: OBJ }); + expect(field(described.json, DENIED)).toMatchObject({ name: DENIED, description: DENIED_TEXT }); + } finally { + await session.close(); + } + }); + + it('describe_object: a field or object that authors no description (or a blank one) carries no description key', async () => { + const session = await connect(MEMBER_READS); + try { + const described = (await session.call('describe_object', { objectName: OBJ })).json; + expect('description' in field(described, 'subject')).toBe(false); + expect('description' in field(described, 'blank_note')).toBe(false); + expect('description' in (await session.call('describe_object', { objectName: PLAIN })).json).toBe(false); + } finally { + await session.close(); + } + }); + + it('list_objects: each object\'s authored description, and no key on an object that authors none', async () => { + const session = await connect(MEMBER_READS); + try { + const listed = (await session.call('list_objects', {})).json; + const found = (name: string) => listed.objects.find((o: any) => o.name === name); + expect(found(OBJ)).toEqual({ name: OBJ, label: 'Deal', description: OBJECT_TEXT, fieldCount: 4 }); + expect(found(PLAIN)).toEqual({ name: PLAIN, label: 'Plain', fieldCount: 2 }); + } finally { + await session.close(); + } + }); +}); diff --git a/packages/mcp/src/stdio-data-bridge.ts b/packages/mcp/src/stdio-data-bridge.ts index 02d2b2a3bfd..2e2ad79208f 100644 --- a/packages/mcp/src/stdio-data-bridge.ts +++ b/packages/mcp/src/stdio-data-bridge.ts @@ -149,6 +149,7 @@ import { declaresOptions } from '@objectstack/formula'; import type { McpDataBridge, McpObjectSummary } from './mcp-http-tools.js'; import type { ListDatasetsOutput, QueryDatasetOutput } from '@objectstack/spec/ai'; import { + authoredDescription, describeServedObject, metaItemsArray, readObjectWithDeclaration, @@ -285,6 +286,7 @@ export type StoredHashDigest = (plain: string) => Promise; interface ObjectDef { name: string; label?: string; + description?: string; fields?: Record; enable?: Record; } @@ -1164,9 +1166,11 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge // [#25138] The protocol's merged listing ({@link readMergedObjects}), // [ADR-0106] as the principal is served it, so `fieldCount` counts the // fields that exist for them ({@link callerObjectView}). + // [#34721] …and the object's authored `description`, as the HTTP twin serves it. return ((await servedView.listObjects()) as ObjectDef[]).map((o) => ({ name: o.name, label: o.label ?? o.name, + ...authoredDescription(o), fieldCount: o.fields ? Object.keys(o.fields).length : undefined, })); }, diff --git a/packages/runtime/src/domains/mcp-object-descriptions-34721.test.ts b/packages/runtime/src/domains/mcp-object-descriptions-34721.test.ts new file mode 100644 index 00000000000..00957c88ab2 --- /dev/null +++ b/packages/runtime/src/domains/mcp-object-descriptions-34721.test.ts @@ -0,0 +1,205 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#34721] The HTTP MCP bridge's `list_objects` and `describe_object` answers + * carry the object's and each field's AUTHORED `description`, read off the + * object as the caller is served it (ADR-0106 D5) — so a field the caller + * cannot read takes its description with it, and a definition that authors + * none keeps the shape it always had (no `description` key). + * + * Driven over the real security layer (`SecurityPlugin` on a real `ObjectQL` + * over a real `SqlDriver`, the protocol over that engine), through the bridge + * the real `/mcp` entry builds for the caller. The stdio twin is + * `packages/mcp/src/stdio-data-bridge.object-descriptions-34721.test.ts`. + */ + +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; +import { + OBJECT_SCHEMA_MASK_DISABLE_ENV, + SysMetadataAuditObject, + SysMetadataHistoryObject, + SysMetadataObject, +} from '@objectstack/metadata-core'; +import { PermissionSetSchema } from '@objectstack/spec/security'; +import { ObjectQL } from '@objectstack/objectql'; +import { SqlDriver } from '@objectstack/driver-sql'; +import { SecurityPlugin } from '@objectstack/plugin-security'; +import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; +import { HttpDispatcher } from '../http-dispatcher.js'; +// Paid at collection, not inside a case's clock: the dispatcher's reach loads it lazily. +import '@objectstack/metadata'; + +/** A kernel over `services`, with an `mcp` service that hands back the bridge `handleMcp` built. */ +function kernelOver(services: Record) { + const mcp: any = { + lastOpts: undefined, + handleHttpRequest: async (_req: Request, o: any) => { + mcp.lastOpts = o; + return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } }); + }, + }; + const all: Record = { ...services, mcp }; + const get = (n: string) => all[n] ?? null; + return { getService: get, getServiceAsync: async (n: string) => get(n), context: { getService: get } } as any; +} + +/** Drive the real `/mcp` entry for `executionContext` and hand back the bridge it built. */ +async function bridgeFor(kernel: any, executionContext: Record) { + const dispatcher = new HttpDispatcher(kernel, undefined, { enforceProjectMembership: false }); + const res = await dispatcher.handleMcp({ jsonrpc: '2.0', id: 1, method: 'tools/list' }, { + request: new Request('http://localhost/api/v1/mcp', { + method: 'POST', + headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream' }, + body: '{}', + }), + response: {}, + environmentId: undefined, + executionContext: { ...executionContext }, + } as any); + expect(res.response?.status, 'precondition: the MCP route must have been served').toBe(200); + return kernel.getService('mcp').lastOpts.bridge; +} + +const OBJ = 'mcp_desc_deal'; +const PLAIN = 'mcp_desc_plain'; +const DENIED = 'secret_margin'; +const OBJECT_TEXT = 'A sales deal, from first call to signed order.'; +const AMOUNT_TEXT = 'Amount, tax excluded.'; +const DENIED_TEXT = 'Internal margin after rebates.'; + +const PERSONAS = { + /** Denied one field. */ + member: { userId: 'usr_member', positions: [] as string[], permissions: ['mcp_desc_member'], systemPermissions: [] as string[] }, + /** Denied nothing: the control. */ + staff: { userId: 'usr_staff', positions: [] as string[], permissions: ['mcp_desc_staff'], systemPermissions: [] as string[] }, +} as const; + +const prevMcp = process.env.OS_MCP_SERVER_ENABLED; +const prevMask = process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV]; +beforeEach(() => { + process.env.OS_MCP_SERVER_ENABLED = 'true'; + delete process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV]; +}); +afterEach(() => { + if (prevMcp === undefined) delete process.env.OS_MCP_SERVER_ENABLED; + else process.env.OS_MCP_SERVER_ENABLED = prevMcp; + if (prevMask === undefined) delete process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV]; + else process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV] = prevMask; +}); + +describe('[#34721] HTTP MCP list_objects and describe_object serve the authored descriptions, as the caller is served the object', () => { + let engine: ObjectQL; + let services: Record; + + 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-object-descriptions', + name: 'MCP object descriptions', + version: '1.0.0', + type: 'plugin', + scope: 'system', + objects: [ + { + name: OBJ, + label: 'Deal', + description: OBJECT_TEXT, + sharingModel: 'public_read_write', + fields: { + subject: { name: 'subject', type: 'text', label: 'Subject' }, + amount: { name: 'amount', type: 'currency', label: 'Amount', description: AMOUNT_TEXT }, + blank_note: { name: 'blank_note', type: 'text', label: 'Note', description: ' ' }, + [DENIED]: { name: DENIED, type: 'currency', label: 'Margin', description: DENIED_TEXT }, + }, + }, + { + name: PLAIN, + label: 'Plain', + sharingModel: 'public_read_write', + fields: { title: { name: 'title', type: 'text', label: 'Title' } }, + }, + ], + } as never); + await engine.syncSchemas(); + const all = { allowRead: true, allowCreate: true, allowEdit: true, allowDelete: true }; + const sets = [ + PermissionSetSchema.parse({ + name: 'mcp_desc_member', label: 'Member', objects: { '*': all }, + fields: { [`${OBJ}.${DENIED}`]: { readable: false, editable: false } }, + }), + PermissionSetSchema.parse({ name: 'mcp_desc_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_desc_staff' }); + await plugin.init(ctx as never); + await plugin.start(ctx as never); + 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 bridgeAs = (persona: Record) => bridgeFor(kernelOver(services), persona); + const field = (described: any, name: string) => described.fields.find((f: any) => f.name === name); + + it('describe_object: a readable field\'s description is returned, a field the member cannot read is withheld with its description', async () => { + const described = await (await bridgeAs(PERSONAS.member)).describeObject(OBJ); + expect(described.description).toBe(OBJECT_TEXT); + expect(field(described, 'amount')).toMatchObject({ name: 'amount', label: 'Amount', description: AMOUNT_TEXT }); + expect(field(described, DENIED)).toBeUndefined(); + expect(JSON.stringify(described)).not.toContain(DENIED_TEXT); + }); + + it('CONTROL — the unrestricted member is returned the same field\'s description', async () => { + const described = await (await bridgeAs(PERSONAS.staff)).describeObject(OBJ); + expect(field(described, DENIED)).toMatchObject({ name: DENIED, description: DENIED_TEXT }); + expect(field(described, 'amount')).toMatchObject({ description: AMOUNT_TEXT }); + }); + + it('describe_object: a field or object that authors no description (or a blank one) carries no description key', async () => { + const bridge = await bridgeAs(PERSONAS.member); + const described = await bridge.describeObject(OBJ); + expect('description' in field(described, 'subject')).toBe(false); + expect('description' in field(described, 'blank_note')).toBe(false); + expect('description' in (await bridge.describeObject(PLAIN))).toBe(false); + }); + + it('list_objects: each object\'s authored description, and no key on an object that authors none', async () => { + const listed: any[] = await (await bridgeAs(PERSONAS.member)).listObjects(); + const deal = listed.find((o) => o.name === OBJ); + const plain = listed.find((o) => o.name === PLAIN); + expect(deal).toMatchObject({ name: OBJ, label: 'Deal', description: OBJECT_TEXT }); + expect(plain).toBeDefined(); + expect('description' in plain).toBe(false); + }); +}); diff --git a/packages/runtime/src/domains/mcp.ts b/packages/runtime/src/domains/mcp.ts index 46c53e6a8eb..dc442f6d118 100644 --- a/packages/runtime/src/domains/mcp.ts +++ b/packages/runtime/src/domains/mcp.ts @@ -699,10 +699,13 @@ function describeServedObject(def: any, declared: any): Record return { name: def.name, label: def.label ?? def.name, + // [#34721] The authored descriptions, off the same served object. + ...authoredDescription(def), fields: Object.entries(def.fields ?? {}).filter(([k]) => k !== SEARCH_COMPANION_FIELD).map(([k, f]: [string, any]) => ({ name: k, type: f?.type, label: f?.label ?? k, + ...authoredDescription(f), required: f?.required ?? false, // [#32530] Judged on the DECLARED field, never the served one: the // caller's mask deletes a readable field's `expression` when it @@ -719,6 +722,23 @@ function describeServedObject(def: any, declared: any): Record }; } +/** + * [#34721] An object's or a field's `description` as `list_objects` and + * `describe_object` serve it: `{ description }` when the definition, as the + * caller is served it ({@link servedToCaller}), carries a non-blank string + * there, and nothing otherwise, so an answer for a definition that authors + * none keeps the shape it always had. The existing key only: the ADR-0106 + * projection removes an unreadable field whole, its description with it, and + * keeps the prose of everything the caller may read, as the `/meta` object + * door serves it. + * + * The twin is `authoredDescription` in `packages/mcp/src/mcp-server-runtime.ts`. + */ +function authoredDescription(def: any): { description?: string } { + const text = def?.description; + return typeof text === 'string' && text.trim() !== '' ? { description: text } : {}; +} + /** * [#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 @@ -1020,6 +1040,8 @@ export function buildMcpBridge( out.push({ name: o.name, label: o.label ?? o.name, + // [#34721] …and its authored description, as the stdio twin serves it. + ...authoredDescription(o), fieldCount: o.fields ? Object.keys(o.fields).length : undefined, }); }