scrapeloop-mcp 0.7.0 → 0.8.0

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.
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Retry contracts for every MCP operation that does not use HTTP GET.
3
+ *
4
+ * A POST may still be read-only, such as an estimate with a JSON filter body.
5
+ * Every true mutation declares whether it is provably idempotent, protected by
6
+ * a durable caller key, reconciliation-only, or forbidden from automatic retry.
7
+ */
8
+
9
+ const read = (method = 'POST') => ({ method, effect: 'read', retry: 'bounded' });
10
+ const idempotent = (method, inspectWith, matchFields) => ({
11
+ method,
12
+ effect: 'mutation',
13
+ retry: 'idempotent',
14
+ inspect_with: inspectWith,
15
+ match_fields: matchFields,
16
+ });
17
+ const keyed = (method, inspectWith, matchFields) => ({
18
+ method,
19
+ effect: 'mutation',
20
+ retry: 'idempotency_key',
21
+ inspect_with: inspectWith,
22
+ match_fields: matchFields,
23
+ });
24
+ const reconcile = (method, inspectWith, matchFields) => ({
25
+ method,
26
+ effect: 'mutation',
27
+ retry: 'reconcile',
28
+ inspect_with: inspectWith,
29
+ match_fields: matchFields,
30
+ });
31
+ const never = (method, inspectWith, matchFields) => ({
32
+ method,
33
+ effect: 'mutation',
34
+ retry: 'never',
35
+ inspect_with: inspectWith,
36
+ match_fields: matchFields,
37
+ });
38
+
39
+ export const MUTATION_POLICIES = Object.freeze({
40
+ create_integration: keyed('POST', ['list_integrations'], ['vendor', 'plugin_kind']),
41
+ add_credential: reconcile('POST', ['list_credentials'], ['integration_id', 'label']),
42
+ test_credential: idempotent('POST', ['list_credentials'], ['credential_id']),
43
+ preview_pipeline: read(),
44
+ preview_scrape_plan: read(),
45
+ create_scrape_plan: keyed('POST', ['list_scrape_plans'], ['name', 'target_list_id', 'kind']),
46
+ pause_scrape_plan: never('POST', ['get_scrape_plan'], ['plan_id']),
47
+ estimate_scrape: read(),
48
+ submit_scrape: keyed('POST', ['list_jobs'], ['kind', 'integration_id', 'credential_id', 'table_id']),
49
+ cancel_job: never('POST', ['get_job'], ['job_id', 'status']),
50
+ attach_job_to_table: idempotent('POST', ['get_job'], ['job_id']),
51
+ search_leads: read(),
52
+ estimate_leads: read(),
53
+ expand_job_titles: read(),
54
+ reveal_lead: idempotent('POST', ['search_leads', 'get_credits'], ['global_person_id']),
55
+ save_leads: reconcile('POST', ['search_leads', 'get_credits'], ['global_person_ids']),
56
+ estimate_lead_import: read(),
57
+ import_leads_to_table: reconcile('POST', ['get_lists', 'get_list_rows'], ['list_id', 'new_list_name']),
58
+ save_search: idempotent('POST', ['list_saved_searches'], ['name']),
59
+ bulk_verify_leads: reconcile('POST', ['list_jobs'], ['lead_ids', 'global_person_ids']),
60
+ search_local_leads: read(),
61
+ estimate_local_leads: read(),
62
+ reveal_local_lead: idempotent('POST', ['search_local_leads', 'get_credits'], ['place_id']),
63
+ fill_coverage_gap: reconcile('POST', ['list_jobs', 'search_local_leads'], ['filters']),
64
+ verify_email: never('POST', ['get_credits'], ['email']),
65
+ verify_catchall: keyed('POST', ['get_credits'], ['email']),
66
+ preview_cleaners: read(),
67
+ apply_cleaners: reconcile('POST', ['get_lists'], ['list_id', 'cleaners']),
68
+ create_preset: reconcile('POST', ['list_presets'], ['name']),
69
+ estimate_enrich: read(),
70
+ run_enrich: never('POST', ['list_jobs'], ['preset_slug', 'preset_id', 'lead_ids', 'list_id']),
71
+ test_recipe: never('POST', ['get_credits'], ['lead_id']),
72
+ update_ai_settings: idempotent('PUT', ['get_ai_settings'], ['default_ai_model', 'enabled_models']),
73
+ update_playbook: idempotent('PUT', ['get_playbook'], ['channels', 'scrape', 'tables', 'checks', 'routing', 'campaigns']),
74
+ set_playbook_niches: idempotent('PUT', ['get_playbook'], ['niches']),
75
+ update_ai_context: idempotent('PUT', ['get_ai_context'], ['company_description', 'icp']),
76
+ generate_ai_context: never('POST', ['get_ai_context', 'get_credits'], ['domain']),
77
+ create_strategy: reconcile('POST', ['list_strategies'], ['name']),
78
+ assign_strategy: reconcile('POST', ['list_strategies'], ['strategy_id', 'lead_ids', 'list_id']),
79
+ import_instantly_campaigns: reconcile('POST', ['list_campaigns'], ['credential_id', 'campaign_ids']),
80
+ import_instantly_lead_list: reconcile('POST', ['get_lists'], ['credential_id', 'lead_list_id']),
81
+ create_segment: reconcile('POST', ['list_segments'], ['name']),
82
+ preview_segment: read(),
83
+ preview_add_leads_to_campaign: read(),
84
+ add_leads_to_campaign: never('POST', ['list_campaigns', 'campaign_stats'], ['campaign_id', 'list_id']),
85
+ create_campaign: keyed('POST', ['list_campaigns'], ['name', 'sender_credential_id', 'source_list_id']),
86
+ update_campaign: idempotent('PATCH', ['list_campaigns'], ['campaign_id']),
87
+ duplicate_campaign: keyed('POST', ['list_campaigns'], ['campaign_id']),
88
+ activate_campaign: keyed('POST', ['list_campaigns', 'campaign_stats'], ['campaign_id', 'status']),
89
+ pause_campaign: reconcile('POST', ['list_campaigns'], ['campaign_id', 'status']),
90
+ sync_campaign: idempotent('POST', ['campaign_stats'], ['campaign_id']),
91
+ update_sender_config: idempotent('PUT', ['get_sender_config'], ['credential_id']),
92
+ // A full-document PUT: sending it twice leaves the campaign in the same state
93
+ // as sending it once, so a lost response is safe to retry.
94
+ create_sender_fields: idempotent(
95
+ 'POST', ['get_campaign_field_mapping'], ['campaign_id', 'names'],
96
+ ),
97
+ set_campaign_field_mapping: idempotent(
98
+ 'PUT',
99
+ ['get_campaign_field_mapping'],
100
+ ['campaign_id'],
101
+ ),
102
+ create_list: keyed('POST', ['get_lists'], ['name']),
103
+ add_list_members: idempotent('POST', ['get_list_rows'], ['list_id', 'global_person_ids']),
104
+ create_pipeline: idempotent('POST', ['get_pipeline'], ['operation_id']),
105
+ create_workbook: reconcile('POST', ['list_workbooks'], ['name', 'list_ids']),
106
+ add_table_to_workbook: reconcile(
107
+ 'POST',
108
+ ['list_workbooks'],
109
+ ['workbook_id', 'list_id', 'new_table_name'],
110
+ ),
111
+ remove_table_from_workbook: reconcile(
112
+ 'DELETE',
113
+ ['list_workbooks'],
114
+ ['workbook_id', 'list_id'],
115
+ ),
116
+ reorder_workbook_table: idempotent(
117
+ 'PATCH',
118
+ ['list_workbooks'],
119
+ ['workbook_id', 'list_id', 'position'],
120
+ ),
121
+ duplicate_workbook: reconcile(
122
+ 'POST',
123
+ ['list_workbooks'],
124
+ ['workbook_id', 'name', 'folder_id'],
125
+ ),
126
+ create_folder: reconcile('POST', ['list_workbooks'], ['name']),
127
+ move_to_folder: idempotent(
128
+ 'PATCH',
129
+ ['list_workbooks'],
130
+ ['folder_id', 'workbook_id', 'list_id'],
131
+ ),
132
+ delete_folder: never('DELETE', ['list_workbooks'], ['folder_id']),
133
+ create_table: idempotent('POST', ['get_tables'], ['name', 'operation_id']),
134
+ create_table_column: idempotent(
135
+ 'POST',
136
+ ['get_table_columns'],
137
+ ['table_id', 'label', 'operation_id'],
138
+ ),
139
+ create_table_preset_column: idempotent(
140
+ 'POST',
141
+ ['get_table_columns'],
142
+ ['table_id', 'preset_slug', 'preset_id', 'label', 'operation_id'],
143
+ ),
144
+ // High-value create: with auto_run it starts a credit-billed backfill, and API
145
+ // idempotency is per (list_id, client_operation_id), so a fresh key on retry
146
+ // would make a second column AND a second paid backfill. One durable key.
147
+ create_table_native_column: keyed(
148
+ 'POST',
149
+ ['get_table_columns', 'get_table_native_tools'],
150
+ ['table_id', 'tool', 'label', 'operation_id'],
151
+ ),
152
+ set_table_cells: idempotent('POST', ['list_table_rows'], ['table_id']),
153
+ import_leads: idempotent(
154
+ 'POST',
155
+ ['get_tables', 'get_list_rows'],
156
+ ['list_id', 'list_name', 'dedupe_by', 'operation_id'],
157
+ ),
158
+ import_leads_csv: idempotent(
159
+ 'POST',
160
+ ['get_tables', 'get_list_rows'],
161
+ ['list_id', 'list_name', 'dedupe_by', 'operation_id'],
162
+ ),
163
+ preview_import: read(),
164
+ preview_apify_import: read(),
165
+ import_apify_dataset: idempotent(
166
+ 'POST',
167
+ ['get_tables', 'get_list_rows'],
168
+ ['list_id', 'list_name', 'dataset_id', 'preview_hash'],
169
+ ),
170
+ capture_community_intent: idempotent(
171
+ 'POST',
172
+ ['get_tables', 'get_list_rows'],
173
+ ['source_url', 'public_profile_url', 'observed_at', 'operation_id'],
174
+ ),
175
+ save_flow_layout: idempotent('PUT', ['get_flow_graph'], ['scope_key']),
176
+ create_table_flow_rule: reconcile('POST', ['list_table_flow_rules'], ['list_id', 'name']),
177
+ toggle_table_flow_rule: idempotent('PATCH', ['list_table_flow_rules'], ['list_id', 'rule_id', 'enabled']),
178
+ create_campaign_flow_rule: reconcile(
179
+ 'POST',
180
+ ['list_campaign_flow_rules'],
181
+ ['campaign_id', 'name'],
182
+ ),
183
+ toggle_campaign_flow_rule: idempotent(
184
+ 'PATCH',
185
+ ['list_campaign_flow_rules'],
186
+ ['campaign_id', 'rule_id', 'enabled'],
187
+ ),
188
+ test_flow_rule: never(
189
+ 'POST',
190
+ ['get_flow_rule_stats', 'list_table_flow_rules', 'list_campaign_flow_rules'],
191
+ ['list_id', 'campaign_id', 'rule_id', 'lead_id', 'execute'],
192
+ ),
193
+ preview_send_to_table: read(),
194
+ send_to_table: idempotent('POST', ['get_list_rows'], ['list_id', 'destination_list_id', 'new_table_name']),
195
+ preview_table_write_back: read(),
196
+ apply_table_write_back: idempotent('POST', ['get_list_rows'], ['list_id', 'column_id', 'field']),
197
+ export_table_csv: reconcile('POST', ['get_table_export'], ['list_id', 'filename']),
198
+ create_table_view: idempotent(
199
+ 'POST',
200
+ ['list_table_views'],
201
+ ['list_id', 'name', 'operation_id'],
202
+ ),
203
+ update_table_view: idempotent('PATCH', ['list_table_views'], ['list_id', 'view_id']),
204
+ delete_table_view: reconcile('DELETE', ['list_table_views'], ['list_id', 'view_id']),
205
+ estimate_table_column: read(),
206
+ run_table_column: never('POST', ['get_list_history'], ['list_id', 'column_id']),
207
+ run_scope_summary: read(),
208
+ estimate_table_run_all: read(),
209
+ run_table_all: never('POST', ['get_list_history'], ['list_id', 'column_ids']),
210
+ remove_table_rows: reconcile('DELETE', ['list_table_rows'], ['list_id', 'lead_ids']),
211
+ create_list_webhook: keyed('POST', ['get_list_webhook'], ['list_id']),
212
+ update_list_webhook: idempotent('PATCH', ['get_list_webhook'], ['list_id']),
213
+ revoke_list_webhook: never('DELETE', ['get_list_webhook'], ['list_id']),
214
+ export_list_to_webhook: never('POST', ['get_list_history'], ['list_id']),
215
+ delete_list: never('DELETE', ['get_lists'], ['list_id']),
216
+ delete_campaign: never('DELETE', ['list_campaigns'], ['campaign_id']),
217
+ update_reply: idempotent('PATCH', ['list_replies'], ['reply_id']),
218
+ add_suppression_entry: reconcile('POST', ['list_suppression_entries'], ['kind', 'value']),
219
+ remove_suppression_entry: reconcile('DELETE', ['list_suppression_entries'], ['entry_id']),
220
+ update_suppression_settings: idempotent('PUT', ['get_suppression_settings'], ['auto_suppress_mode']),
221
+ roadmap_update_status: idempotent('PATCH', ['roadmap_list'], ['slug', 'status']),
222
+ roadmap_create_item: reconcile('POST', ['roadmap_list'], ['slug']),
223
+ roadmap_update_plan: idempotent('PATCH', ['roadmap_list'], ['slug']),
224
+ });
225
+
226
+ export const RETRY_CONTRACT_COPY = Object.freeze({
227
+ bounded: 'Read-only operation. Retries transport errors, 429, and 5xx with bounded backoff.',
228
+ idempotent: 'Proven idempotent write. Retries transient failures with bounded backoff.',
229
+ idempotency_key: 'Durable Idempotency-Key required. Transient retries replay one stored result.',
230
+ reconcile: 'One request only. An ambiguous result returns reconciliation tools and stable match fields.',
231
+ never: 'Never retried automatically. An ambiguous result must be reconciled before any new attempt.',
232
+ });