Skip to content

Commit 44c7a4a

Browse files
feat(analytics): list_datasets offers candidates for a term that matched nothing (#34904)
<!-- 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 #34763 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:`list_datasets` 在某个词一个成员都没精确命中时,服务器填 `candidates`:拿这个词和成员的名字、各语言显示名、同义词比"互相包含"(两边都至少 2 个字符),只从这个调用者能看到的数据集和成员里挑,每个词最多 5 个。`list_datasets` 工具说明和 MCP `initialize` 里的选择规则同步写上:有候选就反问用户,不替用户选,也不把候选当命中;没命中也没候选才回退到对象查询。 - **为什么改**:#34691 裁定 F1 B,「零命中返回候选」由服务器给,产品内 AI 和所有 MCP 客户端读到同一份结果。规范形状已随 #34761 落地,本 PR 是执行器和说明文字那一半。 - **风险与回滚**:精确命中规则和 `matches` 一字不改;只在有词零命中且有相近成员时多一个可选键,规范早已声明。说明文字变长:工具说明 1095 → 1414 字节,`initialize` 规则 453 → 741 字节。回滚就是 revert 本 PR。 - **先看**:`packages/services/service-analytics/src/dataset-term-matcher.ts`(`findDatasetTermCandidates`,"相近"规则、命中压制、顺序和上限都在这里)、`packages/services/service-analytics/src/dataset-tools.ts`(只从已准入成员取候选的那几行,以及 `LIST_DATASETS_DESCRIPTION`)、`packages/mcp/src/mcp-server-runtime.ts`(`DATASET_SELECTION_RULE`)。 - **两分钟验证**:`pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/dataset-term-matcher.test.ts src/__tests__/dataset-tools.test.ts`,预期 2 个文件 58 个测试全绿。 - **需要你做的**:无,席位落地。 ## What changes - **The near-term finder** (`packages/services/service-analytics/src/dataset-term-matcher.ts`, new `findDatasetTermCandidates` beside `matchDatasetTerms`). For each term with no hit in any listed dataset, it returns the members near it as `{ term, dataset, member }`, to the shape, order and cap of `ListDatasetsOutputSchema.candidates` and the ADR-0149 D3 amendment note. - **Near (the card's proposal, kept):** after `normalizeDatasetTerm`, one of the member's targets (its `name`, its `label` in every locale of an inline map, each string `synonym`) contains the term, or the term contains the target, with both sides at least two code points long (`DATASET_TERM_NEAR_MIN_CODE_POINTS = 2`). No edit distance, stem or embedding. I measured nothing that argued for another rule: on the showcase it gives exactly the card's `invoice` answer (below). - **A hit anywhere suppresses the term.** The hit test is the same `matchedOn` equality that `matchDatasetTerms` reports as `matches`, over the same members, so a term with a `matches` entry anywhere in the answer has no candidate. What counts as a match is unchanged, and the existing equality test (no hit on a substring) is untouched. - **Order and cap:** terms in the order sent, datasets in the order listed, each dataset's measures before its dimensions, each in entry order. At most `LIST_DATASETS_MAX_CANDIDATES_PER_TERM` (5) per term, taken from the front, with no marker for the cut. A term sent twice is offered once, since the second copy adds nothing. The spec is silent on repeated terms; this is my choice, and it is pinned. - **The fill** (`packages/services/service-analytics/src/dataset-tools.ts`, `listDatasets`). The finder runs over the per-dataset `dimensions` / `measures` lists that the catalogue entry is built from. Those are already filtered by `admitDatasetCatalogEntry`, so a withheld member, an `internal`-field member and an unadmitted dataset can never be offered, and every pointer names a member listed in the same answer. `candidates` is set only when the list is non-empty, so the key is absent rather than an empty list. - **Selection text, route A** (seat amendment 6951344053 on #34686). `LIST_DATASETS_DESCRIPTION` and `DATASET_SELECTION_RULE` now carry the rows of step 2 in `skills/objectstack-ask/SKILL.md`, each in its own sentences: - each word for a thing measured that matches exactly one measure is computed, and two such words are two metrics, computed both; - one word matching several measures is a question for the user, without picking; - a word with `candidates` is the same question, listing each candidate's label, dataset label and description; a candidate is never picked and never treated as a match; - no match and no candidates falls back to the object tools, labelled as not from a governed metric. The dimension-alone, `membersWithheld`, `provenance`, 非指标口径 and "name the dataset of the fallback object" sentences of the tool description stay. | String | Before (bytes, UTF-8) | After | Delta | |:--|--:|--:|--:| | `LIST_DATASETS_DESCRIPTION` | 1095 | 1414 | +319 | | `DATASET_SELECTION_RULE` | 453 | 741 | +288 | Measured by evaluating each string's source expression at base `d947a93c` and at this branch. The rule's docblock above `DATASET_SELECTION_RULE` now names the candidates row too (follow-up round, after #34881 landed; see below). - **Docs that quote the rule:** `packages/mcp/README.md` (the `initialize` instructions section) and `content/docs/ai/connect-mcp.mdx` (Governed metrics and the `initialize` instructions) carry the same four rows. - **Checklist:** `docs/qa/platform-checklist/areas/ai.json` `ai.mcp-dataset-tools` moves to revision 3. It gains a near-miss step (`terms: ['invoice']`, then `['invoices']`) and a matching clause. The description clause now names the candidates row, the `qa_no_word` clause adds "no `candidates` key", and `automated.ref` names the candidate pins. New step and clause are appended, so earlier indices do not move. The checklist README names no generator; `pnpm check:platform-checklist` is green and wrote nothing. - **Changeset:** `.changeset/34763-list-datasets-candidates-fill.md`. `@objectstack/service-analytics` and `@objectstack/mcp` are both `patch`, because `Metadata-protocol: none` takes `patch` (AGENTS.md Post-Task Checklist step 3). `Clause-②: no`. Outside the claimed surface: none. Every file is inside the claim's file surface. ## Tests - `src/__tests__/dataset-term-matcher.test.ts`: a new top-level `describe('findDatasetTermCandidates')` with 6 tests. They cover: - both containment directions (`金额` near `合同金额`, `合同金额` near `金额`), with name, label locale and synonym targets after normalization; - the two-code-point floor on each side, plus the two-code-point positive control; - a hit in another dataset suppresses the term while the other terms still get candidates; - order: terms as sent, datasets as given, measures before dimensions even when the dimension is declared first; - the cap of 5 per term from the front, counted per term, with every entry a bare `{ dataset, member, term }` pointer; - a repeated term, empty terms and no datasets. - `src/__tests__/dataset-tools.test.ts`: a new top-level `describe('[#34763] …')` with 4 tests over the plugin-wired service and the security double. They cover: - the restricted caller `u_me`: only `rev` → `pipeline.measures.revenue` is offered. Nothing is offered for `secret` (an internal-field member), `rate` or `marg` (members over the unreadable `margin`), or `tot` (in `locked_ds`, which `u_me` may not query, and in `closed_ds`, which is not API-exposed). Nothing is offered for `营收` either, because it matched. - the admin: more is offered by the same rule, and `closed_ds` and `secret_sum` never appear; - `margin`, which equals `margin_total`'s label, gets no candidate although `margin_rate` contains it; the control `marg` is offered both; - the key is absent for no terms, for all-matched terms, and when nothing readable is near. Every candidate is checked to resolve to a member listed in the same answer, and the answer parses under `ListDatasetsOutputSchema`. - `packages/mcp/src/mcp-dataset-tools.test.ts`: a new top-level `describe('[#34763] list_datasets candidates pass through MCP unchanged')` with 3 tests (folded in during the follow-up round; first landed as a separate file): - the fixtures are spec-valid; - `candidates` passes through `tools/call list_datasets` unchanged, with the same entries in the same order and nothing added; - an answer without the key comes back without it. - `packages/mcp/src/initialize-selection-rule-34686.test.ts` pins only that the rule names both tools, not its wording, so it needed no change and is untouched. <details><summary>Test and typecheck runs</summary> Run at `2926ce23` under the shared verify lock. Each part's exit code was echoed separately. - `pnpm --filter @objectstack/service-analytics typecheck` exit 0. Its `tsconfig.json` includes `src`, so `__tests__` is compiled. - `pnpm --filter @objectstack/mcp typecheck` exit 0. This runs `tsc --noEmit && pnpm check:test-typecheck`: `check:test-typecheck: OK — @objectstack/mcp's test layer compiles under packages/mcp/tsconfig.test.json; 6 file(s) / 53 error(s) / 8 pinned signature(s) held` (debt unchanged). - `pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2`: `Test Files 218 passed (218)`, `Tests 5558 passed | 335 skipped (5893)`, exit 0. - `pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2`: `Test Files 70 passed (70)`, `Tests 1244 passed (1244)`, exit 0. - After merging `origin/main` (`14bb6615`; the incoming commits touch one unrelated mcp test file and nothing in service-analytics), under the lock: the whole mcp suite gave `Test Files 70 passed (70)`, `Tests 1244 passed (1244)`, and the two service-analytics files gave `Test Files 2 passed (2)`, `Tests 58 passed (58)`; `VERDICT command-exit 0`. </details> <details><summary>Ablations (one-time; no permanent test file)</summary> Both ran through `scripts/ablation-replace.mjs` at `2926ce23`. The tests import the subject relatively from `src/` (`../dataset-term-matcher.js`, `../dataset-tools.js`), so no `dist/` is involved. - **Per-term cap.** Anchor `if (++offered >= LIST_DATASETS_MAX_CANDIDATES_PER_TERM) break scan;` replaced by `++offered;`. On-disk proof: anchor x1 → x0, replacement x0 → x1, blob `85170dd7` → `85f8238f`. Result: `Tests 1 failed | 57 passed (58)`, and the failing test was `findDatasetTermCandidates > offers at most 5 per term, the first in listing order, with no cut marker`. Restored: blob equals HEAD (`85170dd7`) and `git diff HEAD` is empty. - **A hit suppresses candidates.** Anchor ` if (hit) continue;` replaced by ` void hit;`. On-disk proof: anchor x1 → x0, blob `85170dd7` → `e597fc91`. Result: `Tests 5 failed | 53 passed (58)`. The failing tests were the matcher's "offers nothing for a term with a hit in ANY dataset" and all four `[#34763]` tests in `dataset-tools.test.ts`. Restored: blob equals HEAD, `git diff HEAD` is empty, and `git status --porcelain` is empty. </details> ## Acceptance notes - **Live reading on the showcase** (the card's acceptance), taken at `2926ce23`. The server was booted with `pnpm -C examples/app-showcase exec objectstack dev --fresh -p 38763 --no-watch`, against the showcase closure built under the lock. The root `pnpm dev` refused because its prerequisite check wants every package built. An `osk_` key was minted with `POST /api/v1/keys` as the seeded admin, then `tools/call list_datasets` was sent over HTTP MCP. Eight datasets were listed in each answer, and no answer was `partial`. ```text terms ['invoice'] showcase_invoice_metrics.matches: [] no other entry has a match candidates: [{term:'invoice', dataset:'showcase_invoice_metrics', member:'measures.invoice_count'}, {term:'invoice', dataset:'showcase_invoice_metrics', member:'measures.paid_count'}] terms ['invoices'] showcase_invoice_metrics.matches: [{term:'invoices', member:'measures.invoice_count', matchedOn:'label'}] candidates key: absent terms ['qa_no_word'] every entry's matches: [] candidates key: absent ``` `paid_count` ("Paid Invoices") is offered beside `invoice_count` because its label contains `invoice`. The same boot served the new `initialize` rule and the new `list_datasets` description over `tools/list`, verbatim as in the source. - **One candidate vs the skill's last row.** The ADR-0149 D3 amendment note and the seat's route A say a term with candidates is asked about. The published skill's row "Nothing matches, and the listed measures do not offer several readings of the word" sends one near form to step 4 ("One near form is not a match either: it selects nothing"). For a term with exactly one candidate, the tool texts here say ask, and that row says fall back. Both texts agree that the candidate is never acted on; they differ only on whether to ask first. `skills/**` is outside this card. Seat 3 has since ruled that one candidate asks (see the ruling note below). - **How broad near is, measured.** Containment at two code points is wide on short ASCII terms. In the unit fixture, `tot` reaches `margin_total` ("margin total"), and a two-letter term reaches every target that contains it. The per-term cap of 5 bounds the list. I add no ranking because the spec forbids one. - The tool-table row for `list_datasets` in `content/docs/ai/connect-mcp.mdx` does not quote the rule, so it is left as it is (claim: those docs change only where they quote the rule). ## Verification <details><summary>Targeted gates (local), derived by dispatch-gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands` (no paths) derived 100 families from the tree at `2926ce23`. All 100 were run. - 98 exited 0 on the first pass. - `pnpm --filter @objectstack/spec run check:skill-examples` and `pnpm check:dual-build-cjs-loads` first exited 3 (PREREQUISITE NOT MET, no full build yet, so nothing was measured). After a full `turbo run build` under the lock, both exited 0 (`347 prose examples type-check across 3 surface(s)`; dual-build floors held). - `node scripts/pm/dispatch-gates.mjs --ran` (with `:: exit N` records): `✓ 100 derived famil(ies) accounted for — 100 run, 0 NOT-MEASURED (a DERIVED zero — all 100 recorded an exit code and none of them is 3)`. - `pnpm check:platform-checklist`: `check-platform-checklist: OK — 16 areas, 433 items`. - `node scripts/check-nul-bytes.mjs`: OK. - `node scripts/pm/check-governed-merges.mjs --branch`: `NOT governed`, 494 changed lines (+466 / -28), under 3000. `dispatch-gates --tier`: no path-derived mandate. - `node scripts/pm/overlap-check.mjs` before every push. The first run was exit 1 against #34881 on the docblock (see What changes). After the docblock was left alone, every run was exit 0, the last one at `14bb6615`. - Not run locally, left to CI: the repo-wide scans (`pnpm lint`), `test:repo`, the integration layers and dogfood. The title carries no `!` and there is no `(narrowing)` arm, so no full dogfood run is owed. </details> ## Ruling note: one candidate asks With a single candidate for a term, the tool description and the `initialize` rule say to ask, as the ADR-0149 D3 amendment note does ("With candidates, the AI asks in rule 3's form and acts on none"). This departs from seat 3's earlier ruling on #34792 (Q1 A, record 6945986942: one loose candidate falls back, labelled), which predates `candidates`. Seat 3 ruled on this PR that the ADR note outranks it. The published skill's row "One near form is not a match either: it selects nothing" is amended under #34868 to ask when `list_datasets` returns a candidate. The MCP pin is now folded into `packages/mcp/src/mcp-dataset-tools.test.ts` as a top-level describe (AGENTS.md ruling 6583487846); the separate file is deleted. ## Follow-up round After #34881 landed (`c6ecd1fab8`), this round did four things: - **Merged `origin/main`** (`c81f498b5f`) as merge `762b721b`, with the trailers on the merge commit. It merged cleanly. #34881's changes to `mcp-dataset-tools.test.ts`, `skill-md.ts` and the `DATASET_SELECTION_RULE` docblock all came in as written. - **Folded the MCP pin** into `packages/mcp/src/mcp-dataset-tools.test.ts` as a top-level describe with the same 3 tests. It reuses the harness's `makeBridge` and `callTool`. `packages/mcp/src/list-datasets-candidates-34763.test.ts` is deleted, and the checklist's `automated.ref` no longer names it. - **Updated the docblock.** #34881's docblock above `DATASET_SELECTION_RULE` now also says: - two words with one measure match each are two metrics, both computed; - a word with `candidates` is the same question, listing label, dataset label and description, never a pick and never a match, even for a single candidate; - only a word with no match and no candidate falls back, labelled. The rule string itself is unchanged from the first round. - **Checked that the merged tree agrees with "one candidate asks".** I grepped for `near form`, `selects nothing`, `loose form` and `single candidate` across `packages/mcp`, service-analytics, `skills/objectstack-ask` and the docs. The only text that differs is the skill's row "One near form is not a match either: it selects nothing" in `skills/objectstack-ask/SKILL.md` and in the generated `packages/mcp/src/ask-skill.generated.ts`. Since #34881, that generated file is what the served `/mcp/skill` text is rendered from. This difference is expected until #34868 amends the skill. The tool description, the `initialize` rule, `packages/mcp/README.md` and `content/docs/ai/connect-mcp.mdx` all say to ask. <details><summary>Follow-up runs at 883af46</summary> - Full `turbo run build` under the lock: `VERDICT command-exit 0`. - Under the lock, each exit echoed separately: - `pnpm --filter @objectstack/service-analytics typecheck`: exit 0. - `pnpm --filter @objectstack/mcp typecheck`: exit 0 (`check:test-typecheck: OK — 6 file(s) / 53 error(s) / 8 pinned signature(s) held`). - service-analytics vitest: `Test Files 218 passed (218)`, `Tests 5558 passed | 335 skipped (5893)`. - mcp vitest: `Test Files 71 passed (71)`, `Tests 1252 passed (1252)`. - `mcp-dataset-tools.test.ts` with the verbose reporter: `Tests 25 passed (25)`, including the three `[#34763]` tests. - `dispatch-gates --commands` (no paths) at `883af46685` derived the same 100 families, and all 100 exited 0. `--ran`: `100 run, 0 NOT-MEASURED (a DERIVED zero)`. - `check:platform-checklist`: OK. - `check-governed-merges --branch`: NOT governed, 468 changed lines (+436 / -32). - `overlap-check`: exit 0 against `origin/main` `c81f498b5f`. It also checked #34928, which shares `dataset-term-matcher.ts`, and merges cleanly. </details> --- _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 fff0ad0 commit 44c7a4a

10 files changed

Lines changed: 436 additions & 32 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/service-analytics': patch
3+
'@objectstack/mcp': patch
4+
---
5+
6+
feat(analytics): `list_datasets` offers `candidates` for a term that matched nothing, and the selection text says to ask about them
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
A business word that equalled no member's name, label or synonym used to get nothing back, so an AI went straight to the object query tools even when a listed measure was obviously what the user meant (`invoice` beside the measure labelled `Invoices`).
12+
13+
`list_datasets` now fills the `candidates` member the spec already declares: for each term with no match in any listed dataset, the members near it, as `{ term, dataset, member }` pointers to members listed in the same answer.
14+
15+
- **Near** means that, after the same normalization the matcher uses, one of the member's names, labels (any locale) or synonyms contains the term, or the term contains it, with both at least two characters (code points) long. `金额` is near `合同金额` and the reverse. No edit distance, stems or embeddings.
16+
- **Only what the caller may read.** Candidates come from the datasets and members the answer lists. A member over a field the caller cannot read, a member over an `internal` field, and a dataset the caller may not query are never offered.
17+
- **Never beside a match.** A term with a match anywhere in the answer has no candidates. What counts as a match is unchanged.
18+
- **Listing order, capped.** Terms in the order sent (a repeated term is offered once), then datasets in the order listed, then each dataset's measures before its dimensions. At most `LIST_DATASETS_MAX_CANDIDATES_PER_TERM` (5) per term, with no marker for the cut. When nothing is offered the key is absent, never an empty list.
19+
20+
The `list_datasets` tool description and the `initialize` selection rule the HTTP MCP server sends now say: each word that matches exactly one measure is computed, and two such words are two metrics computed both; one word matching several measures is a question for the user; a word with `candidates` is the same question, listing each candidate's label, dataset label and description, and a candidate is never picked or treated as a match; no match and no candidates falls back to the object tools, saying the answer is not from a governed metric.

‎content/docs/ai/connect-mcp.mdx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,14 @@ between a governed metric and an object query, because a client reads a tool's
289289
description only after it has chosen that tool. Where both dataset tools are
290290
registered for the connection, the instructions say: look for a governed metric
291291
first by calling `list_datasets` with the question's business words; a word
292-
matches only when it equals a name, label or synonym; one measure match is
293-
answered with `query_dataset`; several matches are a question for the user; no
294-
match falls back to `query_records` / `aggregate_records`, saying the answer is
295-
not from a governed metric. A token without `data:read` gets neither tool and no
292+
matches only when it equals a name, label or synonym; each word with exactly one
293+
measure match is answered with `query_dataset`, and two such words are two
294+
metrics computed both; several matches are a question for the user; a word with
295+
no match but with `candidates` in the answer (members offered as possible
296+
readings) is the same question, listing each candidate's label, dataset label
297+
and description, and is never treated as a match; no match and no candidates
298+
falls back to `query_records` / `aggregate_records`, saying the answer is not
299+
from a governed metric. A token without `data:read` gets neither tool and no
296300
such sentence.
297301

298302
The instructions also name the published skills package and the version to

‎docs/qa/platform-checklist/areas/ai.json‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@
11371137
"title": "MCP serves the governed datasets: list_datasets lists each dataset this caller may query with its members and reports which terms match which member, and query_dataset answers rows with provenance, a row count and a truncation fact, never SQL",
11381138
"since": "v18.4",
11391139
"status": "active",
1140-
"revision": 2,
1140+
"revision": 3,
11411141
"priority": "P1",
11421142
"surface": "api",
11431143
"personas": [
@@ -1157,13 +1157,14 @@
11571157
"call query_dataset { datasetName: 'showcase_invoice_metrics', selection: { measures: ['invoice_count'], dimensions: ['status'] } }",
11581158
"the same with selection.limit: 1",
11591159
"query_dataset { datasetName: 'qa_no_such_dataset', selection: { measures: ['invoice_count'] } }",
1160-
"query_dataset { dataset: 'showcase_invoice_metrics', selection: { measures: ['invoice_count'] } }; then { datasetName: 'showcase_invoice_metrics', measures: ['invoice_count'] }"
1160+
"query_dataset { dataset: 'showcase_invoice_metrics', selection: { measures: ['invoice_count'] } }; then { datasetName: 'showcase_invoice_metrics', measures: ['invoice_count'] }",
1161+
"a near miss: list_datasets { terms: ['invoice'] }; then list_datasets { terms: ['invoices'] }"
11611162
],
11621163
"acceptance": [
11631164
{
11641165
"clause": "a keyed session lists both tools, each described with the selection rule the model reads",
11651166
"oracle": "network",
1166-
"verify": "tools/list names list_datasets and query_dataset; the list_datasets description says one match on a measure wins and several matches ask the user (packages/services/service-analytics/src/dataset-tools.ts#getDatasetToolDefinitions; packages/mcp/src/mcp-http-tools.ts#registerDatasetTools)",
1167+
"verify": "tools/list names list_datasets and query_dataset; the list_datasets description says one match on a measure wins, several matches ask the user, and a word with candidates asks the same way and is never a match (packages/services/service-analytics/src/dataset-tools.ts#getDatasetToolDefinitions; packages/mcp/src/mcp-http-tools.ts#registerDatasetTools)",
11671168
"evidence": "the two tool entries"
11681169
},
11691170
{
@@ -1175,7 +1176,7 @@
11751176
{
11761177
"clause": "terms are matched after normalization against name, label and synonym, and each match names its member",
11771178
"oracle": "network",
1178-
"verify": "the invoice entry's matches hold { term: 'invoices', member: 'measures.invoice_count', matchedOn: 'label' } and { term: 'status', member: 'dimensions.status', matchedOn: 'name' }; qa_no_word matches nothing anywhere (packages/spec/src/ui/dataset.zod.ts#normalizeDatasetTerm; packages/spec/src/ai/dataset-tools.zod.ts#DatasetTermMatchSchema)",
1179+
"verify": "the invoice entry's matches hold { term: 'invoices', member: 'measures.invoice_count', matchedOn: 'label' } and { term: 'status', member: 'dimensions.status', matchedOn: 'name' }; qa_no_word matches nothing anywhere, and the answer carries no `candidates` key (packages/spec/src/ui/dataset.zod.ts#normalizeDatasetTerm; packages/spec/src/ai/dataset-tools.zod.ts#DatasetTermMatchSchema)",
11791180
"evidence": "the matches arrays"
11801181
},
11811182
{
@@ -1207,6 +1208,12 @@
12071208
"oracle": "test",
12081209
"verify": "run each file in automated.ref with its package's vitest and `--reporter=tree`, which prints one line per file (RUNNER.md's environment facts); each reports ≥1 test and 0 failed",
12091210
"evidence": "the vitest summary line per file, with the subject sha"
1211+
},
1212+
{
1213+
"clause": "a term that matches nothing is answered with candidates: members near it that this caller may read, offered for a question and never a match; a term that matches has none",
1214+
"oracle": "network",
1215+
"verify": "terms ['invoice']: no dataset's matches holds the term, and `candidates` holds { term: 'invoice', dataset: 'showcase_invoice_metrics', member: 'measures.invoice_count' }, each entry a pointer to a member the same answer lists, at most 5 per term. terms ['invoices']: the label match of step 2 and no `candidates` key (packages/spec/src/ai/dataset-tools.zod.ts#DatasetTermCandidateSchema; packages/services/service-analytics/src/dataset-term-matcher.ts#findDatasetTermCandidates)",
1216+
"evidence": "both answers' matches and candidates"
12101217
}
12111218
],
12121219
"negative": [
@@ -1219,7 +1226,7 @@
12191226
],
12201227
"automated": {
12211228
"kind": "unit",
1222-
"ref": "packages/services/service-analytics/src/__tests__/dataset-tools.test.ts, packages/mcp/src/mcp-dataset-tools.test.ts, packages/runtime/src/mcp-dataset-tools-bridge.test.ts; no live spec opens a keyed MCP session against the datasets"
1229+
"ref": "packages/services/service-analytics/src/__tests__/dataset-tools.test.ts, packages/services/service-analytics/src/__tests__/dataset-term-matcher.test.ts, packages/mcp/src/mcp-dataset-tools.test.ts, packages/runtime/src/mcp-dataset-tools-bridge.test.ts; no live spec opens a keyed MCP session against the datasets"
12231230
},
12241231
"source": [
12251232
"docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md D2 and D3",
@@ -1242,6 +1249,12 @@
12421249
"date": "2026-11-15",
12431250
"change": "acceptance[7].verify names `--reporter=tree`, the reporter that prints the one line per pin file this is scored on: in a runner's non-TTY shell vitest's default reporter prints the run's totals only (RUNNER.md's environment facts; QA run #33784's note 10, comment 6893243542). No clause or threshold changed. Card #33969",
12441251
"ref": "#34068"
1252+
},
1253+
{
1254+
"revision": 3,
1255+
"date": "2026-11-17",
1256+
"change": "a near-miss step and its clause: list_datasets answers a term that matched nothing with `candidates` (ADR-0149 D3 amendment note), and qa_no_word carries none; the description clause names the candidates row; automated.ref names the candidate pins. Card #34763",
1257+
"ref": "#34763"
12451258
}
12461259
]
12471260
},

