Skip to content

Commit df996a7

Browse files
committed
test(mcp): tool-surface pins and the skill line learn delete_records (WIP)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibx1NhZMrqCvW7FBxg5
1 parent be64143 commit df996a7

10 files changed

Lines changed: 31 additions & 7 deletions

‎packages/mcp/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ apply):
118118
'create_record' // Create
119119
'update_record' // Update by id
120120
'delete_record' // Delete by id (destructive; refused without confirm: true)
121+
'delete_records' // Delete many by filter or id list, ≤200 per call (refused with a preview without confirm: true)
121122

122123
// Business actions — operate the app, not just its rows
123124
'list_actions' // Invokable business actions the caller may run
@@ -130,7 +131,7 @@ and `resume_run` only when it implements `resumeRun`; a bridge without those
130131
seams serves the rest and advertises nothing it cannot do.
131132

132133
OAuth scopes narrow the families at consent time: `data:read` covers
133-
list/describe/query/aggregate/get, `data:write` covers create/update/delete, and
134+
list/describe/query/aggregate/get, `data:write` covers create/update/delete (both delete tools), and
134135
`actions:execute` covers `list_actions` / `run_action` / `resume_run`. A tool outside the grant
135136
is **not registered at all**, so the SDK rejects it as an unknown tool — the
136137
grant doubles as dispatch-time enforcement.

