Skip to content

Commit 80d474b

Browse files
fix(mcp): the objectstack://objects resources serve labels in the locale the object tools speak (#35072)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_ Fixes #34995 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:stdio 下的 MCP 资源 `objectstack://objects` 与 `objectstack://objects/{name}` 现在和 `list_objects` / `describe_object` 工具一样,按工作区默认语言返回对象名、字段名、说明和选项名。 - 为什么改:之前资源返回作者原文,工具返回译文,AI 读同一个对象可能拿到两种语言的标签(卡上的完成判据:资源和工具对同一对象返回相同标签)。 - 风险与回滚:只改展示文本,不改名字、字段集合和权限;无权读取的字段照旧不出现。回滚即撤销本 PR,资源回到原文。 - 先看:`packages/mcp/src/stdio-data-bridge.ts` 的 `servedLocaleObjectView`(工具与资源共用的唯一翻译入口);`packages/mcp/src/plugin.ts` 中交给资源的视图套上这层;测试文件 `stdio-data-bridge.object-locale-34872.test.ts` 末尾的 `[#34995]` 三条用例。 - 两分钟验证:`pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2 src/stdio-data-bridge.object-locale-34872.test.ts`,预期 8/8 通过。 - 需要你做的:无,席位落地。 ## What changes - `stdio-data-bridge.ts`: the #34872 translation (`inServedLocale` over `translateMetaList`, with `defaultLocaleSources`) moves out of `createStdioDataBridge` to module scope, unchanged, and is wrapped as `servedLocaleObjectView(view, { i18n, protocol })`: an `McpObjectView` whose `listObjects` / `getObject` answer the wrapped view's objects in the transport's locale, and whose declared-object read hands on the untranslated declaration (only `readonly` is read off it). `list_objects` and `describe_object` now read through this wrapper; the dataset path calls the same module-scope `defaultLocaleSources`. No second translation routine. - `plugin.ts`: the view handed to the object resources (`setRuntimeObjectView`, the call site right before `bridgeResources`) is wrapped in `servedLocaleObjectView` over the same served view (`callerObjectView` under a stdio principal), with the same `i18n` service and `protocol` reads. The served view is what is translated, never the declaration, so a masked field stays absent (ADR-0106 D3/D5). - `mcp-server-runtime.ts`: doc comment only. `buildObjectListResource` / `buildObjectSchemaResource` translate nothing themselves; they serve labels as the view serves them. - `servedLocaleObjectView` is not exported from the package entry (`index.ts`); no published surface changes. - Changeset: `@objectstack/mcp` patch. ## Why The object tools were localized in #34872 (PR #34922); the two resources still served authored text, so a resource read and a tool call for one object could name it in two languages. ## Tests New `[#34995]` block in `packages/mcp/src/stdio-data-bridge.object-locale-34872.test.ts`, booting the real `MCPServerPlugin` and reading over an in-memory MCP client: - zh-CN workspace default: the schema resource serves the bundle's object label, description, field labels and descriptions, and option labels; the list resource serves the translated object label; the schema resource equals `describe_object`'s answer byte-for-byte, and the list resource's labels equal `list_objects`'s (the card's done-when). - A field the principal cannot read stays absent from the translated schema resource, and neither its name nor its authored or translated text appears in the raw text; `fieldCount` counts only served fields. - `en` default with no entry, and no i18n service on the host: authored labels on the resources and the tools alike. ## Acceptance notes - HTTP door: out of scope by construction. Resources are registered only on the long-lived stdio server (`bridgeResources`, `this.mcpServer.registerResource`, `mcp-server-runtime.ts`); `handleHttpRequest` builds a per-request server that registers tools and prompts and no resources, so there is no HTTP resource to localize. - File surface: the claim names `mcp-server-runtime.ts` "and where the resources are registered". The resources' view is handed over and `bridgeResources` is called in `plugin.ts` (`setRuntimeObjectView` at the resource registration call site), so the wrap lands there. It is the only place the resources' view is set. - The engine double in the new test block declares `find` and `getSchema` only (the verbs the stdio principal resolution reads); a first draft carried an unused `update` that `check:engine-double-contract` flagged. ## Verification All readings on head `689463fd78` (after merging `origin/main` at `eb7b09d4d2`) unless noted. <details><summary>@objectstack/mcp tests and typecheck</summary> `pnpm --filter '@objectstack/mcp^...' build` then `pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2` and `pnpm --filter @objectstack/mcp typecheck`, under the verify lock: `VERDICT command-exit 0`; `Test Files 71 passed (71)`, `Tests 1261 passed (1261)`; `check:test-typecheck: OK` (53 errors / 8 pinned signatures held, unchanged). </details> <details><summary>Ablation (one-shot, not kept)</summary> Committed fix first, then `node scripts/ablation-replace.mjs` on `packages/mcp/src/plugin.ts`, anchor `{ i18n: () => optionalService('i18n'), protocol: protocolReads },` replaced by `{},` (the resources' view keeps the wrapper but loses its locale source; the tools are untouched). Anchor x1 to x0, blob 9169554 to 85772e895f. Test file run: `Tests 2 failed | 6 passed (8)`, the zh-CN case (`expected { name: 'deal', label: 'Deal', … } to match … label: '交易'`) and the masked-field case (`expected 'Deal' to be '交易'`); the authored-label case stays green, as expected. Restored: blob equals HEAD (9169554), `git diff HEAD` empty. The test imports `./plugin.js` from source, so no rebuild leg applies. </details> <details><summary>Targeted gates</summary> `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --commands` (no paths): 69 commands, all run; `--ran` with recorded exit codes: `69 derived famil(ies) accounted for — 68 run, 1 NOT-MEASURED`. - NOT MEASURED: `pnpm check:dual-build-cjs-loads`, exit 3 `PREREQUISITE NOT MET` (reads every package's `dist/`; only the mcp closure is built here). CI runs it. - `pnpm check:engine-double-contract` was red (exit 1) on the first run against the test's unused `update` double; green (exit 0) after it was dropped, and again on the merged head. - Re-run on the merged head: `check:engine-double-contract`, `check:type-check-debt`, `check:type-check-coverage`, `check:test-source-alias`, `check:nul-bytes`, `check-empty-changeset`, `check-changeset-no-major`, `check-adr-0087-registration`. - `check-governed-merges --branch`: NOT governed; 304 changed lines, under 3000. `dispatch-gates --tier`: no path-derived mandate. - `overlap-check`: clean against origin/main, #35043 and #35060. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (Repo-wide lint is CI's run; not run locally.) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (Not touched.) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. (The 维护者速读 section is Chinese by the fleet's PR rule.) - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzfR33NbV51QQU6R6bm)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzfR33NbV51QQU6R6bm --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 36d46b5 commit 80d474b

