Skip to content

Commit 46991d0

Browse files
feat(mcp): list_objects and describe_object serve labels and descriptions in the caller's locale (#34922)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBQ3DFv6XZAspQRYGQoEWhr8)_ Fixes #34872 Clause-②: no Metadata-protocol: none repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH ## 维护者速读 - **改了什么**:MCP 的 `list_objects` 和 `describe_object` 现在按调用者的语言返回对象标签、对象描述、字段标签、字段描述和选项标签。HTTP 读请求的 `Accept-Language`,stdio 用 i18n 服务的默认语言。两者调用的都是 REST `/meta` 对象接口用的同一个翻译函数(`translateMetaList`),没有另写一套翻译。 - **为什么改**:中文用户在问数时,如果没有指标能回答,会转去用对象工具,看到的却是英文标签和英文描述。REST 接口对同样的文本已经做了翻译。 - **风险与回滚**:先按字段权限掩码,再翻译,所以被屏蔽的字段和它的译文都不会回来。字段名和选项值不变,输出结构不变。还有一处行为变化:HTTP 请求不带 `Accept-Language` 时,现在会取 i18n 默认语言(en)包里的值,和 REST 一致(app-crm 的 `amount` 因此显示为 "Deal Value")。回滚就是撤销这两个源文件的改动。 - **先看**:① `packages/runtime/src/domains/mcp.ts` 里的 `inCallerLocale`,以及它在 `listObjectSummaries` / `describeObject` 的两处调用(风险点:翻译必须作用在 `servedToCaller` 返回的对象上);② `packages/mcp/src/stdio-data-bridge.ts` 里的 `inServedLocale`,以及 `describeObject`;③ 两个 `*-34872.test.ts` 测试里关于字段掩码的用例。 - **两分钟验证**:`pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/mcp-object-locale-34872.test.ts`,预期 `Tests 5 passed (5)`。 - **需要你做的**:无,席位落地。 ## What changes - **HTTP door** (`packages/runtime/src/domains/mcp.ts`): new `inCallerLocale` translates the objects as the caller is served them (`servedToCaller`, the ADR-0106 mask) with `translateMetaList`, the routine `GET /meta/object` and the dataset tools already run. The locale is this request's, read by `metaRequestLocale` (`Accept-Language`, then `?locale=`, then the i18n default). `list_objects` translates the whole page in one call. `describe_object` translates the one served object, then projects it with `describeServedObject`. `declared` is still read only for the `readonly` verdict. A new module helper, `metaTranslationSources`, holds the i18n, protocol and locale reading. `loadDatasets` now calls it too, so the dataset tools and the object tools answer one caller in one locale. The dataset behaviour is byte-for-byte the same. - **stdio door** (`packages/mcp/src/stdio-data-bridge.ts`): new `inServedLocale` does the same over `callerObjectView`. The locale is the i18n service's default, the reading the stdio `list_datasets` already uses: the transport carries no request. `defaultLocaleSources` is shared with `loadDatasets`. - What gets translated is what the translator translates on the served object: object `label` and `description`, field `label`, field `description` from the bundle's `help` key, option labels (field-level, then the bound picklist's), and validation messages. Names, option values and the answer's shape are unchanged. Clause-② stays no. - The two new test files are named for this card. A patch changeset covers `@objectstack/runtime` and `@objectstack/mcp`. ## Tests <details><summary>New pins: HTTP 5/5, stdio 5/5, plus the sibling #34721 and dataset-locale suites</summary> - `packages/runtime/src/domains/mcp-object-locale-34872.test.ts`: real `SecurityPlugin` on a real `ObjectQL` over `SqlDriver`, through the real `/mcp` entry, with an i18n double carrying a zh-CN bundle. Cases: zh-CN translates the label, description and option label, and names stay; `list_objects` under zh-CN; a masked field stays absent and its zh-CN label and help text never appear, and the member's `fieldCount` is the staff count minus 1; no header (default `en`, no entry) serves the authored text; `fr-FR`, or no i18n service, serves the authored text. - `packages/mcp/src/stdio-data-bridge.object-locale-34872.test.ts`: the real tools (`registerObjectTools`) over the stdio bridge with `securityDoubleFor`. The same five cases at the default locale, including an i18n resolver that throws. - Run at 5334bf9: `mcp` 3 files / 13 tests passed (34872, 34721 and dataset-locale); `runtime` 2 files / 9 tests passed (34872 and 34721). - Whole packages at 2ba60e9: `pnpm --filter @objectstack/mcp test` gave `Test Files 70 passed (70)`, `Tests 1246 passed (1246)`. `pnpm --filter @objectstack/runtime test` gave `Test Files 615 passed (615)`, `Tests 11415 passed | 23 skipped (11438)`. Both lock verdicts were `command-exit 0`. - `pnpm --filter @objectstack/mcp --filter @objectstack/runtime typecheck`: exit 0, including `check:test-typecheck`. </details> <details><summary>Ablation: four legs, each red, each restored to the HEAD blob</summary> The subjects are imported by relative path from `src`, so no `dist` was involved. Each mutation went through `scripts/ablation-replace.mjs`: the anchor went from 1 hit to 0, and the blob was restored equal to HEAD with an empty `git diff HEAD`. 1. HTTP: the translation was skipped (`served.length >= 0`). Blob b4a8eb6 became 7199ebfa2457. Result: `Tests 3 failed | 2 passed (5)` (describe zh-CN, list zh-CN, masked case). Restored. 2. HTTP: the declared (unmasked) object was translated instead of the served one. Blob b4a8eb6 became 15a308b1cfbe. Result: `Tests 1 failed | 4 passed (5)`, at `expect(field(described, DENIED)).toBeUndefined()`. Restored. 3. stdio: the translation was skipped. Blob f4f5d63 became cf940693b548. Result: `Tests 3 failed | 2 passed (5)`. Restored. 4. stdio: the declared object was translated. Blob f4f5d63 became c1f5e4a46e50. Result: `Tests 1 failed | 4 passed (5)` (masked case). Restored. </details> ## Acceptance notes - **Done-when reading** (live, app-crm, HTTP MCP, `Accept-Language: zh-CN`, `describe_object crm_opportunity`). Before, at fc5913e: `Opportunity` / `A potential sale tied to an account.`, stage options `Prospecting, Qualification, Proposal, Closed Won`. After, at 5334bf9: `商机` / `与客户关联的潜在销售机会。`, fields `商机名称`, `阶段` (options `初步接洽, 需求确认, 方案报价, 赢单`), `金额`, `预计成交日期`, `创建时间`. This matches the REST `/meta/object/crm_opportunity` door's zh-CN answer. `list_objects` under zh-CN now lists `客户`, `活动`, `联系人`, `线索`, `商机`, `产品明细`, each with its zh-CN description. - **No-header reading on HTTP** now serves the i18n default locale's (`en`) bundle entries, because `metaRequestLocale` falls back to that default. The REST door does the same: `/meta/object/crm_opportunity` with no header answers `amount: Deal Value`, `close_date: Expected Close`. app-crm's `en` bundle relabels both away from the authored `Amount` / `Close Date`. The MCP answer follows REST here. This is an observation about the example's bundle, not a defect of this change. - **A field that authors `inlineHelpText`**: the translator serves the bundle's `help` entry on `inlineHelpText` and keeps `description` in the source language (its documented slot rule). MCP serves `description` only, so such a field's description stays in the authored language. This is the shared translator's rule, left unchanged. - **The stdio MCP resources** `objectstack://objects` and `objectstack://objects/{name}` (`mcp-server-runtime.ts`) still serve the authored text. The card names the two tools only, so the resources were not changed. carrier: #34659. - **The `describe_object` / `list_objects` tool descriptions** (`mcp-http-tools.ts`) do not mention the locale. The answer's shape is unchanged, so they were left as they are (outside the claim surface). - `main` moved 15 commits after fc5913e. None touches this diff's files. `overlap-check` against origin/main 13e0305 and #34881 reports `VERDICT clean exit 0`. ## Verification <details><summary>Derived gate families (`dispatch-gates --commands`, 68) at 2ba60e9</summary> - 66 of 68 exited 0, including `check:nul-bytes`, `check:test-source-alias`, `check:cross-package-test-inputs`, `check:doc-authoring`, `check:issue-citations`, `check:empty-changeset`, `check:adr-0087-registration` and `check:changeset-no-major`. - 2 exited 3 and are NOT MEASURED: `check:dual-build-cjs-loads` (`PREREQUISITE NOT MET` — only the example-crm closure is built here, 14 packages have no dist), and `check-plugin-teardown-shape.mjs --self-test` (a shallow clone cannot reach the pinned positive-control commit; it grades the checker, not this diff). CI runs both. - `dispatch-gates --ran`: `68 derived, 68 run, 0 NOT-MEASURED, 0 UNRUN`. - `test:repo`, dogfood (no `!`, no narrowing arm) and the type-check lanes run in CI. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 62fbbeb commit 46991d0

5 files changed

Lines changed: 583 additions & 35 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/runtime': patch
3+
'@objectstack/mcp': patch
4+
---
5+
6+
feat(mcp): `list_objects` and `describe_object` serve labels and descriptions in the caller's locale
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
The two MCP object tools now serve the object's label and description, and each field's label, description and option labels, in the caller's locale, the way the REST `/meta` object door serves them. Before, both tools served the authored text in every locale. A client asking in Chinese about an app with a Chinese translation bundle was shown the English labels.
12+
13+
- **HTTP:** the locale is the request's `Accept-Language` (then `?locale=`, then the i18n service's default), read and translated by the `/meta` door's own routine. The dataset tools already used the same routine.
14+
- **stdio:** the transport carries no request, so the locale is the i18n service's default. The stdio `list_datasets` already uses that locale.
15+
16+
Translation runs on the object as the caller is served it, after the field mask, so a field the caller cannot read stays absent and so does its translated text. Names and option values never change. Where the bundle has no entry for a key, or no i18n service is registered, the tools serve the authored text. Without `Accept-Language`, the HTTP tools now serve the i18n default locale's bundle entries, as the REST door does. An app whose `en` bundle relabels a field (app-crm's `amount` is "Deal Value") shows that label there.
17+
18+
The answer's shape is unchanged. Validation rule messages are translated by the same routine where the bundle carries them.
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#34872] The stdio transport's `list_objects` and `describe_object` answer
5+
* the object's and each field's label, option labels and descriptions in the
6+
* locale this transport speaks: it carries no request, so that is the i18n
7+
* service's default (what `metaRequestLocale` answers with no header), the
8+
* reading the stdio `list_datasets` localizes with. The translation is the
9+
* `/meta` object door's own (`translateMetaList`), applied to the object as
10+
* the principal is served it (ADR-0106 D3/D5): a masked field stays absent,
11+
* its translated text with it. An `en` default with no entry, or no i18n
12+
* service the host can resolve, serves the authored text. Names never change.
13+
*
14+
* Driven through the real tools (`registerObjectTools`) over the stdio bridge,
15+
* with a security service built by the shared ADR-0106 double
16+
* (`securityDoubleFor`). The HTTP twin is
17+
* `packages/runtime/src/domains/mcp-object-locale-34872.test.ts`.
18+
*/
19+
20+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
21+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
22+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
23+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
24+
import type { ExecutionContext } from '@objectstack/spec/kernel';
25+
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
26+
import { securityDoubleFor } from '@objectstack/metadata-core/testing';
27+
import { OBJECT_SCHEMA_MASK_DISABLE_ENV } from '@objectstack/metadata-core';
28+
import { createStdioDataBridge } from './stdio-data-bridge.js';
29+
import { registerObjectTools } from './mcp-http-tools.js';
30+
31+
const OBJ = 'deal';
32+
const PLAIN = 'plain';
33+
const DENIED = 'secret_margin';
34+
const OBJECT_TEXT = 'A sales deal, from first call to signed order.';
35+
const AMOUNT_TEXT = 'Amount, tax excluded.';
36+
const DENIED_TEXT = 'Internal margin after rebates.';
37+
38+
const deal = () => ({
39+
name: OBJ,
40+
label: 'Deal',
41+
description: OBJECT_TEXT,
42+
fields: {
43+
id: { name: 'id', type: 'text', label: 'ID' },
44+
subject: { name: 'subject', type: 'text', label: 'Subject' },
45+
amount: { name: 'amount', type: 'currency', label: 'Amount', description: AMOUNT_TEXT },
46+
stage: {
47+
name: 'stage', type: 'select', label: 'Stage',
48+
options: [{ value: 'won', label: 'Won' }, { value: 'lost', label: 'Lost' }],
49+
},
50+
[DENIED]: { name: DENIED, type: 'currency', label: 'Margin', description: DENIED_TEXT },
51+
},
52+
});
53+
const plain = () => ({ name: PLAIN, label: 'Plain', fields: { id: { name: 'id', type: 'text' }, title: { name: 'title', type: 'text', label: 'Title' } } });
54+
55+
/** The zh-CN bundle: the deal, its fields (`help` is the bundle key a field's description is served from) and one option. */
56+
const ZH_CN = {
57+
objects: {
58+
[OBJ]: {
59+
label: '交易',
60+
description: '一笔销售交易,从首次接触到签单。',
61+
fields: {
62+
subject: { label: '主题' },
63+
amount: { label: '金额', help: '金额,不含税。' },
64+
stage: { label: '阶段', options: { won: '赢单' } },
65+
[DENIED]: { label: '毛利', help: '返利后的内部毛利。' },
66+
},
67+
},
68+
},
69+
};
70+
71+
/** An i18n service double: the zh-CN bundle above, an empty `en` one, and the default the case names. */
72+
function i18nService(defaultLocale: string) {
73+
const bundles: Record<string, unknown> = { 'zh-CN': ZH_CN, en: {} };
74+
return {
75+
getLocales: () => Object.keys(bundles),
76+
getTranslations: (locale: string) => bundles[locale],
77+
getDefaultLocale: () => defaultLocale,
78+
};
79+
}
80+
81+
/**
82+
* The real tools over the stdio bridge, the principal reading `readable`
83+
* (every field when omitted), localized by `i18n` (no i18n dependency when omitted).
84+
*/
85+
async function connect(opts: { readable?: readonly string[]; i18n?: () => unknown } = {}) {
86+
const { readable, i18n } = opts;
87+
const security = readable
88+
? securityDoubleFor({
89+
id: 'restricted-caller/34872',
90+
why: 'a principal denied one field',
91+
context: { userId: 'u_member', systemPermissions: [] },
92+
readable: [...readable],
93+
expect: { kind: 'unmasked' },
94+
} as never)
95+
: undefined;
96+
const defs = () => [deal(), plain()];
97+
const bridge = createStdioDataBridge({
98+
engine: {} as unknown as IDataEngine,
99+
metadataService: {
100+
listObjects: vi.fn(async () => defs()),
101+
getObject: vi.fn(async (name: string) => defs().find((d) => d.name === name)),
102+
} as unknown as IMetadataService,
103+
resolvePrincipal: async () => ({ userId: 'u_member', systemPermissions: [] }) as unknown as ExecutionContext,
104+
...(security ? { security: () => security } : {}),
105+
...(i18n ? { i18n } : {}),
106+
});
107+
const server = new McpServer({ name: 'pin', version: '0' });
108+
registerObjectTools(server, bridge);
109+
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
110+
await server.connect(serverSide);
111+
const client = new Client({ name: 'pin', version: '0' });
112+
await client.connect(clientSide);
113+
const call = async (name: string, args: Record<string, unknown>): Promise<{ text: string; json: any; isError: boolean }> => {
114+
const res = (await client.callTool({ name, arguments: args })) as { isError?: boolean; content: Array<{ text: string }> };
115+
const text = res.content[0]!.text;
116+
return { text, json: JSON.parse(text), isError: res.isError === true };
117+
};
118+
return { call, close: () => client.close() };
119+
}
120+
121+
const prevMask = process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV];
122+
beforeEach(() => { delete process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV]; });
123+
afterEach(() => {
124+
if (prevMask === undefined) delete process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV];
125+
else process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV] = prevMask;
126+
});
127+
128+
/** Every field but the denied one (the double answers one readable set for every object). */
129+
const MEMBER_READS = ['id', 'subject', 'amount', 'stage', 'title'] as const;
130+
131+
const field = (described: any, name: string) => described.fields.find((f: any) => f.name === name);
132+
133+
describe('[#34872] stdio list_objects and describe_object serve labels and descriptions in the default locale', () => {
134+
it('describe_object under a zh-CN default: the object\'s and each field\'s label, description and option label are the bundle\'s; names never change', async () => {
135+
const session = await connect({ i18n: () => i18nService('zh-CN') });
136+
try {
137+
const described = await session.call('describe_object', { objectName: OBJ });
138+
expect(described.isError).toBe(false);
139+
expect(described.json).toMatchObject({ name: OBJ, label: '交易', description: '一笔销售交易,从首次接触到签单。' });
140+
expect(field(described.json, 'subject')).toMatchObject({ name: 'subject', label: '主题' });
141+
expect(field(described.json, 'amount')).toMatchObject({ name: 'amount', label: '金额', description: '金额,不含税。' });
142+
expect(field(described.json, 'stage')).toMatchObject({
143+
name: 'stage',
144+
label: '阶段',
145+
options: [{ value: 'won', label: '赢单' }, { value: 'lost', label: 'Lost' }],
146+
});
147+
} finally {
148+
await session.close();
149+
}
150+
});
151+
152+
it('list_objects under a zh-CN default: each object\'s label and description are the bundle\'s; an object the bundle does not carry keeps its own', async () => {
153+
const session = await connect({ readable: MEMBER_READS, i18n: () => i18nService('zh-CN') });
154+
try {
155+
const listed = (await session.call('list_objects', {})).json;
156+
const found = (name: string) => listed.objects.find((o: any) => o.name === name);
157+
expect(found(OBJ)).toEqual({ name: OBJ, label: '交易', description: '一笔销售交易,从首次接触到签单。', fieldCount: 4 });
158+
expect(found(PLAIN)).toEqual({ name: PLAIN, label: 'Plain', fieldCount: 2 });
159+
} finally {
160+
await session.close();
161+
}
162+
});
163+
164+
it('a field the principal cannot read stays absent under translation, its translated label and description with it', async () => {
165+
const session = await connect({ readable: MEMBER_READS, i18n: () => i18nService('zh-CN') });
166+
try {
167+
const described = await session.call('describe_object', { objectName: OBJ });
168+
expect(described.json.label).toBe('交易');
169+
expect(field(described.json, DENIED)).toBeUndefined();
170+
for (const leaked of ['毛利', '返利后的内部毛利。', 'Margin', DENIED_TEXT]) expect(described.text).not.toContain(leaked);
171+
} finally {
172+
await session.close();
173+
}
174+
});
175+
176+
it('an `en` default with no entry: the authored labels, descriptions and option labels', async () => {
177+
const session = await connect({ i18n: () => i18nService('en') });
178+
try {
179+
const described = (await session.call('describe_object', { objectName: OBJ })).json;
180+
expect(described).toMatchObject({ name: OBJ, label: 'Deal', description: OBJECT_TEXT });
181+
expect(field(described, 'amount')).toMatchObject({ label: 'Amount', description: AMOUNT_TEXT });
182+
expect(field(described, 'stage').options).toEqual([{ value: 'won', label: 'Won' }, { value: 'lost', label: 'Lost' }]);
183+
const listed = (await session.call('list_objects', {})).json;
184+
expect(listed.objects.find((o: any) => o.name === OBJ)).toMatchObject({ label: 'Deal', description: OBJECT_TEXT });
185+
} finally {
186+
await session.close();
187+
}
188+
});
189+
190+
it('an i18n service the host cannot resolve (its resolver throws), or none: the authored text, never an error', async () => {
191+
for (const i18n of [() => { throw new Error('i18n not registered'); }, undefined]) {
192+
const session = await connect({ ...(i18n ? { i18n } : {}) });
193+
try {
194+
const described = await session.call('describe_object', { objectName: OBJ });
195+
expect(described.isError).toBe(false);
196+
expect(described.json).toMatchObject({ label: 'Deal', description: OBJECT_TEXT });
197+
const listed = (await session.call('list_objects', {})).json;
198+
expect(listed.objects.find((o: any) => o.name === OBJ)).toMatchObject({ label: 'Deal', description: OBJECT_TEXT });
199+
} finally {
200+
await session.close();
201+
}
202+
}
203+
});
204+
});

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

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,10 @@ export interface StdioDataBridgeDeps {
263263
*/
264264
datasetTools?: StdioDatasetToolsService;
265265
/**
266-
* [ADR-0149 D2] The `i18n` service the saved datasets are localized with,
267-
* resolved at each use. `undefined`, or a resolver that throws, means none:
268-
* the datasets are then served untranslated, as on the HTTP door.
266+
* [ADR-0149 D2 · #34872] The `i18n` service the saved datasets and the
267+
* object tools' labels and descriptions are localized with, resolved at each
268+
* use. `undefined`, or a resolver that throws, means none: they are then
269+
* served untranslated, as on the HTTP door.
269270
*/
270271
i18n?: () => unknown;
271272
}
@@ -1171,13 +1172,50 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
11711172
// the view discovery answers from. The gates below read `objectView` whole.
11721173
const servedView = callerObjectView(objectView, { resolvePrincipal, security, schemaReadDelegates });
11731174

