@sendinel/mcp-server 1.0.213 → 1.0.214
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/tools/connector.js +4 -0
- package/build/tools/contacts.js +4 -0
- package/build/tools/data.js +86 -36
- package/build/tools/gdpr.js +81 -22
- package/build/tools/org.js +58 -36
- package/package.json +1 -1
package/build/tools/connector.js
CHANGED
|
@@ -178,6 +178,7 @@ export function registerConnectorTools(server) {
|
|
|
178
178
|
return j({ error: tableError instanceof Error ? dbToolError(tableError).error : 'Could not list database tables' });
|
|
179
179
|
}
|
|
180
180
|
});
|
|
181
|
+
// No approval preflight (#4550): this tool has no target row to reject.
|
|
181
182
|
server.registerTool('install_connector_schema', {
|
|
182
183
|
title: 'Install Connector Schema',
|
|
183
184
|
annotations: {
|
|
@@ -195,6 +196,7 @@ export function registerConnectorTools(server) {
|
|
|
195
196
|
const result = await callConnectorApi('/api/dashboard/connector/schema/install', { method: 'POST' });
|
|
196
197
|
return j(result.ok ? result.data : { error: result.error });
|
|
197
198
|
});
|
|
199
|
+
// No approval preflight (#4550): this tool has no target row to reject.
|
|
198
200
|
server.registerTool('install_connector_view', {
|
|
199
201
|
title: 'Install Connector Live View',
|
|
200
202
|
annotations: {
|
|
@@ -223,6 +225,7 @@ export function registerConnectorTools(server) {
|
|
|
223
225
|
});
|
|
224
226
|
return j(result.ok ? result.data : { error: result.error });
|
|
225
227
|
});
|
|
228
|
+
// No approval preflight (#4550): mapping is validated by the dashboard route only after this gate.
|
|
226
229
|
server.registerTool('set_connector_mapping', {
|
|
227
230
|
title: 'Set Connector Mapping',
|
|
228
231
|
annotations: {
|
|
@@ -271,6 +274,7 @@ export function registerConnectorTools(server) {
|
|
|
271
274
|
});
|
|
272
275
|
return j(result.ok ? result.data : { error: result.error });
|
|
273
276
|
});
|
|
277
|
+
// No approval preflight (#4550): this tool has no target row to reject.
|
|
274
278
|
server.registerTool('resync_connector', {
|
|
275
279
|
title: 'Resync Connector Contacts',
|
|
276
280
|
annotations: {
|
package/build/tools/contacts.js
CHANGED
|
@@ -2437,6 +2437,8 @@ Requirements: urgency without desperation, acknowledge the gap, one clear CTA, v
|
|
|
2437
2437
|
return dbErrorResult(countError);
|
|
2438
2438
|
return j({ total: count ?? (data ?? []).length, sample: data ?? [] });
|
|
2439
2439
|
});
|
|
2440
|
+
// No approval preflight (#4550): nothing here rejects a missing target. An unknown site_id
|
|
2441
|
+
// returns an empty inactive list, and the approval binds that computed preview.
|
|
2440
2442
|
server.registerTool('identify_inactive', {
|
|
2441
2443
|
title: 'Identify Inactive',
|
|
2442
2444
|
annotations: {
|
|
@@ -2679,6 +2681,8 @@ Requirements: urgency without desperation, acknowledge the gap, one clear CTA, v
|
|
|
2679
2681
|
// total_groups counts every group found; groups_truncated says when limit cut the list.
|
|
2680
2682
|
return j({ duplicate_groups: result, total_groups: groups.length, groups_truncated: groups.length > result.length, coverage });
|
|
2681
2683
|
});
|
|
2684
|
+
// No approval preflight (#4550): a missing target or source is not rejected. The preview uses
|
|
2685
|
+
// target?.email, and the post-approval path calls rpc merge_subscribers with no not-found refusal.
|
|
2682
2686
|
server.registerTool('merge_subscribers', {
|
|
2683
2687
|
title: 'Merge Subscribers',
|
|
2684
2688
|
annotations: {
|
package/build/tools/data.js
CHANGED
|
@@ -4,7 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
import { adminDb, db } from '../db.js';
|
|
5
5
|
import { decrypt, encrypt } from '../crypto.js';
|
|
6
6
|
import { normalizeActiveCampaignAccountUrl } from '../lib/url-validation.js';
|
|
7
|
-
import { approvalPageUrl, assertChannelCanExecute, checkApproval, currentChannelContext, currentExecutingApprovalId, requestApproval, withApproval } from '../lib/action-approvals.js';
|
|
7
|
+
import { approvalPageUrl, assertChannelCanExecute, checkApproval, currentChannelContext, currentExecutingApprovalId, registerApprovalPreflight, requestApproval, withApproval } from '../lib/action-approvals.js';
|
|
8
8
|
import { getProjectId } from '../project.js';
|
|
9
9
|
import { logAudit } from '../audit.js';
|
|
10
10
|
import { dbToolError, deleteBlockedToolResult } from '../lib/db-error.js';
|
|
@@ -161,6 +161,82 @@ async function getPlatformProjectContext(client = adminDb(), orgId) {
|
|
|
161
161
|
throw new Error('organization has no Supabase-auth user to own the connection');
|
|
162
162
|
return { projectId, orgId: project.org_id, userId: userId };
|
|
163
163
|
}
|
|
164
|
+
/** Shared by the handler and the request-only preflight so the refusal text cannot drift. */
|
|
165
|
+
async function lookupSavedCredential(credentialId, orgId) {
|
|
166
|
+
const parsed = parseSavedCredentialId(credentialId);
|
|
167
|
+
if (!parsed)
|
|
168
|
+
return { ok: false, result: j({ error: 'Invalid credential_id' }) };
|
|
169
|
+
const client = adminDb();
|
|
170
|
+
let context;
|
|
171
|
+
try {
|
|
172
|
+
context = await getPlatformProjectContext(client, orgId);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
// Same catch body the handler used. These are business refusals, not a preflight outage.
|
|
176
|
+
return {
|
|
177
|
+
ok: false,
|
|
178
|
+
result: j({ error: error instanceof Error ? dbToolError(error).error : 'Failed to delete provider credential' }),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const table = parsed.source === 'platform' ? 'platform_connections' : 'import_jobs';
|
|
182
|
+
const columns = parsed.source === 'platform'
|
|
183
|
+
? 'id, platform, display_name, status, is_active, created_at'
|
|
184
|
+
: 'id, provider, status, created_at, completed_at';
|
|
185
|
+
const { data: credential, error: credentialErr } = await client
|
|
186
|
+
.schema('email')
|
|
187
|
+
.from(table)
|
|
188
|
+
.select(columns)
|
|
189
|
+
.eq('id', parsed.rowId)
|
|
190
|
+
.eq('org_id', context.orgId)
|
|
191
|
+
.eq('project_id', context.projectId)
|
|
192
|
+
.maybeSingle();
|
|
193
|
+
if (credentialErr)
|
|
194
|
+
return { ok: false, result: j(dbToolError(credentialErr)), dbError: credentialErr };
|
|
195
|
+
if (!credential)
|
|
196
|
+
return { ok: false, result: j({ error: 'Credential not found' }) };
|
|
197
|
+
return { ok: true, parsed, credential, context, client };
|
|
198
|
+
}
|
|
199
|
+
async function findActiveCustomWebhook(connectionId) {
|
|
200
|
+
const client = adminDb();
|
|
201
|
+
const projectId = getProjectId();
|
|
202
|
+
const { data: connection, error: lookupError } = await client
|
|
203
|
+
.schema('email')
|
|
204
|
+
.from('platform_connections')
|
|
205
|
+
.select('id, project_id, display_name, config')
|
|
206
|
+
.eq('id', connectionId)
|
|
207
|
+
.eq('project_id', projectId)
|
|
208
|
+
.eq('platform', 'custom')
|
|
209
|
+
.eq('is_active', true)
|
|
210
|
+
.maybeSingle();
|
|
211
|
+
return { client, projectId, connection, lookupError };
|
|
212
|
+
}
|
|
213
|
+
// Confirmed is not consulted. The outer request-only gate runs before the handler's
|
|
214
|
+
// preview, so the target must exist in this project on the first call as well as on replay.
|
|
215
|
+
async function deleteProviderCredentialPreflight(params) {
|
|
216
|
+
const credentialId = typeof params.credential_id === 'string' ? params.credential_id : '';
|
|
217
|
+
const orgId = typeof params.org_id === 'string' ? params.org_id : undefined;
|
|
218
|
+
const found = await lookupSavedCredential(credentialId, orgId);
|
|
219
|
+
if (!found.ok) {
|
|
220
|
+
if (found.dbError)
|
|
221
|
+
throw found.dbError;
|
|
222
|
+
return found.result;
|
|
223
|
+
}
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
async function rotateCustomWebhookSecretPreflight(params) {
|
|
227
|
+
const connectionId = typeof params.connection_id === 'string' ? params.connection_id : '';
|
|
228
|
+
const { connection, lookupError } = await findActiveCustomWebhook(connectionId);
|
|
229
|
+
if (lookupError)
|
|
230
|
+
throw lookupError;
|
|
231
|
+
if (!connection)
|
|
232
|
+
return j({ error: 'Custom webhook not found' });
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
// Partial test doubles of action-approvals omit this export. Production always provides it.
|
|
236
|
+
if (typeof registerApprovalPreflight === 'function') {
|
|
237
|
+
registerApprovalPreflight('delete_provider_credential', deleteProviderCredentialPreflight);
|
|
238
|
+
registerApprovalPreflight('rotate_custom_webhook_secret', rotateCustomWebhookSecretPreflight);
|
|
239
|
+
}
|
|
164
240
|
function createCampaignMigrationTotals(options) {
|
|
165
241
|
return {
|
|
166
242
|
contacts: { total: options.includeContacts ? 1 : 0, processed: 0 },
|
|
@@ -401,27 +477,10 @@ export function registerDataTools(server) {
|
|
|
401
477
|
},
|
|
402
478
|
}, async ({ org_id, credential_id, confirmed, approval_id }) => {
|
|
403
479
|
try {
|
|
404
|
-
const
|
|
405
|
-
if (!
|
|
406
|
-
return
|
|
407
|
-
const client =
|
|
408
|
-
const context = await getPlatformProjectContext(client, org_id);
|
|
409
|
-
const table = parsed.source === 'platform' ? 'platform_connections' : 'import_jobs';
|
|
410
|
-
const columns = parsed.source === 'platform'
|
|
411
|
-
? 'id, platform, display_name, status, is_active, created_at'
|
|
412
|
-
: 'id, provider, status, created_at, completed_at';
|
|
413
|
-
const { data: credential, error: credentialErr } = await client
|
|
414
|
-
.schema('email')
|
|
415
|
-
.from(table)
|
|
416
|
-
.select(columns)
|
|
417
|
-
.eq('id', parsed.rowId)
|
|
418
|
-
.eq('org_id', context.orgId)
|
|
419
|
-
.eq('project_id', context.projectId)
|
|
420
|
-
.maybeSingle();
|
|
421
|
-
if (credentialErr)
|
|
422
|
-
return j(dbToolError(credentialErr));
|
|
423
|
-
if (!credential)
|
|
424
|
-
return j({ error: 'Credential not found' });
|
|
480
|
+
const found = await lookupSavedCredential(credential_id, org_id);
|
|
481
|
+
if (!found.ok)
|
|
482
|
+
return found.result;
|
|
483
|
+
const { parsed, credential, context, client } = found;
|
|
425
484
|
const provider = parsed.source === 'platform' ? credential.platform : credential.provider;
|
|
426
485
|
const approvalParams = {
|
|
427
486
|
credential_id,
|
|
@@ -870,21 +929,12 @@ export function registerDataTools(server) {
|
|
|
870
929
|
},
|
|
871
930
|
}, async ({ connection_id, confirmed, approval_id }) => {
|
|
872
931
|
try {
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
.from('platform_connections')
|
|
878
|
-
.select('id, project_id, display_name, config')
|
|
879
|
-
.eq('id', connection_id)
|
|
880
|
-
.eq('project_id', projectId)
|
|
881
|
-
.eq('platform', 'custom')
|
|
882
|
-
.eq('is_active', true)
|
|
883
|
-
.maybeSingle();
|
|
884
|
-
if (lookupError)
|
|
885
|
-
return j(dbToolError(lookupError));
|
|
886
|
-
if (!connection)
|
|
932
|
+
const lookedUp = await findActiveCustomWebhook(connection_id);
|
|
933
|
+
if (lookedUp.lookupError)
|
|
934
|
+
return j(dbToolError(lookedUp.lookupError));
|
|
935
|
+
if (!lookedUp.connection)
|
|
887
936
|
return j({ error: 'Custom webhook not found' });
|
|
937
|
+
const { client, projectId, connection } = lookedUp;
|
|
888
938
|
if (!confirmed) {
|
|
889
939
|
return j({
|
|
890
940
|
confirmation_required: true,
|
package/build/tools/gdpr.js
CHANGED
|
@@ -3,11 +3,81 @@ import { z } from 'zod';
|
|
|
3
3
|
import { db } from '../db.js';
|
|
4
4
|
import { getProjectId } from '../project.js';
|
|
5
5
|
import { logAudit } from '../audit.js';
|
|
6
|
-
import { approvalSatisfied, assertChannelCanExecute, currentChannelContext, requestApproval, checkApproval } from '../lib/action-approvals.js';
|
|
6
|
+
import { approvalSatisfied, assertChannelCanExecute, currentChannelContext, requestApproval, checkApproval, registerApprovalPreflight } from '../lib/action-approvals.js';
|
|
7
7
|
import { dbToolError, deleteBlockedToolResult } from '../lib/db-error.js';
|
|
8
8
|
import { subscriberBlockers } from '../lib/delete-blockers.js';
|
|
9
9
|
const txt = (text) => ({ content: [{ type: 'text', text }] });
|
|
10
10
|
const j = (data) => txt(JSON.stringify(data, null, 2));
|
|
11
|
+
async function findSubscriberForDeletion(contactId) {
|
|
12
|
+
const { data, error } = await db()
|
|
13
|
+
.from('subscribers')
|
|
14
|
+
.select('id, email')
|
|
15
|
+
.eq('id', contactId)
|
|
16
|
+
.eq('project_id', getProjectId())
|
|
17
|
+
.maybeSingle();
|
|
18
|
+
return { contact: (data ?? null), error };
|
|
19
|
+
}
|
|
20
|
+
// A database error is not "missing". The handler still maps it to the old not-found text;
|
|
21
|
+
// the preflight throws so the registration boundary reports internal_error and writes no approval.
|
|
22
|
+
async function deleteSubscriberDataPreflight(params) {
|
|
23
|
+
const contactId = typeof params.contact_id === 'string' ? params.contact_id : '';
|
|
24
|
+
const { contact, error } = await findSubscriberForDeletion(contactId);
|
|
25
|
+
if (error)
|
|
26
|
+
throw error;
|
|
27
|
+
if (!contact)
|
|
28
|
+
return txt('Contact not found or does not belong to this project.');
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
async function loadCcpaRequest(requestId) {
|
|
32
|
+
const projectId = getProjectId();
|
|
33
|
+
const { data, error } = await db()
|
|
34
|
+
.from('compliance_requests')
|
|
35
|
+
.select('id, email, request_type, status, expires_at')
|
|
36
|
+
.eq('id', requestId)
|
|
37
|
+
.eq('project_id', projectId)
|
|
38
|
+
.eq('regulation', 'ccpa')
|
|
39
|
+
.maybeSingle();
|
|
40
|
+
return { projectId, request: (data ?? null), error };
|
|
41
|
+
}
|
|
42
|
+
function ccpaNotActionable(request) {
|
|
43
|
+
if (!request)
|
|
44
|
+
return 'CCPA request not found or does not belong to this project.';
|
|
45
|
+
if (request.status === 'completed' || request.status === 'expired') {
|
|
46
|
+
return `Request is already "${request.status}" and cannot be actioned further.`;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
function ccpaNotReadyToComplete(request) {
|
|
51
|
+
if (request.status !== 'verified') {
|
|
52
|
+
return `Request must be "verified" before it can be completed (currently "${request.status}"). Call this tool with status: "verified" first.`;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
// Only completed + delete requests the hand-written approval. status:'verified' updates the row
|
|
57
|
+
// with no approval, and a non-delete completion does too. approvalSatisfied can skip the gate
|
|
58
|
+
// only after those refusals, so this preflight refuses the same rows the handler refuses first.
|
|
59
|
+
async function actionCcpaRequestPreflight(params) {
|
|
60
|
+
if (params.status !== 'completed')
|
|
61
|
+
return undefined;
|
|
62
|
+
const requestId = typeof params.request_id === 'string' ? params.request_id : '';
|
|
63
|
+
const { request, error } = await loadCcpaRequest(requestId);
|
|
64
|
+
if (error)
|
|
65
|
+
throw error;
|
|
66
|
+
const closed = ccpaNotActionable(request);
|
|
67
|
+
if (closed)
|
|
68
|
+
return txt(closed);
|
|
69
|
+
const notReady = ccpaNotReadyToComplete(request);
|
|
70
|
+
if (notReady)
|
|
71
|
+
return txt(notReady);
|
|
72
|
+
if (request.request_type !== 'delete')
|
|
73
|
+
return undefined;
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
// Partial test doubles of action-approvals omit this export. Production always provides it.
|
|
77
|
+
if (typeof registerApprovalPreflight === 'function') {
|
|
78
|
+
registerApprovalPreflight('delete_subscriber_data', deleteSubscriberDataPreflight);
|
|
79
|
+
registerApprovalPreflight('action_ccpa_request', actionCcpaRequestPreflight);
|
|
80
|
+
}
|
|
11
81
|
export function registerGdprTools(server) {
|
|
12
82
|
server.registerTool('delete_subscriber_data', {
|
|
13
83
|
title: 'Delete Subscriber Data',
|
|
@@ -24,13 +94,9 @@ export function registerGdprTools(server) {
|
|
|
24
94
|
approval_id: z.string().uuid().optional().describe('Required — get this by calling once without it, then have a human approve via dashboard.'),
|
|
25
95
|
},
|
|
26
96
|
}, async ({ contact_id, reason, approval_id }) => {
|
|
27
|
-
// Verify contact belongs to this project (defense in depth)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.select('id, email')
|
|
31
|
-
.eq('id', contact_id)
|
|
32
|
-
.eq('project_id', getProjectId())
|
|
33
|
-
.maybeSingle();
|
|
97
|
+
// Verify contact belongs to this project (defense in depth). A lookup error stays
|
|
98
|
+
// the historical not-found text; the registered preflight reports it as internal_error.
|
|
99
|
+
const { contact } = await findSubscriberForDeletion(contact_id);
|
|
34
100
|
if (!contact)
|
|
35
101
|
return txt('Contact not found or does not belong to this project.');
|
|
36
102
|
const approvalParams = { contact_id, email: contact.email, reason };
|
|
@@ -132,21 +198,14 @@ export function registerGdprTools(server) {
|
|
|
132
198
|
approval_id: z.string().uuid().optional().describe('Required to complete a delete request after a human approves the summary in the dashboard.'),
|
|
133
199
|
},
|
|
134
200
|
}, async ({ request_id, status, approval_id }) => {
|
|
135
|
-
const projectId =
|
|
136
|
-
const { data: request, error: fetchErr } = await db()
|
|
137
|
-
.from('compliance_requests')
|
|
138
|
-
.select('id, email, request_type, status, expires_at')
|
|
139
|
-
.eq('id', request_id)
|
|
140
|
-
.eq('project_id', projectId)
|
|
141
|
-
.eq('regulation', 'ccpa')
|
|
142
|
-
.maybeSingle();
|
|
201
|
+
const { projectId, request, error: fetchErr } = await loadCcpaRequest(request_id);
|
|
143
202
|
if (fetchErr)
|
|
144
203
|
return txt(`Error: ${dbToolError(fetchErr).error}`);
|
|
204
|
+
const closed = ccpaNotActionable(request);
|
|
205
|
+
if (closed)
|
|
206
|
+
return txt(closed);
|
|
145
207
|
if (!request)
|
|
146
208
|
return txt('CCPA request not found or does not belong to this project.');
|
|
147
|
-
if (request.status === 'completed' || request.status === 'expired') {
|
|
148
|
-
return txt(`Request is already "${request.status}" and cannot be actioned further.`);
|
|
149
|
-
}
|
|
150
209
|
if (status === 'verified') {
|
|
151
210
|
if (request.status !== 'pending') {
|
|
152
211
|
return txt(`Request must be "pending" to verify (currently "${request.status}").`);
|
|
@@ -177,9 +236,9 @@ export function registerGdprTools(server) {
|
|
|
177
236
|
});
|
|
178
237
|
return j({ ok: true, request: data });
|
|
179
238
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
239
|
+
const notReady = ccpaNotReadyToComplete(request);
|
|
240
|
+
if (notReady)
|
|
241
|
+
return txt(notReady);
|
|
183
242
|
if (request.request_type === 'delete') {
|
|
184
243
|
const approvalParams = {
|
|
185
244
|
request_id,
|
package/build/tools/org.js
CHANGED
|
@@ -3,7 +3,7 @@ import { z } from 'zod';
|
|
|
3
3
|
import { logAudit } from '../audit.js';
|
|
4
4
|
import { adminDb, db } from '../db.js';
|
|
5
5
|
import { getProjectId } from '../project.js';
|
|
6
|
-
import { assertChannelCanExecute, checkApproval, currentChannelContext, requestApproval, withApproval } from '../lib/action-approvals.js';
|
|
6
|
+
import { assertChannelCanExecute, checkApproval, currentChannelContext, registerApprovalPreflight, requestApproval, withApproval } from '../lib/action-approvals.js';
|
|
7
7
|
import { callSendinelV1 } from '../lib/v1-client.js';
|
|
8
8
|
import { dbToolError } from '../lib/db-error.js';
|
|
9
9
|
import { checkPlanLimit } from '../plan-limits.js';
|
|
@@ -62,7 +62,7 @@ async function resolveCurrentOrgId(requestedOrgId) {
|
|
|
62
62
|
.eq('id', getProjectId())
|
|
63
63
|
.maybeSingle();
|
|
64
64
|
if (error)
|
|
65
|
-
return { ok: false, ...dbToolError(error) };
|
|
65
|
+
return { ok: false, ...dbToolError(error), cause: error };
|
|
66
66
|
if (!project?.org_id)
|
|
67
67
|
return { ok: false, error: 'Project has no organization', code: 'NO_ORG' };
|
|
68
68
|
if (requestedOrgId && requestedOrgId !== project.org_id) {
|
|
@@ -70,6 +70,46 @@ async function resolveCurrentOrgId(requestedOrgId) {
|
|
|
70
70
|
}
|
|
71
71
|
return { ok: true, orgId: project.org_id };
|
|
72
72
|
}
|
|
73
|
+
/** Shared by the handler and the request-only preflight so the refusal text cannot drift. */
|
|
74
|
+
async function lookupOrgMember(userId, orgId) {
|
|
75
|
+
const context = await resolveCurrentOrgId(orgId);
|
|
76
|
+
if (!context.ok) {
|
|
77
|
+
const dbError = 'cause' in context ? context.cause : undefined;
|
|
78
|
+
return { ok: false, result: j({ error: context.error, code: context.code }), dbError };
|
|
79
|
+
}
|
|
80
|
+
const { data: member, error: memberErr } = await db()
|
|
81
|
+
.from('org_members')
|
|
82
|
+
.select('id, user_id, role')
|
|
83
|
+
.eq('org_id', context.orgId)
|
|
84
|
+
.eq('user_id', userId)
|
|
85
|
+
.maybeSingle();
|
|
86
|
+
if (memberErr)
|
|
87
|
+
return { ok: false, result: j(dbToolError(memberErr)), dbError: memberErr };
|
|
88
|
+
if (!member)
|
|
89
|
+
return { ok: false, result: j({ error: 'Member not found', code: 'NOT_FOUND' }) };
|
|
90
|
+
return { ok: true, orgId: context.orgId, member: member };
|
|
91
|
+
}
|
|
92
|
+
function preflightOrgId(params) {
|
|
93
|
+
return typeof params.org_id === 'string' ? params.org_id : undefined;
|
|
94
|
+
}
|
|
95
|
+
// Existence and org ownership are checked whether or not confirmed is present (schema default
|
|
96
|
+
// false). The last-owner refusal runs only after confirmed=true in the handler. Applying it
|
|
97
|
+
// here would refuse an unconfirmed request-only call that currently receives an approval request.
|
|
98
|
+
async function teamMemberTargetPreflight(params) {
|
|
99
|
+
const userId = typeof params.user_id === 'string' ? params.user_id : '';
|
|
100
|
+
const found = await lookupOrgMember(userId, preflightOrgId(params));
|
|
101
|
+
if (!found.ok) {
|
|
102
|
+
if (found.dbError)
|
|
103
|
+
throw found.dbError;
|
|
104
|
+
return found.result;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
// Partial test doubles of action-approvals omit this export. Production always provides it.
|
|
109
|
+
if (typeof registerApprovalPreflight === 'function') {
|
|
110
|
+
registerApprovalPreflight('remove_team_member', teamMemberTargetPreflight);
|
|
111
|
+
registerApprovalPreflight('set_team_member_role', teamMemberTargetPreflight);
|
|
112
|
+
}
|
|
73
113
|
function normalizeHost(host) {
|
|
74
114
|
if (!host)
|
|
75
115
|
return null;
|
|
@@ -208,33 +248,24 @@ export function registerOrgTools(server) {
|
|
|
208
248
|
approval_id: z.string().uuid().optional().describe('Approval token from a previous confirmed call without approval_id. Required when the action is not autonomous.'),
|
|
209
249
|
},
|
|
210
250
|
}, async ({ user_id, org_id, confirmed, approval_id }) => {
|
|
211
|
-
const
|
|
212
|
-
if (!
|
|
213
|
-
return
|
|
214
|
-
const {
|
|
215
|
-
|
|
216
|
-
.select('id, user_id, role')
|
|
217
|
-
.eq('org_id', context.orgId)
|
|
218
|
-
.eq('user_id', user_id)
|
|
219
|
-
.maybeSingle();
|
|
220
|
-
if (memberErr)
|
|
221
|
-
return j(dbToolError(memberErr));
|
|
222
|
-
if (!member)
|
|
223
|
-
return j({ error: 'Member not found', code: 'NOT_FOUND' });
|
|
224
|
-
const approvalParams = { user_id, org_id: context.orgId };
|
|
251
|
+
const found = await lookupOrgMember(user_id, org_id);
|
|
252
|
+
if (!found.ok)
|
|
253
|
+
return found.result;
|
|
254
|
+
const { orgId, member } = found;
|
|
255
|
+
const approvalParams = { user_id, org_id: orgId };
|
|
225
256
|
if (!confirmed) {
|
|
226
257
|
return j({
|
|
227
258
|
confirmation_required: true,
|
|
228
259
|
tool: 'remove_team_member',
|
|
229
260
|
member: { user_id: member.user_id, role: member.role },
|
|
230
|
-
message: `Removing this member (role: ${member.role}) revokes their access to org ${
|
|
261
|
+
message: `Removing this member (role: ${member.role}) revokes their access to org ${orgId}. Call again with confirmed=true to proceed.`,
|
|
231
262
|
});
|
|
232
263
|
}
|
|
233
264
|
if (member.role === 'owner') {
|
|
234
265
|
const { count } = await db()
|
|
235
266
|
.from('org_members')
|
|
236
267
|
.select('id', { count: 'exact', head: true })
|
|
237
|
-
.eq('org_id',
|
|
268
|
+
.eq('org_id', orgId)
|
|
238
269
|
.eq('role', 'owner');
|
|
239
270
|
if ((count ?? 0) <= 1)
|
|
240
271
|
return j({ error: 'Cannot remove the last owner', code: 'LAST_OWNER' });
|
|
@@ -257,7 +288,7 @@ export function registerOrgTools(server) {
|
|
|
257
288
|
const { error } = await db()
|
|
258
289
|
.from('org_members')
|
|
259
290
|
.delete()
|
|
260
|
-
.eq('org_id',
|
|
291
|
+
.eq('org_id', orgId)
|
|
261
292
|
.eq('user_id', user_id);
|
|
262
293
|
if (error)
|
|
263
294
|
return j(dbToolError(error));
|
|
@@ -265,7 +296,7 @@ export function registerOrgTools(server) {
|
|
|
265
296
|
action: 'remove_member',
|
|
266
297
|
resourceType: 'org_member',
|
|
267
298
|
resourceId: member.id,
|
|
268
|
-
details: { org_id:
|
|
299
|
+
details: { org_id: orgId, removed_user: user_id, role: member.role },
|
|
269
300
|
}).catch(() => { });
|
|
270
301
|
return j({ ok: true, removed_user_id: user_id });
|
|
271
302
|
});
|
|
@@ -286,20 +317,11 @@ export function registerOrgTools(server) {
|
|
|
286
317
|
approval_id: z.string().uuid().optional(),
|
|
287
318
|
},
|
|
288
319
|
}, async ({ user_id, role, org_id, confirmed, approval_id }) => {
|
|
289
|
-
const
|
|
290
|
-
if (!
|
|
291
|
-
return
|
|
292
|
-
const {
|
|
293
|
-
|
|
294
|
-
.select('id, user_id, role')
|
|
295
|
-
.eq('org_id', context.orgId)
|
|
296
|
-
.eq('user_id', user_id)
|
|
297
|
-
.maybeSingle();
|
|
298
|
-
if (memberErr)
|
|
299
|
-
return j(dbToolError(memberErr));
|
|
300
|
-
if (!member)
|
|
301
|
-
return j({ error: 'Member not found', code: 'NOT_FOUND' });
|
|
302
|
-
const approvalParams = { user_id, role, org_id: context.orgId };
|
|
320
|
+
const found = await lookupOrgMember(user_id, org_id);
|
|
321
|
+
if (!found.ok)
|
|
322
|
+
return found.result;
|
|
323
|
+
const { orgId, member } = found;
|
|
324
|
+
const approvalParams = { user_id, role, org_id: orgId };
|
|
303
325
|
if (!confirmed) {
|
|
304
326
|
return j({
|
|
305
327
|
confirmation_required: true,
|
|
@@ -326,7 +348,7 @@ export function registerOrgTools(server) {
|
|
|
326
348
|
const { data, error } = await db()
|
|
327
349
|
.from('org_members')
|
|
328
350
|
.update({ role })
|
|
329
|
-
.eq('org_id',
|
|
351
|
+
.eq('org_id', orgId)
|
|
330
352
|
.eq('user_id', user_id)
|
|
331
353
|
.select('user_id, role')
|
|
332
354
|
.maybeSingle();
|
|
@@ -336,7 +358,7 @@ export function registerOrgTools(server) {
|
|
|
336
358
|
action: 'update_member_role',
|
|
337
359
|
resourceType: 'org_member',
|
|
338
360
|
resourceId: member.id,
|
|
339
|
-
details: { org_id:
|
|
361
|
+
details: { org_id: orgId, user_id, new_role: role },
|
|
340
362
|
}).catch(() => { });
|
|
341
363
|
return j({ member: data });
|
|
342
364
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendinel/mcp-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.214",
|
|
4
4
|
"description": "AI-controlled email operations control plane for campaigns, contacts, segments, analytics, and multi-provider sending via MCP.",
|
|
5
5
|
"mcpName": "ai.sendinel/mcp-server",
|
|
6
6
|
"type": "module",
|