Skip to content

Commit 59ae25a

Browse files
committed
fix(mcp): describe_object skips the hidden search companion on both transports
The registry serves an object with the hidden __search companion beside its display field where pinyin search is on. describe_object listed it, while no caller may read, write or name it. Both describeServedObject twins now skip SEARCH_COMPANION_FIELD (from @objectstack/spec/data), pinned on the stdio tool and resource and on the HTTP bridge over a real engine. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cw787kMeaX7oyz7DDC
1 parent 3c1cdfa commit 59ae25a

5 files changed

Lines changed: 174 additions & 4 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/mcp': patch
3+
'@objectstack/runtime': patch
4+
---
5+
6+
fix(mcp): `describe_object` no longer lists the hidden `__search` search companion, on either MCP transport
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Where pinyin search is on, the registry serves an object with the hidden `__search` companion column beside its display field. `describe_object` described every served field, so it offered an agent that column (as `readonly` and `system`), while no caller may read, write or name it: a record never echoes it, a `$searchFields` override naming it is refused, and `validate_expression` answers `unknown-field` for a read of it.
12+
13+
`describe_object` now leaves the companion out on both transports: the HTTP bridge in `@objectstack/runtime`, and the stdio bridge and the `objectstack://objects/{name}` resource in `@objectstack/mcp`. Both skip it by the protocol's one constant, `SEARCH_COMPANION_FIELD` from `@objectstack/spec/data`. Every other field is listed as before, the injected system columns such as `organization_id` and `created_at` included.

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

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

