Repository navigation
Commit 46991d0
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
- .changeset
- packages
- mcp/src
- runtime/src/domains
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
267 | | - | |
268 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
| |||
1171 | 1172 | | |
1172 | 1173 | | |
1173 | 1174 | | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
1174 | 1211 | | |
1175 | 1212 | | |
1176 | 1213 | | |
1177 | 1214 | | |
1178 | 1215 | | |
1179 | 1216 | | |
1180 | | - | |
| 1217 | + | |
| 1218 | + | |
1181 | 1219 | | |
1182 | 1220 | | |
1183 | 1221 | | |
| |||
1220 | 1258 | | |
1221 | 1259 | | |
1222 | 1260 | | |
1223 | | - | |
1224 | | - | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
1225 | 1265 | | |
1226 | 1266 | | |
1227 | 1267 | | |
| |||
1440 | 1480 | | |
1441 | 1481 | | |
1442 | 1482 | | |
1443 | | - | |
1444 | | - | |
1445 | | - | |
1446 | | - | |
1447 | | - | |
1448 | | - | |
1449 | | - | |
1450 | | - | |
1451 | | - | |
1452 | | - | |
1453 | | - | |
1454 | | - | |
1455 | | - | |
1456 | | - | |
1457 | | - | |
| 1483 | + | |
1458 | 1484 | | |
1459 | 1485 | | |
1460 | 1486 | | |
| |||
0 commit comments