@sendinel/mcp-server 1.0.43 → 1.0.44
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/contacts.js +37 -79
- package/package.json +1 -1
package/build/tools/contacts.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { CONTACT_ENRICHMENT_PROVIDERS } from '@desler/models';
|
|
3
3
|
import { createContactEnrichmentAdapters, enrichContactFromConnections, } from '@desler/models/contact-enrichment';
|
|
4
|
-
import { buildPreviewAttentionEnvelope, applySegmentRules, ContactPropertyAnomalyLogger, normalizeContactProperties, getAttentionDecision, getContactNeighborhood, getScheduledTouches, } from '@sendinel/domain';
|
|
4
|
+
import { buildPreviewAttentionEnvelope, applySegmentRules, ContactPropertyAnomalyLogger, normalizeContactProperties, getAttentionDecision, getContactNeighborhood, getScheduledTouches, findContactDuplicateGroups, } from '@sendinel/domain';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { db, projectClientForWriteback } from '../db.js';
|
|
7
7
|
import { getProjectId } from '../project.js';
|
|
@@ -2104,7 +2104,7 @@ Requirements: urgency without desperation, acknowledge the gap, one clear CTA, v
|
|
|
2104
2104
|
idempotentHint: true,
|
|
2105
2105
|
openWorldHint: false,
|
|
2106
2106
|
},
|
|
2107
|
-
description: 'Find duplicate contacts using fuzzy email matching and exact name matching. Returns grouped candidates with confidence scores.',
|
|
2107
|
+
description: 'Find duplicate contacts using fuzzy email matching and exact name matching. Returns grouped candidates with confidence scores. Each group also suggests which contact to keep (suggested_target_id, source_ids) for merge_subscribers, and flags probably_different_people when the first names differ (e.g. two people at one company): never merge those without asking the user.',
|
|
2108
2108
|
inputSchema: {
|
|
2109
2109
|
confidence_threshold: z.number().min(0.5).max(1).optional().describe('Minimum similarity (0.5-1.0, default 0.8)'),
|
|
2110
2110
|
limit: z.number().int().min(1).max(200).optional().describe('Max duplicate groups (default 50)'),
|
|
@@ -2130,15 +2130,35 @@ Requirements: urgency without desperation, acknowledge the gap, one clear CTA, v
|
|
|
2130
2130
|
return j({ duplicate_groups: [], total_groups: 0, coverage: { contacts_scanned: 0, contacts_matching: 0, contact_limit: CONTACT_SCAN_LIMIT, complete: true } });
|
|
2131
2131
|
siteIds = ids;
|
|
2132
2132
|
}
|
|
2133
|
+
// If the last sync time can't be read, hide nothing extra: a longer list beats a missing duplicate.
|
|
2134
|
+
let byodCutoff = null;
|
|
2135
|
+
try {
|
|
2136
|
+
const { data: lastSync } = await db()
|
|
2137
|
+
.from('cron_runs')
|
|
2138
|
+
.select('started_at')
|
|
2139
|
+
.eq('job_name', 'byod-sync')
|
|
2140
|
+
.eq('status', 'success')
|
|
2141
|
+
.order('started_at', { ascending: false })
|
|
2142
|
+
.limit(1)
|
|
2143
|
+
.maybeSingle();
|
|
2144
|
+
byodCutoff = lastSync?.started_at ?? null;
|
|
2145
|
+
}
|
|
2146
|
+
catch {
|
|
2147
|
+
byodCutoff = null;
|
|
2148
|
+
}
|
|
2133
2149
|
const pageQuery = (from) => {
|
|
2134
2150
|
let q = db()
|
|
2135
2151
|
.from('subscribers')
|
|
2136
2152
|
.select('id, email, first_name, last_name, engagement_score, lifecycle_stage, created_at, source', { count: 'exact' })
|
|
2137
|
-
.eq('project_id', projectId)
|
|
2138
|
-
.eq('global_unsubscribed', false);
|
|
2153
|
+
.eq('project_id', projectId);
|
|
2139
2154
|
// #3604: hide seed/fixture rows like every other default contact view.
|
|
2140
2155
|
if (!include_test)
|
|
2141
2156
|
q = q.not('is_test', 'is', true);
|
|
2157
|
+
// #3750: scan the same contacts as the dashboard's Find & Merge Duplicates screen. Unsubscribed
|
|
2158
|
+
// contacts are still duplicates (a merge keeps their consent), and rows the last BYOD sync
|
|
2159
|
+
// no longer saw are hidden there.
|
|
2160
|
+
if (byodCutoff)
|
|
2161
|
+
q = q.or(`source.neq.database_import,updated_at.gte.${byodCutoff}`);
|
|
2142
2162
|
if (siteIds)
|
|
2143
2163
|
q = q.in('id', siteIds);
|
|
2144
2164
|
return q.order('created_at', { ascending: true }).order('id', { ascending: true })
|
|
@@ -2168,82 +2188,20 @@ Requirements: urgency without desperation, acknowledge the gap, one clear CTA, v
|
|
|
2168
2188
|
const coverage = { contacts_scanned: scanned, contacts_matching: matching, contact_limit: CONTACT_SCAN_LIMIT, complete: matching === null ? null : matching <= scanned };
|
|
2169
2189
|
if (!contacts?.length)
|
|
2170
2190
|
return j({ duplicate_groups: [], total_groups: 0, coverage });
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
}
|
|
2183
|
-
return dp[m];
|
|
2184
|
-
};
|
|
2185
|
-
const similarity = (a, b) => {
|
|
2186
|
-
if (a === b)
|
|
2187
|
-
return 1;
|
|
2188
|
-
const maxLen = Math.max(a.length, b.length);
|
|
2189
|
-
if (maxLen === 0)
|
|
2190
|
-
return 1;
|
|
2191
|
-
return 1 - lev(a, b) / maxLen;
|
|
2192
|
-
};
|
|
2193
|
-
const byDomain = {};
|
|
2194
|
-
for (const c of contacts) {
|
|
2195
|
-
const [, domain] = c.email.toLowerCase().split('@');
|
|
2196
|
-
if (!byDomain[domain])
|
|
2197
|
-
byDomain[domain] = [];
|
|
2198
|
-
byDomain[domain].push(c);
|
|
2199
|
-
}
|
|
2200
|
-
const groups = [];
|
|
2201
|
-
const merged = new Set();
|
|
2202
|
-
for (const domain of Object.keys(byDomain)) {
|
|
2203
|
-
const dc = byDomain[domain];
|
|
2204
|
-
for (let i = 0; i < dc.length; i++) {
|
|
2205
|
-
if (merged.has(dc[i].id))
|
|
2206
|
-
continue;
|
|
2207
|
-
const localA = dc[i].email.split('@')[0].toLowerCase();
|
|
2208
|
-
const group = [dc[i]];
|
|
2209
|
-
for (let jj = i + 1; jj < dc.length; jj++) {
|
|
2210
|
-
if (merged.has(dc[jj].id))
|
|
2211
|
-
continue;
|
|
2212
|
-
const localB = dc[jj].email.split('@')[0].toLowerCase();
|
|
2213
|
-
const sim = similarity(localA, localB);
|
|
2214
|
-
if (sim >= confidence_threshold && sim < 1) {
|
|
2215
|
-
group.push(dc[jj]);
|
|
2216
|
-
merged.add(dc[jj].id);
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
if (group.length > 1) {
|
|
2220
|
-
merged.add(dc[i].id);
|
|
2221
|
-
const avgSim = similarity(group[0].email.split('@')[0].toLowerCase(), group[1].email.split('@')[0].toLowerCase());
|
|
2222
|
-
groups.push({ group, confidence: Math.round(avgSim * 100) / 100, reason: 'similar_email' });
|
|
2223
|
-
}
|
|
2224
|
-
}
|
|
2225
|
-
}
|
|
2226
|
-
const byName = {};
|
|
2227
|
-
for (const c of contacts) {
|
|
2228
|
-
if (merged.has(c.id))
|
|
2229
|
-
continue;
|
|
2230
|
-
const fn = (c.first_name ?? '').toLowerCase().trim();
|
|
2231
|
-
const ln = (c.last_name ?? '').toLowerCase().trim();
|
|
2232
|
-
if (!fn && !ln)
|
|
2233
|
-
continue;
|
|
2234
|
-
const key = `${fn}|${ln}`;
|
|
2235
|
-
if (!byName[key])
|
|
2236
|
-
byName[key] = [];
|
|
2237
|
-
byName[key].push(c);
|
|
2238
|
-
}
|
|
2239
|
-
for (const nameGroup of Object.values(byName)) {
|
|
2240
|
-
if (nameGroup.length > 1) {
|
|
2241
|
-
groups.push({ group: nameGroup, confidence: 0.7, reason: 'same_name' });
|
|
2242
|
-
}
|
|
2243
|
-
}
|
|
2244
|
-
groups.sort((a, b) => b.confidence - a.confidence);
|
|
2191
|
+
// The matching rule is shared with the dashboard screen (@sendinel/domain, #3743/#3750).
|
|
2192
|
+
const groups = findContactDuplicateGroups(contacts, { threshold: confidence_threshold })
|
|
2193
|
+
.map((g) => ({
|
|
2194
|
+
group: g.contacts,
|
|
2195
|
+
confidence: g.confidence,
|
|
2196
|
+
reason: g.reason,
|
|
2197
|
+
suggested_target_id: g.suggested_target_id,
|
|
2198
|
+
source_ids: g.source_ids,
|
|
2199
|
+
probably_different_people: g.probably_different_people,
|
|
2200
|
+
different_first_names: g.different_first_names,
|
|
2201
|
+
}));
|
|
2245
2202
|
const result = groups.slice(0, maxGroups);
|
|
2246
|
-
|
|
2203
|
+
// total_groups counts every group found; groups_truncated says when limit cut the list.
|
|
2204
|
+
return j({ duplicate_groups: result, total_groups: groups.length, groups_truncated: groups.length > result.length, coverage });
|
|
2247
2205
|
});
|
|
2248
2206
|
server.registerTool('merge_subscribers', {
|
|
2249
2207
|
title: 'Merge Subscribers',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendinel/mcp-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
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",
|