1175+
/**
1176+
* [ADR-0149 D2 · #34872] What the HTTP door's `/meta` translation reads, on
1177+
* a transport that carries no request: the i18n service ({@link
1178+
* StdioDataBridgeDeps.i18n}; a resolver that throws is none) and, for the
1179+
* locale, `metaRequestLocale` with no request — the i18n service's default,
1180+
* the workspace default the stdio principal speaks. `resolveProtocol`
1181+
* answers the protocol the read was served from (an object's packaged base,
1182+
* a declared override's pair translations), or none.
1183+
*/
1184+
const defaultLocaleSources = (resolveProtocol: () => Promise<unknown>) => ({
1185+
resolveI18nService: async () => {
1186+
try {
1187+
return deps.i18n?.();
1188+
} catch {
1189+
return undefined;
1190+
}
1191+
},
1192+
resolveProtocol,
1193+
requestLocale: (i18n?: unknown) => metaRequestLocale(undefined, i18n),
1194+
});
1195+
1196+
/**
1197+
* [#34872] Served objects in the locale this transport speaks: the HTTP
1198+
* door's `/meta` object translation (`translateMetaList`), ⛔ never a second
1199+
* routine, over the objects AS THE PRINCIPAL IS SERVED THEM ({@link
1200+
* callerObjectView}): the translator rewrites the text of the fields it is
1201+
* given and adds none, so a masked field stays absent, its translated text
1202+
* with it (ADR-0106 D3/D5). No locale, or a key the bundle does not carry,
1203+
* leaves the authored text; names never change.
1204+
*/
1205+
const inServedLocale = async (served: readonly ObjectDef[]): Promise<ObjectDef[]> => {
1206+
if (served.length === 0) return [...served];
1207+
const translated = await translateMetaList(defaultLocaleSources(async () => protocol?.()), 'object', [...served]);
1208+
return Array.isArray(translated) ? (translated as ObjectDef[]) : [...served];
1209+
};
1210+
11741211
const bridge: McpDataBridge = {
11751212
async listObjects(): Promise<McpObjectSummary[]> {
11761213
// [#25138] The protocol's merged listing ({@link readMergedObjects}),
11771214
// [ADR-0106] as the principal is served it, so `fieldCount` counts the
11781215
// fields that exist for them ({@link callerObjectView}).
11791216
// [#34721] …and the object's authored `description`, as the HTTP twin serves it.
1180-
return ((await servedView.listObjects()) as ObjectDef[]).map((o) => ({
1217+
// [#34872] …in the locale this transport speaks ({@link inServedLocale}).
1218+
return (await inServedLocale((await servedView.listObjects()) as ObjectDef[])).map((o) => ({
11811219
name: o.name,
11821220
label: o.label ?? o.name,
11831221
...authoredDescription(o),
@@ -1220,8 +1258,10 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
12201258
// is read off the declaration.
12211259
async describeObject(name: string): Promise<unknown | null> {
12221260
const { served, declared } = await readObjectWithDeclaration(servedView, name);
1223-
const def = served as ObjectDef | undefined;
1224-
if (!def) return null;
1261+
if (!served) return null;
1262+
// [#34872] …in the locale this transport speaks ({@link inServedLocale});
1263+
// `declared` is read for the `readonly` verdict alone.
1264+
const [def] = await inServedLocale([served as ObjectDef]);
12251265
// The field list is an ARRAY here, not the stored map: `validate_expression`
12261266
// reads `Array.isArray(def.fields)` off this very value, and the HTTP
12271267
// bridge projects the same shape. A map would type-check and silently
@@ -1440,21 +1480,7 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
14401480
} else {
14411481
items = (await metadataService.list('dataset')) ?? [];
14421482
}
1443-
const translated = await translateMetaList(
1444-
{
1445-
resolveI18nService: async () => {
1446-
try {
1447-
return deps.i18n?.();
1448-
} catch {
1449-
return undefined;
1450-
}
1451-
},
1452-
resolveProtocol: async () => merged,
1453-
requestLocale: (i18n?: unknown) => metaRequestLocale(undefined, i18n),
1454-
},
1455-
'dataset',
1456-
items,
1457-
);
1483+
const translated = await translateMetaList(defaultLocaleSources(async () => merged), 'dataset', items);
14581484
return Array.isArray(translated) ? translated : items;
14591485
};
14601486
const executor = (maxQueryLimit?: number) =>

0 commit comments

Comments
 (0)