|
30 | 30 | * action tools yield PER ACTION: a `sys_*` action whose author declared |
31 | 31 | * `ai.exposed: true` (the bridge attests it as `aiExposed`) is listed and |
32 | 32 | * run like any other exposed action (#27681, ADR-0011) — no other key and |
33 | | - * no deployment switch opens one. |
| 33 | + * no deployment switch opens one. The READ tools (list, describe, query, |
| 34 | + * get one, aggregate) yield PER OBJECT the same way: a `sys_*` object whose |
| 35 | + * author declared `enable.aiReadable: true` (the bridge attests it through |
| 36 | + * `isAiReadExposed`, {@link McpDataBridge.aiReadExposed}) is read like any |
| 37 | + * other object, under every later gate (#32442). No write tool ever opens a |
| 38 | + * `sys_*` object. |
34 | 39 | * - The bridge is bound to the caller's principal; tools cannot widen it. |
35 | 40 | * - Errors are returned as tool errors (text), never thrown across the wire, |
36 | 41 | * and never include secrets. |
@@ -144,6 +149,24 @@ export interface McpDataBridge { |
144 | 149 | */ |
145 | 150 | listObjectsDiagnosed?(): Promise<DiagnosedObjectListing<McpObjectSummary>>; |
146 | 151 | describeObject(name: string): Promise<unknown | null>; |
| 152 | + /** |
| 153 | + * [#32442, ruling A] Has the system object `name` opted its records into the |
| 154 | + * AI READ tools? The bridge answers with `isAiReadExposed` |
| 155 | + * (`@objectstack/spec/data`), the ONE reading of `enable.aiReadable`, over |
| 156 | + * the object's whole served definition: the stored-metadata family answers |
| 157 | + * `false` before the key is read, and only the boolean `true` opens. |
| 158 | + * |
| 159 | + * The read tools (`list_objects`, `describe_object`, `query_records`, |
| 160 | + * `get_record`, `aggregate_records`) ask it only for a `sys_*` name their |
| 161 | + * fail-closed guard would otherwise refuse. An attested object is then read |
| 162 | + * exactly like a business object: AS the caller, under the caller's |
| 163 | + * permissions, row-level security, the object's own read gates and field |
| 164 | + * masking. It never opens a write: every write tool keeps refusing `sys_*`. |
| 165 | + * |
| 166 | + * OPTIONAL and fail-closed: a bridge that omits it, or whose answer throws, |
| 167 | + * keeps every system object refused, exactly as before. |
| 168 | + */ |
| 169 | + aiReadExposed?(name: string): Promise<boolean>; |
147 | 170 | /** |
148 | 171 | * [#28715] The fields of `name` that declare options — the fields a |
149 | 172 | * formula's `label(record.<field>)` can answer on — or `null` when no such |
@@ -494,6 +517,12 @@ function isSystemObject(name: string): boolean { |
494 | 517 | return /^sys_/i.test(name); |
495 | 518 | } |
496 | 519 |
|
| 520 | +/** `items` kept where `keep` answers true, asked concurrently, in order. */ |
| 521 | +async function filterAsync<T>(items: readonly T[], keep: (item: T) => Promise<boolean>): Promise<T[]> { |
| 522 | + const verdicts = await Promise.all(items.map(keep)); |
| 523 | + return items.filter((_, i) => verdicts[i]); |
| 524 | +} |
| 525 | + |
497 | 526 | /** |
498 | 527 | * [#27681] Whether the action tools may list a summary with `allowSystemObjects` |
499 | 528 | * off: any action not on a `sys_*` object, and a `sys_*` one only when the |
@@ -2283,6 +2312,30 @@ export function registerObjectTools( |
2283 | 2312 | } |
2284 | 2313 | return undefined; |
2285 | 2314 | }; |
| 2315 | + /** |
| 2316 | + * [#32442] Does the bridge attest this system object's read opt-in |
| 2317 | + * ({@link McpDataBridge.aiReadExposed})? Fail-closed: no member, or a throw, |
| 2318 | + * is `false`. |
| 2319 | + */ |
| 2320 | + const attestsAiRead = async (objectName: string): Promise<boolean> => { |
| 2321 | + if (typeof bridge.aiReadExposed !== 'function') return false; |
| 2322 | + try { |
| 2323 | + return (await bridge.aiReadExposed(objectName)) === true; |
| 2324 | + } catch { |
| 2325 | + return false; |
| 2326 | + } |
| 2327 | + }; |
| 2328 | + /** |
| 2329 | + * [#32442] The guard of the READ tools only (`describe_object`, |
| 2330 | + * `query_records`, `get_record`, `aggregate_records`): {@link guard}, except |
| 2331 | + * that a `sys_*` object the bridge attests as AI-readable is admitted. Every |
| 2332 | + * write tool keeps {@link guard}, so no declaration opens a system write. |
| 2333 | + */ |
| 2334 | + const readGuard = async (objectName: string): Promise<string | undefined> => { |
| 2335 | + const bad = guard(objectName); |
| 2336 | + if (bad === undefined || !isSystemObject(objectName)) return bad; |
| 2337 | + return (await attestsAiRead(objectName)) ? undefined : bad; |
| 2338 | + }; |
2286 | 2339 |
|
2287 | 2340 | if (canRead) { |
2288 | 2341 | server.registerTool( |
@@ -2321,9 +2374,11 @@ export function registerObjectTools( |
2321 | 2374 | const diagnosed = bridge.listObjectsDiagnosed |
2322 | 2375 | ? await bridge.listObjectsDiagnosed() |
2323 | 2376 | : { objects: await bridge.listObjects(), degraded: false, errors: [] }; |
| 2377 | + // [#32442] A system object is listed only where the bridge attests |
| 2378 | + // its read opt-in, the same admission `readGuard` makes. |
2324 | 2379 | const visible = allowSystem |
2325 | 2380 | ? diagnosed.objects |
2326 | | - : diagnosed.objects.filter((o) => !isSystemObject(o.name)); |
| 2381 | + : await filterAsync(diagnosed.objects, async (o) => !isSystemObject(o.name) || await attestsAiRead(o.name)); |
2327 | 2382 | if (!diagnosed.degraded) { |
2328 | 2383 | return textResult({ objects: visible, totalCount: visible.length }); |
2329 | 2384 | } |
@@ -2357,7 +2412,7 @@ export function registerObjectTools( |
2357 | 2412 | annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }, |
2358 | 2413 | }, |
2359 | 2414 | async ({ objectName }) => { |
2360 | | - const bad = guard(objectName); |
| 2415 | + const bad = await readGuard(objectName); |
2361 | 2416 | if (bad) return errorResult(bad); |
2362 | 2417 | try { |
2363 | 2418 | const def = await bridge.describeObject(objectName); |
@@ -2546,7 +2601,13 @@ export function registerObjectTools( |
2546 | 2601 | { |
2547 | 2602 | description: |
2548 | 2603 | 'Query records from an object with optional filter, field selection, sorting and pagination. ' + |
2549 | | - 'Runs under the caller\'s permissions and row-level security.', |
| 2604 | + 'Runs under the caller\'s permissions and row-level security. ' + |
| 2605 | + 'A filter value "{current_user_id}" stands for you. ' + |
| 2606 | + // [#32442] The console's My Pending list, filter for filter: the |
| 2607 | + // participant read alone also serves requests the caller submitted |
| 2608 | + // or already decided, so an agent must not guess "mine" from it. |
| 2609 | + 'For example, where the app runs approvals, the ones waiting on you: objectName "sys_approval_request", where ' + |
| 2610 | + '{"status":"pending","pending_approvers":{"$contains":"{current_user_id}"}}; decide one with run_action.', |
2550 | 2611 | inputSchema: strictToolInput( |
2551 | 2612 | { |
2552 | 2613 | surface: 'this query_records call', |
@@ -2592,7 +2653,7 @@ export function registerObjectTools( |
2592 | 2653 | annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }, |
2593 | 2654 | }, |
2594 | 2655 | async ({ objectName, where, fields, limit, offset, orderBy }) => { |
2595 | | - const bad = guard(objectName); |
| 2656 | + const bad = await readGuard(objectName); |
2596 | 2657 | if (bad) return errorResult(bad); |
2597 | 2658 | try { |
2598 | 2659 | const result = await bridge.query(objectName, { |
@@ -2693,7 +2754,7 @@ export function registerObjectTools( |
2693 | 2754 | annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }, |
2694 | 2755 | }, |
2695 | 2756 | async ({ objectName, aggregations, groupBy, where, timezone }) => { |
2696 | | - const bad = guard(objectName); |
| 2757 | + const bad = await readGuard(objectName); |
2697 | 2758 | if (bad) return errorResult(bad); |
2698 | 2759 | try { |
2699 | 2760 | const rows = (await aggregateFn(objectName, { |
@@ -2731,7 +2792,7 @@ export function registerObjectTools( |
2731 | 2792 | annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }, |
2732 | 2793 | }, |
2733 | 2794 | async ({ objectName, recordId }) => { |
2734 | | - const bad = guard(objectName); |
| 2795 | + const bad = await readGuard(objectName); |
2735 | 2796 | if (bad) return errorResult(bad); |
2736 | 2797 | try { |
2737 | 2798 | const record = await bridge.get(objectName, recordId); |
|
0 commit comments