You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8856afc
Browse filesBrowse the repository at this point in the historyBrowse files
feat(mcp): a refused record read says what is not recorded, in the caller's language (#35198)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8AJJJRiYjshMUNgyMZSqBsr)_
Refs #35138 (item notRecorded)
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:MCP 的 `query_records` / `aggregate_records` / `get_record`
被拒绝时,若调用点名的对象或字段在调用者自己的 schema 里不存在,拒绝旁边多出
`notRecorded`(点名的是哪个对象/字段,原样取自调用者的输入)和
`ifNotRecorded`(按调用者语言的一句话:告诉用户"这项数据没有记录",不要报 0);新增 `@objectstack/core`
的共享句子语言选择器,数据集工具改用它,行为不变。
- 为什么改:托管侧实测模型拿到裸的 not-found 会绕着答(报 0 或拿别的字段凑),开源 MCP
门的客户端和每日问数轮次拿不到这条信号;本 PR 把它搬进框架。
-
风险与回滚:原有拒绝(`isError`、`code`、`message`、`status`)字节不变,只在拒绝旁追加两个成员;两个成员只由"调用者发送的名字"和"调用者被服务的
schema"构成,不点名调用者看不到的任何东西。回滚即 revert 本 PR。
- 先看:`packages/mcp/src/mcp-http-tools.ts` 的 `notRecordedMembersOf` /
`recordReadErrorResult`(决定何时出现成员、成员由什么构成);`packages/core/src/sentence-locale.ts`(共享选择器);`packages/services/service-analytics/src/dataset-next-step.ts`(改用共享选择器)。
- 两分钟验证:`pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2
src/mcp-not-recorded.test.ts`,预期 14 个用例全绿,其中 CONTROL
用例断言"看不到的字段/对象"与"不存在的字段/对象"成员文本逐字节相同。
- 需要你做的:无,席位落地。
## What changes
- **`notRecorded` / `ifNotRecorded` on a refused record read.**
`query_records`, `aggregate_records` and `get_record` keep their coded
refusal byte for byte and, where the call named an object or a field
that the caller's served schema (`describeObject`, the `describe_object`
answer) does not show, render `{ error, notRecorded, ifNotRecorded }`:
- `notRecorded`: `{ object }` when the schema shows no such object; `{
object, fields }` with the field names the call sent that the schema
does not show, in the order sent (read from `where` through `$and` /
`$or` / `$nor` / `$not`, a dotted key by its head, `fields`, `orderBy`,
`groupBy`, each aggregation's `field` and `filter`);
- `ifNotRecorded`: one sentence in the caller's language (en, zh-Hans,
zh-Hant, ja), written in the executor (ADR-0149 M1: no wording in the
spec).
- **The rule.** The answer names only what the caller can see: both
members are built from the names the caller sent and the caller's served
schema, nothing else, with one wording for every case; nothing the
schema shows is named or counted. A read that answers, a refusal about a
field the schema shows, a server fault, and a refusal whose schema read
throws carry no member. `id`, `created_at`, `updated_at` (answered on
every object, `PLATFORM_PROVISIONED_COLUMNS`) are never named.
- **One sentence-locale picker** in `@objectstack/core`:
`pickSentenceLocale(locales, written)` and
`platformLocaleNamedBy(code)`, moved from `service-analytics`'
`dataset-next-step.ts`. `datasetToolSentenceLocale` now wraps it; its
pins are unchanged and green.
- **A locale member on both bridges:** optional
`McpDataBridge.userTextLocales()`. HTTP: `userTextLocalesOf(ec)`, the
ladder the dataset tools read on that door. stdio: the principal's
ladder (what the dataset tools read there), then the i18n service's
default. Absent or throwing: `en`.
- Type stays local to `packages/mcp` (`NotRecordedMembers`); nothing
enters `packages/spec`.
## Tests
- `packages/mcp/src/mcp-not-recorded.test.ts` (14): unknown object on
all three tools; unknown field on `query_records` and
`aggregate_records`; CONTROL: a field (and an object) the caller cannot
see answers members byte-identical to one that does not exist, whatever
refusal stands beside them; a readable existing field, `id` /
`created_at` / `updated_at`, a successful read, a server fault and a
failing schema read carry no member; zh / zh-Hant / ja / fallback /
no-member / throwing locale; the stdio bridge's `userTextLocales`.
- `packages/runtime/src/domains/mcp-not-recorded.test.ts` (5): over the
real security layer (`SecurityPlugin`, `ObjectQL`, `SqlDriver`,
protocol), the HTTP bridge's served schema shows neither a field the
caller is denied nor an unknown field, `describeObject` answers `null`
for an object the caller cannot read as for an unknown name, a read
naming either is refused 4xx, CONTROL the staff reads both, and
`userTextLocales` answers `userTextLocalesOf(ec)`.
- `packages/core/src/sentence-locale.test.ts` (2): whole-code and prefix
lookup, next rung, `en` floor.
- Existing pins adjusted: the tripwire's face roster and the stdio
member roster gain `userTextLocales`; the HTTP twin in
`stdio-data-bridge.not-found.test.ts` now serves `task` (as the stdio
side does), so the PARITY pin still compares like with like.
<details><summary>Package runs (head e4c3aa0, then the merge of
origin/main at ee70211)</summary>
- `@objectstack/mcp` typecheck (incl. `check:test-typecheck`) exit 0;
`vitest run`: 72 files / 1285 tests passed at e4c3aa0, 73 files /
1306 tests passed at ee70211.
- `@objectstack/core` + `@objectstack/service-analytics` `vitest run`:
161 files / 3734 tests and 218 files / 5592 passed, 335 skipped;
typecheck exit 0 for both.
- `@objectstack/runtime` typecheck exit 0; `vitest run`: 627 files /
12969 passed, 25 skipped (e4c3aa0 tree before the member move;
`src/domains/mcp*` re-run at ee70211: 9 files / 289 passed).
</details>
<details><summary>Ablations (each through scripts/ablation-replace.mjs:
anchor hit once, blob changed, restored to the HEAD blob with an empty
git diff HEAD)</summary>
| Mutation | Pin | Result |
|:--|:--|:--|
| members never computed | object + field + CONTROL + locale | 9 failed
|
| sent field names never compared | field pins + CONTROL | 3 failed / 14
|
| members made to depend on the refusal's code | CONTROL | 2 failed / 14
|
| served fields not read | readable-field pin | 3 failed / 14 |
| always-answered columns dropped | readable-field pin | 3 failed / 14 |
| sentence always en | zh pin | 1 failed / 14 |
| dataset picker narrowed to en | service-analytics nextStep /
sourceLine locale pins | 8 failed |
| core picker without prefix lookup | core pin | 1 failed / 2 (the first
run stayed green: every code in the test was named whole by the table;
prefix-only codes added, then red) |
| HTTP bridge locale member empty | runtime locale pin | 1 failed / 5 |
| stdio i18n-default rung dropped | stdio pin | 1 failed / 14 |
</details>
## Acceptance notes
- The members are decided by the names sent and the caller's served
schema alone, never by the refusal beside them; a server fault (5xx)
carries none.
- `ifNotRecorded` is not described in the three tool descriptions; the
sentence states its own instruction. The card's ask cards (`#35113`) are
outside this PR's file surface.
- `aggregate_records` reads the served object a second way for option
order and currency (`servedFieldsOf`, landed in this card's PR 2,
through `servedObjectDefinitionOf`); this PR reads `describeObject`,
which tells an unserved object (`null`) from one it cannot read and
leaves the search companion out, which that helper does not.
- `pnpm check:dual-build-cjs-loads` locally: PREREQUISITE NOT MET (needs
a full workspace build); CI runs it.
## Verification
<details><summary>Derived gate families (dispatch-gates --commands, head
e4c3aa0)</summary>
76 derived, 75 exit 0, 1 NOT MEASURED (`pnpm
check:dual-build-cjs-loads`, exit 3, no full build). `dispatch-gates
--ran`: 76 accounted, 75 run, 1 NOT-MEASURED. After merging origin/main
(ee70211) re-run: `check:type-check-coverage`,
`check-adr-0087-registration`, `check-changeset-no-major`,
`check-empty-changeset`, `check:nul-bytes`, `check:doc-authoring`,
`check:issue-citations`, `check:test-source-alias`,
`check:cross-package-test-inputs`, `check:published-files` all exit 0;
`check:type-check-debt` hit the local 300 s timeout (exit 124, NOT
MEASURED there; exit 0 at e4c3aa0). `overlap-check.mjs` before each
push.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
feat(mcp): a refused record read says the data is not recorded, in the caller's language
9
+
10
+
Clause-②: yes (widening)
11
+
Metadata-protocol: none
12
+
13
+
When `query_records`, `aggregate_records` or `get_record` is refused and the call named an object, or a field, that the caller's own schema does not show (the object as `describe_object` serves it to them), the refusal now carries two members beside it, on the HTTP and the stdio server alike:
14
+
15
+
-`notRecorded`: what is not recorded, as the caller sent it: `{ "object": "<name>" }`, or `{ "object": "<name>", "fields": ["<name>", …] }` for the field names the call sent that the schema does not show, in the order sent. Every sent name is read by its head on every channel (`where`, `fields`, `orderBy`, `groupBy`, an aggregation's `field` and `filter`), so `owner.name` is judged by `owner`, and a dotted name whose head the schema shows is never named.
16
+
-`ifNotRecorded`: one sentence, in the caller's language (English, Simplified and Traditional Chinese, Japanese), telling the model to say the data is not recorded, never to report 0 or an empty result for it, and not to answer with another object or field in its place.
17
+
18
+
The answer names only what the caller can see: both members are built from the names the caller sent and from the caller's served schema, and nothing else. The refusal itself (`isError`, its `code`, `message` and `status`) is unchanged, byte for byte. A read that answers, a refusal about a field the caller's schema shows, a server fault, and a refusal whose schema read cannot be made carry no member. `id`, `created_at` and `updated_at`, which every object answers, are never named.
19
+
20
+
The language is chosen by one shared picker, `pickSentenceLocale` (with `platformLocaleNamedBy`), now exported from `@objectstack/core`: the first of the caller's locales (the request's, then the workspace default) that names a language the sentence is written in, else `en`. The dataset tools' `nextStep` and `sourceLine` (`@objectstack/service-analytics`) use the same picker, with unchanged behaviour. `McpDataBridge` gains an optional `userTextLocales()` member: the HTTP bridge answers the request's ladder, the stdio bridge the principal's ladder and then the i18n service's default. A bridge without it is answered in `en`.
0 commit comments