‎packages/mcp/README.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ grant, then two parts:
7878

7979
- **The selection rule**, only where this request registers both
8080
`list_datasets` and `query_dataset`: look for a governed metric first with
81-
`list_datasets` and the question's business words; one measure match answers
82-
through `query_dataset`; several matches are a question for the user; no
83-
match falls back to the object tools and says the answer is not from a
84-
governed metric. A grant without `data:read` gets no such sentence.
81+
`list_datasets` and the question's business words; each word with exactly
82+
one measure match answers through `query_dataset`, and two such words are two
83+
metrics computed both; several matches are a question for the user; a word
84+
with `candidates` in the answer is the same question, never a match; no match
85+
and no candidates falls back to the object tools and says the answer is not
86+
from a governed metric. A grant without `data:read` gets no such sentence.
8587
- **The skills install line**: `Published skills: @objectstack/skills <version>`
8688
and its `pnpm add -D` command, at this package's own version (the two are
8789
released together), never the `version` option.

‎packages/mcp/src/mcp-dataset-tools.test.ts‎

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
* bridge's definitions carry, never a copy in this package; the arguments reach
1111
* the bridge as sent, with the tool's page cap beside them; an undeclared key is
1212
* refused before the bridge is asked, in the spec's words; a refusal the bridge
13-
* throws comes back as the coded tool error.
13+
* throws comes back as the coded tool error; `list_datasets.candidates` comes
14+
* back exactly as the executor answered it (#34763).
1415
*/
1516

1617
import { describe, it, expect, beforeEach, vi } from 'vitest';
1718
import {
1819
LIST_DATASETS_TOOL_NAME,
20+
ListDatasetsOutputSchema,
1921
MCP_OAUTH_SCOPE_DATA_READ,
2022
MCP_OAUTH_SCOPE_DATA_WRITE,
2123
QUERY_DATASET_TOOL_NAME,
@@ -369,3 +371,75 @@ describe('[ADR-0149 D2] dataset tools on MCP — the spec refusal is kept whole'
369371
expect(bridge.calls.filter((c) => c[0] === 'listDatasets')).toEqual([]);
370372
});
371373
});
374+
375+
/**
376+
* [#34763, ADR-0149 D3 amendment note] `list_datasets.candidates` reaches an
377+
* MCP client exactly as the executor answered it. The members offered for a
378+
* term that matched nothing are chosen by the service-analytics executor
379+
* (`findDatasetTermCandidates`, pinned there); the MCP tool layer holds no copy
380+
* of that rule and must neither drop the key, reorder its entries nor add one.
381+
*/
382+
describe('[#34763] list_datasets candidates pass through MCP unchanged', () => {
383+
const WITH_CANDIDATES: ListDatasetsOutput = {
384+
datasets: [
385+
{
386+
name: 'showcase_invoice_metrics',
387+
label: 'Invoice Metrics',
388+
object: 'showcase_invoice',
389+
dimensions: [{ name: 'status', label: 'Status', type: 'string' }],
390+
measures: [
391+
{ name: 'invoice_count', label: 'Invoices', aggregate: 'count' },
392+
{ name: 'paid_count', label: 'Paid Invoices', aggregate: 'count' },
393+
],
394+
matches: [],
395+
},
396+
],
397+
candidates: [
398+
{ term: 'invoice', dataset: 'showcase_invoice_metrics', member: 'measures.invoice_count' },
399+
{ term: 'invoice', dataset: 'showcase_invoice_metrics', member: 'measures.paid_count' },
400+
],
401+
};
402+
const WITHOUT_CANDIDATES: ListDatasetsOutput = {
403+
datasets: [{
404+
...WITH_CANDIDATES.datasets[0],
405+
matches: [{ term: 'invoices', member: 'measures.invoice_count', matchedOn: 'label' }],
406+
}],
407+
};
408+
409+
function bridgeAnswering(answer: ListDatasetsOutput) {
410+
const bridge = makeBridge();
411+
bridge.listDatasets = async (input) => {
412+
bridge.calls.push(['listDatasets', input]);
413+
return answer;
414+
};
415+
return bridge;
416+
}
417+
418+
let runtime: MCPServerRuntime;
419+
beforeEach(() => {
420+
runtime = new MCPServerRuntime({ name: 't', version: '1.0.0' });
421+
});
422+
423+
it('the fixtures are answers the spec accepts', () => {
424+
expect(ListDatasetsOutputSchema.safeParse(WITH_CANDIDATES).success).toBe(true);
425+
expect(ListDatasetsOutputSchema.safeParse(WITHOUT_CANDIDATES).success).toBe(true);
426+
});
427+
428+
it('passes the executor\'s candidates through unchanged: same entries, same order, nothing added', async () => {
429+
const bridge = bridgeAnswering(WITH_CANDIDATES);
430+
const json = await callTool(runtime, bridge, LIST_DATASETS_TOOL_NAME, { terms: ['invoice'] });
431+
expect(json.result?.isError).toBeFalsy();
432+
const answer = JSON.parse(json.result!.content[0].text) as ListDatasetsOutput;
433+
expect(answer).toEqual(WITH_CANDIDATES);
434+
expect(answer.candidates).toEqual(WITH_CANDIDATES.candidates);
435+
expect(bridge.calls.filter((c) => c[0] === 'listDatasets')).toEqual([['listDatasets', { terms: ['invoice'] }]]);
436+
});
437+
438+
it('an answer without candidates comes back without the key', async () => {
439+
const json = await callTool(runtime, bridgeAnswering(WITHOUT_CANDIDATES), LIST_DATASETS_TOOL_NAME, { terms: ['invoices'] });
440+
expect(json.result?.isError).toBeFalsy();
441+
const answer = JSON.parse(json.result!.content[0].text) as ListDatasetsOutput;
442+
expect(answer).toEqual(WITHOUT_CANDIDATES);
443+
expect('candidates' in answer).toBe(false);
444+
});
445+
});

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,17 +1805,26 @@ const DEFAULT_HTTP_INSTRUCTIONS =
18051805
* tools' own descriptions and in the served skill's data loop
18061806
* (`ASK_SKILL_DATA_LOOP`, generated from `skills/objectstack-ask/SKILL.md` and
18071807
* rendered by `skill-md.ts`). All three hold an exact name, label or synonym as
1808-
* the only match, one measure match as the answer, and several matches on one
1809-
* word as a question for the user; the skill also asks before it falls back
1810-
* when a word with no match is a loose form of several listed measures.
1808+
* the only match, one measure match as the answer (two words with one measure
1809+
* match each are two metrics, both computed), and several matches on one word
1810+
* as a question for the user. [#34763] A word with no match may come back with
1811+
* `list_datasets` `candidates` (the ADR-0149 D3 amendment note): the rule makes
1812+
* that the same question, listing each candidate's label, dataset label and
1813+
* description, never a pick and never a match, even for a single candidate;
1814+
* only a word with no match and no candidate falls back to the object tools,
1815+
* with the answer labelled. The skill's own loose-form rows predate
1816+
* `candidates` and are amended in its lane.
18111817
* Sent only where both dataset tools register ({@link datasetToolsServed}).
18121818
*/
18131819
const DATASET_SELECTION_RULE =
18141820
'For a question about a business number, look for a governed metric first: call list_datasets with the '
18151821
+ 'question\'s business words. A word matches only when it equals a measure\'s or dimension\'s name, label or '
1816-
+ 'synonym, never a similar word. One measure match: answer with query_dataset. Several matches: ask the user '
1817-
+ 'which one they mean; do not pick. No match: fall back to query_records / aggregate_records and say the answer '
1818-
+ 'is not from a governed metric.';
1822+
+ 'synonym, never a similar word. Each word that matches exactly one measure: answer with query_dataset; two '
1823+
+ 'such words are two metrics, so compute both. One word matching several measures: ask the user which one '
1824+
+ 'they mean; do not pick. A word with no match but with candidates in the answer: ask the same way, listing '
1825+
+ 'each candidate\'s label, dataset label and description; do not pick one or treat it as a match. No match '
1826+
+ 'and no candidates: fall back to query_records / aggregate_records and say the answer is not from a governed '
1827+
+ 'metric.';
18191828

18201829
/**
18211830
* [#34686] The published skills package an open server points a client to

0 commit comments

Comments
 (0)