Skip to content
Merged
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
20 changes: 20 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,20 @@
---
'@objectstack/service-record-context': patch
'@objectstack/runtime': patch
'@objectstack/mcp': patch
'@objectstack/spec': patch
'@objectstack/types': 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-②: yes (widening)
Metadata-protocol: none

ADR-0160 D3 "Object level", as amended, and its second amendment. No pack, key or code changes. The published surface widens by optional members only: `RecordContextDoor.pageCap?()`, and `StdioDataBridgeDeps.security` may carry `getQueryableFields`; `@objectstack/types` adds `resolveQueryReadPageCap`.

- **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, and the `rows` and `truncated` descriptions of a related list in the tool's output schema, now say a list is cut at its entry's `limit`, at the row cap, or below either at the door's page cap.
- `@objectstack/types` exports `resolveQueryReadPageCap()`: the smaller of `OS_DATA_MAX_PAGE_SIZE` and `OS_DATA_QUERY_ROW_BUDGET`, `undefined` when neither is set. Both doors answer `pageCap` from this one function, so they cut at the same row.
8 changes: 4 additions & 4 deletions content/docs/references/ai/record-context-tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ const result = GetRecordContextInputSchema.parse(data);
| **object** | `string` | ✅ | The child object |
| **label** | `string` | ✅ | The child object's plural label at the caller's locale |
| **field** | `string` | ✅ | The child's field that points at the record |
| **rows** | `{ id?: string; displayName?: string; fields: object[] }[]` | ✅ | The rows the caller may read, up to the row cap |
| **truncated** | `true` | optional | Present when more rows existed past the row cap |
| **rows** | `{ id?: string; displayName?: string; fields: object[] }[]` | ✅ | The rows the caller may read, up to the list's `limit` (the row cap when it names none), or fewer when the door's page cap is lower |
| **truncated** | `true` | optional | Present when more rows existed past the rows given: at the list's `limit`, at the row cap, or below either at the door's page cap |

### Nested Shape: `RecordContextData.body`

Expand Down Expand Up @@ -221,8 +221,8 @@ const result = GetRecordContextInputSchema.parse(data);
| **object** | `string` | ✅ | The child object |
| **label** | `string` | ✅ | The child object's plural label at the caller's locale |
| **field** | `string` | ✅ | The child's field that points at the record |
| **rows** | `{ id?: string; displayName?: string; fields: object[] }[]` | ✅ | The rows the caller may read, up to the row cap |
| **truncated** | `true` | optional | Present when more rows existed past the row cap |
| **rows** | `{ id?: string; displayName?: string; fields: object[] }[]` | ✅ | The rows the caller may read, up to the list's `limit` (the row cap when it names none), or fewer when the door's page cap is lower |
| **truncated** | `true` | optional | Present when more rows existed past the rows given: at the list's `limit`, at the row cap, or below either at the door's page cap |

### Nested Shape: `RecordContextRelatedList.rows[number]`

Expand Down
24 changes: 21 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 { resolveQueryReadPageCap, 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 Down Expand Up @@ -250,8 +250,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 +1921,20 @@ 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 (`resolveQueryReadPageCap`), the
// same value the `/mcp` door answers.
pageCap: () => resolveQueryReadPageCap(),
userTextLocales: () => self.userTextLocales!(),
});
bridge.recordContextToolDefinitions = () => service.recordContextTools().definitions;
Expand Down
22 changes: 21 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, resolveQueryReadPageCap } 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: () => resolveQueryReadPageCap(),
}));
}
return bridge;
Expand Down Expand Up @@ -1795,6 +1813,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