Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/37361-record-context-left-out-queryable-doors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@objectstack/service-record-context': patch
'@objectstack/runtime': patch
'@objectstack/mcp': patch
'@objectstack/spec': patch
---

fix(service-record-context): get_record_context leaves out a related child the caller is not served, and both MCP doors hand over the caller's queryable fields and their page cap

Clause-②: no
Metadata-protocol: none

ADR-0160 D3 "Object level", as amended, and its second amendment. No pack, key or code changes.

- **A related child this caller is not served is left out, not refused.** The answer carries the root and every served section, with the one `not_visible` note, and names the child nowhere; nothing of the child is read after its object-level judgement, its published definition included. A child is still refused whole, as before, when a gate refuses it for everyone: the read guard, or API exposure — which is now asked before the served definition, so a child whose package is disabled (`OBJECT_PACKAGE_DISABLED`, which also serves its object to nobody) keeps its `PERMISSION_DENIED` refusal. A served-definition read that fails refuses the call, unnamed, and is never read as a narrowing.
- **Both doors supply `queryableFieldsOf`.** The `/mcp` door and the stdio door now hand the executor the security service's `getQueryableFields` answer for the caller they resolved, so a related list's `where` or `orderBy` is judged on that answer before the read. A field outside it drops the section with the note, and is never refused by the engine's guard; a masked field this caller is served whole (its unmask capability held) is now filtered and sorted on, where the fallback dropped the section.
- **A door's page cap is a stated cut.** A door may report its page cap (`pageCap`, optional); the executor then asks a related list for at most that many rows, cuts the list one row under it, and states the cut. Both doors report the deployment's smaller read limit (`OS_DATA_MAX_PAGE_SIZE`, `OS_DATA_QUERY_ROW_BUDGET`). Before, under a maximum page size below a list's cut plus its probe row, the `/mcp` door refused the whole call `MAX_RECORDS_EXCEEDED` and the stdio door read the full list.
- The `related_truncated` note kind's doc line now says a list is cut at its entry's `limit`, at the row cap, or at the door's page cap.
38 changes: 35 additions & 3 deletions packages/mcp/src/stdio-data-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ import {
// context-pack listing before the record-context executor parses it.
stripReadDecorations,
} from '@objectstack/spec/kernel';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import type { IDataEngine, IMetadataService, ISecurityService } from '@objectstack/spec/contracts';
import { resolveObjectSortability } from '@objectstack/spec/api';
// [#32442] The ONE reading of `enable.aiReadable` (ruling A, #32865).
import { isAiReadExposed } from '@objectstack/spec/data';
Expand Down Expand Up @@ -172,7 +172,7 @@ import {
diagnoseObjectListRead,
type DiagnosedObjectListing,
} from './metadata-completeness.js';
import { staleSummaryRefusalOrThrow, withEarnedAnswer, type SummaryRecomputeRefusal } from '@objectstack/types';
import { resolveQueryReadLimits, staleSummaryRefusalOrThrow, withEarnedAnswer, type SummaryRecomputeRefusal } from '@objectstack/types';
// [ADR-0149 D2] The `/meta` list translation and its locale parse, the pair
// the HTTP door's `loadDatasets` runs — imported, never restated, so both
// transports localize a saved dataset with one function.
Expand All @@ -192,6 +192,21 @@ import {
type ObjectSchemaReadDelegateSource,
} from '@objectstack/metadata-core';

/**
* [ADR-0160 D3] The most rows one record-context read may ask for, offset 0:
* the smaller of the deployment's maximum page size and its query row budget
* (`resolveQueryReadLimits`), `undefined` when neither is set. This
* transport's engine read plans no read window of its own, but the limits are
* one value per deployment, which the `/mcp` door's data door refuses past and
* `query_records` probes within on this transport too; asked of both doors, a
* principal's pack is cut at the same row on each, and the cut is stated.
*/
function recordContextPageCap(): number | undefined {
const { maxPageSize, rowBudget } = resolveQueryReadLimits();
const caps = [maxPageSize, rowBudget].filter((n): n is number => n !== undefined);
return caps.length > 0 ? Math.min(...caps) : undefined;
}

