Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/34721-mcp-object-descriptions.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 9 additions & 2 deletions packages/mcp/src/mcp-http-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 },
},
Expand Down Expand Up @@ -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 '
Expand Down
27 changes: 26 additions & 1 deletion packages/mcp/src/mcp-server-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ interface ObjectDef {
export interface ServedObjectDef {
name: string;
label?: string;
description?: string;
fields?: Record<string, ServedFieldDef>;
validations?: unknown[];
enable?: Record<string, unknown>;
Expand All @@ -101,6 +102,7 @@ export interface ServedObjectDef {
interface ServedFieldDef {
type?: string;
label?: string;
description?: string;
required?: boolean;
readonly?: boolean;
system?: boolean;
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
142 changes: 142 additions & 0 deletions packages/mcp/src/stdio-data-bridge.object-descriptions-34721.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>): 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();
}
});
});
4 changes: 4 additions & 0 deletions packages/mcp/src/stdio-data-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -285,6 +286,7 @@ export type StoredHashDigest = (plain: string) => Promise<string>;
interface ObjectDef {
name: string;
label?: string;
description?: string;
fields?: Record<string, { type?: string; label?: string; required?: boolean }>;
enable?: Record<string, unknown>;
}
Expand Down Expand Up @@ -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,
}));
},
Expand Down
Loading
Loading