6464
/**
6565
* Configuration for the MCP Server Runtime.
@@ -124,6 +124,13 @@ interface ServedFieldDef {
124124
* — ⛔ never its condition, pattern or transition table: the rule's message is
125125
* what a refused write answers with, and its expression is server policy.
126126
*
127+
* ⛔ Never the hidden search companion (`SEARCH_COMPANION_FIELD`), which the
128+
* registry serves beside the display field where pinyin search is on: no
129+
* caller may read, write or name it (a record never echoes it, a
130+
* `$searchFields` override naming it is refused, `validate_expression`
131+
* answers `unknown-field`), so the door that offers an agent a field to use
132+
* does not list it. The HTTP twin skips it by the same constant.
133+
*
127134
* One projection for this package's two readers of it: the stdio bridge's
128135
* `describeObject` (`stdio-data-bridge.ts`) and the `objectstack://objects/{name}`
129136
* resource ({@link buildObjectSchemaResource}), each handing it the object as
@@ -140,7 +147,7 @@ export function describeServedObject(def: ServedObjectDef, declared: ServedObjec
140147
return {
141148
name: def.name,
142149
label: def.label ?? def.name,
143-
fields: Object.entries(def.fields ?? {}).map(([key, f]) => ({
150+
fields: Object.entries(def.fields ?? {}).filter(([key]) => key !== SEARCH_COMPANION_FIELD).map(([key, f]) => ({
144151
name: key,
145152
type: f?.type,
146153
label: f?.label ?? key,

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ import {
4040
} from '@objectstack/metadata-core/testing';
4141
import {
4242
OBJECT_SCHEMA_MASK_DISABLE_ENV,
43+
applyInjectedSystemColumns,
4344
assertEngineUpdateDispatch,
4445
type ObjectSchemaReadDelegateSource,
4546
} from '@objectstack/metadata-core';
47+
import { SEARCH_COMPANION_FIELD } from '@objectstack/spec/data';
48+
import { provisionSearchCompanion } from '@objectstack/objectql/core';
4649
import { callerObjectView, createStdioDataBridge, stdioObjectView } from './stdio-data-bridge.js';
4750
import { registerObjectTools } from './mcp-http-tools.js';
4851
import { MCPServerPlugin } from './plugin.js';
@@ -721,3 +724,67 @@ describe('stdio describe_object and the objects resource judge readonly on the D
721724
expect((await describeOverResource()).json.fields).toEqual((await describeOverStdio()).json.fields);
722725
});
723726
});
727+
728+
describe('stdio describe_object and the objects resource never list the hidden search companion', () => {
729+
// A field-scoped search object as the registry serves it with pinyin search
730+
// on: the injected system columns, and the companion the engine stamps
731+
// beside the display field (`provisionSearchCompanion`, the producer's own
732+
// function, not a transcription of its output). The companion is a column
733+
// no caller may read, write or name, so the door that offers an agent a
734+
// field to use does not list it. The HTTP twin is pinned on a real engine in
735+
// `packages/runtime/src/domains/mcp-object-schema-mask.test.ts`.
736+
const CONTACT = 'sc_contact';
737+
const served = () => provisionSearchCompanion(applyInjectedSystemColumns({
738+
name: CONTACT,
739+
label: 'Contact',
740+
fields: {
741+
name: { type: 'text', label: 'Name', required: true },
742+
email: { type: 'email', label: 'Email' },
743+
},
744+
}));
745+
const metadataService = () => ({
746+
listObjects: vi.fn(async () => [served()]),
747+
getObject: vi.fn(async (name: string) => (name === CONTACT ? served() : undefined)),
748+
}) as unknown as IMetadataService;
749+
const KEPT = ['name', 'email', 'created_at', 'updated_at', 'organization_id'];
750+
const namesOf = (described: any): string[] => described.fields.map((f: any) => f.name);
751+
752+
it('precondition: the served object carries the companion', () => {
753+
expect(Object.keys(served().fields)).toContain(SEARCH_COMPANION_FIELD);
754+
});
755+
756+
it('describe_object over stdio', async () => {
757+
const bridge = createStdioDataBridge({
758+
engine: {} as unknown as IDataEngine,
759+
metadataService: metadataService(),
760+
resolvePrincipal: async () => ({ userId: 'u_member' }) as unknown as ExecutionContext,
761+
});
762+
expect(Object.keys((await bridge.servedObjectDefinitionOf!(CONTACT))!.fields as object)).toContain(SEARCH_COMPANION_FIELD);
763+
const server = new McpServer({ name: 'pin', version: '0' });
764+
registerObjectTools(server, bridge);
765+
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
766+
await server.connect(serverSide);
767+
const client = new Client({ name: 'pin', version: '0' });
768+
await client.connect(clientSide);
769+
try {
770+
const res = (await client.callTool({ name: 'describe_object', arguments: { objectName: CONTACT } })) as {
771+
isError?: boolean;
772+
content: Array<{ text: string }>;
773+
};
774+
expect(res.isError === true).toBe(false);
775+
const names = namesOf(JSON.parse(res.content[0]!.text));
776+
expect(names).not.toContain(SEARCH_COMPANION_FIELD);
777+
expect(names).toEqual(expect.arrayContaining(KEPT));
778+
expect(res.content[0]!.text).not.toContain(SEARCH_COMPANION_FIELD);
779+
} finally {
780+
await client.close();
781+
}
782+
});
783+
784+
it('the objectstack://objects/{name} resource', async () => {
785+
const result = await buildObjectSchemaResource(metadataService(), CONTACT);
786+
const text = result.contents[0]!.text;
787+
expect(namesOf(JSON.parse(text))).toEqual(expect.arrayContaining(KEPT));
788+
expect(text).not.toContain(SEARCH_COMPANION_FIELD);
789+
});
790+
});

‎packages/runtime/src/domains/mcp-object-schema-mask.test.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
SysMetadataObject,
4343
} from '@objectstack/metadata-core';
4444
import { PermissionSetSchema } from '@objectstack/spec/security';
45+
import { SEARCH_COMPANION_FIELD } from '@objectstack/spec/data';
4546
import { ObjectQL } from '@objectstack/objectql';
4647
import { SqlDriver } from '@objectstack/driver-sql';
4748
import { SecurityPlugin } from '@objectstack/plugin-security';
@@ -1711,3 +1712,78 @@ describe('[#32530] describe_object serves readonly where a write never stands
17111712
expect((engine.getSchema(OBJ) as any).fields.marked_up.expression, 'the declaration still carries it').toBeDefined();
17121713
});
17131714
});
1715+
1716+
// The hidden search companion the registry provisions beside an object's
1717+
// display field (`provisionSearchCompanion`, `@objectstack/objectql`) is a
1718+
// column no caller may read, write or name: a record never echoes it, a
1719+
// `$searchFields` override naming it is refused, and `validate_expression`
1720+
// answers `unknown-field` for a read of it. `describe_object` is the door that
1721+
// offers an agent a field to use, so it does not list it either. The stdio
1722+
// twin is pinned in `packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts`.
1723+
describe('describe_object never lists the hidden search companion — the real engine', () => {
1724+
const OBJ = 'mcp_search_contact';
1725+
let engine: ObjectQL;
1726+
let services: Record<string, any>;
1727+
const CALLER = { userId: 'usr_search_member', positions: [] as string[], permissions: [] as string[], systemPermissions: [] as string[] };
1728+
const prevPinyin = process.env.OS_SEARCH_PINYIN_ENABLED;
1729+
1730+
beforeAll(async () => {
1731+
// The deployment switch the registry provisions the companion under,
1732+
// read once, when the registry is built.
1733+
process.env.OS_SEARCH_PINYIN_ENABLED = 'true';
1734+
engine = new ObjectQL();
1735+
const driver = new SqlDriver({ client: 'better-sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true } as any);
1736+
const storeObjects = [SysMetadataObject, SysMetadataHistoryObject, SysMetadataAuditObject] as any[];
1737+
await driver.initObjects(storeObjects);
1738+
engine.registerDriver(driver as any, true);
1739+
await engine.init();
1740+
for (const o of storeObjects) engine.registry.registerObject(o, '@objectstack/platform-objects');
1741+
engine.registerApp({
1742+
id: 'com.objectstack.qa.mcp-describe-search-companion',
1743+
name: 'MCP describe search companion',
1744+
version: '1.0.0',
1745+
type: 'plugin',
1746+
scope: 'system',
1747+
objects: [{
1748+
name: OBJ,
1749+
label: 'Contact',
1750+
sharingModel: 'public_read_write',
1751+
fields: {
1752+
// The display field: the companion's source.
1753+
name: { name: 'name', type: 'text', label: 'Name', required: true },
1754+
email: { name: 'email', type: 'email', label: 'Email' },
1755+
},
1756+
}],
1757+
} as never);
1758+
await engine.syncSchemas();
1759+
vi.spyOn((engine as unknown as { logger: { warn: () => void } }).logger, 'warn').mockImplementation(() => undefined);
1760+
services = { protocol: new ObjectStackProtocolImplementation(engine as any), objectql: engine };
1761+
vi.spyOn(console, 'warn').mockImplementation(() => undefined);
1762+
}, 60_000);
1763+
1764+
afterAll(async () => {
1765+
vi.restoreAllMocks();
1766+
if (prevPinyin === undefined) delete process.env.OS_SEARCH_PINYIN_ENABLED;
1767+
else process.env.OS_SEARCH_PINYIN_ENABLED = prevPinyin;
1768+
try { await engine?.destroy(); } catch { /* noop */ }
1769+
});
1770+
1771+
const describedNames = async (): Promise<string[]> => {
1772+
const { bridge } = await bridgeFor(kernelOver(services), CALLER);
1773+
return ((await bridge.describeObject(OBJ)) as any).fields.map((f: any) => f.name);
1774+
};
1775+
1776+
it('precondition: the registry serves the object WITH the companion', async () => {
1777+
expect(Object.keys((engine.getSchema(OBJ) as any).fields)).toContain(SEARCH_COMPANION_FIELD);
1778+
const { bridge } = await bridgeFor(kernelOver(services), CALLER);
1779+
expect(Object.keys((await bridge.servedObjectDefinitionOf(OBJ)).fields)).toContain(SEARCH_COMPANION_FIELD);
1780+
});
1781+
1782+
it('the answer has no companion, and keeps the declared fields and the platform\'s other system columns', async () => {
1783+
const names = await describedNames();
1784+
expect(names).not.toContain(SEARCH_COMPANION_FIELD);
1785+
expect(names).toEqual(expect.arrayContaining(['name', 'email', 'created_at', 'updated_at', 'organization_id']));
1786+
const { bridge } = await bridgeFor(kernelOver(services), CALLER);
1787+
expect(JSON.stringify(await bridge.describeObject(OBJ))).not.toContain(SEARCH_COMPANION_FIELD);
1788+
});
1789+
});