‎packages/mcp/src/mcp-coded-refusal.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ const SITES: readonly Site[] = [
102102
{ tool: 'update_record', args: { objectName: 'task', recordId: 't9', data: { title: 'x' } }, member: 'update' },
103103
// `confirm: true` passes the confirmation gate, so the call reaches `remove`.
104104
{ tool: 'delete_record', args: { objectName: 'task', recordId: 't9', confirm: true }, member: 'remove' },
105+
// [#30891] The selection read is the member a bulk delete calls first; a
106+
// refusal there refuses the whole call, rendered as the data tools render it.
107+
{ tool: 'delete_records', args: { objectName: 'task', where: {}, confirm: true }, member: 'query' },
105108
{ tool: 'list_actions', args: {}, member: 'listActions' },
106109
{ tool: 'run_action', args: { actionName: 'complete' }, member: 'runAction', actionDoor: true },
107110
{ tool: 'resume_run', args: { runId: 'r1' }, member: 'resumeRun', actionDoor: true },

‎packages/mcp/src/mcp-http-tools.scopes.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { MCPServerRuntime } from './mcp-server-runtime.js';
2323
import type { McpActionBridge, McpDataBridge } from './mcp-http-tools.js';
2424

2525
const READ_TOOLS = ['list_objects', 'describe_object', 'validate_expression', 'query_records', 'get_record', 'aggregate_records'];
26-
const WRITE_TOOLS = ['create_record', 'update_record', 'delete_record'];
26+
const WRITE_TOOLS = ['create_record', 'update_record', 'delete_record', 'delete_records'];
2727
const ACTION_TOOLS = ['list_actions', 'run_action'];
2828

2929
function makeBridge(): McpDataBridge & McpActionBridge & { calls: any[] } {

‎packages/mcp/src/mcp-http-tools.unknown-argument-keys.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ const VALID_ARGS: Record<string, Record<string, unknown>> = {
108108
update_record: { objectName: 'crm_opportunity', recordId: 'r1', data: { name: 'x' } },
109109
// `confirm: true`: without it the confirmation gate refuses before the bridge.
110110
delete_record: { objectName: 'crm_opportunity', recordId: 'r1', confirm: true },
111+
// [#30891] A selection is required (`where` or `recordIds`); `confirm: true`
112+
// deletes, where an unconfirmed call is answered with the refusal and a preview.
113+
delete_records: { objectName: 'crm_opportunity', where: { stage: 'closed_lost' }, confirm: true },
111114
list_actions: {},
112115
run_action: { actionName: 'complete_task' },
113116
resume_run: { runId: 'run_1' },
@@ -214,12 +217,13 @@ describe('MCP tool arguments — undeclared keys are refused (#16913)', () => {
214217

215218
// ── The sweep: every advertised tool holds the same posture ────────────────
216219

217-
it('advertises the twelve tools this sweep covers', async () => {
220+
it('advertises the thirteen tools this sweep covers', async () => {
218221
const json = await rpc(runtime, bridge, 'tools/list');
219222
const names = (json.result?.tools ?? []).map((t: any) => t.name).sort();
220223
expect(names).toEqual(Object.keys(VALID_ARGS).sort());
221-
// [#15705] Twelve with `resume_run`, which this stub's bridge implements.
222-
expect(names).toHaveLength(12);
224+
// [#15705] Twelve with `resume_run`, which this stub's bridge implements;
225+
// [#30891] thirteen with `delete_records`.
226+
expect(names).toHaveLength(13);
223227
});
224228

225229
it('every advertised tool ACCEPTS its declared arguments (the sweep control)', async () => {

‎packages/mcp/src/mcp-server-runtime.authoring-scope.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import type {
5353
// ---------------------------------------------------------------------------
5454

5555
const READ_TOOLS = ['list_objects', 'describe_object', 'validate_expression', 'query_records', 'get_record', 'aggregate_records'];
56-
const WRITE_TOOLS = ['create_record', 'update_record', 'delete_record'];
56+
const WRITE_TOOLS = ['create_record', 'update_record', 'delete_record', 'delete_records'];
5757
const ACTION_TOOLS = ['list_actions', 'run_action'];
5858
const NATIVE_TOOLS = [...READ_TOOLS, ...WRITE_TOOLS, ...ACTION_TOOLS].sort();
5959

‎packages/mcp/src/mcp-server-runtime.http.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ describe('MCPServerRuntime.handleHttpRequest (Streamable HTTP)', () => {
9797
[
9898
'create_record',
9999
'delete_record',
100+
'delete_records',
100101
'describe_object',
101102
'get_record',
102103
'list_objects',

‎packages/mcp/src/mcp-stdio-tools.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ function makeBridge(): McpDataBridge & { calls: any[][] } {
184184
const OBJECT_TOOLS = [
185185
'create_record',
186186
'delete_record',
187+
'delete_records',
187188
'describe_object',
188189
'get_record',
189190
'list_objects',

‎packages/mcp/src/skill-md.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('renderSkillMarkdown', () => {
7272
'create_record',
7373
'update_record',
7474
'delete_record',
75+
'delete_records',
7576
'list_actions',
7677
'run_action',
7778
'resume_run',

‎packages/mcp/src/skill-md.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import type { AIToolDefinition } from '@objectstack/spec/contracts';
3434
import { MCP_OAUTH_SCOPE_DATA_READ, MCP_OAUTH_SCOPE_METADATA_WRITE } from '@objectstack/spec/ai';
35-
import { grantsAuthoringTools } from './mcp-http-tools.js';
35+
import { DELETE_RECORDS_MAX_PER_CALL, grantsAuthoringTools } from './mcp-http-tools.js';
3636

3737
/** Skill identity (mirrors the `SKILL.md` YAML frontmatter). */
3838
export const OBJECTSTACK_SKILL_NAME = 'objectstack';
@@ -289,6 +289,15 @@ create/update payload.
289289
permanently. The server REFUSES a call without \`confirm: true\`
290290
(\`ACTION_CONFIRMATION_REQUIRED\`) and nothing is deleted. Ask your human
291291
first; the flag asserts an approval, it does not obtain one.
292+
- **delete_records({ objectName, where | recordIds, confirm })** — delete many
293+
records of one object in one call, instead of one \`delete_record\` per row.
294+
Without \`confirm: true\` it deletes nothing and is REFUSED
295+
(\`ACTION_CONFIRMATION_REQUIRED\`) with a \`preview\`: how many records match
296+
and sample ids. Show that to your human, then retry with \`confirm: true\`.
297+
A confirmed call deletes up to ${DELETE_RECORDS_MAX_PER_CALL} records, each under your permissions and the
298+
object's delete rules (no one bypasses them); refused records stay and come
299+
back grouped by reason with their ids, and \`remaining\` says how many still
300+
match. Call again to continue.
292301
- **list_actions()** — list the business actions available to you (only those
293302
the app author exposed to AI and you are permitted to run), with each
294303
action's declared parameters, whether it operates on a record, and whether

‎packages/mcp/src/stdio-data-bridge.stored-metadata-body.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ const ENGINE_READ_SITES: Record<string, Record<string, number>> = {
492492
'stdio-data-bridge.ts': { 'find(object)': 2, 'aggregate(object)': 1 },
493493
// The ADR-0101 record resource reader.
494494
'plugin.ts': { 'find(objectName)': 1 },
495+
// [#30891] NOT an engine read: `delete_records` counting its selection
496+
// through the BRIDGE's `aggregate` member, the one enumerated above for
497+
// this transport, so the stored-body and hash refusals apply to it there.
498+
'mcp-http-tools.ts': { 'aggregate(objectName)': 1 },
495499
};
496500

497501
const ENGINE_READ_VERBS: ReadonlySet<string> = new Set(['find', 'findOne', 'aggregate', 'count']);

0 commit comments

Comments
 (0)