Repository navigation
feat(mcp): query_records expand and get_record related, every reached object judged by the read guard - #35225
Conversation
… 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>
Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
…tion is judged 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
Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
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
…d does Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbaX2qDxUq9sF93EqqL Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 55 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 11 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 37 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # 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
|
|
repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL Contract-review-claim: session_01JQwxbaX2qDxUq9sF93EqqL · head |
|
repo:objectstack#1 · os-warren · session_01JQwxbXr9wLAH24MEgxaLud 席位核对L1 full · REWORK (2 must-fix) · Head-sha: Net diff against merge base Must-fix
Against the card
Read at the head
Nits (none blocks)
Owed after the fix
|
|
repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL Contract reviewServed-tier: 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 ① Derived judgmentsThe diff widens the published MCP tool surface in four places, and adds one optional member to an exported interface. Each one, judged:
Findings. None is must-fix.
② Semver level
③ Boundary flags
Implemented-by: 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>
|
repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL Contract-review-claim: session_01JQwxbaX2qDxUq9sF93EqqL · head |
|
repo:objectstack#1 · os-warren · session_01JQwxbXr9wLAH24MEgxaLud 席位核对L1 delta · ACCEPT · Head-sha: What the delta changesThe delta has two commits of this PR's own and one merge of main (
Read at the head
Not mine, still owed
|
|
repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL Contract reviewServed-tier: Delta over the PASS 6985818359 at Shape of the delta: two PR commits ( ① Derived judgments
Prior findings, re-judged:
New findings. None is must-fix.
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL Landing · 2026-11-18T18:43Z. Head
Marked ready, and auto-merge is armed. |
…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>
Fixes #35145 (PR 2 of 2:
expandonquery_recordsandrelatedonget_record; PR 1,latestPer, landed as #35199)Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
query_records新增expand(一次把商机的客户、负责人等查找字段展开成完整记录),get_record新增related(一次读出客户及其商机、活动等子记录列表)。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_recordsgainsexpand(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 asexpand; the HTTP bridge hands them tofindData(which lowers and gates them as on REST:assertExpandTargetsExist,servedExpand), and the engine expands them through its one expansion path: one batchedid IN (...)read per field viaengine.find, under the target's permissions, row-level security and field masking. It combines withlatestPer(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_recordgainsrelated: 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 linkfieldmust 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 onequery_records-shaped bridge read of the child withwhere= the link to that record alone ($containsfor a multi-value link), the child's ownfieldsandorderBy, andlimit + 1. Each list carries the same delegation-narrowing notice (delegationNarrowed,warning; ADR-0090 D10) thatquery_recordsadds when the agent ceiling narrowed that object. A list's rows are capped at 20 (RELATED_LIST_MAX_ROWS, never abovemaxQueryLimit) and served by the sharedservedQueryPage, so a capped list carriestruncated: true. The answer is{ record, related: [{ object, field, records, total, hasMore, truncated? }] }; withoutrelatedit is the record alone, as before.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 withPERMISSION_DENIED/ 403 and nothing is read. Other refusals, all before any read:INVALID_FIELD/ 400 (unknown or non-relationexpandname, 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).packages/runtime/src/domains/mcp.ts): forwardsexpandinto thefindDataquery. One line.packages/mcp/src/stdio-data-bridge.ts): servesexpandtoo, built as the data door builds it (stdioExpandMap): a non-reference name isINVALID_FIELD, a target whose declaration does not servegetis withheld (its field keeps the stored id, asservedExpanddoes).McpDataBridge.querygains an optionalexpand?: string[].@objectstack/specis unchanged. Docs:content/docs/ai/connect-mcp.mdxgains anexpand/relatedsection. 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) isPERMISSION_DENIEDwith no read; unknown, non-relation and dotted names areINVALID_FIELD; more than 3 is refused at the door; no definition member isNOT_IMPLEMENTED; a control withoutexpand.related: the record is read before the lists, each list filtered by the link alone withlimit + 1, the default cap 20,truncated: truefrom 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;$containsfor 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 callerwhereare refused at the door; each list'swithheldFieldsequals a plainquery_recordsof 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 withoutrelated. The stdio bridge: the expand map, a target that does not servegetwithheld, 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 onwithheldFields): the CRM example over the live/mcptransport, 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.probabilityandcrm_account.annual_revenuewithheld. Pins: deals expandaccountandowner_idinto records with the account's withheld field still withheld;expandwithlatestPer; 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 isRECORD_NOT_FOUNDfor B; B sees only its own deal); a 25-row list answers 20 rows withtruncated: trueandtotal25,limit: 5with an order answers the first 5 andtruncated: true;expand: ['organization_id']and arelatedsys_organizationrefuse the whole call withPERMISSION_DENIEDand no record data; a related object the member may not read refuses withOBJECT_NOT_FOUND;expandofcrm_activity.contactontocrm_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 areINVALID_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.judgeTarget's admit line mutated to admit every target, viascripts/ablation-replace.mjs; readings below).Acceptance notes
expand: one batchedid IN (...)read per expanded field throughengine.find(the engine's existing expansion path, no per-row loop).related: one list read per related list throughfindData/engine.findwith the parent-id filter, plus the door's match count that servestotal(the same count a plainquery_recordspage runs). No in-app join.OBJECT_NOT_FOUND/ 404, notPERMISSION_DENIED: its definition is not served to the caller, so the call is refused while the relation is judged, before any record read. The dispatch named "a target object the caller cannot read refuses the call"; it does, with that code.referenceNameVisiblewhere declared); only the MCP read guard's refusal refuses the whole call. Pinned in the dogfood run (crm_activity.contactontocrm_contact); the tool text, docs and changeset say exactly this.diagnoseDelegationcheck on its child object thatquery_recordsruns and carrieswithDelegationNoticewhen narrowed; a diagnosis that fails leaves the list as is.packages/core/src/security/second-object-read-exposure.pin.test.tsclassifies every non-test caller ofreferenceTargetOf; it now lists the two new callers (stdioExpandMapinstdio-data-bridge.tsas the decidedgetserving check, pinned bymcp-relation-reads.test.ts;mcp-relation-reads.tsas executing what the data door decides). This file is outside the claimed file surface: the classification is the pin's own requirement for any new caller. Its absence was theTest Core (9/10)failure on3d6e7691fee(this PR's, not main's); green on0e7914f180eand after.withheldFields(feat(mcp): query_records and get_record name the fields field-level security withheld from the caller #35179) landed onmainwhile this was built and is merged in: the record and each related list carrywithheldFieldsexactly as a plainget_record/query_recordsof that object does (pinned in the unit suite with a visibility double, and in the dogfood run as parity with the plain reads). Rows nested underexpandstay masked as a plain read of the target masks them; no per-targetwithheldFieldsis stated for them, because the note is per row set and an expanded record is nested in another object's rows.expandmember answers unexpanded ids. Both in-repo bridges serve it.overlap-checkat this head:origin/mainmerges cleanly; and the one open PR sharing files (feat(mcp): aggregate_records orders, cuts and counts groups in the database #35193) merges cleanly too. (Earlier in the build feat(mcp): query_records and get_record name the fields field-level security withheld from the caller #35179 and feat(mcp): a refused record read says what is not recorded, in the caller's language #35198 conflicted; feat(mcp): query_records and get_record name the fields field-level security withheld from the caller #35179 has since landed and is merged in.)#35145closes on merge: PR 1 (feat(mcp, objectql, driver-sql): query_records latestPer, each X with its latest Y in one call #35199) carriedlatestPer; this PR carries the related-objects read. The ask-card kinds named in the card's "Done when" live on scenarios: the open ask cards cover the ten question kinds the hosted ask set asks, so an ask regression is caught here first #35113.Verification
Rework readings from head
977e416ad0a(merge oforigin/maininto0e7914f180e; this PR's files unchanged by the merge) unless a line says otherwise. Every heavy run went throughos-verify-lock; each exit code was captured before any pipe.Targeted suites (rework)
mcp-relation-reads.test.ts: Tests 28 passed (28)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/corerepo pinsecond-object-read-exposure.pin.test.ts: Tests 4 passed (4);@objectstack/core--project repoat0e7914f180e: Test Files 8 passed, Tests 108 passed@objectstack/mcptypecheck (withcheck:test-typecheck): exit 0@objectstack/mcpfull suite at3d6e7691fee: Test Files 76 passed (76), Tests 1376 passed (1376)Dogfood battery
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 lineif (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 throughdist/(rebuild +ablation-dist-preflight) 1 failed / 8 passed (exactly THE RULE pin). Restore legs: blob == HEAD,git diff HEADempty, preflight--absent.Gates
dispatch-gates --commandsat977e416ad0a: 101 families, all run locally, all exit 0 (includingcheck:skill-examplesandcheck:dual-build-cjs-loadsafter building the six packages they read).--ranreconciliation with every exit code recorded: 101 derived, 101 run, 0 NOT-MEASURED (a derived zero).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) andLint & Repo Gatessuccess.overlap-checkat977e416ad0a:origin/mainmerges cleanly; feat(mcp): aggregate_records orders, cuts and counts groups in the database #35193 now conflicts inpackages/mcp/src/stdio-data-bridge.ts(it changed after round 1); the second of the two to land resolves it.Generated by Claude Code