Skip to content

Commit c6ecd1f

Browse files
fix(mcp): render the /mcp/skill data loop from the published objectstack-ask skill (#34881)
<!-- 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 #34686 This is the second half of the card: the data-loop text of `GET /mcp/skill` is now rendered from the published ask-data skill (`skills/objectstack-ask/SKILL.md`, landed by #34685 as `581c9165`), and a test pins the two equal. The first half (the HTTP `initialize` instructions) landed as #34790 (`c513d62a`). Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:`/mcp/skill` 页面里"问数"那段流程不再手写,改为由脚本从已发布的 `objectstack-ask` 技能正文生成进 `packages/mcp/src/ask-skill.generated.ts`,页面在新小节 "Answering a business question" 下原样输出;两个数据集工具条目只留签名和返回内容一句话。 - **为什么改**:手写版已经和技能文字分叉(例如 `membersWithheld` 的说法、松散词要先反问、两个词各命中一个指标要都算)。卡片要求单一来源,并用测试钉住两者相等。 - **风险与回滚**:只影响带数据集工具且凭据有 `data:read`(或无 scope)的页面,其他宿主和凭据的页面逐字节不变。全量宿主页面从 16,623 增至 20,272 字节。回滚就是 revert 本 PR。范围外文件:`turbo.json` 加两行测试输入(门禁强制);修复轮 1 在 `scripts/pm/dispatch-gates.data.mjs` 加一行分类(修 CI 的 PM dispatch-gates 自测)。 - **先看**:`packages/mcp/src/skill-md.ts`(`datasetToolsTaught` 门与 `renderAskSection` 插入位置)、`scripts/gen-mcp-ask-skill.mjs`(截取规则:技能 H1 标题之后的全部正文)、`packages/mcp/src/skill-single-source-34686.test.ts`。 - **两分钟验证**:`pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2 src/skill-single-source-34686.test.ts`,预期 3 个测试全绿;改技能里任意一个词再跑,预期 2 个转红。 - **需要你做的**:无,席位落地。 ## What changes - **Mechanism (measured, then chosen).** A generated module committed in the package, held equal to the skill by a test: - `scripts/gen-mcp-ask-skill.mjs` writes `packages/mcp/src/ask-skill.generated.ts` (`ASK_SKILL_DATA_LOOP`, one string) from `skills/objectstack-ask/SKILL.md`. `--check` exits 1 when the module is stale or missing, and writes nothing. - Why not a read of the skill at run time: `@objectstack/mcp` ships only `dist`, README and CHANGELOG (`files[]`), so `skills/**` is not on disk in an installed package; and `@objectstack/skills` exports only `./package.json`, so a runtime dependency on it would mean a filesystem read of another package's build output on every host. Not chosen. - Why not a bundler inline (an esbuild text loader importing the `.md`): turbo hashes `@objectstack/mcp#build` from the package directory plus the root scripts `turbo.json` lists (`build.inputs` is `$TURBO_DEFAULT$` plus those), and `skills/**` is not among them. A skill-only edit would replay a cached `dist` carrying the old text. It would also need a tsup config change, a `*.md` module declaration for `tsc`, and a vitest loader. Not chosen. - A module under `src/` is hashed with the package, ships in its `dist` (measured: the section heading and the skill's sentence "One near form is not a match either" are in `dist/index.js` and `dist/index.cjs` after `pnpm --filter @objectstack/mcp build`), and the pin test goes red on any difference. - **Which part of the skill is the data loop.** The skill's body after its title: every line after its one H1 (`# Answering a business question over an ObjectStack environment`), with blank lines at either end dropped. That is the intro paragraph and steps 1 to 6 (lift the words, decide by the matches with the step 2 table, compute, fall back, when the data cannot answer, writing the answer). The frontmatter and the title stay with the skill. The served page gives the text its own heading, `## Answering a business question` (`ASK_SECTION_HEADING`), and copies the rest byte for byte, the skill's `##` step headings included. - **What stays served-page prose.** The two entries in the page's tool list, `list_datasets({ terms? })` and `query_dataset({ datasetName, selection })`, keep a one-sentence description of what each answer carries and point to the section. Every rule (selection, `membersWithheld`, fallback, data that cannot answer) now comes only from the skill. - **Gate unchanged.** `datasetToolsTaught` is the condition `renderDatasetToolLines` held inline: `datasetTools === true` AND (no scopes OR scopes include `data:read`). Both the tool entries and the section render only under it. The section is placed after every other block of the tool list (file, dataset, federation, authoring, data-only) and before `## Conventions & gotchas`, so a render that does not teach the pair is byte-identical to before. The route `packages/runtime/src/domains/mcp.ts` is unchanged. - **Comment fix** in `packages/mcp/src/mcp-server-runtime.ts`: the `DATASET_SELECTION_RULE` doc comment pointed at `DATASET_TOOL_LINES` as holding "the same thing". It now points at `ASK_SKILL_DATA_LOOP` and states where the skill goes further. No code change there. - **Changeset** `.changeset/34686-skill-single-source.md`: `@objectstack/mcp` patch, `Clause-②: no`, `Metadata-protocol: none`. ### Old served text vs new (every divergence found) Old = `DATASET_TOOL_LINES` at `7752cac7` (`packages/mcp/src/skill-md.ts:265-292`). New = the skill, as now served. 1. **`membersWithheld`.** Old: "some measures exist that you may not read: say so rather than saying the metric does not exist." New: "Say that it has members (measures or groupings) you may not read; the metric asked for may be among them. Do not say the metric does not exist." 2. **Row 1, one match per word.** Old: "One measure match: answer with `query_dataset`." New: "Each word for a thing measured matches exactly one measure: compute. Two words with one measure each ("营收和赢单率") are two metrics, not a choice: compute both, with one `query_dataset` per dataset." 3. **Row 2, several matches.** Old: "Several matches (two datasets or two members): ask the user …; do not pick." That read as asking whenever the answer held more than one match. New: "One word matches several measures, in one dataset or in two: ask …". Several matches across different words are row 1 (compute both). 4. **Loose-form row (new).** Old: no match always fell back. New: "Nothing matches, and the word is a loose form of several listed measures: ask the user which one they mean … Do not pick one, and compute nothing yet", plus the paragraph defining a loose form ("revenue" against Won Revenue, Annual Revenue and Planned Revenue). 5. **"One near form is not a match either: it selects nothing" (new),** on the fallback row. 6. **Dimension-only row.** Old: "A dimension match alone … is not an answer: you still need a measure match, or ask." New: "That is a grouping ("by stage"), not a number. You still need a measure match; without one, ask which number is meant." Same meaning. 7. **Terms.** New: pass the words "as the user wrote them and in the user's language. Do not translate or reword a term". Old said only "the business words of the question". 8. **Asking.** New: "the reply is the question alone: no figure, and no tool call until the user answers"; `partial: true` / `warning` on the catalogue are explained. Old had neither. 9. **`query_dataset`.** Old named `measures`, `dimensions`, `runtimeFilter`. New adds `dateGranularity`, `order`, `limit`, and `truncated` / `warning` handling. Provenance and description use are the same. 10. **Fallback.** Old: "fall back to `query_records` / `aggregate_records` and say the answer is not from a governed metric." New (step 4): `list_objects` then `describe_object`, filter an option field by its `value`, use `aggregate_records` and never add up pages of `query_records`, open with one line saying it is not from a governed metric (非指标口径) naming the object and fields, and add one line naming a listed dataset on that object (ADR-0149 D3 rule 4's recommended practice; the old page did not carry it). 11. **When the data cannot answer.** Old: "… Never fill the gap with an assumed value, nor draw a conclusion from one ("under a typical term, none would…"). Any figure you add comes from a tool answer; cite it." New (step 5): "Never fill the gap with an assumed value, and never draw a conclusion from one." The quoted example is gone, and "Any figure … cite it" becomes step 6's "Every figure comes from a tool answer in this conversation." 12. **Writing the answer (new, step 6):** the user's language, labels rather than machine names or raw option values, the filter and time window stated in words. 13. **Intro (new):** "Never skip step 1: a governed metric … outranks a number you work out yourself." The skill's line "No `list_datasets` among your tools: … Go to step 4" is served too. On this page it never applies, because the section renders only where `list_datasets` is registered. It is kept so the copy stays exact. ### `/mcp/skill` size, bytes (UTF-8) In-process `renderSkillMarkdown` with `mcpUrl: 'http://localhost:3000/api/v1/mcp'`, no `grantedScopes` (what the public route passes for every caller, admin included): | Host carries | Before (`7752cac7`) | After (`e8dd0048`) | |:--|--:|--:| | file tools + new-record upload links + dataset tools | 16,623 | 20,272 | | file tools + dataset tools | 15,943 | 19,592 | | dataset tools only | 14,859 | 18,508 | | file tools + new-record upload links, no dataset tools | 14,707 | 14,707 | | file tools, no dataset tools | 14,027 | 14,027 | | none | 12,943 | 12,943 | The first row is the card's `examples/app-crm` reading. The card measured 16,625 with a five-digit port, which adds one byte to each of the URL's two occurrences. After, with grants: `data:read` 19,031; `data:write` 14,184; `metadata:write` 12,943 (no dataset text in the last two). ## Tests - **New `packages/mcp/src/skill-single-source-34686.test.ts`, 3 tests.** It reads `skills/objectstack-ask/SKILL.md` and takes its data loop by the generator's rule. (1) `ASK_SKILL_DATA_LOOP` equals it. (2) The section `renderSkillMarkdown` serves under `ASK_SECTION_HEADING` equals it, for four renders: unscoped, a full host with a URL, `data:read`, and `data:read` + `metadata:write` with an authoring tool. (3) The gate still drops it: `data:write`, `metadata:write`, an empty grant, no `datasetTools`, and `datasetTools: false` with `data:read` each render no section, no step heading and no `list_datasets`. The failure text says to run `node scripts/gen-mcp-ask-skill.mjs`. - **`packages/mcp/src/mcp-dataset-tools.test.ts`, two tests rewritten.** "renders the rule…" asserted the old prose ('Choosing between a metric and an object query', 'nor draw a conclusion from one', 'Any figure you add comes from a tool answer; cite it.'). Those words are now the skill's, and the new file pins the whole section byte-equal to it. The two tests now assert the section heading is present, sits after `**query_dataset(` and before the conventions, and is absent without the pair. The third test (the `data:read` gate on `list_datasets`) is unchanged. - The Console mirror pin (`skill-md.test.ts`, `renderObjectStackSkill(options) === renderSkillMarkdown(options)`) and the native-surface drift guard (`skill-md-surface-guard.test.ts`) pass unchanged. The mirror renders no dataset text, so the Console copy (`ui/apps/console/src/pages/developer/objectstack-skill.ts`) needs no edit. <details><summary>Test runs (head e8dd004 unless stated)</summary> - `pnpm --filter @objectstack/mcp test` (under the shared verify lock): `Test Files 70 passed (70)`, `Tests 1244 passed (1244)`, `VERDICT command-exit 0`. - `pnpm --filter @objectstack/mcp typecheck` at `29cd2d0e` (the second commit touches only `turbo.json` and the registry): `tsc --noEmit` exit 0, then `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), `VERDICT command-exit 0`. - `node scripts/gen-mcp-ask-skill.mjs --check`: `packages/mcp/src/ask-skill.generated.ts is current with skills/objectstack-ask/SKILL.md.`, exit 0. Before the module existed, the same command printed `is missing … Run: node scripts/gen-mcp-ask-skill.mjs` and exited 1. - `pnpm --filter @objectstack/mcp build`: `check-dts-emitted: @objectstack/mcp - 2/2 declared declaration file(s) present.` </details> <details><summary>Ablation (one-shot, scripts/ablation-replace.mjs, at 29cd2d0)</summary> One word of the skill, in the worktree only: anchor `outranks a number you work out yourself` was replaced by `outranks a number you compute yourself`. Output: `anchor x1 -> x0`, `replace x0 -> x1`, `blob 482410f -> 7e726754f3fa`. Then `× the generated module equals the skill's data loop`, `× the served section equals the skill's data loop, for every grant that is taught the dataset pair`, `Tests 2 failed | 1 passed (3)`. Restore: `ok restored: blob == HEAD (482410f) and git diff HEAD is empty`. `git hash-object` of the file and `HEAD:skills/objectstack-ask/SKILL.md` were both `482410fbd632e8e09f9e1d88017906f35d58fc4a` afterwards. No `dist/` is involved: the test imports the module from source and reads the skill from disk. </details> ## Outside the claimed surface The claim's PR2 surface is `packages/mcp/src/skill-md.ts`, new modules and tests in `packages/mcp/src/`, `packages/runtime/src/domains/mcp.ts` (not touched), `scripts/cross-package-test-inputs.mjs` and `.changeset/`. Outside it: - `scripts/gen-mcp-ask-skill.mjs`: new, the generator. No `package.json` script was added. A `gen:` script would enter the generator ledger that `git-merge-regen.mjs` reconciles; the pin test already fails in CI on drift. - `turbo.json`: two lines added to `@objectstack/mcp#test` inputs (`$TURBO_ROOT$/skills/objectstack-ask/SKILL.md`, `$TURBO_ROOT$/scripts/gen-mcp-ask-skill.mjs`). `check:cross-package-test-inputs` requires every glob declared in the registry to be mirrored there. Without them it is red: `turbo.json "@objectstack/mcp#test" inputs are missing the declared glob(s): $TURBO_ROOT$/skills/objectstack-ask/SKILL.md`. The generator is declared because the test names it in its failure text, and the gate flagged it as `named in packages/mcp/src/skill-single-source-34686.test.ts`. - `packages/mcp/src/mcp-server-runtime.ts`: doc comment only, see What changes. - `packages/mcp/src/mcp-dataset-tools.test.ts`: an existing test file, see Tests. - `scripts/pm/dispatch-gates.data.mjs`: one `GOVERNED_READ_FLOOR` row and its doc paragraph (fix round 1, below). ## Acceptance notes - **`DATASET_SELECTION_RULE` vs the skill.** This is the `initialize` rule from #34790, at `packages/mcp/src/mcp-server-runtime.ts:1813-1818` on this head. Not changed here. It says "Several matches: ask the user which one they mean" and "No match: fall back to query_records / aggregate_records". The skill (`skills/objectstack-ask/SKILL.md:48`, `:51`) computes two metrics when two words each match one measure, and asks before falling back when a word with no match is a loose form of several listed measures. The `list_datasets` tool description (`packages/services/service-analytics/src/dataset-tools.ts:85-96`) carries the same text as the rule, and ADR-0149 D3's amendment names #34763 as the carrier for the tool descriptions' question-before-fallback branch. Changing only the instructions here would make them disagree with the tool description instead. This is left to the seat (see the report). - The section serves the skill's line "No `list_datasets` among your tools … Go to step 4" on a page that only renders where `list_datasets` is registered. It is inert there and kept for exactness. - The skill's step headings are served as `##`, siblings of the page's own `##` sections. They are not demoted, because a transform would make the copy no longer the skill's bytes. ## Verification - Gates: `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 84 families at `29cd2d0e` and 85 at `e8dd0048` (`+ pnpm check:turbo-task-graph` for `turbo.json`). All were run locally. Reconciliation `--ran` with exit codes: `85 derived famil(ies) accounted for — 84 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)`. - `pnpm check:cross-package-test-inputs` was red at `29cd2d0e` (the two findings quoted above). After the `turbo.json` and registry commit: `OK: 32 package(s) read outside themselves, all declared, and turbo.json hashes every declared glob`. - `pnpm check:ci-filter-parity` and `pnpm check:turbo-task-graph` were re-run after that commit: both OK. - NOT MEASURED: `check:dual-build-cjs-loads`, reason: `PREREQUISITE NOT MET — this gate reads built output, and some package has no dist/` (48 unbuilt packages outside this diff's closure). It runs in CI's Lint & Repo Gates. - `node scripts/pm/check-governed-merges.mjs --branch claude/issue-34686-skill-single-source`: `0 of 9 path(s) hit the register … NOT governed`, 465 changed lines. - `node scripts/pm/overlap-check.mjs` on `e8dd0048`: `origin/main: merges cleanly`, `VERDICT clean exit 0`. - Lint of the changed files (`pnpm exec eslint --no-inline-config` on the seven code files): exit 0. The repo-wide lint is CI's. ## Fix round 1 CI on `e8dd0048` was red on `Lint · PM dispatch-gates` (and so on `Lint & Repo Gates`) with one self-test case: `every structural read of a GOVERNED file under scripts/ is classified in GOVERNED_READ_FLOOR — unpinned: scripts/gen-mcp-ask-skill.mjs::skills/objectstack-ask/SKILL.md`, `1 of 2217 case(s) failed`. Reproduced locally with `pnpm check:pm-dispatch-gates`: the same single failure. - **Fix (`4a78d86b`):** one row in `GOVERNED_READ_FLOOR` (`scripts/pm/dispatch-gates.data.mjs`), `{ script: 'scripts/gen-mcp-ask-skill.mjs', file: 'skills/objectstack-ask/SKILL.md', declared: false }`, with an "eighth row" doc paragraph. `declared` is false because the floor reads it off a `self-test-reads` line, and the generator has no self-test; it spells the skill path in its module body, the shape of the `check-skill-top-level-keys.mjs` row. The case `each pinned row's DECLARED flag still reads off the file` passes, so the flag is the live one. - **No gate family runs the generator**, so the census case `every governed read in the census is DERIVED for the file it reads` has no family to place it under (it passes: `none underived`). Nothing new was declared. A change to `skills/objectstack-ask/SKILL.md` alone derives 27 families (for example `check:skill-docs`, `check:cross-package-test-inputs`, `check-skills-token-ratchet.mjs`), and none of them is `gen-mcp-ask-skill.mjs --check`. What re-runs on such a change is the `@objectstack/mcp` test suite (Test Core), through the `turbo.json` input and the `cross-package-test-inputs` row added earlier in this PR, and its `skill-single-source-34686.test.ts` fails on drift and names the generator. - **After the fix:** `pnpm check:pm-dispatch-gates` exit 0, `✓ dispatch-gates self-test (fast tier): 2217 cases pass; 9 slow section(s) deferred.` - `check-governed-merges --branch`: `0 of 10 path(s) hit the register … NOT governed`, 482 changed lines. The branch merges cleanly with `origin/main` (`fc5913e1`), so it was not merged. `overlap-check` on `4a78d86b`: `VERDICT clean exit 0` (it shares `dispatch-gates.data.mjs` with #34893 and #34841, and both merge cleanly). A first run had answered exit 3 (`files of #34837 unreadable`) and the re-run answered clean. <details><summary>Gates for this round</summary> The 63 families derived for `scripts/pm/dispatch-gates.data.mjs` were run locally on `4a78d86b`: 62 exit 0, and `pnpm check:i18n-coverage` exit 3 (PREREQUISITE NOT MET: unbuilt `dist/`), so it is NOT MEASURED here. `--ran` over the whole branch: `115 derived, 62 run, 1 NOT-MEASURED, 52 UNRUN`. The 52 unrun are derived from this PR's earlier files, which this round did not change. On `e8dd0048` every check-run but the two above was success or skipped. </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 b8408d8 commit c6ecd1f

10 files changed

Lines changed: 425 additions & 57 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/mcp': patch
3+
---
4+
5+
fix(mcp): the data loop on `GET /mcp/skill` is the published `objectstack-ask` skill's text
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The page an open server serves at `GET /mcp/skill` taught the governed-metric procedure in its own hand-written words, and those words had drifted from the published `objectstack-ask` skill. The page now carries the skill's own steps, generated from `skills/objectstack-ask/SKILL.md` into the package, under a new section **Answering a business question**. A test fails when the two differ.
11+
12+
What a connected client now reads on that page, where it reads differently from before:
13+
14+
- Each word for a thing measured is decided on its own: two words with one measure each are two metrics, computed both, not a question for the user. One word that matches several measures is still a question.
15+
- A word with no match that is a loose form of several listed measures (a bare "revenue" beside Won Revenue, Annual Revenue and Planned Revenue) is a question too, with nothing computed yet. One near form selects nothing.
16+
- `membersWithheld: true` is reported as members (measures or groupings) the user may not read, and the metric asked for may be among them.
17+
- The fallback to object queries reads the object's fields first, uses `aggregate_records` rather than adding pages up, opens with a line saying the answer is not from a governed metric, and names a listed dataset on that object when there is one.
18+
- The answer is written in the user's language, with labels rather than machine names, and states its filter and time window.
19+
20+
The two dataset tool entries in the page's tool list now give only each tool's signature and what its answer carries. The section renders where it did before and nowhere else: only when the host carries the dataset tools and the grant has `data:read` (or names no scopes). Pages for other hosts and grants are byte-identical to before.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
// GENERATED by scripts/gen-mcp-ask-skill.mjs from skills/objectstack-ask/SKILL.md.
4+
// Do not edit this file: change the skill, then run `node scripts/gen-mcp-ask-skill.mjs`.
5+
6+
/**
7+
* The ask-data skill's data loop: its body after the title, served under its
8+
* own heading by `renderSkillMarkdown` (`skill-md.ts`) where the dataset tools
9+
* register for the grant. One source: the published skill.
10+
*/
11+
export const ASK_SKILL_DATA_LOOP: string = [
12+
'You are connected to a live environment through its MCP tools, and the user',
13+
'asked for a figure or a list from its data. Work these steps in order for every',
14+
'question. Never skip step 1: a governed metric (a dataset measure whose owner',
15+
'wrote its business definition) outranks a number you work out yourself.',
16+
'',
17+
'## 1. Lift the business words and look for a governed metric',
18+
'',
19+
'- Lift the question\'s business words: the thing measured ("win rate", "营收",',
20+
' "商机数") and what it is grouped or filtered by ("by stage", "按行业").',
21+
'- Call `list_datasets({ terms })` with those words, as the user wrote them and',
22+
' in the user\'s language. Do not translate or reword a term: a match on a word',
23+
' you supplied is your reading, not the user\'s.',
24+
'- Each dataset in the answer carries `matches`: one entry per hit, with the',
25+
' `term`, the `member` it names (`measures.<name>` or `dimensions.<name>`) and',
26+
' `matchedOn`. A word matches only when it equals a member\'s name, label or',
27+
' synonym (case, spacing, `_` and `-` aside), never by similarity.',
28+
'- No `list_datasets` among your tools: this environment serves you no governed',
29+
' metrics. Go to step 4.',
30+
'',
31+
'## 2. Decide by the matches',
32+
'',
33+
'| What the answer shows | What you do |',
34+
'|:--|:--|',
35+
'| Each word for a thing measured matches exactly one measure | Compute: step 3. Two words with one measure each ("营收和赢单率") are two metrics, not a choice: compute both, with one `query_dataset` per dataset. |',
36+
'| One word matches several measures, in one dataset or in two | Ask the user which one they mean. List each candidate\'s label, its dataset\'s label and its description. Do not pick one. |',
37+
'| Only a dimension matches | That is a grouping ("by stage"), not a number. You still need a measure match; without one, ask which number is meant. |',
38+
'| Nothing matches, and the word is a loose form of several listed measures | Ask the user which one they mean, listing the same three things. Do not pick one, and compute nothing yet. |',
39+
'| Nothing matches, and the listed measures do not offer several readings of the word | Step 4, and say in the answer that no governed metric was used. One near form is not a match either: it selects nothing. |',
40+
'| `membersWithheld: true` on a dataset | Say that it has members (measures or groupings) you may not read; the metric asked for may be among them. Do not say the metric does not exist. |',
41+
'',
42+
'The same answer lists every dataset you may query with all its measures,',
43+
'matched or not (a call without `terms` returns that catalogue too), so the',
44+
'loose-form check needs no second read. A loose form is a word a listed',
45+
'measure\'s name, label or description contains, directly or in translation:',
46+
'"revenue" against Won Revenue, Annual Revenue and Planned Revenue; "金额"',
47+
'against several amounts.',
48+
'',
49+
'When you ask, the reply is the question alone: no figure, and no tool call',
50+
'until the user answers. `partial: true` on the answer means the catalogue may',
51+
'be incomplete; `warning` says why, and you repeat it when you fall back.',
52+
'',
53+
'## 3. Compute a governed metric',
54+
'',
55+
'- `query_dataset({ datasetName, selection })`. `selection.measures` and',
56+
' `selection.dimensions` take the names `list_datasets` gave;',
57+
' `selection.runtimeFilter` filters; `selection.dateGranularity` buckets a date',
58+
' dimension for a trend; `selection.order` and `selection.limit` rank.',
59+
'- Cite the source from the answer\'s `provenance` (the dataset\'s label and each',
60+
' measure\'s label, as in 「指标:营收(数据集:销售分析)」), not from memory.',
61+
'- Use the measure\'s `description` to say what the number includes and excludes.',
62+
'- `truncated: true`: more rows existed than came back. Say the result is',
63+
' partial. A `warning` on the answer narrows what you were allowed to read:',
64+
' repeat it.',
65+
'',
66+
'## 4. Fallback: object queries',
67+
'',
68+
'- `list_objects`, then `describe_object({ objectName })` on the object you will',
69+
' read. Read its fields before you filter: a field with `options` is filtered',
70+
' by the option\'s `value`, never its label.',
71+
'- Use `aggregate_records` for a count, sum, average or breakdown. Never page',
72+
' through `query_records` to add numbers up yourself. `truncated: true` on its',
73+
' answer means groups were cut off: say so.',
74+
'- Open the answer with one line saying it is not from a governed metric',
75+
' (非指标口径), and name the object and fields you computed it from.',
76+
'- When that object is a listed dataset\'s `object`, add one line naming the',
77+
' dataset and its measures, so the user can ask for the governed figure.',
78+
'',
79+
'## 5. When the data cannot answer',
80+
'',
81+
'- No metric, object or field records what the question needs: say the data you',
82+
' can read does not record it, name what is missing (such as a shipment\'s',
83+
' weight), and offer the computation if the user supplies it.',
84+
'- Never fill the gap with an assumed value, and never draw a conclusion from',
85+
' one.',
86+
'',
87+
'## 6. Writing the answer',
88+
'',
89+
'- Answer in the user\'s language.',
90+
'- Show labels, not machine names or raw option values.',
91+
'- Every figure comes from a tool answer in this conversation.',
92+
'- State the filter and the time window you used, in words.',
93+
].join('\n');

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { RETIRED_KEY_UPGRADE_GUIDE_SENTENCE } from '@objectstack/spec/shared';
2626
import { MCPServerRuntime } from './mcp-server-runtime.js';
2727
import { hasDatasetTools, type McpDataBridge } from './mcp-http-tools.js';
2828
import { createStdioDataBridge, type StdioDatasetToolsService } from './stdio-data-bridge.js';
29-
import { renderSkillMarkdown } from './skill-md.js';
29+
import { ASK_SECTION_HEADING, renderSkillMarkdown } from './skill-md.js';
3030

3131
const DATASET_TOOLS = [LIST_DATASETS_TOOL_NAME, QUERY_DATASET_TOOL_NAME].sort();
3232

@@ -273,23 +273,22 @@ describe('[ADR-0149 D2] dataset tools on MCP — calls', () => {
273273
});
274274

275275
describe('[ADR-0149 D3] the SKILL.md teaches the selection rule where the pair registers', () => {
276-
it('renders both tools and the rule for a host whose bridge carries them', () => {
276+
it('renders both tools and the ask-data data loop for a host whose bridge carries them', () => {
277277
const md = renderSkillMarkdown({ datasetTools: true });
278278
for (const name of DATASET_TOOLS) expect(md).toContain(`**${name}(`);
279-
expect(md).toContain('Choosing between a metric and an object query');
279+
expect(md).toContain(`\n${ASK_SECTION_HEADING}\n`);
280280
});
281281

282-
it('renders the rule for a question the data cannot answer beside the selection rule', () => {
282+
// [#34686] The data loop's words (the selection rule, the fallback, and a
283+
// question the data cannot answer) are the published ask-data skill's, and
284+
// skill-single-source-34686.test.ts pins the served section byte-equal to
285+
// it. What stays here is where the section sits and when it is absent.
286+
it('renders the data loop after the tool entries, and not without the pair', () => {
283287
const md = renderSkillMarkdown({ datasetTools: true });
284-
const rule = md.indexOf('**When the data cannot answer.**');
285-
expect(rule).toBeGreaterThan(md.indexOf('Choosing between a metric and an object query'));
286-
const text = md.slice(rule, md.indexOf('\n- ', rule) === -1 ? undefined : md.indexOf('\n- ', rule));
287-
expect(text).toContain('say the data you can read does not record it');
288-
expect(text).toContain('offer the computation');
289-
expect(text).toContain('Never fill the gap with an assumed value');
290-
expect(text).toContain('nor draw a conclusion from one');
291-
expect(text).toContain('Any figure you add comes from a tool answer; cite it.');
292-
expect(renderSkillMarkdown({})).not.toContain('When the data cannot answer');
288+
const section = md.indexOf(`\n${ASK_SECTION_HEADING}\n`);
289+
expect(section).toBeGreaterThan(md.indexOf('**query_dataset('));
290+
expect(section).toBeLessThan(md.indexOf('\n## Conventions & gotchas'));
291+
expect(renderSkillMarkdown({})).not.toContain(ASK_SECTION_HEADING);
293292
});
294293

295294
it('renders them for a data:read grant, and not without one or without the pair', () => {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,10 +1802,12 @@ const DEFAULT_HTTP_INSTRUCTIONS =
18021802
* (ADR-0149 D3), in the few lines `initialize` carries. It rides the
18031803
* instructions because a client reads a tool's description only after it has
18041804
* chosen that tool (#34659 ruling D5 = A); the full procedure stays in the
1805-
* tools' own descriptions and in the served skill (`DATASET_TOOL_LINES` in
1806-
* `skill-md.ts`), which say the same thing: an exact name, label or synonym is
1807-
* the only match, one measure match answers, several are a question for the
1808-
* user, none falls back to the object tools with the answer labelled.
1805+
* tools' own descriptions and in the served skill's data loop
1806+
* (`ASK_SKILL_DATA_LOOP`, generated from `skills/objectstack-ask/SKILL.md` and
1807+
* 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.
18091811
* Sent only where both dataset tools register ({@link datasetToolsServed}).
18101812
*/
18111813
const DATASET_SELECTION_RULE =

‎packages/mcp/src/skill-md.ts‎

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import type { AIToolDefinition } from '@objectstack/spec/contracts';
3434
import { MCP_OAUTH_SCOPE_DATA_READ, MCP_OAUTH_SCOPE_DATA_WRITE, MCP_OAUTH_SCOPE_METADATA_WRITE } from '@objectstack/spec/ai';
35+
import { ASK_SKILL_DATA_LOOP } from './ask-skill.generated.js';
3536
import {
3637
DELETE_AMBIGUOUS_ASKS_FIRST,
3738
DELETE_NAMED_RECORD_IS_APPROVAL,
@@ -125,7 +126,8 @@ export interface RenderSkillOptions {
125126
/**
126127
* [ADR-0149 D2] Whether the host's bridge carries the dataset pair
127128
* (`list_datasets` / `query_dataset`, `registerDatasetTools`). The entries,
128-
* and the D3 selection rule that teaches a client when to use them, render
129+
* and the ask-data skill's data loop that teaches a client when to use them
130+
* (#34686: generated from the published skill), render
129131
* only when this is true AND {@link grantedScopes} admit `data:read`, so the
130132
* skill names them exactly where `tools/list` lists them. Default false: the
131133
* renderer cannot see the bridge, so the host says so.
@@ -253,50 +255,55 @@ const NEW_RECORD_UPLOAD_LINK_LINES = ` For a record you have not created yet (a
253255
`;
254256

255257
/**
256-
* [ADR-0149 D2/D3] The dataset pair's entries and the selection rule that
257-
* tells a client when a governed metric answers instead of an object query.
258-
* The rule is ADR-0149 D3's, in the client's terms: an exact word match
259-
* (after normalization) is the only hit, one hit wins, several hits are a
260-
* question for the user, no hit falls back to the object tools with the
261-
* answer labelled as not a governed metric, and a dimension alone is not an
262-
* answer. The last entry covers a question no tool can answer: name what the
263-
* data lacks, never answer from an assumed value.
258+
* [ADR-0149 D2] The dataset pair's entries in the tool list: each tool's
259+
* signature and what its answer carries, in a sentence. When to call them and
260+
* how to read their answers (ADR-0149 D3's selection rule, the fallback, and a
261+
* question the data cannot answer) is {@link ASK_SECTION_HEADING}'s section,
262+
* which the published skill writes.
264263
*/
265264
const DATASET_TOOL_LINES = `- **list_datasets({ terms? })** — the governed datasets (business metrics)
266265
you may query: each dataset's measures and dimensions with their business
267-
labels, descriptions and synonyms. Pass the business words of the question
268-
as \`terms\`; the answer's \`matches\` says which member each word names
269-
exactly. \`membersWithheld: true\` means some measures exist that you may not
270-
read: say so rather than saying the metric does not exist.
271-
- **query_dataset({ datasetName, selection })** — compute a governed metric:
272-
\`selection\` takes \`measures\`, \`dimensions\` and a \`runtimeFilter\`, by
273-
the names \`list_datasets\` gives. The answer carries \`provenance\` (the
274-
dataset and measures used); cite the source from it, not from memory, and
275-
use a measure's \`description\` to explain what the number includes.
276-
- **Choosing between a metric and an object query.** Call \`list_datasets\`
277-
with the question's business words first. A word matches only when it
278-
equals a member's name, label or synonym (case, spacing, \`_\` and \`-\`
279-
aside), never by similarity. One measure match: answer with
280-
\`query_dataset\`. Several matches (two datasets or two members): ask the
281-
user which one they mean, listing each candidate's label, dataset and
282-
description; do not pick. No match: fall back to \`query_records\` /
283-
\`aggregate_records\` and say the answer is not from a governed metric. A
284-
dimension match alone (a grouping such as "by stage") is not an answer: you
285-
still need a measure match, or ask.
286-
- **When the data cannot answer.** No metric, object or field records what the
287-
question needs: say the data you can read does not record it and name what
288-
is missing (such as a shipment's weight), and offer the computation if the
289-
user supplies it. Never fill the gap with an assumed value,
290-
nor draw a conclusion from one ("under a typical term, none would…").
291-
Any figure you add comes from a tool answer; cite it.
266+
labels, descriptions and synonyms, and, for the \`terms\` you pass, the
267+
\`matches\` each word made.
268+
- **query_dataset({ datasetName, selection })** — compute a governed metric
269+
by the names \`list_datasets\` gives; the answer carries \`provenance\`.
270+
When to call these two, and how to read their answers: the section
271+
**Answering a business question** below.
292272
`;
293273

294-
/** The dataset pair's entries for a host whose bridge carries them, under the grant that registers them. */
295-
function renderDatasetToolLines(options: RenderSkillOptions): string {
296-
if (options.datasetTools !== true) return '';
274+
/**
275+
* [#34686] The heading the served page gives the ask-data skill's data loop.
276+
* The text under it is {@link ASK_SKILL_DATA_LOOP}, generated from
277+
* `skills/objectstack-ask/SKILL.md` (`scripts/gen-mcp-ask-skill.mjs`) and pinned
278+
* equal to it by `skill-single-source-34686.test.ts`: the published skill is
279+
* the one source, and nothing here restates it.
280+
*/
281+
export const ASK_SECTION_HEADING = '## Answering a business question';
282+
283+
/**
284+
* Whether this render teaches the dataset pair: a host whose bridge carries
285+
* them, under a grant that registers them.
286+
*/
287+
function datasetToolsTaught(options: RenderSkillOptions): boolean {
288+
if (options.datasetTools !== true) return false;
297289
// Mirrors the gate in `registerDatasetTools` (`!scopes || scopes.includes(data:read)`).
298290
const scopes = options.grantedScopes;
299-
return !scopes || scopes.includes(MCP_OAUTH_SCOPE_DATA_READ) ? DATASET_TOOL_LINES : '';
291+
return !scopes || scopes.includes(MCP_OAUTH_SCOPE_DATA_READ);
292+
}
293+
294+
/** The dataset pair's entries in the tool list, where {@link datasetToolsTaught}. */
295+
function renderDatasetToolLines(options: RenderSkillOptions): string {
296+
return datasetToolsTaught(options) ? DATASET_TOOL_LINES : '';
297+
}
298+
299+
/**
300+
* [#34686] The ask-data skill's data loop under its own heading, where
301+
* {@link datasetToolsTaught}. It renders after every other block of the tool
302+
* list and before the conventions, so a render that does not teach the pair is
303+
* byte-identical to one from before this section existed.
304+
*/
305+
function renderAskSection(options: RenderSkillOptions): string {
306+
return datasetToolsTaught(options) ? `\n${ASK_SECTION_HEADING}\n\n${ASK_SKILL_DATA_LOOP}\n` : '';
300307
}
301308

302309
/** The file pair's entries for a host whose bridge carries them, each for the grant that registers it. */
@@ -522,7 +529,7 @@ create/update payload.
522529
(the person's confirmation, in your client or in the app, for an action its
523530
author declared \`requiresConfirmation\`, the refusal of a call that sends \`confirm\`,
524531
and its refusal under an AI service account's own key whatever the call sends).
525-
${renderFileToolLines(options)}${renderDatasetToolLines(options)}${options.federationTools === true && grantsAuthoringTools(options.grantedScopes) ? FEDERATION_TOOL_LINES : ''}${authoringTools ? renderAuthoringSection(authoringTools, describeObjectRegistered) : ''}${dataOnlyBlock}
532+
${renderFileToolLines(options)}${renderDatasetToolLines(options)}${options.federationTools === true && grantsAuthoringTools(options.grantedScopes) ? FEDERATION_TOOL_LINES : ''}${authoringTools ? renderAuthoringSection(authoringTools, describeObjectRegistered) : ''}${dataOnlyBlock}${renderAskSection(options)}
526533
## Conventions & gotchas
527534
528535
- **Permissions/RLS apply to every call.** Fewer rows than expected, or a

0 commit comments

Comments
 (0)