Skip to content

feat(mcp): query_records expand and get_record related, every reached object judged by the read guard - #35225

Merged
objectstack-fleet[bot] merged 14 commits into
mainfrom
claude/issue-35145-mcp-related-read
Nov 18, 2026
Merged

objectstack-fleet[bot] merged 14 commits into
mainfrom
claude/issue-35145-mcp-related-read

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #35145 (PR 2 of 2: expand on query_records and related on get_record; PR 1, latestPer, landed as #35199)

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 改了什么:MCP 的 query_records 新增 expand(一次把商机的客户、负责人等查找字段展开成完整记录),get_record 新增 related(一次读出客户及其商机、活动等子记录列表)。
  • 为什么改:问数场景里“这个客户和它的商机/活动”“每笔商机连同客户名”原本要 AI 连发多次调用再自己拼接;现在一次调用完成,且仍在调用者的权限、行级安全和字段屏蔽之下。
  • 风险与回滚:不传新参数的调用完全不变;展开或关联到的每个对象都要过 MCP 读守卫,被守卫拒绝的对象让整次调用失败、不读任何数据;守卫放行但调用者无权读的展开目标不展开,字段保留原 id,调用照常返回。回滚即撤销本 PR,无数据迁移。
  • 先看:packages/mcp/src/mcp-relation-reads.ts(读守卫对目标对象的判定、关联字段校验、上限),packages/mcp/src/mcp-http-tools.ts 中 get_record 处理函数(先读父记录、再按父链接读子列表、截断标记),packages/mcp/src/stdio-data-bridge.ts 的 stdioExpandMap。
  • 两分钟验证:pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2 src/mcp-relation-reads.test.ts,预期 28 条全绿(含系统对象目标整单拒绝、什么都没读)。
  • 需要你做的:无,席位落地。