‎packages/runtime/src/domains/mcp.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { readDispatchedBody } from '../deferred-request-body.js';
4343
// [#28715] The engine's own reading of "this field declares options" (its
4444
// `label()` map is built from it), never a second spelling here.
4545
import { declaresOptions } from '@objectstack/formula';
46-
import { RUNTIME_OWNED_FIELD_TYPES, isVirtualSearchField } from '@objectstack/spec/data';
46+
import { RUNTIME_OWNED_FIELD_TYPES, SEARCH_COMPANION_FIELD, isVirtualSearchField } from '@objectstack/spec/data';
4747
// [#15705] The resume door's one refusal table, shared with
4848
// `POST /automation/:name/runs/:runId/resume` so the two doors answer one
4949
// engine result identically.
@@ -676,6 +676,13 @@ async function warnIfSkillListIncomplete(
676676
* ⛔ never its condition, pattern or transition table: the rule's message is
677677
* what a refused write answers with, and its expression is server policy.
678678
*
679+
* ⛔ Never the hidden search companion (`SEARCH_COMPANION_FIELD`), which the
680+
* registry serves beside the display field where pinyin search is on: no
681+
* caller may read, write or name it (a record never echoes it, a
682+
* `$searchFields` override naming it is refused, `validate_expression`
683+
* answers `unknown-field`), so the door that offers an agent a field to use
684+
* does not list it. The stdio twin skips it by the same constant.
685+
*
679686
* `declared` is the object `def` was projected from (the caller's mask
680687
* applied to it gives `def`): `readonly` is judged on it,
681688
* {@link writeNeverSetsField}. Nothing else is read from it.
@@ -690,7 +697,7 @@ function describeServedObject(def: any, declared: any): Record<string, unknown>
690697
return {
691698
name: def.name,
692699
label: def.label ?? def.name,
693-
fields: Object.entries(def.fields ?? {}).map(([k, f]: [string, any]) => ({
700+
fields: Object.entries(def.fields ?? {}).filter(([k]) => k !== SEARCH_COMPANION_FIELD).map(([k, f]: [string, any]) => ({
694701
name: k,
695702
type: f?.type,
696703
label: f?.label ?? k,

0 commit comments

Comments
 (0)