Skip to content

Commit c787255

Browse files
feat(mcp): query_records says truncated: true on a capped page, and the stdio door counts its total (#35185)
<!-- 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 capped) Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:MCP 的 `query_records` 在一页被行数上限截断时多答一个 `truncated: true`;stdio 通道的 `total` 改为真实计数,不再拿本页行数冒充总数。 - 为什么改:模型会把被截断的一页当成全集去求和、排名;托管端已有这个提示,开源 MCP 门此前没有(#35138 的 capped 一项)。 - 风险与回滚:只加字段(仅为真时出现),不删不改既有字段;stdio 分页读多一次 count。回滚 = revert 本 PR。 - 先看:`packages/mcp/src/mcp-http-tools.ts`(`servedQueryPage` / `queryPageProbeFits` 与 `query_records` 处理器);`packages/mcp/src/stdio-data-bridge.ts`(`query` 末尾的计数);`packages/mcp/src/query-records-truncated.test.ts`。 - 两分钟验证:`pnpm --filter @objectstack/mcp exec vitest run src/query-records-truncated.test.ts`,预期 11 条全绿。 - 需要你做的:无,席位落地。 ## What changes - `query_records` (`packages/mcp/src/mcp-http-tools.ts`, this handler only) asks the bridge for one row more than the page. When that row comes back, the tool serves the page and adds `truncated: true`. The member is present only when true: a page holding every matching row, exactly `limit` rows included, answers as before. Where the bridge answers `hasMore`, it is restated from the probe, because the door counted it against the widened read. - The data door's read window refuses, never clamps, a read over `OS_DATA_MAX_PAGE_SIZE` or past `OS_DATA_QUERY_ROW_BUDGET` (`packages/types/src/query-read-limits.ts` `planQueryReadWindow`). Where the probe row would cross either, the page is read as asked and the door's counted `hasMore` decides `truncated`. Without this, a host with `OS_DATA_MAX_PAGE_SIZE` equal to the MCP page cap would refuse every full-page `query_records`. - The tool description now says the answer is one page and that a `truncated` page must not be summed, counted or ranked as if whole: read on with `offset`, or use `aggregate_records` where it is offered. - The stdio bridge's `query` (`packages/mcp/src/stdio-data-bridge.ts`) answered `{ object, records, total: records.length }` with no `hasMore` (origin/main `7d8dcf693a`, line 1378), so a capped stdio page claimed to be the whole set. The HTTP door goes through `callData('query')` (`packages/runtime/src/action-execution.ts` 858-867) into `findData`, which counts (`packages/metadata-protocol/src/protocol-data-crud.ts` 761-822). The stdio bridge now answers the same page facts: a paged read is counted under the same `where`, as the caller (`engine.count(object, { where }, { context })`). `total` is the match total and `hasMore` says whether rows remain. If the count fails, `total` is left out and `hasMore` answers from the page alone, as the data door's `$count=false` arm does. An unpaged read keeps `total: records.length` and `hasMore: false`, and no count runs. - The type stays local to `packages/mcp`. The spec types only the `source` block of `query_records`' result (`packages/spec/src/ai/object-query-source.zod.ts`), not the result itself, so nothing enters `packages/spec` (ADR-0149 M1). - No existing member is renamed or removed. `aggregate_records` and its `totalGroups` / `truncated` are untouched. ## Tests - New `packages/mcp/src/query-records-truncated.test.ts` drives `query_records` through `registerObjectTools` over an in-memory MCP client on both doors. The HTTP door uses a bridge answering `findData`'s counted page facts. The stdio door uses `createStdioDataBridge` over a stand-in engine. Pins per door: a capped page answers `truncated: true` with the page only, and the probe asks for `limit + 1`. A page of exactly `limit` rows answers no `truncated`. The last page of a paged read is not capped. Under `OS_DATA_MAX_PAGE_SIZE` equal to the page, no probe is sent and `hasMore` decides. Pins on the stdio bridge itself: a capped page answers the counted total, not the page length. A failing count states no total. An unpaged read runs no count. - Two preservation pins now expect the probe row the bridge receives: `mcp-http-tools.unknown-argument-keys.test.ts` (limit 3 becomes 4) and `mcp-server-runtime.http.test.ts` (5 becomes 6). The page served is unchanged. - `stdio-data-bridge.stored-metadata-body.test.ts`: the engine-read census names the new `count(object)` site. It is a number, never a row, counted under the `where` that the stored-body and hash refusals already judged. <details><summary>Ablations (scripts/ablation-replace.mjs, each restored to the HEAD blob, git diff HEAD empty)</summary> - A1, the `truncated` member deleted from `servedQueryPage`: 4 failed, 7 passed (both doors' capped and read-window pins). - A2, `records.length > page` mutated to `>=`: 2 failed, 9 passed (both doors' exact-limit pins). - A3, the stdio bridge back to `total: records.length`: 5 failed, 6 passed (the stdio door's capped, exact-limit, last-page and read-window pins, and the counted-total pin). </details> ## Acceptance notes - `findData` falls back to a page-local `total` when `engine.count` throws (`packages/metadata-protocol/src/protocol-data-crud.ts` 804-808). That is a total the HTTP door did not count. It is outside this PR's file surface, so it is noted here and not changed. - On the stdio door, every paged `bridge.query` now runs one `engine.count`. That includes `delete_records`' selection read, which goes through the same bridge member. ## Verification All readings below were taken at head `d85434872f`. <details><summary>Local runs</summary> - `pnpm --filter '@objectstack/mcp^...' build` (under the verify lock): VERDICT command-exit 0. - `pnpm --filter @objectstack/mcp test`: Test Files 72 passed (72), Tests 1281 passed (1281). - `pnpm --filter @objectstack/mcp typecheck`: tsc clean; `check:test-typecheck` OK, 6 files / 53 errors / 8 pinned signatures held, unchanged. - `dispatch-gates --commands`: 68 derived families. 67 exited 0. `pnpm check:dual-build-cjs-loads` exited 3, PREREQUISITE NOT MET (it reads every package's `dist/`, and only the mcp dependency closure is built here). NOT MEASURED locally; CI's Lint and Repo Gates runs it. `--ran` reconciliation: 68 derived, 67 run, 1 NOT-MEASURED, 0 UNRUN. - `overlap-check.mjs`: clean against origin/main, 0 open PR heads share a file. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent bfd6b6b commit c787255

7 files changed

Lines changed: 292 additions & 11 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@objectstack/mcp": patch
3+
---
4+
5+
Clause-②: yes (widening)
6+
Metadata-protocol: none
7+
8+
`query_records` says when a page hit its row cap. The tool asks for one row more than the page; when that row comes back, it serves the page and adds `truncated: true`. The member is present only when true, so a page that holds every matching row, exactly `limit` rows included, is unchanged. The tool description now tells a model not to sum, count or rank a truncated page as if whole, and to read on with `offset` or use `aggregate_records` for totals.
9+
10+
The stdio door's `query_records` now answers the same page facts as the HTTP door: a paged read is counted under the same filter, as the caller, so `total` is the match total and `hasMore` says whether rows remain. Before, a capped stdio page answered `total` equal to the page length. If the count fails, `total` is left out and is never estimated.
11+
12+
When the host's read window (`OS_DATA_MAX_PAGE_SIZE`, `OS_DATA_QUERY_ROW_BUDGET`) would refuse the extra row, the page is read as asked, and the door's counted `hasMore` decides `truncated`.

‎packages/mcp/src/mcp-http-tools.ts‎

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,54 @@ function wireCodeOf(err: unknown, thrownCode: string): string {
17991799
return typeof armCode === 'string' ? armCode : thrownCode;
18001800
}
18011801

1802+
/**
1803+
* [#35138] May `query_records` read one row past its page, to learn whether
1804+
* the page was capped?
1805+
*
1806+
* The data door's read window REFUSES, never clamps, a read asking for more
1807+
* rows than `OS_DATA_MAX_PAGE_SIZE` or walking past `OS_DATA_QUERY_ROW_BUDGET`
1808+
* (`@objectstack/types`' `query-read-limits.ts`). A probe row that crosses
1809+
* either would turn a page the caller may read into a refusal, so there the
1810+
* page is read exactly as asked and the door's counted `hasMore` decides
1811+
* ({@link servedQueryPage}).
1812+
*/
1813+
function queryPageProbeFits(page: number, offset: number | undefined): boolean {
1814+
const { maxPageSize, rowBudget } = resolveQueryReadLimits();
1815+
if (maxPageSize !== undefined && page + 1 > maxPageSize) return false;
1816+
if (rowBudget !== undefined && (offset ?? 0) + page + 1 > rowBudget) return false;
1817+
return true;
1818+
}
1819+
1820+
/**
1821+
* [#35138] Serve one `query_records` page, and say when it was capped.
1822+
*
1823+
* A page read with a probe (`probed`: the bridge was asked for `page + 1`
1824+
* rows) is capped when the probe row came back: the extra row is dropped and
1825+
* the answer carries `truncated: true`. A page read without one is capped
1826+
* when the door's own counted `hasMore` says so. `truncated` is present only
1827+
* when true, so an answer whose page holds every matching row (exactly
1828+
* `page` rows included) is unchanged. `hasMore`, where the bridge answers it,
1829+
* states the same fact: it was counted against the probe-widened read, so it
1830+
* is restated from the probe rather than left one row out.
1831+
*
1832+
* Anything that is not a `{ records: [...] }` object is served as it came —
1833+
* the {@link withDelegationNotice} posture: no wrapper is invented to carry a
1834+
* flag about a shape this tool cannot read.
1835+
*/
1836+
function servedQueryPage(result: unknown, page: number, probed: boolean): unknown {
1837+
if (result === null || typeof result !== 'object' || Array.isArray(result)) return result;
1838+
const answer = result as Record<string, unknown>;
1839+
const records = answer.records;
1840+
if (!Array.isArray(records)) return result;
1841+
const truncated = probed ? records.length > page : answer.hasMore === true;
1842+
return {
1843+
...answer,
1844+
records: probed ? records.slice(0, page) : records,
1845+
...(probed && typeof answer.hasMore === 'boolean' ? { hasMore: truncated } : {}),
1846+
...(truncated ? { truncated: true as const } : {}),
1847+
};
1848+
}
1849+
18021850
/**
18031851
* [ADR-0090 D10 — ruling 2026-09-08, consequence 2] Attach the D10 narrowing
18041852
* notice to a query result WITHOUT reshaping it.
@@ -2910,6 +2958,11 @@ export function registerObjectTools(
29102958
description:
29112959
'Query records from an object with optional filter, field selection, sorting and pagination. ' +
29122960
'Runs under the caller\'s permissions and row-level security. ' +
2961+
// [#35138] A capped page is one page, never the set: the model is
2962+
// told not to sum, count or rank it as if whole.
2963+
'The answer is one page of at most limit rows. When more records match, it carries "truncated": true: ' +
2964+
'the rows are not all of them, so do not sum, count or rank them as if whole; read on with offset, ' +
2965+
'or, where it is offered, use aggregate_records for totals and breakdowns. ' +
29132966
'A filter value "{current_user_id}" stands for you. ' +
29142967
// [#32442] The console's My Pending list, filter for filter: the
29152968
// participant read alone also serves requests the caller submitted
@@ -2971,13 +3024,21 @@ export function registerObjectTools(
29713024
const bad = await readGuard(objectName);
29723025
if (bad) return errorResult(bad);
29733026
try {
2974-
const result = await bridge.query(objectName, {
2975-
where,
2976-
fields,
2977-
limit: Math.min(limit ?? maxLimit, maxLimit),
2978-
offset,
2979-
orderBy,
2980-
});
3027+
// [#35138] A capped page says so: one row past the page is asked
3028+
// for, and its coming back is the cap (`servedQueryPage`).
3029+
const page = Math.min(limit ?? maxLimit, maxLimit);
3030+
const probed = queryPageProbeFits(page, offset);
3031+
const result = servedQueryPage(
3032+
await bridge.query(objectName, {
3033+
where,
3034+
fields,
3035+
limit: probed ? page + 1 : page,
3036+
offset,
3037+
orderBy,
3038+
}),
3039+
page,
3040+
probed,
3041+
);
29813042
// [ADR-0090 D10 — ruling 2026-09-08, consequence 2] A delegated read
29823043
// the agent ceiling NARROWED is served with the narrowing stated. The
29833044
// rows are still served — a partial answer is the most useful true

‎packages/mcp/src/mcp-http-tools.unknown-argument-keys.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ describe('MCP tool arguments — undeclared keys are refused (#16913)', () => {
197197
where: { status: 'open' },
198198
fields: ['name', 'amount'],
199199
orderBy: [{ field: 'amount', order: 'desc' }],
200-
limit: 3,
200+
// [#35138] The page asked for plus the one probe row the handler's
201+
// `truncated` is decided by; the page served is still 3 rows.
202+
limit: 4,
201203
offset: 6,
202204
});
203205
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ describe('MCPServerRuntime.handleHttpRequest (Streamable HTTP)', () => {
150150
const queryCall = bridge.calls.find((c) => c[0] === 'query');
151151
expect(queryCall[1]).toBe('task');
152152
expect(queryCall[2].where).toEqual({ status: 'open' });
153-
expect(queryCall[2].limit).toBe(5);
153+
// [#35138] The capped page (5) plus the one probe row `truncated` is decided by.
154+
expect(queryCall[2].limit).toBe(6);
154155
});
155156

156157
it('rejects system objects on object-scoped tools (fail-closed)', async () => {
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#35138] A `query_records` page that hit its row cap says so with
5+
* `truncated: true`, on both doors, so a model does not sum or rank one page
6+
* as if it were the whole set.
7+
*
8+
* The flag is decided by a probe: the handler asks the bridge for one row
9+
* more than the page, serves the page, and flags it when the extra row came
10+
* back. A page holding exactly `limit` rows and no more carries no flag. The
11+
* flag is present only when true.
12+
*
13+
* The two doors are the two bridges the tool runs over: the HTTP door's
14+
* (`packages/runtime` `domains/mcp.ts`, `callData('query')` into the data
15+
* door's `findData`, which answers a counted `total` and `hasMore`; the stand
16+
* in below answers the same page facts) and the stdio door's
17+
* (`createStdioDataBridge`, over a stand-in engine). The stdio bridge used to
18+
* answer `total: records.length` with no `hasMore`, so a capped stdio page
19+
* claimed to be whole; it now counts, as the data door does, and never states
20+
* a total it did not count.
21+
*
22+
* Where the host's read window (`OS_DATA_MAX_PAGE_SIZE` /
23+
* `OS_DATA_QUERY_ROW_BUDGET`) would refuse the probe row, the page is read as
24+
* asked and the door's counted `hasMore` decides.
25+
*/
26+
27+
import { afterEach, describe, it, expect, vi } from 'vitest';
28+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
29+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
30+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
31+
import type { ExecutionContext } from '@objectstack/spec/kernel';
32+
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
33+
import { createStdioDataBridge } from './stdio-data-bridge.js';
34+
import { registerObjectTools, type McpDataBridge } from './mcp-http-tools.js';
35+
36+
const OBJECT = 'cap_deal';
37+
const DEF = { name: OBJECT, fields: { name: { type: 'text' } } };
38+
const PRINCIPAL = { userId: 'u1', isSystem: false } as unknown as ExecutionContext;
39+
40+
const rowsOf = (n: number) => Array.from({ length: n }, (_, i) => ({ id: `d${i + 1}`, name: `deal ${i + 1}` }));
41+
42+
type QueryOpts = { limit?: number; offset?: number };
43+
44+
/** The HTTP door's bridge: the data door's `findData` page facts — a counted total and `hasMore`. */
45+
function httpDoor(stored: number) {
46+
const rows = rowsOf(stored);
47+
const asked: QueryOpts[] = [];
48+
const bridge = {
49+
async listObjects() { return [{ name: OBJECT, label: 'Deal' }]; },
50+
async describeObject(name: string) { return { name }; },
51+
async query(object: string, opts: QueryOpts) {
52+
asked.push({ limit: opts.limit, offset: opts.offset });
53+
const offset = opts.offset ?? 0;
54+
const records = rows.slice(offset, opts.limit === undefined ? undefined : offset + opts.limit);
55+
return { object, records, total: rows.length, hasMore: offset + records.length < rows.length };
56+
},
57+
async get(object: string, id: string) { return { object, id }; },
58+
async create(object: string, data: unknown) { return { object, data }; },
59+
async update(object: string, id: string) { return { object, id }; },
60+
async remove(object: string, id: string) { return { object, id, success: true }; },
61+
} as unknown as McpDataBridge;
62+
return { bridge, asked };
63+
}
64+
65+
/** The stdio door's bridge, over a stand-in engine that honours `limit` / `offset` and counts. */
66+
function stdioDoor(stored: number, opts: { countThrows?: boolean } = {}) {
67+
const rows = rowsOf(stored);
68+
const asked: QueryOpts[] = [];
69+
const engine = {
70+
find: vi.fn(async (_object: string, query: QueryOpts) => {
71+
asked.push({ limit: query.limit, offset: query.offset });
72+
const offset = query.offset ?? 0;
73+
return rows.slice(offset, query.limit === undefined ? undefined : offset + query.limit);
74+
}),
75+
count: vi.fn(async () => {
76+
if (opts.countThrows) throw new Error('count unavailable');
77+
return rows.length;
78+
}),
79+
};
80+
const metadataService = { getObject: vi.fn(async (name: string) => (name === OBJECT ? DEF : undefined)) };
81+
const bridge = createStdioDataBridge({
82+
engine: engine as unknown as IDataEngine,
83+
metadataService: metadataService as unknown as IMetadataService,
84+
resolvePrincipal: async () => PRINCIPAL,
85+
});
86+
return { bridge, asked, engine };
87+
}
88+
89+
async function queryRecords(bridge: McpDataBridge, args: Record<string, unknown>): Promise<any> {
90+
const server = new McpServer({ name: 'pin', version: '0' });
91+
registerObjectTools(server, bridge);
92+
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
93+
await server.connect(serverSide);
94+
const client = new Client({ name: 'pin', version: '0' });
95+
await client.connect(clientSide);
96+
try {
97+
const res = (await client.callTool({
98+
name: 'query_records',
99+
arguments: { objectName: OBJECT, ...args },
100+
})) as { isError?: boolean; content: Array<{ text: string }> };
101+
expect(res.isError, res.content[0]?.text).toBeFalsy();
102+
return JSON.parse(res.content[0]!.text);
103+
} finally {
104+
await client.close();
105+
}
106+
}
107+
108+
const DOORS = [
109+
['HTTP', httpDoor],
110+
['stdio', stdioDoor],
111+
] as const;
112+
113+
afterEach(() => {
114+
vi.unstubAllEnvs();
115+
});
116+
117+
describe('query_records — a capped page says `truncated: true` (#35138)', () => {
118+
for (const [door, make] of DOORS) {
119+
it(`${door} door: a page that hit its cap answers truncated: true, with the page only`, async () => {
120+
const { bridge, asked } = make(5);
121+
const payload = await queryRecords(bridge, { limit: 3 });
122+
expect(payload.truncated).toBe(true);
123+
expect(payload.records.map((r: { id: string }) => r.id)).toEqual(['d1', 'd2', 'd3']);
124+
expect(payload.total).toBe(5);
125+
expect(payload.hasMore).toBe(true);
126+
// The probe: one row past the page was asked for.
127+
expect(asked).toEqual([{ limit: 4, offset: undefined }]);
128+
});
129+
130+
it(`${door} door: a page with exactly limit rows and no more answers no truncated`, async () => {
131+
const { bridge } = make(3);
132+
const payload = await queryRecords(bridge, { limit: 3 });
133+
expect('truncated' in payload).toBe(false);
134+
expect(payload.records).toHaveLength(3);
135+
expect(payload.total).toBe(3);
136+
expect(payload.hasMore).toBe(false);
137+
});
138+
139+
it(`${door} door: the last page of a paged read is not capped`, async () => {
140+
const { bridge } = make(5);
141+
const payload = await queryRecords(bridge, { limit: 3, offset: 3 });
142+
expect('truncated' in payload).toBe(false);
143+
expect(payload.records.map((r: { id: string }) => r.id)).toEqual(['d4', 'd5']);
144+
expect(payload.hasMore).toBe(false);
145+
});
146+
147+
it(`${door} door: where the read window would refuse the probe row, the page is read as asked and hasMore decides`, async () => {
148+
vi.stubEnv('OS_DATA_MAX_PAGE_SIZE', '3');
149+
const capped = make(5);
150+
const payload = await queryRecords(capped.bridge, { limit: 3 });
151+
expect(capped.asked).toEqual([{ limit: 3, offset: undefined }]);
152+
expect(payload.truncated).toBe(true);
153+
expect(payload.records).toHaveLength(3);
154+
155+
const whole = make(3);
156+
expect('truncated' in (await queryRecords(whole.bridge, { limit: 3 }))).toBe(false);
157+
});
158+
}
159+
});
160+
161+
describe('stdio query: the page facts are counted, never the page length (#35138)', () => {
162+
it('a capped page answers the match total and hasMore, not total: records.length', async () => {
163+
const { bridge, engine } = stdioDoor(5);
164+
const page: any = await bridge.query(OBJECT, { limit: 3 });
165+
expect(page.records).toHaveLength(3);
166+
expect(page.total).toBe(5);
167+
expect(page.hasMore).toBe(true);
168+
// Counted as the caller, under the caller's filter.
169+
expect(engine.count).toHaveBeenCalledWith(OBJECT, {}, { context: PRINCIPAL });
170+
});
171+
172+
it('a count that fails states no total at all', async () => {
173+
const { bridge } = stdioDoor(5, { countThrows: true });
174+
const page: any = await bridge.query(OBJECT, { limit: 3 });
175+
expect(page.records).toHaveLength(3);
176+
expect('total' in page).toBe(false);
177+
expect(page.hasMore).toBe(true);
178+
});
179+
180+
it('an unpaged read is the whole set: its length is the total, and no count runs', async () => {
181+
const { bridge, engine } = stdioDoor(4);
182+
const page: any = await bridge.query(OBJECT, {});
183+
expect(page.total).toBe(4);
184+
expect(page.hasMore).toBe(false);
185+
expect(engine.count).not.toHaveBeenCalled();
186+
});
187+
});

‎packages/mcp/src/stdio-data-bridge.stored-metadata-body.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@ const BRIDGE_MEMBERS: Record<string, string> = {
491491
*/
492492
const ENGINE_READ_SITES: Record<string, Record<string, number>> = {
493493
// findById (get, and the update / remove existence probes) and query; aggregate.
494-
'stdio-data-bridge.ts': { 'find(object)': 2, 'aggregate(object)': 1 },
494+
// [#35138] `count(object)`: `query`'s page total, a number and never a row,
495+
// counted under the `where` the stored-body and hash refusals already judged.
496+
'stdio-data-bridge.ts': { 'find(object)': 2, 'aggregate(object)': 1, 'count(object)': 1 },
495497
// The ADR-0101 record resource reader.
496498
'plugin.ts': { 'find(objectName)': 1 },
497499
// [#30891] NOT an engine read: `delete_records` counting its selection

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,23 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
13751375
dropType: read.addedType,
13761376
}).map((row) => serveStoredMetadataHashes(object, row, digest)),
13771377
);
1378-
return { object, records, total: records.length };
1378+
// [#35138] The page facts the data door answers (`findData`): a paged
1379+
// read is counted under the same filter, as the caller, so `total` is
1380+
// the match total and `hasMore` says whether rows remain past this page.
1381+
// Before, a capped page answered `total: records.length` and claimed to
1382+
// be the whole set. ⛔ A total this bridge did not count is never stated:
1383+
// a count that fails leaves `total` out, and `hasMore` answers from the
1384+
// page alone, the door's `$count=false` arm (a full page may have more).
1385+
const limit = typeof opts?.limit === 'number' ? opts.limit : undefined;
1386+
const offset = typeof opts?.offset === 'number' && opts.offset > 0 ? opts.offset : 0;
1387+
if (limit === undefined && offset === 0) return { object, records, total: records.length, hasMore: false };
1388+
let counted: number;
1389+
try {
1390+
counted = await engine.count(object, opts?.where ? { where: opts.where } : {}, { context });
1391+
} catch {
1392+
return { object, records, hasMore: limit !== undefined && records.length >= limit };
1393+
}
1394+
return { object, records, total: counted, hasMore: offset + records.length < counted };
13791395
},
13801396

13811397
async get(object, id) {

0 commit comments

Comments
 (0)