consulti-mcp 2.4.2 → 2.6.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.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm version](https://img.shields.io/npm/v/consulti-mcp.svg)](https://www.npmjs.com/package/consulti-mcp)
4
4
  [![license](https://img.shields.io/npm/l/consulti-mcp.svg)](./LICENSE)
5
5
 
6
- MCP server for the Consulti lead intelligence API — **10 stable tools** to search 500M+ B2B leads, search Instagram profiles, verify emails (including catch-all mailbox resolution), enrich leads by email or LinkedIn URL, manage saved lists, and check credit balance.
6
+ MCP server for the Consulti lead intelligence API — **14 stable tools** to search 500M+ B2B leads, search Instagram profiles, verify emails (including catch-all mailbox resolution), enrich leads by email or LinkedIn URL, manage saved lists, run inbox placement tests, and check credit balance.
7
7
 
8
8
  > **Stable surface only.** Beta endpoints (name-domain lookup, local-business search, creator search) are intentionally NOT exposed via MCP — their schemas may change. The REST local-business search accepts US states, DC, and Canadian provinces/territories by full name or two-letter code. To use beta endpoints, call the REST API directly: https://www.consulti.ai/api-docs
9
9
 
@@ -100,7 +100,7 @@ Resolve whether a specific mailbox on a catch-all domain actually exists — the
100
100
 
101
101
  ### enrich_lead
102
102
 
103
- Enrich a lead's full profile using their email address.
103
+ Enrich a lead's full profile using their email address. The response includes a `company` object (funding stage, total funding, monthly web visits, operating status, HQ, LinkedIn followers, specialties) when the lead is linked to a company; `company` is null when unlinked.
104
104
 
105
105
  **Cost:** 1 lead credit — only deducted on a successful match; 404 responses are free.
106
106
 
@@ -136,7 +136,7 @@ Search a database of 500M+ B2B leads with filters like job title, industry, loca
136
136
 
137
137
  | Input | Type | Description |
138
138
  | ---------------- | -------- | ------------------------------------------------------------------ |
139
- | `q` | string | Free text search across name, title, company, and industry |
139
+ | `q` | string | Free text search across job title, company, and industry |
140
140
  | `titles` | string[] | Job titles to filter by (e.g. ["CEO", "VP Marketing"]) |
141
141
  | `industries` | string[] | Industries to filter by (e.g. ["Technology", "Finance"]) |
142
142
  | `technologies` | string[] | Website tech, exact Wappalyzer-style names (e.g. ["Shopify"]); OR-matched. Canonical list: `GET /api/v1/meta/technologies` |
@@ -147,7 +147,10 @@ Search a database of 500M+ B2B leads with filters like job title, industry, loca
147
147
  | `company` | string | Company name to search for |
148
148
  | `empMin` | number | Minimum employee count |
149
149
  | `empMax` | number | Maximum employee count |
150
- | `excludeListId` | string | UUID of a saved list owned by the API key holder — leads in this list will be excluded from results. Canonical singular field name; `exclude_list_id` and other variants return HTTP 400. |
150
+ | `revenueMin` | number | Minimum annual revenue in USD, whole dollars. |
151
+ | `revenueMax` | number | Maximum annual revenue in USD, whole dollars. |
152
+ | `excludeTitles` | string[] | Job titles to exclude. Leads matching any of these are removed. |
153
+ | `excludeListId` | string | UUID of a **lead-kind** saved list owned by the API key holder — leads in this list are excluded from results before billing. Business, podcast, YouTube and Instagram lists return HTTP 400. Canonical singular field name; `exclude_list_id` and other variants also return HTTP 400. |
151
154
  | `page` | number | Page number (default: 1) |
152
155
  | `size` | number | Results per page (default: 25, max: 100) |
153
156
 
@@ -255,6 +258,43 @@ Check the authenticated user's current lead and verification credit balance. Fre
255
258
  }
256
259
  ```
257
260
 
261
+ ### create_placement_test
262
+
263
+ Create an inbox placement test. Checking starts at create. Send one email from the mailbox you want to test to every seed address within 15 minutes, with the returned `test_code` in the subject or body, then poll `get_placement_test`.
264
+
265
+ **Cost:** 1 lead credit, charged when the test is created. Requires the Pro plan or higher. A retried call creates, and charges for, a new test. `Idempotency-Key` has no effect. A 429 `too_many_open_tests` is free and safe to retry after `retry_after`.
266
+
267
+ | Input | Type | Description |
268
+ | --------- | ------ | -------------------------------------------------------- |
269
+ | `name` | string | Optional label (max 120 characters) |
270
+ | `subject` | string | Optional subject of the email you will send (max 998) |
271
+ | `body` | string | Optional body of the email you will send (max 100,000) |
272
+
273
+ ### mark_placement_test_sent
274
+
275
+ Start checking a test that was created as a draft, after the email has gone out. On a test that is already checking it changes nothing. Free.
276
+
277
+ | Input | Type | Description |
278
+ | ----- | ------ | ---------------------------- |
279
+ | `id` | string | **Required.** The test id |
280
+
281
+ ### get_placement_test
282
+
283
+ Status, per-seed placement, summary, 0 to 10 score and report for one test. Free.
284
+
285
+ | Input | Type | Description |
286
+ | ----- | ------ | ---------------------------- |
287
+ | `id` | string | **Required.** The test id |
288
+
289
+ ### list_placement_tests
290
+
291
+ List your placement tests, newest first. Free.
292
+
293
+ | Input | Type | Description |
294
+ | ------ | ------ | ---------------------------------- |
295
+ | `page` | number | Page number, from 1 (default 1) |
296
+ | `size` | number | Tests per page, 1 to 100 (default 25) |
297
+
258
298
  ## Get your API key
259
299
 
260
300
  Sign up at [www.consulti.ai](https://www.consulti.ai) and generate an API key under **Settings → Integrations → API Keys**.
@@ -266,7 +306,7 @@ Sign up at [www.consulti.ai](https://www.consulti.ai) and generate an API key un
266
306
  | `CONSULTI_API_KEY` | **Yes** | — | Your Consulti API key (starts with `capi_`). |
267
307
  | `MCP_BASE_URL` | No | `https://www.consulti.ai/api/v1` | Override the API base URL. Only set this for staging / local dev — never in prod. |
268
308
 
269
- The server enforces a 30-second timeout on every API request; timed-out calls return a structured `{"error": "Request timed out after 30s"}` so MCP clients can parse and retry.
309
+ The server waits up to 130 seconds for `search_b2b_leads` and 310 seconds for every other call, so it never gives up before the API does. Failed calls return a structured error with `status`, `code` and `retry_after` when known. A timeout or a 5xx on a paid call may still have been charged, so the error says to call `get_credits` before retrying.
270
310
 
271
311
  ## Versioning
272
312
 
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import { z } from "zod";
5
- const VERSION = "2.4.2";
3
+ import { VERSION, createConsultiMcpServer } from "./server.js";
4
+ import { createApi } from "./transport.js";
6
5
  if (process.argv.includes("--version") || process.argv.includes("-v")) {
7
6
  console.log(VERSION);
8
7
  process.exit(0);
@@ -14,260 +13,8 @@ if (!CONSULTI_API_KEY) {
14
13
  }
15
14
  const BASE_URL = process.env.MCP_BASE_URL || "https://www.consulti.ai/api/v1";
16
15
  const USER_AGENT = `consulti-mcp/${VERSION}`;
17
- const REQUEST_TIMEOUT_MS = 30_000;
18
- async function apiPost(path, body) {
19
- const controller = new AbortController();
20
- const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
21
- try {
22
- const response = await fetch(`${BASE_URL}${path}`, {
23
- method: "POST",
24
- headers: {
25
- "Authorization": `Bearer ${CONSULTI_API_KEY}`,
26
- "Content-Type": "application/json",
27
- "User-Agent": USER_AGENT,
28
- },
29
- body: JSON.stringify(body),
30
- signal: controller.signal,
31
- });
32
- const data = await response.json();
33
- if (!response.ok) {
34
- const message = data?.error || data?.message || `API returned ${response.status}`;
35
- // Preserve the machine-readable code when the API sends one. An agent
36
- // can only branch on a code that survives this wrapper, and collapsing
37
- // every failure to prose forces it to pattern-match on wording.
38
- return JSON.stringify(data?.code ? { error: message, code: data.code } : { error: message }, null, 2);
39
- }
40
- return JSON.stringify(data, null, 2);
41
- }
42
- catch (error) {
43
- if (error instanceof Error && error.name === "AbortError") {
44
- return JSON.stringify({ error: `Request timed out after ${REQUEST_TIMEOUT_MS / 1000}s` }, null, 2);
45
- }
46
- const message = error instanceof Error ? error.message : "Unknown error";
47
- return JSON.stringify({ error: `Request failed: ${message}` }, null, 2);
48
- }
49
- finally {
50
- clearTimeout(timer);
51
- }
52
- }
53
- async function apiGet(path) {
54
- const controller = new AbortController();
55
- const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
56
- try {
57
- const response = await fetch(`${BASE_URL}${path}`, {
58
- method: "GET",
59
- headers: {
60
- "Authorization": `Bearer ${CONSULTI_API_KEY}`,
61
- "User-Agent": USER_AGENT,
62
- },
63
- signal: controller.signal,
64
- });
65
- const data = await response.json();
66
- if (!response.ok) {
67
- const message = data?.error || data?.message || `API returned ${response.status}`;
68
- // Preserve the machine-readable code when the API sends one. An agent
69
- // can only branch on a code that survives this wrapper, and collapsing
70
- // every failure to prose forces it to pattern-match on wording.
71
- return JSON.stringify(data?.code ? { error: message, code: data.code } : { error: message }, null, 2);
72
- }
73
- return JSON.stringify(data, null, 2);
74
- }
75
- catch (error) {
76
- if (error instanceof Error && error.name === "AbortError") {
77
- return JSON.stringify({ error: `Request timed out after ${REQUEST_TIMEOUT_MS / 1000}s` }, null, 2);
78
- }
79
- const message = error instanceof Error ? error.message : "Unknown error";
80
- return JSON.stringify({ error: `Request failed: ${message}` }, null, 2);
81
- }
82
- finally {
83
- clearTimeout(timer);
84
- }
85
- }
86
- const server = new McpServer({
87
- name: "consulti-mcp",
88
- version: VERSION,
89
- });
90
- server.tool("verify_email", "Verify if an email address is valid and deliverable. Cost: 1 verification credit per call.", { email: z.string().describe("The email address to verify") }, async ({ email }) => ({
91
- content: [{ type: "text", text: await apiPost("/verify", { email }) }],
92
- }));
93
- server.tool("verify_catchall", "Resolve whether a specific mailbox on a catch-all domain actually exists — the ESP-engine probe that plain SMTP (verify_email) cannot do. Use it on addresses verify_email returns with is_catch_all=true. Cost: 5 verification credits per call; requires a plan with catch-all verification enabled (Pro or higher).", { email: z.string().describe("The email address on a catch-all domain to resolve") }, async ({ email }) => ({
94
- content: [{ type: "text", text: await apiPost("/verify/catchall", { email }) }],
95
- }));
96
- server.tool("enrich_lead", "Enrich a lead's full profile using their email address. Cost: 1 lead credit — only deducted on a successful match; 404 responses are free.", { email: z.string().describe("The email address of the lead to enrich") }, async ({ email }) => ({
97
- content: [{ type: "text", text: await apiPost("/leads/enrich", { email }) }],
98
- }));
99
- server.tool("enrich_linkedin", "Enrich a person by their LinkedIn profile URL → a verified work email plus their US mobile phone (free add-on). Cache-first: served instantly when we already hold a verified email for that profile, otherwise enriched live and cached. Cost: 1 lead credit — charged ONLY when an email is returned; phone-only or no-match responses are free.", { linkedin_url: z.string().describe("The LinkedIn profile URL, e.g. https://linkedin.com/in/johndoe") }, async ({ linkedin_url }) => ({
100
- content: [{ type: "text", text: await apiPost("/enrich/linkedin", { linkedin_url }) }],
101
- }));
102
- server.tool("search_b2b_leads", "Search a database of 500M+ B2B leads with filters like job title, industry, location, and company size. Country and state/region alias-group members are equivalent, so names and codes return identical populations. Results are always restricted to leads carrying our verified email label (there is no option to include unverified leads). Cost: 1 lead credit per result returned — reserved up to `size` then refunded down to the actual row count; 0 results = 0 credits. Call get_credits first before large `size` values.", {
103
- q: z.string().optional().describe("Free text search across name, title, company, and industry"),
104
- titles: z.array(z.string()).optional().describe("Job titles to filter by (e.g. [\"CEO\", \"VP Marketing\"])"),
105
- industries: z.array(z.string()).optional().describe("Industries to filter by (case-sensitive exact match). Get the canonical list: GET https://www.consulti.ai/api/v1/meta/industries"),
106
- technologies: z.array(z.string()).optional().describe("Technologies the company's website uses, exact Wappalyzer-style names (e.g. [\"Shopify\", \"HubSpot\", \"WordPress\"]). OR-matched: a lead matches if it uses ANY listed technology. Canonical list: GET https://www.consulti.ai/api/v1/meta/technologies"),
107
- excludeTechnologies: z.array(z.string()).optional().describe("Technologies to EXCLUDE, same Wappalyzer-style names. A lead is dropped if its company uses ANY listed technology; leads with no technology data are kept."),
108
- countries: z.array(z.string()).optional().describe("Countries to filter by. Alias-group members are equivalent (e.g. \"United States\" and \"US\"). Accepted values: GET https://www.consulti.ai/api/v1/meta/countries"),
109
- states: z.array(z.string()).optional().describe("States/regions to filter by. Alias-group members are equivalent (e.g. \"Ontario\" and \"ON\"). Accepted values: GET https://www.consulti.ai/api/v1/meta/states"),
110
- cities: z.array(z.string()).optional().describe("Cities to filter by (e.g. [\"San Francisco\", \"London\"])"),
111
- company: z.string().optional().describe("Company name to search for"),
112
- empMin: z.number().optional().describe("Minimum employee count"),
113
- empMax: z.number().optional().describe("Maximum employee count"),
114
- excludeListId: z.string().optional().describe("UUID of a saved list owned by the API key holder — leads in this list will be excluded from results. Response includes both `total` (pre-exclusion) and `total_after_exclusion` (post) so the caller can verify exclusion fired."),
115
- page: z.number().optional().describe("Page number (default: 1)"),
116
- size: z.number().optional().describe("Results per page (default: 25, max: 100)"),
117
- }, async (params) => {
118
- const body = {};
119
- if (params.q)
120
- body.q = params.q;
121
- if (params.titles)
122
- body.titles = params.titles;
123
- if (params.industries)
124
- body.industries = params.industries;
125
- if (params.technologies)
126
- body.technologies = params.technologies;
127
- if (params.excludeTechnologies)
128
- body.excludeTechnologies = params.excludeTechnologies;
129
- if (params.countries)
130
- body.countries = params.countries;
131
- if (params.states)
132
- body.states = params.states;
133
- if (params.cities)
134
- body.cities = params.cities;
135
- if (params.company)
136
- body.company = params.company;
137
- if (params.empMin !== undefined)
138
- body.empMin = params.empMin;
139
- if (params.empMax !== undefined)
140
- body.empMax = params.empMax;
141
- if (params.excludeListId)
142
- body.excludeListId = params.excludeListId;
143
- if (params.page !== undefined)
144
- body.page = params.page;
145
- if (params.size !== undefined)
146
- body.size = params.size;
147
- return {
148
- content: [{ type: "text", text: await apiPost("/leads/search", body) }],
149
- };
150
- });
151
- server.tool("search_instagram_profiles", "Search a database of Instagram profiles with filters like follower count, category, location, and data quality. Cost: 1 lead credit per result returned — reserved up to `size` then refunded down to the actual row count; 0 results = 0 credits. Call get_credits first before large operations.", {
152
- q: z.string().optional().describe("Free text search across username and bio"),
153
- bioKeywords: z.array(z.string()).optional().describe("Keywords to search for in profile bios"),
154
- excludeKeywords: z.array(z.string()).optional().describe("Exclude profiles whose bio matches any of these keywords"),
155
- excludeAdultContent: z.boolean().optional().describe("Exclude profiles with adult/sexual content terms in their bio"),
156
- followerMin: z.number().optional().describe("Minimum follower count"),
157
- followerMax: z.number().optional().describe("Maximum follower count"),
158
- followingMin: z.number().optional().describe("Minimum following count"),
159
- followingMax: z.number().optional().describe("Maximum following count"),
160
- postsMin: z.number().optional().describe("Minimum post count"),
161
- postsMax: z.number().optional().describe("Maximum post count"),
162
- categories: z.array(z.string()).optional().describe("Categories to filter by (e.g. [\"Digital creator\", \"Photographer\"]). Canonical list: GET https://www.consulti.ai/api/v1/meta/instagram-categories"),
163
- accountTypes: z.array(z.string()).optional().describe("Account types to filter by (e.g. [\"business\", \"personal\"]). Canonical list: GET https://www.consulti.ai/api/v1/meta/instagram-account-types"),
164
- emailStatus: z.array(z.string()).optional().describe("Email verification status to filter by (e.g. [\"good\", \"risky\", \"bad\", \"catch_all\"]). Canonical list: GET https://www.consulti.ai/api/v1/meta/instagram-email-statuses"),
165
- verified: z.boolean().optional().describe("Filter to only verified accounts"),
166
- hasEmail: z.boolean().optional().describe("Filter to only accounts with an email on file"),
167
- hasPhone: z.boolean().optional().describe("Filter to only accounts with phone number"),
168
- hasWebsite: z.boolean().optional().describe("Filter to only accounts with website"),
169
- countries: z.array(z.string()).optional().describe("Countries to filter by (exact match). Canonical list: GET https://www.consulti.ai/api/v1/meta/instagram-countries"),
170
- sortBy: z.string().optional().describe("Field to sort by (followers, posts, engagement, username)"),
171
- sortOrder: z.string().optional().describe("Sort order (asc or desc)"),
172
- page: z.number().optional().describe("Page number (default: 1)"),
173
- size: z.number().optional().describe("Results per page (default: 25, max: 100)"),
174
- }, async (params) => {
175
- const body = {};
176
- if (params.q)
177
- body.q = params.q;
178
- if (params.bioKeywords)
179
- body.bioKeywords = params.bioKeywords;
180
- if (params.excludeKeywords)
181
- body.excludeKeywords = params.excludeKeywords;
182
- if (params.excludeAdultContent !== undefined)
183
- body.excludeAdultContent = params.excludeAdultContent;
184
- if (params.followerMin !== undefined)
185
- body.followerMin = params.followerMin;
186
- if (params.followerMax !== undefined)
187
- body.followerMax = params.followerMax;
188
- if (params.followingMin !== undefined)
189
- body.followingMin = params.followingMin;
190
- if (params.followingMax !== undefined)
191
- body.followingMax = params.followingMax;
192
- if (params.postsMin !== undefined)
193
- body.postsMin = params.postsMin;
194
- if (params.postsMax !== undefined)
195
- body.postsMax = params.postsMax;
196
- if (params.categories)
197
- body.categories = params.categories;
198
- if (params.accountTypes)
199
- body.accountTypes = params.accountTypes;
200
- if (params.emailStatus)
201
- body.emailStatus = params.emailStatus;
202
- if (params.verified !== undefined)
203
- body.verified = params.verified;
204
- if (params.hasEmail !== undefined)
205
- body.hasEmail = params.hasEmail;
206
- if (params.hasPhone !== undefined)
207
- body.hasPhone = params.hasPhone;
208
- if (params.hasWebsite !== undefined)
209
- body.hasWebsite = params.hasWebsite;
210
- if (params.countries)
211
- body.countries = params.countries;
212
- if (params.sortBy)
213
- body.sortBy = params.sortBy;
214
- if (params.sortOrder)
215
- body.sortOrder = params.sortOrder;
216
- if (params.page !== undefined)
217
- body.page = params.page;
218
- if (params.size !== undefined)
219
- body.size = params.size;
220
- return {
221
- content: [{ type: "text", text: await apiPost("/instagram/search", body) }],
222
- };
223
- });
224
- server.tool("get_lists", "Get all saved lists for the authenticated user, with member counts and each list's kind", {}, async () => ({
225
- content: [{ type: "text", text: await apiGet("/lists") }],
226
- }));
227
- server.tool("create_list", "Create a new saved list. A list holds exactly one entity kind. Use kind='lead' to store B2B lead emails and kind='business' to store local business IDs. Choose the kind that matches what you plan to add, because members cannot be added to a list of a different kind.", {
228
- name: z.string().describe("Name of the list"),
229
- description: z.string().optional().describe("Optional description of the list"),
230
- // Only the two kinds add_leads_to_list can actually populate. Offering
231
- // podcast, youtube, or instagram here would let an agent create a list it
232
- // can never add a member to, because this package sends only emails or
233
- // businessIds. Those kinds are created in the dashboard.
234
- kind: z
235
- .enum(["lead", "business"])
236
- .optional()
237
- .describe("Entity kind this list holds. Defaults to 'lead' for B2B emails. Use 'business' before adding businessIds from local business search."),
238
- }, async ({ name, description, kind }) => {
239
- const body = { name };
240
- if (description)
241
- body.description = description;
242
- if (kind)
243
- body.kind = kind;
244
- return {
245
- content: [{ type: "text", text: await apiPost("/lists", body) }],
246
- };
247
- });
248
- server.tool("add_leads_to_list", "Add members to a saved list. Send 'emails' to a list with kind='lead', or 'businessIds' to a list with kind='business'. Send only one of the two per call. Adding members whose type does not match the list's kind produces a list that cannot be opened or exported, so create the list with the matching kind first.", {
249
- listId: z.string().describe("UUID of the target list"),
250
- emails: z
251
- .array(z.string())
252
- .optional()
253
- .describe("Email addresses of B2B leads to add. Requires a list with kind='lead'."),
254
- businessIds: z
255
- .array(z.number())
256
- .optional()
257
- .describe("Business IDs from local business search. Requires a list with kind='business'."),
258
- }, async ({ listId, emails, businessIds }) => {
259
- const body = {};
260
- if (emails)
261
- body.emails = emails;
262
- if (businessIds)
263
- body.businessIds = businessIds;
264
- return {
265
- content: [{ type: "text", text: await apiPost(`/lists/${listId}/add-leads`, body) }],
266
- };
267
- });
268
- server.tool("get_credits", "Check the authenticated user's current lead and verification credit balance. Free — no credits deducted. Use before bulk operations to avoid running out mid-task.", {}, async () => ({
269
- content: [{ type: "text", text: await apiGet("/credits") }],
270
- }));
16
+ const { apiPost, apiGet } = createApi({ baseUrl: BASE_URL, apiKey: CONSULTI_API_KEY, userAgent: USER_AGENT });
17
+ const server = createConsultiMcpServer({ apiPost, apiGet });
271
18
  async function main() {
272
19
  const transport = new StdioServerTransport();
273
20
  await server.connect(transport);
@@ -0,0 +1,194 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Field validators for `search_b2b_leads`.
4
+ *
5
+ * `@modelcontextprotocol/sdk@1.30.0` `server.tool(name, desc, shape, cb)` only
6
+ * accepts a raw shape and wraps it with non-strict `z.object()`, which STRIPS
7
+ * unknown keys before the handler runs. A misspelled `excludeTitles` then
8
+ * becomes a billable unfiltered search. `server.tool()` also throws if given a
9
+ * real ZodObject. Registration therefore uses `server.registerTool` with
10
+ * `searchB2bLeadsInputObjectSchema` (a `.strict()` ZodObject).
11
+ *
12
+ * Do not register the refined schema: `.refine()` is a ZodEffects with no
13
+ * `.shape`, and ListTools would emit `{ type: "object", properties: {} }`.
14
+ * Reversed revenue bounds are still enforced in `handleSearchB2bLeads`.
15
+ */
16
+ export declare const searchB2bLeadsInputShape: {
17
+ q: z.ZodOptional<z.ZodString>;
18
+ titles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
19
+ industries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
20
+ technologies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
21
+ excludeTechnologies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
22
+ countries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
23
+ states: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
24
+ cities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
25
+ company: z.ZodOptional<z.ZodString>;
26
+ empMin: z.ZodOptional<z.ZodNumber>;
27
+ empMax: z.ZodOptional<z.ZodNumber>;
28
+ revenueMin: z.ZodOptional<z.ZodNumber>;
29
+ revenueMax: z.ZodOptional<z.ZodNumber>;
30
+ excludeTitles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
31
+ excludeListId: z.ZodOptional<z.ZodString>;
32
+ page: z.ZodOptional<z.ZodNumber>;
33
+ size: z.ZodOptional<z.ZodNumber>;
34
+ };
35
+ export declare const searchB2bLeadsInputObjectSchema: z.ZodObject<{
36
+ q: z.ZodOptional<z.ZodString>;
37
+ titles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
38
+ industries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
39
+ technologies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
40
+ excludeTechnologies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
41
+ countries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
42
+ states: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
43
+ cities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
44
+ company: z.ZodOptional<z.ZodString>;
45
+ empMin: z.ZodOptional<z.ZodNumber>;
46
+ empMax: z.ZodOptional<z.ZodNumber>;
47
+ revenueMin: z.ZodOptional<z.ZodNumber>;
48
+ revenueMax: z.ZodOptional<z.ZodNumber>;
49
+ excludeTitles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
50
+ excludeListId: z.ZodOptional<z.ZodString>;
51
+ page: z.ZodOptional<z.ZodNumber>;
52
+ size: z.ZodOptional<z.ZodNumber>;
53
+ }, "strict", z.ZodTypeAny, {
54
+ q?: string | undefined;
55
+ titles?: string[] | undefined;
56
+ industries?: string[] | undefined;
57
+ technologies?: string[] | undefined;
58
+ excludeTechnologies?: string[] | undefined;
59
+ countries?: string[] | undefined;
60
+ states?: string[] | undefined;
61
+ cities?: string[] | undefined;
62
+ company?: string | undefined;
63
+ empMin?: number | undefined;
64
+ empMax?: number | undefined;
65
+ revenueMin?: number | undefined;
66
+ revenueMax?: number | undefined;
67
+ excludeTitles?: string[] | undefined;
68
+ excludeListId?: string | undefined;
69
+ page?: number | undefined;
70
+ size?: number | undefined;
71
+ }, {
72
+ q?: string | undefined;
73
+ titles?: string[] | undefined;
74
+ industries?: string[] | undefined;
75
+ technologies?: string[] | undefined;
76
+ excludeTechnologies?: string[] | undefined;
77
+ countries?: string[] | undefined;
78
+ states?: string[] | undefined;
79
+ cities?: string[] | undefined;
80
+ company?: string | undefined;
81
+ empMin?: number | undefined;
82
+ empMax?: number | undefined;
83
+ revenueMin?: number | undefined;
84
+ revenueMax?: number | undefined;
85
+ excludeTitles?: string[] | undefined;
86
+ excludeListId?: string | undefined;
87
+ page?: number | undefined;
88
+ size?: number | undefined;
89
+ }>;
90
+ export declare const searchB2bLeadsInputSchema: z.ZodEffects<z.ZodObject<{
91
+ q: z.ZodOptional<z.ZodString>;
92
+ titles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
93
+ industries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
94
+ technologies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
95
+ excludeTechnologies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
96
+ countries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
97
+ states: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
98
+ cities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
99
+ company: z.ZodOptional<z.ZodString>;
100
+ empMin: z.ZodOptional<z.ZodNumber>;
101
+ empMax: z.ZodOptional<z.ZodNumber>;
102
+ revenueMin: z.ZodOptional<z.ZodNumber>;
103
+ revenueMax: z.ZodOptional<z.ZodNumber>;
104
+ excludeTitles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
105
+ excludeListId: z.ZodOptional<z.ZodString>;
106
+ page: z.ZodOptional<z.ZodNumber>;
107
+ size: z.ZodOptional<z.ZodNumber>;
108
+ }, "strict", z.ZodTypeAny, {
109
+ q?: string | undefined;
110
+ titles?: string[] | undefined;
111
+ industries?: string[] | undefined;
112
+ technologies?: string[] | undefined;
113
+ excludeTechnologies?: string[] | undefined;
114
+ countries?: string[] | undefined;
115
+ states?: string[] | undefined;
116
+ cities?: string[] | undefined;
117
+ company?: string | undefined;
118
+ empMin?: number | undefined;
119
+ empMax?: number | undefined;
120
+ revenueMin?: number | undefined;
121
+ revenueMax?: number | undefined;
122
+ excludeTitles?: string[] | undefined;
123
+ excludeListId?: string | undefined;
124
+ page?: number | undefined;
125
+ size?: number | undefined;
126
+ }, {
127
+ q?: string | undefined;
128
+ titles?: string[] | undefined;
129
+ industries?: string[] | undefined;
130
+ technologies?: string[] | undefined;
131
+ excludeTechnologies?: string[] | undefined;
132
+ countries?: string[] | undefined;
133
+ states?: string[] | undefined;
134
+ cities?: string[] | undefined;
135
+ company?: string | undefined;
136
+ empMin?: number | undefined;
137
+ empMax?: number | undefined;
138
+ revenueMin?: number | undefined;
139
+ revenueMax?: number | undefined;
140
+ excludeTitles?: string[] | undefined;
141
+ excludeListId?: string | undefined;
142
+ page?: number | undefined;
143
+ size?: number | undefined;
144
+ }>, {
145
+ q?: string | undefined;
146
+ titles?: string[] | undefined;
147
+ industries?: string[] | undefined;
148
+ technologies?: string[] | undefined;
149
+ excludeTechnologies?: string[] | undefined;
150
+ countries?: string[] | undefined;
151
+ states?: string[] | undefined;
152
+ cities?: string[] | undefined;
153
+ company?: string | undefined;
154
+ empMin?: number | undefined;
155
+ empMax?: number | undefined;
156
+ revenueMin?: number | undefined;
157
+ revenueMax?: number | undefined;
158
+ excludeTitles?: string[] | undefined;
159
+ excludeListId?: string | undefined;
160
+ page?: number | undefined;
161
+ size?: number | undefined;
162
+ }, {
163
+ q?: string | undefined;
164
+ titles?: string[] | undefined;
165
+ industries?: string[] | undefined;
166
+ technologies?: string[] | undefined;
167
+ excludeTechnologies?: string[] | undefined;
168
+ countries?: string[] | undefined;
169
+ states?: string[] | undefined;
170
+ cities?: string[] | undefined;
171
+ company?: string | undefined;
172
+ empMin?: number | undefined;
173
+ empMax?: number | undefined;
174
+ revenueMin?: number | undefined;
175
+ revenueMax?: number | undefined;
176
+ excludeTitles?: string[] | undefined;
177
+ excludeListId?: string | undefined;
178
+ page?: number | undefined;
179
+ size?: number | undefined;
180
+ }>;
181
+ export type SearchB2bLeadsInput = z.infer<typeof searchB2bLeadsInputSchema>;
182
+ export type LeadsSearchApiPost = (path: string, body: Record<string, unknown>) => Promise<string>;
183
+ export declare function buildSearchB2bLeadsBody(params: SearchB2bLeadsInput): Record<string, unknown>;
184
+ /**
185
+ * Registered `search_b2b_leads` callback. Parses the full object schema
186
+ * (including the revenueMin <= revenueMax refine) before building the
187
+ * request body or dispatching HTTP.
188
+ */
189
+ export declare function handleSearchB2bLeads(params: unknown, apiPost: LeadsSearchApiPost): Promise<{
190
+ content: Array<{
191
+ type: "text";
192
+ text: string;
193
+ }>;
194
+ }>;
@@ -0,0 +1,97 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Field validators for `search_b2b_leads`.
4
+ *
5
+ * `@modelcontextprotocol/sdk@1.30.0` `server.tool(name, desc, shape, cb)` only
6
+ * accepts a raw shape and wraps it with non-strict `z.object()`, which STRIPS
7
+ * unknown keys before the handler runs. A misspelled `excludeTitles` then
8
+ * becomes a billable unfiltered search. `server.tool()` also throws if given a
9
+ * real ZodObject. Registration therefore uses `server.registerTool` with
10
+ * `searchB2bLeadsInputObjectSchema` (a `.strict()` ZodObject).
11
+ *
12
+ * Do not register the refined schema: `.refine()` is a ZodEffects with no
13
+ * `.shape`, and ListTools would emit `{ type: "object", properties: {} }`.
14
+ * Reversed revenue bounds are still enforced in `handleSearchB2bLeads`.
15
+ */
16
+ export const searchB2bLeadsInputShape = {
17
+ q: z.string().optional().describe("Free text search across job title, company, and industry"),
18
+ titles: z.array(z.string()).optional().describe("Job titles to filter by (e.g. [\"CEO\", \"VP Marketing\"])"),
19
+ industries: z.array(z.string()).optional().describe("Industries to filter by (case-sensitive exact match). Get the canonical list: GET https://www.consulti.ai/api/v1/meta/industries"),
20
+ technologies: z.array(z.string()).optional().describe("Technologies the company's website uses, exact Wappalyzer-style names (e.g. [\"Shopify\", \"HubSpot\", \"WordPress\"]). OR-matched: a lead matches if it uses ANY listed technology. Canonical list: GET https://www.consulti.ai/api/v1/meta/technologies"),
21
+ excludeTechnologies: z.array(z.string()).optional().describe("Technologies to EXCLUDE, same Wappalyzer-style names. A lead is dropped if its company uses ANY listed technology; leads with no technology data are kept."),
22
+ countries: z.array(z.string()).optional().describe("Countries to filter by. Alias-group members are equivalent (e.g. \"United States\" and \"US\"). Accepted values: GET https://www.consulti.ai/api/v1/meta/countries"),
23
+ states: z.array(z.string()).optional().describe("States/regions to filter by. Alias-group members are equivalent (e.g. \"Ontario\" and \"ON\"). Accepted values: GET https://www.consulti.ai/api/v1/meta/states"),
24
+ cities: z.array(z.string()).optional().describe("Cities to filter by (e.g. [\"San Francisco\", \"London\"])"),
25
+ company: z.string().optional().describe("Company name to search for"),
26
+ empMin: z.number().optional().describe("Minimum employee count"),
27
+ empMax: z.number().optional().describe("Maximum employee count"),
28
+ revenueMin: z.number().int().nonnegative().optional().describe("Minimum annual revenue in USD, whole dollars."),
29
+ revenueMax: z.number().int().nonnegative().optional().describe("Maximum annual revenue in USD, whole dollars."),
30
+ excludeTitles: z
31
+ .array(z.string().trim().min(1))
32
+ .max(25)
33
+ .optional()
34
+ .describe("Job titles to exclude. Leads matching any of these are removed."),
35
+ excludeListId: z.string().optional().describe("UUID of a LEAD-kind saved list owned by the API key holder — leads in this list are excluded from results before billing. Must be a list created with kind \"lead\"; business, podcast, YouTube and Instagram lists hold no lead emails and return HTTP 400. Response includes both `total` (pre-exclusion) and `total_after_exclusion` (post); a LOWER total_after_exclusion proves rows were excluded, while equal values are inconclusive (no overlap with this search, or both counts at the 10001 cap)."),
36
+ page: z.number().optional().describe("Page number (default: 1)"),
37
+ size: z.number().optional().describe("Results per page (default: 25, max: 100)"),
38
+ };
39
+ export const searchB2bLeadsInputObjectSchema = z
40
+ .object(searchB2bLeadsInputShape)
41
+ .strict();
42
+ export const searchB2bLeadsInputSchema = searchB2bLeadsInputObjectSchema.refine((data) => data.revenueMin === undefined ||
43
+ data.revenueMax === undefined ||
44
+ data.revenueMin <= data.revenueMax, {
45
+ message: "revenueMin must be less than or equal to revenueMax",
46
+ path: ["revenueMin"],
47
+ });
48
+ export function buildSearchB2bLeadsBody(params) {
49
+ const body = {};
50
+ if (params.q)
51
+ body.q = params.q;
52
+ if (params.titles)
53
+ body.titles = params.titles;
54
+ if (params.industries)
55
+ body.industries = params.industries;
56
+ if (params.technologies)
57
+ body.technologies = params.technologies;
58
+ if (params.excludeTechnologies)
59
+ body.excludeTechnologies = params.excludeTechnologies;
60
+ if (params.countries)
61
+ body.countries = params.countries;
62
+ if (params.states)
63
+ body.states = params.states;
64
+ if (params.cities)
65
+ body.cities = params.cities;
66
+ if (params.company)
67
+ body.company = params.company;
68
+ if (params.empMin !== undefined)
69
+ body.empMin = params.empMin;
70
+ if (params.empMax !== undefined)
71
+ body.empMax = params.empMax;
72
+ if (params.revenueMin !== undefined)
73
+ body.revenueMin = params.revenueMin;
74
+ if (params.revenueMax !== undefined)
75
+ body.revenueMax = params.revenueMax;
76
+ if (params.excludeTitles)
77
+ body.excludeTitles = params.excludeTitles;
78
+ if (params.excludeListId)
79
+ body.excludeListId = params.excludeListId;
80
+ if (params.page !== undefined)
81
+ body.page = params.page;
82
+ if (params.size !== undefined)
83
+ body.size = params.size;
84
+ return body;
85
+ }
86
+ /**
87
+ * Registered `search_b2b_leads` callback. Parses the full object schema
88
+ * (including the revenueMin <= revenueMax refine) before building the
89
+ * request body or dispatching HTTP.
90
+ */
91
+ export async function handleSearchB2bLeads(params, apiPost) {
92
+ const parsed = searchB2bLeadsInputSchema.parse(params);
93
+ const body = buildSearchB2bLeadsBody(parsed);
94
+ return {
95
+ content: [{ type: "text", text: await apiPost("/leads/search", body) }],
96
+ };
97
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Names of tools the real Consulti MCP server registers, from a ListTools
3
+ * round-trip over InMemoryTransport. Import-safe: no stdio, no env reads.
4
+ */
5
+ export declare function listConsultiMcpToolNames(): Promise<string[]>;
@@ -0,0 +1,26 @@
1
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
+ import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
3
+ import { createConsultiMcpServer } from "./server.js";
4
+ /**
5
+ * Names of tools the real Consulti MCP server registers, from a ListTools
6
+ * round-trip over InMemoryTransport. Import-safe: no stdio, no env reads.
7
+ */
8
+ export async function listConsultiMcpToolNames() {
9
+ const server = createConsultiMcpServer({
10
+ apiPost: async () => "{}",
11
+ apiGet: async () => "{}",
12
+ });
13
+ const client = new Client({ name: "consulti-mcp-list-tools", version: "0.0.0" });
14
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
15
+ await Promise.all([
16
+ client.connect(clientTransport),
17
+ server.connect(serverTransport),
18
+ ]);
19
+ try {
20
+ const listed = await client.listTools();
21
+ return listed.tools.map((tool) => tool.name);
22
+ }
23
+ finally {
24
+ await Promise.all([client.close(), server.close()]);
25
+ }
26
+ }
@@ -0,0 +1,12 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ export declare const VERSION = "2.6.0";
3
+ export type ConsultiMcpApiPost = (path: string, body: Record<string, unknown>) => Promise<string>;
4
+ export type ConsultiMcpApiGet = (path: string) => Promise<string>;
5
+ /**
6
+ * Build the Consulti MCP server with every stable tool registered.
7
+ * Import-safe: does not connect a transport, read env, or start stdio.
8
+ */
9
+ export declare function createConsultiMcpServer(options: {
10
+ apiPost: ConsultiMcpApiPost;
11
+ apiGet: ConsultiMcpApiGet;
12
+ }): McpServer;
package/dist/server.js ADDED
@@ -0,0 +1,193 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+ import { handleSearchB2bLeads, searchB2bLeadsInputObjectSchema } from "./leads-search.js";
4
+ export const VERSION = "2.6.0";
5
+ /**
6
+ * Build the Consulti MCP server with every stable tool registered.
7
+ * Import-safe: does not connect a transport, read env, or start stdio.
8
+ */
9
+ export function createConsultiMcpServer(options) {
10
+ const { apiPost, apiGet } = options;
11
+ const server = new McpServer({
12
+ name: "consulti-mcp",
13
+ version: VERSION,
14
+ });
15
+ server.tool("verify_email", "Verify if an email address is valid and deliverable. Cost: 1 verification credit per call.", { email: z.string().describe("The email address to verify") }, async ({ email }) => ({
16
+ content: [{ type: "text", text: await apiPost("/verify", { email }) }],
17
+ }));
18
+ server.tool("verify_catchall", "Resolve whether a specific mailbox on a catch-all domain actually exists — the ESP-engine probe that plain SMTP (verify_email) cannot do. Use it on addresses verify_email returns with is_catch_all=true. Cost: 5 verification credits per call; requires a plan with catch-all verification enabled (Pro or higher).", { email: z.string().describe("The email address on a catch-all domain to resolve") }, async ({ email }) => ({
19
+ content: [{ type: "text", text: await apiPost("/verify/catchall", { email }) }],
20
+ }));
21
+ server.tool("enrich_lead", "Enrich a lead's full profile using their email address, including company-level funding, traffic, HQ, followers, and specialties when the lead is linked to a company. Cost: 1 lead credit — only deducted on a successful match; 404 responses are free.", { email: z.string().describe("The email address of the lead to enrich") }, async ({ email }) => ({
22
+ content: [{ type: "text", text: await apiPost("/leads/enrich", { email }) }],
23
+ }));
24
+ server.tool("enrich_linkedin", "Enrich a person by their LinkedIn profile URL → a verified work email plus their US mobile phone (free add-on). Cache-first: served instantly when we already hold a verified email for that profile, otherwise enriched live and cached. Cost: 1 lead credit — charged ONLY when an email is returned; phone-only or no-match responses are free.", { linkedin_url: z.string().describe("The LinkedIn profile URL, e.g. https://linkedin.com/in/johndoe") }, async ({ linkedin_url }) => ({
25
+ content: [{ type: "text", text: await apiPost("/enrich/linkedin", { linkedin_url }) }],
26
+ }));
27
+ server.registerTool("search_b2b_leads", {
28
+ description: "Search a database of B2B leads with filters like job title, industry, location, and company size. Country and state/region alias-group members are equivalent, so names and codes return identical populations. Results are always restricted to leads carrying our verified email label (there is no option to include unverified leads). Cost: 1 lead credit per result returned — reserved up to `size` then refunded down to the actual row count; 0 results = 0 credits. Call get_credits first before large `size` values.",
29
+ inputSchema: searchB2bLeadsInputObjectSchema,
30
+ }, async (params) => handleSearchB2bLeads(params, apiPost));
31
+ server.tool("search_instagram_profiles", "Search a database of Instagram profiles with filters like follower count, category, location, and data quality. Cost: 1 lead credit per result returned — reserved up to `size` then refunded down to the actual row count; 0 results = 0 credits. Call get_credits first before large operations.", {
32
+ q: z.string().optional().describe("Free text search across username and bio"),
33
+ bioKeywords: z.array(z.string()).optional().describe("Keywords to search for in profile bios"),
34
+ excludeKeywords: z.array(z.string()).optional().describe("Exclude profiles whose bio matches any of these keywords"),
35
+ excludeAdultContent: z.boolean().optional().describe("Exclude profiles with adult/sexual content terms in their bio"),
36
+ followerMin: z.number().optional().describe("Minimum follower count"),
37
+ followerMax: z.number().optional().describe("Maximum follower count"),
38
+ followingMin: z.number().optional().describe("Minimum following count"),
39
+ followingMax: z.number().optional().describe("Maximum following count"),
40
+ postsMin: z.number().optional().describe("Minimum post count"),
41
+ postsMax: z.number().optional().describe("Maximum post count"),
42
+ categories: z.array(z.string()).optional().describe("Categories to filter by (e.g. [\"Digital creator\", \"Photographer\"]). Canonical list: GET https://www.consulti.ai/api/v1/meta/instagram-categories"),
43
+ accountTypes: z.array(z.string()).optional().describe("Account types to filter by (e.g. [\"business\", \"personal\"]). Canonical list: GET https://www.consulti.ai/api/v1/meta/instagram-account-types"),
44
+ emailStatus: z.array(z.string()).optional().describe("Email verification status to filter by (e.g. [\"good\", \"risky\", \"bad\", \"catch_all\"]). Canonical list: GET https://www.consulti.ai/api/v1/meta/instagram-email-statuses"),
45
+ verified: z.boolean().optional().describe("Filter to only verified accounts"),
46
+ hasEmail: z.boolean().optional().describe("Filter to only accounts with an email on file"),
47
+ hasPhone: z.boolean().optional().describe("Filter to only accounts with phone number"),
48
+ hasWebsite: z.boolean().optional().describe("Filter to only accounts with website"),
49
+ countries: z.array(z.string()).optional().describe("Countries to filter by (exact match). Canonical list: GET https://www.consulti.ai/api/v1/meta/instagram-countries"),
50
+ excludeListId: z.string().optional().describe("UUID of an INSTAGRAM-kind saved list owned by the API key holder. Profiles on it are removed before billing, so they cost nothing. Another kind, an unknown list or someone else's list returns HTTP 400, a list over 100,000 members returns 422, and a temporary lookup failure returns 503, all before anything is charged (get_lists reports each list's kind). With it the response adds `total_after_exclusion`; both totals then count up to 10001 and can be null on a timeout, so paginate on has_more."),
51
+ sortBy: z.string().optional().describe("Field to sort by (followers, posts, engagement, username)"),
52
+ sortOrder: z.string().optional().describe("Sort order (asc or desc)"),
53
+ page: z.number().optional().describe("Page number (default: 1)"),
54
+ size: z.number().optional().describe("Results per page (default: 25, max: 100)"),
55
+ }, async (params) => {
56
+ const body = {};
57
+ if (params.q)
58
+ body.q = params.q;
59
+ if (params.bioKeywords)
60
+ body.bioKeywords = params.bioKeywords;
61
+ if (params.excludeKeywords)
62
+ body.excludeKeywords = params.excludeKeywords;
63
+ if (params.excludeAdultContent !== undefined)
64
+ body.excludeAdultContent = params.excludeAdultContent;
65
+ if (params.followerMin !== undefined)
66
+ body.followerMin = params.followerMin;
67
+ if (params.followerMax !== undefined)
68
+ body.followerMax = params.followerMax;
69
+ if (params.followingMin !== undefined)
70
+ body.followingMin = params.followingMin;
71
+ if (params.followingMax !== undefined)
72
+ body.followingMax = params.followingMax;
73
+ if (params.postsMin !== undefined)
74
+ body.postsMin = params.postsMin;
75
+ if (params.postsMax !== undefined)
76
+ body.postsMax = params.postsMax;
77
+ if (params.categories)
78
+ body.categories = params.categories;
79
+ if (params.accountTypes)
80
+ body.accountTypes = params.accountTypes;
81
+ if (params.emailStatus)
82
+ body.emailStatus = params.emailStatus;
83
+ if (params.verified !== undefined)
84
+ body.verified = params.verified;
85
+ if (params.hasEmail !== undefined)
86
+ body.hasEmail = params.hasEmail;
87
+ if (params.hasPhone !== undefined)
88
+ body.hasPhone = params.hasPhone;
89
+ if (params.hasWebsite !== undefined)
90
+ body.hasWebsite = params.hasWebsite;
91
+ if (params.countries)
92
+ body.countries = params.countries;
93
+ // !== undefined, not truthiness: a blank id must reach the API and get its
94
+ // 400 rather than silently running (and billing) an unexcluded search.
95
+ if (params.excludeListId !== undefined)
96
+ body.excludeListId = params.excludeListId;
97
+ if (params.sortBy)
98
+ body.sortBy = params.sortBy;
99
+ if (params.sortOrder)
100
+ body.sortOrder = params.sortOrder;
101
+ if (params.page !== undefined)
102
+ body.page = params.page;
103
+ if (params.size !== undefined)
104
+ body.size = params.size;
105
+ return {
106
+ content: [{ type: "text", text: await apiPost("/instagram/search", body) }],
107
+ };
108
+ });
109
+ server.tool("get_lists", "Get all saved lists for the authenticated user, with member counts and each list's kind", {}, async () => ({
110
+ content: [{ type: "text", text: await apiGet("/lists") }],
111
+ }));
112
+ server.tool("create_list", "Create a new saved list. A list holds exactly one entity kind. Use kind='lead' to store B2B lead emails and kind='business' to store local business IDs. Choose the kind that matches what you plan to add, because members cannot be added to a list of a different kind.", {
113
+ name: z.string().describe("Name of the list"),
114
+ description: z.string().optional().describe("Optional description of the list"),
115
+ // Only the two kinds add_leads_to_list can actually populate. Offering
116
+ // podcast, youtube, or instagram here would let an agent create a list it
117
+ // can never add a member to, because this package sends only emails or
118
+ // businessIds. Those kinds are created in the dashboard.
119
+ kind: z
120
+ .enum(["lead", "business"])
121
+ .optional()
122
+ .describe("Entity kind this list holds. Defaults to 'lead' for B2B emails. Use 'business' before adding businessIds from local business search."),
123
+ }, async ({ name, description, kind }) => {
124
+ const body = { name };
125
+ if (description)
126
+ body.description = description;
127
+ if (kind)
128
+ body.kind = kind;
129
+ return {
130
+ content: [{ type: "text", text: await apiPost("/lists", body) }],
131
+ };
132
+ });
133
+ server.tool("add_leads_to_list", "Add members to a saved list. Send 'emails' to a list with kind='lead', or 'businessIds' to a list with kind='business'. Send only one array per call. Email saves are free. Business saves cost 1 lead credit per newly unlocked business with usable email data. Already unlocked IDs, including successful paid local search results, cost no additional credits. Check credits_used and already_unlocked in the response.", {
134
+ listId: z.string().describe("UUID of the target list"),
135
+ emails: z
136
+ .array(z.string())
137
+ .optional()
138
+ .describe("Email addresses of B2B leads to add. Requires a list with kind='lead'."),
139
+ businessIds: z
140
+ .array(z.number())
141
+ .optional()
142
+ .describe("Business IDs from local business search. Requires a list with kind='business'."),
143
+ }, async ({ listId, emails, businessIds }) => {
144
+ const body = {};
145
+ if (emails)
146
+ body.emails = emails;
147
+ if (businessIds)
148
+ body.businessIds = businessIds;
149
+ return {
150
+ content: [{ type: "text", text: await apiPost(`/lists/${listId}/add-leads`, body) }],
151
+ };
152
+ });
153
+ server.tool("get_credits", "Check the authenticated user's current lead and verification credit balance. Free — no credits deducted. Use before bulk operations to avoid running out mid-task.", {}, async () => ({
154
+ content: [{ type: "text", text: await apiGet("/credits") }],
155
+ }));
156
+ server.tool("create_placement_test", "Create an inbox placement test. Checking starts when the test is created: send one email from the mailbox you want to test to every address in seed_addresses within 15 minutes, with the test_code anywhere in the subject or the body, then poll get_placement_test. Results usually arrive within a few minutes of sending. Cost: 1 lead credit per test, charged when the test is created and refunded if creation fails; requires the Pro plan or higher. A retried call creates, and charges for, a new test: an Idempotency-Key header has no effect at present, so check list_placement_tests before retrying instead of repeating the call. At most 3 tests can be checking at once; another create returns 429 with code too_many_open_tests and retry_after, is not charged, and is safe to retry after that many seconds. If the response says status \"draft\", the test could not be started: call mark_placement_test_sent after sending.", {
157
+ name: z.string().optional().describe("Optional label for the test (max 120 characters). Defaults to the subject."),
158
+ subject: z.string().optional().describe("Optional subject of the email you will send (max 998 characters). Used for the content check when no seed returns a body."),
159
+ body: z.string().optional().describe("Optional body of the email you will send (max 100,000 characters), for the same purpose."),
160
+ }, async ({ name, subject, body }) => {
161
+ const payload = {};
162
+ if (name !== undefined)
163
+ payload.name = name;
164
+ if (subject !== undefined)
165
+ payload.subject = subject;
166
+ if (body !== undefined)
167
+ payload.body = body;
168
+ return {
169
+ content: [{ type: "text", text: await apiPost("/placement-tests", payload) }],
170
+ };
171
+ });
172
+ server.tool("mark_placement_test_sent", "Start checking a placement test that create_placement_test returned with status \"draft\", once the email has gone out. Optional: a test created through the API is already checking, and calling this on a checking test changes nothing. A completed test returns 409 already_finished. Free; the test was charged when it was created.", { id: z.string().describe("The test id returned by create_placement_test") }, async ({ id }) => ({
173
+ content: [{ type: "text", text: await apiPost(`/placement-tests/${encodeURIComponent(id)}/sent`, {}) }],
174
+ }));
175
+ server.tool("get_placement_test", "Get a placement test: status, where the email landed for each seed (inbox, spam, promotions and other tabs, not_found), the SPF, DKIM and DMARC verdicts, a summary, and the 0 to 10 score and full report once built. A test can complete before expires_at and still correct a missing seed until then; results are final at expires_at. Another account's test, or an unknown id, returns 404. Free.", { id: z.string().describe("The test id returned by create_placement_test") }, async ({ id }) => ({
176
+ content: [{ type: "text", text: await apiGet(`/placement-tests/${encodeURIComponent(id)}`) }],
177
+ }));
178
+ server.tool("list_placement_tests", "List your placement tests, newest first. Only tests your account created are listed. Free.", {
179
+ page: z.number().optional().describe("Page number, from 1 (default 1)"),
180
+ size: z.number().optional().describe("Tests per page, 1 to 100 (default 25)"),
181
+ }, async ({ page, size }) => {
182
+ const query = new URLSearchParams();
183
+ if (page !== undefined)
184
+ query.set("page", String(page));
185
+ if (size !== undefined)
186
+ query.set("size", String(size));
187
+ const qs = query.toString();
188
+ return {
189
+ content: [{ type: "text", text: await apiGet(`/placement-tests${qs ? `?${qs}` : ""}`) }],
190
+ };
191
+ });
192
+ return server;
193
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Per-route client timeouts, keyed by path template. The client must outlast the route's
3
+ * maxDuration, otherwise it aborts while the server is still working and bills, and a
4
+ * retry then charges again. /leads/search runs for up to 120 s; a route that exports no
5
+ * maxDuration runs under Vercel's 300 s default.
6
+ */
7
+ export declare const TOOL_TIMEOUT_MS: Record<string, number>;
8
+ export declare const DEFAULT_TIMEOUT_MS = 310000;
9
+ /** Timeout for a request path. Query strings are ignored. */
10
+ export declare function timeoutFor(path: string): number;
11
+ export interface ApiOptions {
12
+ baseUrl: string;
13
+ apiKey: string;
14
+ userAgent: string;
15
+ fetchImpl?: typeof fetch;
16
+ }
17
+ export declare function createApi(options: ApiOptions): {
18
+ apiPost: (path: string, body: Record<string, unknown>) => Promise<string>;
19
+ apiGet: (path: string) => Promise<string>;
20
+ };
@@ -0,0 +1,118 @@
1
+ // HTTP transport for the MCP server. Import-safe: no env reads, no process.exit, no stdio.
2
+ /**
3
+ * Per-route client timeouts, keyed by path template. The client must outlast the route's
4
+ * maxDuration, otherwise it aborts while the server is still working and bills, and a
5
+ * retry then charges again. /leads/search runs for up to 120 s; a route that exports no
6
+ * maxDuration runs under Vercel's 300 s default.
7
+ */
8
+ export const TOOL_TIMEOUT_MS = {
9
+ "/leads/search": 130_000,
10
+ };
11
+ export const DEFAULT_TIMEOUT_MS = 310_000;
12
+ /** Timeout for a request path. Query strings are ignored. */
13
+ export function timeoutFor(path) {
14
+ return TOOL_TIMEOUT_MS[path.split("?")[0]] ?? DEFAULT_TIMEOUT_MS;
15
+ }
16
+ /** False for the calls that never debit credits: balance, lists, and placement reads and /sent. */
17
+ function isBillable(method, path) {
18
+ const p = path.split("?")[0];
19
+ if (p === "/credits" || p === "/lists")
20
+ return false;
21
+ if (/^\/placement-tests\/[^/]+\/sent$/.test(p))
22
+ return false;
23
+ if (method === "GET" && p.startsWith("/placement-tests"))
24
+ return false;
25
+ return true;
26
+ }
27
+ const BILLED_HINT = "The request may still have been billed. Call get_credits before retrying.";
28
+ function retryAfterFrom(header, body) {
29
+ const fromHeader = header === null || header.trim() === "" ? NaN : Number(header);
30
+ if (Number.isFinite(fromHeader))
31
+ return fromHeader;
32
+ const fromBody = body?.retry_after;
33
+ return typeof fromBody === "number" && Number.isFinite(fromBody) ? fromBody : undefined;
34
+ }
35
+ function nonJsonCode(status) {
36
+ if (status === 403 || status === 429)
37
+ return "blocked";
38
+ if (status === 502 || status === 504)
39
+ return "gateway_timeout";
40
+ return "non_json";
41
+ }
42
+ export function createApi(options) {
43
+ const { baseUrl, apiKey, userAgent } = options;
44
+ const fetchImpl = options.fetchImpl ?? fetch;
45
+ async function request(method, path, body) {
46
+ const timeoutMs = timeoutFor(path);
47
+ const billable = isBillable(method, path);
48
+ const controller = new AbortController();
49
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
50
+ const fail = (fields) => JSON.stringify(fields, null, 2);
51
+ try {
52
+ const response = await fetchImpl(`${baseUrl}${path}`, {
53
+ method,
54
+ headers: {
55
+ "Authorization": `Bearer ${apiKey}`,
56
+ ...(method === "POST" ? { "Content-Type": "application/json" } : {}),
57
+ "User-Agent": userAgent,
58
+ },
59
+ ...(method === "POST" ? { body: JSON.stringify(body ?? {}) } : {}),
60
+ signal: controller.signal,
61
+ });
62
+ const text = await response.text();
63
+ let data;
64
+ try {
65
+ const parsed = JSON.parse(text);
66
+ if (parsed !== null && typeof parsed === "object")
67
+ data = parsed;
68
+ }
69
+ catch {
70
+ // Not JSON: a firewall challenge, a platform error page or a plain-text body.
71
+ }
72
+ if (response.ok && data)
73
+ return JSON.stringify(data, null, 2);
74
+ const status = response.status;
75
+ const retryAfter = retryAfterFrom(response.headers.get("Retry-After"), data);
76
+ // A 503 that reports credits_used 0 was sent only after a confirmed refund. A 2xx that
77
+ // reached here has an unreadable body, so the route may have charged without our seeing it.
78
+ const refunded = status === 503 && data?.credits_used === 0;
79
+ const maybeBilled = billable && ((status >= 500 && !refunded) || response.ok);
80
+ if (!data) {
81
+ return fail({
82
+ error: `API returned ${status} with a non-JSON body`,
83
+ code: nonJsonCode(status),
84
+ status,
85
+ ...(retryAfter !== undefined ? { retry_after: retryAfter } : {}),
86
+ body_snippet: text.slice(0, 200),
87
+ ...(maybeBilled ? { hint: BILLED_HINT } : {}),
88
+ });
89
+ }
90
+ // Keep status, code and retry_after: an agent can only tell a retryable failure from a final one
91
+ // if they survive this wrapper, and collapsing every failure to prose forces it to match on wording.
92
+ const message = data.error || data.message || `API returned ${status}`;
93
+ return fail({
94
+ error: message,
95
+ ...(data.code ? { code: data.code } : {}),
96
+ status,
97
+ ...(retryAfter !== undefined ? { retry_after: retryAfter } : {}),
98
+ ...(data.credits_used !== undefined ? { credits_used: data.credits_used } : {}),
99
+ ...(maybeBilled ? { hint: BILLED_HINT } : {}),
100
+ });
101
+ }
102
+ catch (error) {
103
+ const hint = billable ? { hint: BILLED_HINT } : {};
104
+ if (error instanceof Error && error.name === "AbortError") {
105
+ return fail({ error: `Request timed out after ${timeoutMs / 1000}s`, code: "timeout", ...hint });
106
+ }
107
+ const message = error instanceof Error ? error.message : "Unknown error";
108
+ return fail({ error: `Request failed: ${message}`, code: "network_error", ...hint });
109
+ }
110
+ finally {
111
+ clearTimeout(timer);
112
+ }
113
+ }
114
+ return {
115
+ apiPost: (path, body) => request("POST", path, body),
116
+ apiGet: (path) => request("GET", path),
117
+ };
118
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "consulti-mcp",
3
- "version": "2.4.2",
4
- "description": "Consulti.ai MCP server — 10 stable tools for email verification (incl. catch-all mailbox resolution), B2B lead search/enrichment, LinkedIn-URL enrichment, Instagram profile search, list management, and credit-balance checks. Stable surface only; beta endpoints are not exposed via MCP. Compatible with Claude Desktop, Cursor, and any MCP client.",
3
+ "version": "2.6.0",
4
+ "description": "Consulti.ai MCP server — 14 stable tools for email verification (incl. catch-all mailbox resolution), B2B lead search/enrichment, LinkedIn-URL enrichment, Instagram profile search, list management, inbox placement tests, and credit-balance checks. Stable surface only; beta endpoints are not exposed via MCP. Compatible with Claude Desktop, Cursor, and any MCP client.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "consulti-mcp": "dist/index.js"
@@ -14,7 +14,8 @@
14
14
  "scripts": {
15
15
  "build": "tsc",
16
16
  "dev": "tsx src/index.ts",
17
- "prepublishOnly": "npm run build"
17
+ "prepublishOnly": "npm run build",
18
+ "test": "vitest run"
18
19
  },
19
20
  "keywords": [
20
21
  "mcp",
@@ -41,6 +42,7 @@
41
42
  "devDependencies": {
42
43
  "@types/node": "^22.15.2",
43
44
  "tsx": "^4.23.4",
44
- "typescript": "^5.8.3"
45
+ "typescript": "^5.8.3",
46
+ "vitest": "^4.1.11"
45
47
  }
46
48
  }