What changes

  • query_records gains expand (packages/mcp/src/mcp-http-tools.ts): up to 3 (QUERY_EXPAND_MAX_FIELDS) of the queried object's lookup, master-detail, user or tree fields, one level deep (no dotted path). Each name is judged against the object as the caller is served it (servedObjectDefinitionOf), and the object it points at passes the MCP read guard, before any read. The names go to the bridge as expand; the HTTP bridge hands them to findData (which lowers and gates them as on REST: assertExpandTargetsExist, servedExpand), and the engine expands them through its one expansion path: one batched id IN (...) read per field via engine.find, under the target's permissions, row-level security and field masking. It combines with latestPer (the engine expands after the window read). Only the MCP read guard's refusal refuses the call: a target the guard admits but the engine does not expand for the caller (for example, no object permission on it) leaves the field holding its stored id, and the call is answered. The tool text says exactly that.
  • get_record gains related: up to 3 (GET_RECORD_MAX_RELATED_LISTS) entries { object, field?, fields?, orderBy?, limit? }, strict (no caller filter). Every child object passes the read guard first; then its link field must be a reference field of the child, as the caller is served it, that points at the parent (left out, the child's one such field is used; none or several is refused with the candidates named). The record is read first; each list is then one query_records-shaped bridge read of the child with where = the link to that record alone ($contains for a multi-value link), the child's own fields and orderBy, and limit + 1. Each list carries the same delegation-narrowing notice (delegationNarrowed, warning; ADR-0090 D10) that query_records adds when the agent ceiling narrowed that object. A list's rows are capped at 20 (RELATED_LIST_MAX_ROWS, never above maxQueryLimit) and served by the shared servedQueryPage, so a capped list carries truncated: true. The answer is { record, related: [{ object, field, records, total, hasMore, truncated? }] }; without related it is the record alone, as before.
  • The rule (packages/mcp/src/mcp-relation-reads.ts): every object a new read shape reaches is judged by the MCP read guard exactly as the object the call names. A target the guard refuses refuses the whole call with PERMISSION_DENIED / 403 and nothing is read. Other refusals, all before any read: INVALID_FIELD / 400 (unknown or non-relation expand name, a link field that does not point at the parent, ambiguous or missing link), OBJECT_NOT_FOUND / 404 (a related object whose definition is not served to the caller), NOT_IMPLEMENTED / 501 (a bridge that serves no object definitions). A related list's own read refusal is the whole call's, with its code.
  • withheldFields: the record and each related list name the fields withheld from them, as plain reads do (feat(mcp): query_records and get_record name the fields field-level security withheld from the caller #35179's helper, applied per row set).
  • HTTP bridge (packages/runtime/src/domains/mcp.ts): forwards expand into the findData query. One line.
  • stdio bridge (packages/mcp/src/stdio-data-bridge.ts): serves expand too, built as the data door builds it (stdioExpandMap): a non-reference name is INVALID_FIELD, a target whose declaration does not serve get is withheld (its field keeps the stored id, as servedExpand does).
  • McpDataBridge.query gains an optional expand?: string[]. @objectstack/spec is unchanged. Docs: content/docs/ai/connect-mcp.mdx gains an expand / related section. Changeset: @objectstack/mcp, @objectstack/runtime, patch.

Tests

  • packages/mcp/src/mcp-relation-reads.test.ts (28): the tool against a recording bridge. expand: the judged, de-duplicated names reach the one query; a guard-refused target (sys_organization) is PERMISSION_DENIED with no read; unknown, non-relation and dotted names are INVALID_FIELD; more than 3 is refused at the door; no definition member is NOT_IMPLEMENTED; a control without expand. related: the record is read before the lists, each list filtered by the link alone with limit + 1, the default cap 20, truncated: true from the probe row; a guard-refused child refuses the call with zero bridge calls; link inference, the several-links and no-link refusals, a field that points elsewhere, an unserved object; $contains for a multi-value link; an unreadable record reads no list; a list's own refusal is the call's; 4 lists, a limit above 20 and a caller where are refused at the door; each list's withheldFields equals a plain query_records of that object; a list the agent ceiling narrowed carries the delegation notice and the others do not; a diagnosis that throws never fails the list; a control without related. The stdio bridge: the expand map, a target that does not serve get withheld, a non-reference name refused before the engine.
  • packages/qa/dogfood/test/related-read-over-mcp.dogfood.test.ts (10, plus parity with plain reads on withheldFields): the CRM example over the live /mcp transport, real SecurityPlugin, SQL driver, multiTenant: 'posture-only' with two organizations. A member with read on accounts, deals and activities (not contacts), a row policy hiding closed-lost deals, crm_opportunity.probability and crm_account.annual_revenue withheld. Pins: deals expand account and owner_id into records with the account's withheld field still withheld; expand with latestPer; an account's related deals and activities, the RLS-hidden deal never in the list, withheld fields withheld on the rows; the tenant wall (organization B's deal pointing at A's account never appears in A's list; A's account is RECORD_NOT_FOUND for B; B sees only its own deal); a 25-row list answers 20 rows with truncated: true and total 25, limit: 5 with an order answers the first 5 and truncated: true; expand: ['organization_id'] and a related sys_organization refuse the whole call with PERMISSION_DENIED and no record data; a related object the member may not read refuses with OBJECT_NOT_FOUND; expand of crm_activity.contact onto crm_contact, which the guard admits but the member may not read, answers the call with the field holding its stored id and no contact data (the account on the same rows still expands); unknown and non-relation names are INVALID_FIELD; a control without either. Armed controls: the wall is real, the hidden deal and the cross-tenant deal exist at rest, the row policy binds, contacts are unreadable.
  • Ablation of the read-guard check on targets (judgeTarget's admit line mutated to admit every target, via scripts/ablation-replace.mjs; readings below).

Acceptance notes

Verification

Rework readings from head 977e416ad0a (merge of origin/main into 0e7914f180e; this PR's files unchanged by the merge) unless a line says otherwise. Every heavy run went through os-verify-lock; each exit code was captured before any pipe.

Targeted suites (rework)
  • mcp-relation-reads.test.ts: Tests 28 passed (28)
  • dogfood related-read-over-mcp.dogfood.test.ts (10) + latest-per-over-mcp.dogfood.test.ts (7): Test Files 2 passed (2), Tests 17 passed (17)
  • @objectstack/core repo pin second-object-read-exposure.pin.test.ts: Tests 4 passed (4); @objectstack/core --project repo at 0e7914f180e: Test Files 8 passed, Tests 108 passed
  • @objectstack/mcp typecheck (with check:test-typecheck): exit 0
  • @objectstack/mcp full suite at 3d6e7691fee: Test Files 76 passed (76), Tests 1376 passed (1376)
Dogfood battery
  • Not re-run this round: the rework touches the mcp package (tool text, the per-list notice), docs, changeset, one dogfood file and one core repo pin; the two dogfood files that read it are run above. The full battery at fb450168623: Test Files 482 passed, 3 skipped (485); Tests 4091 passed, 68 skipped (4159).
Ablation of the read-guard check on targets (round 1, `judgeTarget` unchanged since)

judgeTarget's admit line if (bad === undefined) return; mutated to admit every target (scripts/ablation-replace.mjs, anchor 1 to 0): unit 2 failed / 23 passed (exactly the two guard pins); dogfood through dist/ (rebuild + ablation-dist-preflight) 1 failed / 8 passed (exactly THE RULE pin). Restore legs: blob == HEAD, git diff HEAD empty, preflight --absent.

Gates
  • dispatch-gates --commands at 977e416ad0a: 101 families, all run locally, all exit 0 (including check:skill-examples and check:dual-build-cjs-loads after building the six packages they read). --ran reconciliation with every exit code recorded: 101 derived, 101 run, 0 NOT-MEASURED (a derived zero).
  • CI on 977e416ad0a: all 70 check-runs completed, 60 success and 10 skipped by their selectors, none failed; PR-body guards, Check Changeset, Test Core (all 10 shards) and Lint & Repo Gates success.
  • overlap-check at 977e416ad0a: origin/main merges cleanly; feat(mcp): aggregate_records orders, cuts and counts groups in the database #35193 now conflicts in packages/mcp/src/stdio-data-bridge.ts (it changed after round 1); the second of the two to land resolves it.

Generated by Claude Code

… read guard

WIP: tool surface, relation judging, runtime and stdio bridge forwarding.

Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL
Co-authored-by: Claude <noreply@anthropic.com>
…p-related-read

# Conflicts:
#	packages/mcp/src/mcp-http-tools.ts
#	packages/runtime/src/domains/mcp.ts
…p-related-read

# Conflicts:
#	packages/mcp/src/mcp-http-tools.ts
@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/mcp, @objectstack/runtime, touching 27 documentable anchor(s).

55 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 3e4d531d8ff39985ad044067b8d550e4af30799c.

⛔ 11 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 2 anchor(s) matched too much of the corpus to be a work list: PERMISSION_DENIED (literal, 56 pages), owner_id (literal, 46 pages)
  • 4 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 37 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 3e4d531d8ff39985ad044067b8d550e4af30799c → packageMentionDocs.

Which tree this was computed on

This run read content/docs from cf9115e837647a8fa118abf300eaf203ff53dea8 — the merge of head 977e416ad0a93972e380cd100c297e191a878c73 into base 3e4d531d8ff39985ad044067b8d550e4af30799c, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin cf9115e837647a8fa118abf300eaf203ff53dea8 && git checkout cf9115e837647a8fa118abf300eaf203ff53dea8
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 3e4d531d8ff39985ad044067b8d550e4af30799c 977e416ad0a93972e380cd100c297e191a878c73 && git checkout -B drift-repro 3e4d531d8ff39985ad044067b8d550e4af30799c && git merge --no-ff 977e416ad0a93972e380cd100c297e191a878c73

node scripts/docs-audit/affected-docs.mjs --json 3e4d531d8ff39985ad044067b8d550e4af30799c

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 3e4d531d8ff39985ad044067b8d550e4af30799c → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL

Contract-review-claim: session_01JQwxbaX2qDxUq9sF93EqqL · head fb45016862 · 2026-11-18T17:05Z (TIER_DEFAULT, owed by the Clause-②: yes (widening) declaration: query_records gains expand, get_record gains related)

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXr9wLAH24MEgxaLud

席位核对

L1 full · REWORK (2 must-fix) · Head-sha: fb4501686231790f6339cb12d9b6a7d1ef0f1dde · card #35145 (Fixes #35145, PR 2 of 2) · read 2026-11-18T17:08Z

Net diff against merge base ec227fc7b18: 8 files, +1185 / -8. query_records gains expand (forward references, one level, at most 3), and get_record gains related (child lists, at most 3, capped at 20 rows each).

Must-fix

  • M1. One new sentence in the tool text is false for a case the PR itself describes. The query_records description ends its expand sentence with "a field whose object you may not read refuses the call". Per this PR's own acceptance note and the engine's expansion path, only the MCP read guard's refusal refuses the call. A target the engine does not expand for the caller (for example, one the caller holds no object permission on) answers the stored id on the row, and the call succeeds. The model reads this text, so it must say what the tool does.
    • Reword it so the guard's refusal is what refuses the call, and so an unexpanded target keeps its id.
    • Add one pin for that case. The CRM example has one ready: crm_activity.contact points at crm_contact, which the dogfood member may not read. Expanding it should answer the call, with the field holding its stored id.
  • M2. CI is red at this head: PR-body guards reports that the PR closes mcp: one read that answers "each X with its latest Y" and reads several related objects, in place of a chain of calls the client stitches #35145 with no Claim: on the card naming claude/issue-35145-mcp-related-read. Post a claim amendment on the card that names this branch, then re-run the guard.

Against the card

Read at the head

  • The rule, at rule level. Every object a new read shape reaches is judged by the MCP read guard exactly as the named object, and a refusal refuses the whole call before any record is read.
    • For expand, the queried object has already passed the guard. Each name is judged against that object's definition as the caller is served it, then every target goes through the guard, and only then is the one query run.
    • For related, every child goes through the guard first. Then each link field is judged against the child as served. Then the record is read, and only then the lists, so no list is read for a record the caller cannot see.
    • No caller filter reaches a list. The related entry schema is strict and has no where. A list's where is the link to the record alone, with $contains for a multi-value link.
    • Each list is capped at 20, and never above the door's page cap. A probe row gives truncated: true through the shared servedQueryPage.
  • Under the caller's security.
    • On HTTP, the expanded names go through findData, with the existing expand gates and the engine's one batched expansion per field.
    • The stdio bridge builds the same map: a non-reference name is INVALID_FIELD, and a target that does not serve get is withheld.
    • Each list is an ordinary bridge.query of the child as the caller, so its fields/orderBy meet that read's own gates.
    • The record and each list carry withheldFields from feat(mcp): query_records and get_record name the fields field-level security withheld from the caller #35179's helper, per row set.
  • The declared 404. A related object whose definition is not served to the caller is refused OBJECT_NOT_FOUND before any record read. This matches the existing reading of an unserved object, and the changeset and docs both say it.
  • Docs and changeset, read sentence by sentence. connect-mcp.mdx gains the section, and the changeset covers @objectstack/mcp and @objectstack/runtime, both patch, Clause-②: yes (widening), Metadata-protocol: none. That level is right: there are new optional arguments, and an answer without them is unchanged. Neither text carries M1's sentence. Each refusal and bound they state matches the code and a pin.
  • Merges cleanly onto origin/main ec227fc7b1.
  • Check-runs at this head: 52 in total. 1 failed (M2), 17 still running, and the rest are success or skipped.

Nits (none blocks)

Owed after the fix

  • A delta L1 at the fixed head, once CI is green.
  • Contract review (claim 6985686134) and landing, through the seat.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL

Contract review

Served-tier: TIER_DEFAULT
Head-sha: fb4501686231790f6339cb12d9b6a7d1ef0f1dde
Local-runs: none

Inputs read: card #35145 (body and all 7 comments: triage 6972038283, claim 6973844822, claim amendment 6974061928, the two regrades, the two os-dev-reports 6979530359 / 6985647470); PR #35225 (body, 8 files, net diff origin/main...fb45016862); the 52 check-runs on this head.

① Derived judgments

The diff widens the published MCP tool surface in four places, and adds one optional member to an exported interface. Each one, judged:

  1. query_records accepts expand (string[], 1 to 3, QUERY_EXPAND_MAX_FIELDS). Right.
    • Each name is checked against the queried object as the caller is served it (servedObjectDefinitionOf, which both bridges build from the caller's own object view, ADR-0106 D1). So a field hidden by field-level security cannot be expanded, and the refusal calls it "Unknown field", which reveals nothing about it.
    • Each target comes from referenceTargetOf. That is the same function assertExpandTargetsExist, servedExpand and the engine's expansion loop use, so the object the guard judges is the object the engine reads.
    • Each target then passes the same readGuard closure the top-level call passed. This happens in judgeQueryExpand, before bridge.query. A refusal is PERMISSION_DENIED/403 for the whole call.
    • The only thing read before the verdict is the already-guarded object's own served definition. No records are read.
    • Rows: the engine's existing expansion does one batched id IN (...) per field through engine.find with the caller's context. That keeps the target's tenant wall, RLS and field masking. The dogfood pin shows crm_account.annual_revenue still withheld inside an expanded account.
    • Depth: the call is one level. Dotted names fail the served-field check, and the names reach findData with no nested expand.
    • Combined with latestPer: also judged before the read.
  2. get_record accepts related (1 to 3 strict entries {object, field?, fields?, orderBy?, limit?}). Right.
    • Every child goes through readGuard first, all of them before anything about any child is read, its definition included (judgeRelatedLists).
    • The link field is then checked against the child as the caller is served it, and must point at the parent. A link hidden by field-level security cannot be followed.
    • Caller input matches the amendment 6974061928: .strict() on each entry and on orderBy items, no where, and the list's only filter is relatedListWhere, the link to the record's id.
    • Order of reads: the parent record is read first, so a parent the caller cannot see answers RECORD_NOT_FOUND and no list is read.
    • Each list is read like query_records: bridge.query as the caller. It carries the child's tenant wall, RLS and field-level judgement (sort keys included), plus withheldFields from withheldFieldsFor(child, fields). Dogfood pins the RLS-hidden deal, the two-org wall and the withheld fields.
  3. Cap and truncated on related lists. Right.
    • relatedMaxRows = min(20, maxLimit). Zod .max(relatedMaxRows) refuses a larger limit at the door, and judgeRelatedLists clamps again.
    • Each list uses a limit+1 probe when queryPageProbeFits. Otherwise it uses the door's hasMore.
    • Both paths go through the shared servedQueryPage, so truncated: true is the same key and the same rule as query_records. Pinned: 25 rows answer 20 with truncated, and limit: 5 is pinned too.
  4. McpDataBridge.query gains an optional expand?: string[]. Right. The member is optional, so third-party bridges still compile. One that ignores it answers stored ids, which is declared.
    • HTTP bridge (runtime/domains/mcp.ts): forwards the names into findData, which lowers and gates them as REST does.
    • stdio bridge (stdioExpandMap): builds the expansion the way the data door does. A non-reference name is INVALID_FIELD. A target from a disabled package, or one that does not serve get, is withheld and keeps its stored id, as servedExpand does. The tool-level guard has already judged every target on this transport too.
  5. Declared deviation: a related object the caller lacks object permission on answers OBJECT_NOT_FOUND/404, not PERMISSION_DENIED. Accepted.

Findings. None is must-fix.

  • should-fix (follow-up). Related lists carry total but not the ADR-0090 D10 delegation-narrowing statement that query_records attaches (diagnoseDelegation). The rows are still narrowed by the engine, so this is the honest-count notice and not a row bound. Plain get_record carries none on main either.
  • nit. A list's refusal renders recordReadErrorResult(..., []), so the entry's own fields/orderBy names are not reported as not-recorded alongside the refusal.
  • nit. Records nested under expand stay masked but carry no per-target withheldFields. This is declared in Acceptance notes. The tool description could say so.
  • nit. The PR body's 维护者速读 says the unit file has 25 tests; the Tests section and the report say 26.

② Semver level

  • The changeset is @objectstack/mcp: patch and @objectstack/runtime: patch. These are the only two published packages the diff moves; content/docs and the dogfood tests do not publish. With Metadata-protocol: none and @objectstack/spec unchanged, AGENTS.md's level rule says a non-protocol change ships patch, so patch is right. It matches PR 1 (feat(mcp, objectql, driver-sql): query_records latestPer, each X with its latest Y in one call #35199).
  • Both declaration lines appear in the PR body and in the changeset body.
  • Clause-②: yes (widening) — confirmed. Only optional inputs and one optional interface member are added. Calls without expand or related are byte-identical (control pins in both suites). Nothing is narrowed or renamed, so no BREAKING banner or ADR-0087 disposition is owed.

③ Boundary flags

  • open_questions: []. security_findings: none. out_of_scope_findings: []. Nothing to answer.
  • Dev flag, the deviation in ① item 5: answered, accepted.
  • Dev flag, a third-party bridge that ignores expand: answered. This is a declared limit and fails safe (ids only).
  • SQL push-down (Prime Directive 5): no finding.
    • expand uses the engine's existing one-batched-read-per-field path. The reason is stated: each target's own permissions, RLS and FLS on one expansion path. This diff adds no new id materialisation.
    • related makes one pushed-down list read per child, filtered by a single parent id, plus the door's existing count. There is no in-app join, and no id set is materialised.
  • Gate verdict, escalated to the seat, not a contract finding: PR-body guards is red on this head. The failing check is check:closing-target-claim: "PR feat(mcp): query_records expand and get_record related, every reached object judged by the read guard #35225 closes mcp: one read that answers "each X with its latest Y" and reads several related objects, in place of a chain of calls the client stitches #35145 with no Claim: on the card naming claude/issue-35145-mcp-related-read". The card's claim and amendment name claude/issue-35145-mcp-latest-per-and-related-read. The fix is a claim amendment on the card naming this branch; no code changes.
  • Gate verdict, still open: at read time, the Test Core shards, Build Core, Build Docs, the Type Check jobs and several Lint jobs were in_progress. Landing waits for their conclusions.

Implemented-by: claude/issue-35145-mcp-related-read
Reviewed-by: session_01JQwxbaX2qDxUq9sF93EqqL

VERDICT: PASS

…ts carry the delegation notice

The query_records description now says a field whose object the door does not
serve refuses the call, while a record the caller may not read on a served
object keeps its stored id. Each related list carries the delegation notice
query_records carries. Docs, changeset and a dogfood pin follow.

Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL
Co-authored-by: Claude <noreply@anthropic.com>
…nd-object read pin

The MCP stdio bridge's expand asks the target's get exposure in stdioExpandMap
(decided); the MCP relation judging reads no record and executes through the
data door's servedExpand.

Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL

Contract-review-claim: session_01JQwxbaX2qDxUq9sF93EqqL · head 977e416ad0 · 2026-11-18T18:38Z (TIER_DEFAULT delta over the PASS 6985818359 at fb45016862, owed by the same Clause-②: yes (widening) declaration)

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXr9wLAH24MEgxaLud

席位核对

L1 delta · ACCEPT · Head-sha: 977e416ad0a93972e380cd100c297e191a878c73 · card #35145 (Fixes #35145, PR 2 of 2) · delta fb450168..977e416a, answering 6985771362 · read 2026-11-18T18:40Z

What the delta changes

The delta has two commits of this PR's own and one merge of main (3e4d531d8f, which brought #35222, #35226 and #35227, none of them touching this PR's files). The PR's net diff is now 9 files, +1259 / -8.

  • M1 is fixed. The query_records text now says that a field whose object this door does not serve refuses the call. A record the caller may not read on a served object is not expanded, and the field keeps its stored id. connect-mcp.mdx and the changeset say the same in the same terms. The new dogfood pin expands crm_activity.contact onto crm_contact, which the member may not read, in the same call as account. The call is answered, contact holds its stored id, no contact field value appears anywhere in the payload, and account comes back expanded.
  • M2 is fixed. PR-body guards is green against claim 6985788194.
  • The docblock nit is fixed. The two lines in stdio-data-bridge.ts carry their * again.
  • Added for the L2 should-fix. Each related list now carries the delegation-narrowing notice query_records carries, through the same withDelegationNotice, when the agent ceiling narrowed that list's read. The probe is caught, so a failing diagnosis never fails the list. Two unit pins cover it: a narrowed list next to an unnarrowed one, and a probe that throws. The changeset and docs name the notice.
  • A declared step outside the claimed surface. packages/core/src/security/second-object-read-exposure.pin.test.ts classifies the two new referenceTargetOf callers: stdio-data-bridge.ts as decided in stdioExpandMap, and mcp-relation-reads.ts as executing through the data door. Each classification matches the code I read. It is a test-only pin roster, and the pin had to name them, so I read this as a deviation needed to make CI green, not a scope change.

Read at the head

  • The full L1 at fb450168 (6985771362) stands for everything else. That covers the read-guard rule on every target before any read, no caller filter on a related list, the 20-row cap with truncated, withheldFields per row set, the declared 404, and Fixes.
  • Merges cleanly onto origin/main 02a1e2f29c.
  • Check-runs at this head: 74 in total, all completed, none failed (62 success, 12 skipped).

Not mine, still owed

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 977e416ad0a93972e380cd100c297e191a878c73
Local-runs: none

Delta over the PASS 6985818359 at fb45016862. Inputs read: card #35145 (body and every comment, including claim 6985788194 and the delta os-dev-report 6987956358); PR #35225 (the updated body, 9 files, and the PR's own change between fb45016862 and this head, restricted to the PR's files); the L1 REWORK 6985771362 and the prior PASS; the 74 check-runs on this head.

Shape of the delta: two PR commits (3d6e7691fee, 0e7914f180e) and one merge of origin/main (977e416ad0a). The merge changes none of the PR's 9 files, and the three main commits it brings in (#35222, #35227, #35226) touch none of them either, so it resolved no conflict. The PR's own delta is 7 files, +84 / -10. mcp-relation-reads.ts and runtime/src/domains/mcp.ts are unchanged.

① Derived judgments

  1. query_records tool text for expand. Right.
    • The text now says: "A field whose object this door does not serve you refuses the call; a record you may not read on a served object is not expanded, and the field keeps its stored id."
    • The first clause uses the read guard's own words. judgeTarget refuses with "reaches object '…', which this door does not serve you", as PERMISSION_DENIED / 403, before any read.
    • The second clause is what the engine does. expandRelatedRecords reads each target through this.find with the caller's context. A refused sub-read is caught, and the bare FK id is kept. A row the target's row policy hides is missing from the id map, so the field falls back to the stored id.
    • On HTTP, servedExpand withholds a target that does not serve get. On stdio, stdioExpandMap does the same with continue. Both keep the id.
    • Pinned in the dogfood suite. crm_activity.contact points at crm_contact, which the guard admits but the member may not read; the armed control shows contacts are unreadable. The call is answered, contact equals the stored id, no contact data appears, and account on the same row still expands.
    • The docs and the changeset say the same. The docs also name the hidden-row case.
  2. Delegation-narrowing notice on each related list. Right. This closes the prior should-fix.
    • Each list runs bridge.diagnoseDelegation(plan.object) with a catch that turns a failure into no answer, and adds withDelegationNotice only when the result is narrowed and carries a statement. That is the same guard and the same helper query_records uses, so the notice is the same delegationNarrowed / warning pair.
    • The diagnosis is keyed on the child object, which is the object the list reads. It runs after the list read, so it cannot fail the list or change which rows it holds.
    • Two unit pins. A narrowed list carries the notice, a sibling list does not, and a plain query_records gives the same answer. A diagnosis that throws still answers the list.
  3. The two new referenceTargetOf callers in second-object-read-exposure.pin.test.ts.
    • stdio-data-bridge.ts as decided / get (stdioExpandMap): true.
      • This is the file's only arbiter call (line 333).
      • The function asks canServeApiOperation(declared?.enable, 'get') on the target before adding it to the expand map. The file imports the decision from @objectstack/spec/data.
      • The wiring call stdioExpandMap(reads, object exists (line 1473).
      • The named pin (mcp-relation-reads.test.ts, its stdio block) holds a target with apiEnabled: false withheld.
      • The get operation matches the data door's servesExpansionTarget row.
    • mcp-relation-reads.ts as executes, decided in protocol-query-validation.ts: true in substance, with a nit.
      • The file's arbiter calls (targetOf, used by judgeQueryExpand and the related-link checks) read no record. They only name the object to ask the MCP guard, and check that a link points at the parent. The also text says so.
      • On the HTTP bridge, findData reads the expansion, and servedExpand / servesExpansionTarget decides it.
      • Nit: the read and also wording describe the HTTP path only. On stdio, the expansion is decided in stdioExpandMap (its own decided row, above), and each list goes through the stdio bridge's query, not findData. The pin's invariant still holds, because every path reaches a classified decided door. Only the prose is narrower than the code.
  4. The earlier ① judgments still hold. The delta leaves the guard, the judging order, judgeRelatedLists, the cap and probe, servedQueryPage, both bridges' expand and the declared OBJECT_NOT_FOUND deviation untouched. The only mcp-http-tools.ts changes are the description string and the per-list notice.

Prior findings, re-judged:

  • should-fix (delegation notice): closed by item 2.
  • nit (unit-test count): closed. The body says 28 everywhere, which matches the delta report.
  • nit (a list refusal renders recordReadErrorResult(..., [])): open, still a nit.
  • nit (no per-target withheldFields under expand): open, still a nit. It is declared in Acceptance notes.

New findings. None is must-fix.

  • nit. The pin's mcp-relation-reads.ts row describes the HTTP path only (item 3).
  • nit. The changeset's expand bullet says "Only the read guard's refusal refuses the call". That is true of target objects, but INVALID_FIELD / NOT_IMPLEMENTED also refuse. The next bullet states them, so nothing contradicts it.

② Semver level

  • The changeset is unchanged in frontmatter: @objectstack/mcp: patch, @objectstack/runtime: patch. Only its body gains two sentences, and both match the code.
  • The new core file is a repo test pin, which does not publish, so no @objectstack/core entry is owed. Check Changeset is success.
  • patch is still right: Metadata-protocol: none, and @objectstack/spec is unchanged.
  • Clause-②: yes (widening) is still confirmed.
    • The delta adds an optional notice to list entries this PR introduces, and rewords a description.
    • Calls without expand or related are unchanged.
    • Nothing is narrowed or renamed.
    • Both declaration lines are in the PR body and the changeset body.

③ Boundary flags

  • L1 must-fixes.
    • M1: closed (① item 1). The text is reworded, there is one dogfood pin on the named CRM case, and the docs and changeset are aligned.
    • M2: closed. Claim 6985788194 on the card names claude/issue-35145-mcp-related-read. Both PR-body guards check-runs on this head are success.
    • L1 nit: closed. The stdio docblock lines have their * prefix back.
  • Dev flags (delta report 6987956358). open_questions is [], and security_findings is none.
    • Deviation, the core pin outside the claimed file surface: accepted. The pin requires every new arbiter caller to be classified, and leaving it out was the CI failure on 3d6e7691fee. The edit only adds two classification rows and one decided-function name.
    • Escalated to the seat: whether to amend the claim's file surface. No gate refuses it.
    • Deviation, the PR-body PATCH: answered. The seat applied the body, and it matches the report and this head.
    • out_of_scope_findings, the feat(mcp): aggregate_records orders, cuts and counts groups in the database #35193 overlap in stdio-data-bridge.ts: noted. Whichever PR lands second resolves it. This is not a contract finding.
  • SQL push-down (Prime Directive 5): no finding. The delta adds no record read, no id materialisation and no in-app join. The per-list diagnoseDelegation is a permission probe, not a row read. The earlier push-down judgment stands.
  • Gate verdicts on this head.
    • All 74 check-runs are completed: 62 success, 12 skipped, 0 failure.
    • Test Core (all 10 shards), Lint & Repo Gates, every Type Check job, Build Core, Build Docs and Check Changeset are success.
    • For the seat, not a finding: the Dogfood Regression Gate matrix shards were skipped by their selector, and the aggregate job is success. The new dogfood pin's only reading is therefore the dev's local run (17/17 at this head, under os-verify-lock).

Implemented-by: claude/issue-35145-mcp-related-read
Reviewed-by: session_01JQwxbaX2qDxUq9sF93EqqL

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL

Landing · 2026-11-18T18:43Z. Head 977e416ad0a93972e380cd100c297e191a878c73 (PR 2 of 2, Fixes #35145):

  • L1: full REWORK 6985771362, then delta ACCEPT 6988064360 (M1 tool text plus the crm_activity.contact pin, M2 claim 6985788194, docblock nit).
  • Contract review at TIER_DEFAULT, owed by the Clause-②: yes (widening) declaration (query_records gains expand, get_record gains related): PASS 6985818359 at fb45016862, then delta PASS 6988113126 at this head. The should-fix (delegation-narrowing notice on each related list) is done in the delta.
  • Declared deviation, accepted by both reviews: packages/core/src/security/second-object-read-exposure.pin.test.ts classifies the two new referenceTargetOf callers (a test-only roster CI required).
  • Check-runs: 74, with 62 success, 12 skipped and 0 failed. The dogfood regression shards were skipped by their selector; the new dogfood pins read 17/17 locally at this head (6987956358).
  • Shape: not governed, 9 files, +1259/−8.
  • Overlap: feat(mcp): aggregate_records orders, cuts and counts groups in the database #35193 also touches packages/mcp/src/stdio-data-bridge.ts; whichever lands second merges main.

Marked ready, and auto-merge is armed.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 18, 2026 18:44
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit dbb2f68 Nov 18, 2026
75 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-35145-mcp-related-read branch November 18, 2026 19:11
os-warren pushed a commit that referenced this pull request Nov 18, 2026
…e order and cut

One conflict, in packages/mcp/src/stdio-data-bridge.ts, resolved keeping
both sides: the two Symbol.for read-option constants (this branch's
STDIO_AGGREGATE_ORDER_CUT and #35199's STDIO_LATEST_PER), each under its
own docblock, then #35225's stdioExpandMap byte-identical to main, then
unwrapRows under its own docblock. mcp-http-tools.ts and runtime
domains/mcp.ts merged without conflict.

Claude-Session: https://claude.ai/code/session_01JQwxbWDsbbJizuYnDwBxT8
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp: one read that answers "each X with its latest Y" and reads several related objects, in place of a chain of calls the client stitches

2 participants