5 files changed

Lines changed: 256 additions & 47 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+
---
4+
5+
fix(mcp): the `objectstack://objects` resources serve labels in the locale the object tools speak
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Over the stdio transport, the `objectstack://objects` and `objectstack://objects/{name}` resources now answer an object's label, description, field labels, field descriptions and option labels in the workspace's default locale, as `list_objects` and `describe_object` have since the object tools were localized. Before, the resources served the authored text, so a resource read and a tool call for the same object could name it in two languages.
11+
12+
- The resources read the same localized view the two tools read, through the same translation the HTTP door's `/meta` answers use. A resource read and a tool call for one object answer the same labels.
13+
- A field the caller cannot read stays absent from the resources, its translated text with it.
14+
- With no default locale, or a key the bundle does not carry, the authored text is served, as before. Names never change.
15+
- The Streamable HTTP door registers no resources, so nothing changes there.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,10 @@ export class MCPServerRuntime {
21612161
*
21622162
* [#25245] The two object resources read the view this runtime's host gave
21632163
* (`setRuntimeObjectView`, package-internal), at each read; without one they
2164-
* read `metadataService`, as before.
2164+
* read `metadataService`, as before. [#34995] Labels are served as that view
2165+
* serves them: the stdio host's view is localized as the object tools are
2166+
* (`servedLocaleObjectView`, `stdio-data-bridge.ts`), so the two builders
2167+
* below translate nothing themselves.
21652168
*/
21662169
bridgeResources(
21672170
metadataService: IMetadataService,

‎packages/mcp/src/plugin.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
GATED_ACTIONS,
4545
serveStoredMetadataHashes,
4646
serveStoredMetadataRow,
47+
servedLocaleObjectView,
4748
stdioObjectView,
4849
type StdioObjectReads,
4950
type StdioDatasetToolsService,
@@ -901,12 +902,19 @@ export class MCPServerPlugin implements Plugin {
901902
// object-schema mask (`callerObjectView`), the view the tools read, so
902903
// a resource never names a field the tools withhold. With no principal
903904
// (this process starts no stdio transport) the view is the bare one.
905+
// [#34995] …in the locale the object tools speak: the served view,
906+
// localized through the wrapper the stdio bridge's `list_objects` /
907+
// `describe_object` read (`servedLocaleObjectView`), with the same i18n
908+
// service, so a resource and a tool answer one object with one label.
904909
const objectView = stdioObjectView({ metadataService, protocol: protocolReads });
905910
setRuntimeObjectView(
906911
this.runtime,
907-
schemaPrincipal
908-
? callerObjectView(objectView, { resolvePrincipal: schemaPrincipal, security: securityReads, schemaReadDelegates })
909-
: objectView,
912+
servedLocaleObjectView(
913+
schemaPrincipal
914+
? callerObjectView(objectView, { resolvePrincipal: schemaPrincipal, security: securityReads, schemaReadDelegates })
915+
: objectView,
916+
{ i18n: () => optionalService('i18n'), protocol: protocolReads },
917+
),
910918
);
911919
this.runtime.bridgeResources(metadataService, getRecord);
912920
// Awaited: the prompt bridge reads `skill` metadata to project each

‎packages/mcp/src/stdio-data-bridge.object-locale-34872.test.ts‎

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { securityDoubleFor } from '@objectstack/metadata-core/testing';
2727
import { OBJECT_SCHEMA_MASK_DISABLE_ENV } from '@objectstack/metadata-core';
2828
import { createStdioDataBridge } from './stdio-data-bridge.js';
2929
import { registerObjectTools } from './mcp-http-tools.js';
30+
import { MCPServerPlugin } from './plugin.js';
31+
import type { MCPServerRuntime } from './mcp-server-runtime.js';
3032

3133
const OBJ = 'deal';
3234
const PLAIN = 'plain';
@@ -202,3 +204,136 @@ describe('[#34872] stdio list_objects and describe_object serve labels and descr
202204
}
203205
});
204206
});
207+
208+
describe('[#34995] the stdio object resources serve labels in the locale the object tools speak', () => {
209+
const originalEnv = { ...process.env };
210+
beforeEach(() => {
211+
process.env = { ...originalEnv };
212+
delete process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV];
213+
process.env.OS_MCP_STDIO_API_KEY = 'osk_object_locale_resource_pin';
214+
});
215+
afterEach(() => {
216+
process.env = { ...originalEnv };
217+
vi.restoreAllMocks();
218+
});
219+
220+
/**
221+
* `MCPServerPlugin` over a host registering `i18n` (none when omitted) and a
222+
* security service answering `readable`, and a client on its long-lived
223+
* server: the composition that hands the tools and the resources their views.
224+
*/
225+
async function boot(opts: { readable: readonly string[]; i18n?: unknown }) {
226+
const defs = () => [deal(), plain()];
227+
const metadata = {
228+
listObjects: vi.fn(async () => defs()),
229+
getObject: vi.fn(async (name: string) => defs().find((d) => d.name === name) ?? null),
230+
get: vi.fn(async () => null),
231+
list: vi.fn(async () => []),
232+
exists: vi.fn(async () => false),
233+
getRegisteredTypes: vi.fn(async () => ['object']),
234+
register: vi.fn(),
235+
unregister: vi.fn(),
236+
};
237+
const objectql = {
238+
// The stdio principal resolves from this key row and its owner.
239+
find: vi.fn(async (object: string, query?: any) => {
240+
if (object === 'sys_api_key') return [{ id: 'k1', user_id: 'usr_stdio', revoked: false }];
241+
if (object === 'sys_user') return query?.where?.id === 'usr_stdio' ? [{ id: 'usr_stdio' }] : [];
242+
return [];
243+
}),
244+
getSchema: vi.fn(() => undefined),
245+
};
246+
const answer = async () => [...opts.readable];
247+
const security = { getReadableFields: vi.fn(answer), getMetadataReadableFields: vi.fn(answer) };
248+
const registry = new Map<string, unknown>([['metadata', metadata], ['objectql', objectql], ['security', security]]);
249+
if (opts.i18n) registry.set('i18n', opts.i18n);
250+
const ctx: any = {
251+
registerService: vi.fn((name: string, service: unknown) => registry.set(name, service)),
252+
getService: vi.fn((name: string) => {
253+
if (!registry.has(name)) throw new Error(`Service "${name}" not found`);
254+
return registry.get(name);
255+
}),
256+
replaceService: vi.fn(),
257+
getServices: vi.fn(() => registry),
258+
hook: vi.fn(),
259+
trigger: vi.fn(async () => {}),
260+
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
261+
getKernel: vi.fn(() => ({})),
262+
};
263+
const plugin = new MCPServerPlugin({ autoStart: true });
264+
await plugin.init(ctx);
265+
const runtime = registry.get('mcp') as MCPServerRuntime;
266+
// `start()` would claim this process's real stdin/stdout.
267+
vi.spyOn(runtime, 'start').mockResolvedValue(undefined);
268+
await plugin.start(ctx);
269+
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
270+
await runtime.server.connect(serverSide);
271+
const client = new Client({ name: 'pin', version: '0' });
272+
await client.connect(clientSide);
273+
const tool = async (name: string, args: Record<string, unknown>) => {
274+
const res = (await client.callTool({ name, arguments: args })) as { isError?: boolean; content: Array<{ text: string }> };
275+
return { isError: res.isError === true, text: res.content[0]!.text, json: JSON.parse(res.content[0]!.text) };
276+
};
277+
const resource = async (uri: string) => {
278+
const res = await client.readResource({ uri });
279+
const text = (res.contents[0] as { text: string }).text;
280+
return { text, json: JSON.parse(text) };
281+
};
282+
return { tool, resource, close: () => client.close() };
283+
}
284+
285+
/** Each listed object's name and label. */
286+
const labelsOf = (listed: any) => Object.fromEntries(listed.objects.map((o: any) => [o.name, o.label]));
287+
288+
it('under a zh-CN default: each resource serves the bundle\'s labels, exactly as describe_object and list_objects do', async () => {
289+
const k = await boot({ readable: MEMBER_READS, i18n: i18nService('zh-CN') });
290+
try {
291+
const schema = await k.resource(`objectstack://objects/${OBJ}`);
292+
expect(schema.json).toMatchObject({ name: OBJ, label: '交易', description: '一笔销售交易,从首次接触到签单。' });
293+
expect(field(schema.json, 'subject')).toMatchObject({ name: 'subject', label: '主题' });
294+
expect(field(schema.json, 'amount')).toMatchObject({ name: 'amount', label: '金额', description: '金额,不含税。' });
295+
expect(field(schema.json, 'stage').options).toEqual([{ value: 'won', label: '赢单' }, { value: 'lost', label: 'Lost' }]);
296+
const listing = await k.resource('objectstack://objects');
297+
expect(labelsOf(listing.json)).toEqual({ [OBJ]: '交易', [PLAIN]: 'Plain' });
298+
299+
// The card's done-when: a resource read and a tool call for the same object answer the same labels.
300+
const described = await k.tool('describe_object', { objectName: OBJ });
301+
expect(described.isError).toBe(false);
302+
expect(schema.json).toEqual(described.json);
303+
expect(labelsOf(listing.json)).toEqual(labelsOf((await k.tool('list_objects', {})).json));
304+
} finally {
305+
await k.close();
306+
}
307+
});
308+
309+
it('a field the principal cannot read stays absent from the translated resources, its translated text with it', async () => {
310+
const k = await boot({ readable: MEMBER_READS, i18n: i18nService('zh-CN') });
311+
try {
312+
const schema = await k.resource(`objectstack://objects/${OBJ}`);
313+
expect(schema.json.label).toBe('交易');
314+
expect(field(schema.json, DENIED)).toBeUndefined();
315+
for (const leaked of [DENIED, '毛利', '返利后的内部毛利。', 'Margin', DENIED_TEXT]) expect(schema.text).not.toContain(leaked);
316+
const listing = await k.resource('objectstack://objects');
317+
expect(listing.json.objects.find((o: any) => o.name === OBJ)?.fieldCount).toBe(4);
318+
} finally {
319+
await k.close();
320+
}
321+
});
322+
323+
it('an `en` default with no entry, or no i18n service on the host: the authored labels on the resources and the tools alike', async () => {
324+
for (const i18n of [i18nService('en'), undefined]) {
325+
const k = await boot({ readable: MEMBER_READS, ...(i18n ? { i18n } : {}) });
326+
try {
327+
const schema = await k.resource(`objectstack://objects/${OBJ}`);
328+
expect(schema.json).toMatchObject({ name: OBJ, label: 'Deal', description: OBJECT_TEXT });
329+
expect(field(schema.json, 'amount')).toMatchObject({ label: 'Amount', description: AMOUNT_TEXT });
330+
expect(schema.json).toEqual((await k.tool('describe_object', { objectName: OBJ })).json);
331+
const listing = await k.resource('objectstack://objects');
332+
expect(labelsOf(listing.json)).toEqual({ [OBJ]: 'Deal', [PLAIN]: 'Plain' });
333+
expect(labelsOf(listing.json)).toEqual(labelsOf((await k.tool('list_objects', {})).json));
334+
} finally {
335+
await k.close();
336+
}
337+
}
338+
});
339+
});

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