/**
* [#25138] The object reads this transport asks of the `protocol` service,
* and the data door's internal-field gate beside them. Every member is optional: the slot is filled by name from a host-owned
Expand Down Expand Up @@ -250,8 +265,12 @@ export interface StdioDataBridgeDeps {
* use and `undefined` when this host registers none — the deployment then
* has no field-level posture, and the schema is served as declared, as on
* every other object-schema exit.
*
* [ADR-0160 D3, second amendment] The same service answers the fields the
* principal may query on (`getQueryableFields`, feature-detected), which
* the record-context door hands its executor.
*/
security?: () => ObjectSchemaMaskSecuritySurface | undefined;
security?: () => (ObjectSchemaMaskSecuritySurface & Pick<Partial<ISecurityService>, 'getQueryableFields'>) | undefined;
/**
* [decision 6840464379] Where the object-schema mask finds an object's
* declared `schemaReadDelegate` ({@link CallerObjectViewDeps.schemaReadDelegates}).
Expand Down Expand Up @@ -1917,6 +1936,19 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
get: (object: string, id: string) => self.get(object, id),
query: (object: string, o: Parameters<McpDataBridge['query']>[1]) => self.query(object, o),
fieldVisibilityOf: (object: string) => self.fieldVisibilityOf!(object),
// [ADR-0160 D3, second amendment] The fields the principal may query
// on: the security service's own answer (`getQueryableFields`), judged
// on the map its engine guard refuses a filter or sort with, so a
// related list's `where` or `orderBy` the guard would refuse is dropped
// and stated before the read. No security service, or one predating the
// method: `undefined`, and the executor takes the contract's fallback.
queryableFieldsOf: async (object: string) => {
const surface = security?.();
if (typeof surface?.getQueryableFields !== 'function') return undefined;
return await surface.getQueryableFields(object, await resolvePrincipal());
},
// [ADR-0160 D3] The deployment's page cap ({@link recordContextPageCap}).
pageCap: () => recordContextPageCap(),
userTextLocales: () => self.userTextLocales!(),
});
bridge.recordContextToolDefinitions = () => service.recordContextTools().definitions;
Expand Down
36 changes: 35 additions & 1 deletion packages/runtime/src/domains/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Fetch-Request normalization ride along as family helpers.
*/

import { isMcpServerEnabled } from '@objectstack/types';
import { isMcpServerEnabled, resolveQueryReadLimits } from '@objectstack/types';
import { MCP_OAUTH_SCOPES, MCP_OAUTH_SCOPE_DATA_READ, deriveAiFaceName } from '@objectstack/spec/ai';
import type { ErrorCode, MetadataProtocol } from '@objectstack/spec/api';
import type { ISecurityService } from '@objectstack/spec/contracts';
Expand Down Expand Up @@ -1739,6 +1739,24 @@ export function buildMcpBridge(
// [ADR-0150 D6, addendum 2026-11-25] A package's pack is spelt by
// its face `NS-NAME`, as a package-held skill's prompt name is.
packageNamespace: (packageId: string) => packageNamespaceOf(contextPackEngine, packageId),
// [ADR-0160 D3, second amendment] The fields this caller may query
// on: THIS request's security service's own answer
// (`getQueryableFields`), judged on the map its engine guard
// refuses a filter or sort with, so a related list's `where` or
// `orderBy` the guard would refuse is dropped and stated before
// the read. No security service, or one predating the method:
// `undefined`, and the executor takes the contract's fallback.
queryableFieldsOf: async (object: string) => {
const security = await deps.resolveService(context, 'security', envId) as
Partial<ISecurityService> | undefined;
if (typeof security?.getQueryableFields !== 'function') return undefined;
return await security.getQueryableFields(object, ec);
},
// [ADR-0160 D3] The data door's page cap: `findData` refuses a
// read asking for more rows than the deployment's maximum page
// size or its row budget (`@objectstack/types`'
// `query-read-limits.ts`), so the executor asks for no more.
pageCap: () => recordContextPageCap(),
}));
}
return bridge;
Expand Down Expand Up @@ -1778,6 +1796,20 @@ export async function resolveMcpRecordContextToolsService(
return service && typeof service.recordContextTools === 'function' ? (service as McpRecordContextToolsService) : undefined;
}

/**
* [ADR-0160 D3] The most rows one record-context read may ask the data door
* for, offset 0: the smaller of the deployment's maximum page size and its
* query row budget, `undefined` when neither is set. The data door refuses,
* never clamps, a read over either (`resolveQueryReadLimits`), so a related
* list asked for more would refuse the whole call instead of being cut and
* stated.
*/
function recordContextPageCap(): number | undefined {
const { maxPageSize, rowBudget } = resolveQueryReadLimits();
const caps = [maxPageSize, rowBudget].filter((n): n is number => n !== undefined);
return caps.length > 0 ? Math.min(...caps) : undefined;
}

/**
* [ADR-0160 D3/D4] The bridge's two record-context members. The door handed
* to the executor is built per call from the bridge's own members — `get`,
Expand All @@ -1795,6 +1827,8 @@ function recordContextMembers(
publishedObjectDefinitionOf(name: string): Promise<Record<string, unknown> | null>;
listContextPacks(): Promise<readonly unknown[]>;
packageNamespace(packageId: string): string | undefined;
queryableFieldsOf(object: string): Promise<readonly string[] | undefined>;
pageCap(): number | undefined;
},
) {
return {
Expand Down
Loading
Loading