Lines changed: 91 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,85 @@ export function callerObjectView(view: McpObjectView, deps: CallerObjectViewDeps
644644
return served;
645645
}
646646

647+
/** What {@link servedLocaleObjectView} localizes with: the host's `i18n` service and `protocol`. */
648+
export interface ServedLocaleSources {
649+
/** The `i18n` service, resolved at each use ({@link StdioDataBridgeDeps.i18n}); a resolver that throws is none. */
650+
i18n?: () => unknown;
651+
/** The `protocol` service: an object's packaged base and a declared override's pair translations. */
652+
protocol?: () => StdioProtocolObjectReads | undefined;
653+
}
654+
655+
/**
656+
* [ADR-0149 D2 · #34872] What the HTTP door's `/meta` translation reads, on a
657+
* transport that carries no request: the i18n service (a resolver that throws
658+
* is none) and, for the locale, `metaRequestLocale` with no request — the i18n
659+
* service's default, the workspace default the stdio principal speaks.
660+
* `resolveProtocol` answers the protocol the read was served from (an object's
661+
* packaged base, a declared override's pair translations), or none.
662+
*/
663+
function defaultLocaleSources(i18n: (() => unknown) | undefined, resolveProtocol: () => Promise<unknown>) {
664+
return {
665+
resolveI18nService: async () => {
666+
try {
667+
return i18n?.();
668+
} catch {
669+
return undefined;
670+
}
671+
},
672+
resolveProtocol,
673+
requestLocale: (service?: unknown) => metaRequestLocale(undefined, service),
674+
};
675+
}
676+
677+
/**
678+
* [#34872] Served objects in the locale this transport speaks: the HTTP door's
679+
* `/meta` object translation (`translateMetaList`), ⛔ never a second routine,
680+
* over the objects AS THE PRINCIPAL IS SERVED THEM ({@link callerObjectView}):
681+
* the translator rewrites the text of the fields it is given and adds none, so
682+
* a masked field stays absent, its translated text with it (ADR-0106 D3/D5).
683+
* No locale, or a key the bundle does not carry, leaves the authored text;
684+
* names never change.
685+
*/
686+
async function inServedLocale(sources: ServedLocaleSources, served: readonly ObjectDef[]): Promise<ObjectDef[]> {
687+
if (served.length === 0) return [...served];
688+
const translated = await translateMetaList(
689+
defaultLocaleSources(sources.i18n, async () => sources.protocol?.()),
690+
'object',
691+
[...served],
692+
);
693+
return Array.isArray(translated) ? (translated as ObjectDef[]) : [...served];
694+
}
695+
696+
/**
697+
* [#34872 · #34995] `view` in the locale this transport speaks
698+
* ({@link inServedLocale}): what the object tools (`list_objects`,
699+
* `describe_object`) and the `objectstack://objects` resources read, so a
700+
* resource and a tool describe one object with one set of labels. Wrap the
701+
* view the principal is served ({@link callerObjectView}): the served object
702+
* is what is translated, never the declaration, so a masked field stays absent
703+
* (ADR-0106 D3/D5). The declaration that object was projected from is handed
704+
* on untranslated ({@link readObjectWithDeclaration}): only `readonly` is read
705+
* off it.
706+
*/
707+
export function servedLocaleObjectView(view: McpObjectView, sources: ServedLocaleSources): McpObjectView {
708+
const readWithDeclaration = async (name: string) => {
709+
const { served, declared } = await readObjectWithDeclaration(view, name);
710+
if (!served) return { served, declared };
711+
const [def] = await inServedLocale(sources, [served as ObjectDef]);
712+
return { served: def, declared };
713+
};
714+
const localized: McpObjectView = {
715+
async listObjects() {
716+
return inServedLocale(sources, ((await view.listObjects()) ?? []) as ObjectDef[]);
717+
},
718+
async getObject(name) {
719+
return (await readWithDeclaration(name)).served;
720+
},
721+
};
722+
setDeclaredObjectRead(localized, readWithDeclaration);
723+
return localized;
724+
}
725+
647726
/**
648727
* The ADR-0049 object exposure gate, applied before a data verb dispatches
649728
* (#8083). Throws {@link McpExposureError} when the object's own declaration
@@ -1172,50 +1251,20 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
11721251
// the view discovery answers from. The gates below read `objectView` whole.
11731252
const servedView = callerObjectView(objectView, { resolvePrincipal, security, schemaReadDelegates });
11741253

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-
};
1254+
// [#34872 · #34995] …and in the locale this transport speaks
1255+
// ({@link servedLocaleObjectView}): the view the object tools describe
1256+
// from, through the wrapper `plugin.ts` puts on the view the
1257+
// `objectstack://objects` resources read, so the two answer alike.
1258+
const localizedView = servedLocaleObjectView(servedView, { i18n: deps.i18n, protocol });
12101259

12111260
const bridge: McpDataBridge = {
12121261
async listObjects(): Promise<McpObjectSummary[]> {
12131262
// [#25138] The protocol's merged listing ({@link readMergedObjects}),
12141263
// [ADR-0106] as the principal is served it, so `fieldCount` counts the
12151264
// fields that exist for them ({@link callerObjectView}).
12161265
// [#34721] …and the object's authored `description`, as the HTTP twin serves it.
1217-
// [#34872] …in the locale this transport speaks ({@link inServedLocale}).
1218-
return (await inServedLocale((await servedView.listObjects()) as ObjectDef[])).map((o) => ({
1266+
// [#34872] …in the locale this transport speaks ({@link servedLocaleObjectView}).
1267+
return ((await localizedView.listObjects()) as ObjectDef[]).map((o) => ({
12191268
name: o.name,
12201269
label: o.label ?? o.name,
12211270
...authoredDescription(o),
@@ -1257,17 +1306,16 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
12571306
// twin judges it ({@link readObjectWithDeclaration}): only that boolean
12581307
// is read off the declaration.
12591308
async describeObject(name: string): Promise<unknown | null> {
1260-
const { served, declared } = await readObjectWithDeclaration(servedView, name);
1261-
if (!served) return null;
1262-
// [#34872] …in the locale this transport speaks ({@link inServedLocale});
1309+
// [#34872] …in the locale this transport speaks ({@link servedLocaleObjectView});
12631310
// `declared` is read for the `readonly` verdict alone.
1264-
const [def] = await inServedLocale([served as ObjectDef]);
1311+
const { served: def, declared } = await readObjectWithDeclaration(localizedView, name);
1312+
if (!def) return null;
12651313
// The field list is an ARRAY here, not the stored map: `validate_expression`
12661314
// reads `Array.isArray(def.fields)` off this very value, and the HTTP
12671315
// bridge projects the same shape. A map would type-check and silently
12681316
// leave that tool with zero fields in scope.
12691317
// [#32435] …each field and rule carrying what a write needs.
1270-
return describeServedObject(def, declared as ServedObjectDef);
1318+
return describeServedObject(def as ServedObjectDef, declared as ServedObjectDef);
12711319
},
12721320

12731321
// [#28715] From the object `describeObject` reads: the protocol's served
@@ -1480,7 +1528,7 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
14801528
} else {
14811529
items = (await metadataService.list('dataset')) ?? [];
14821530
}
1483-
const translated = await translateMetaList(defaultLocaleSources(async () => merged), 'dataset', items);
1531+
const translated = await translateMetaList(defaultLocaleSources(deps.i18n, async () => merged), 'dataset', items);
14841532
return Array.isArray(translated) ? translated : items;
14851533
};
14861534
const executor = (maxQueryLimit?: number) =>

0 commit comments

Comments
 (0)