@coldiq/mcp 0.3.17 → 0.3.18

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.
@@ -23,11 +23,13 @@ export declare const findEmailsSchema: {
23
23
  }>, "many">;
24
24
  use_providers: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
25
25
  };
26
- export declare function findEmailsHandler(input: Record<string, unknown>): Promise<{
26
+ type ToolResult = {
27
27
  content: [{
28
- type: "text";
28
+ type: 'text';
29
29
  text: string;
30
30
  }];
31
31
  isError?: boolean;
32
- }>;
32
+ };
33
+ export declare function findEmailsHandler(input: Record<string, unknown>): Promise<ToolResult>;
34
+ export {};
33
35
  //# sourceMappingURL=find-emails.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-emails.d.ts","sourceRoot":"","sources":["../../src/tools/find-emails.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,cAAc,gBAAgB,CAAA;AAE3C,eAAO,MAAM,qBAAqB,QAOqE,CAAA;AAEvG,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;CAe5B,CAAA;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;GAIrE"}
1
+ {"version":3,"file":"find-emails.d.ts","sourceRoot":"","sources":["../../src/tools/find-emails.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,cAAc,gBAAgB,CAAA;AAE3C,eAAO,MAAM,qBAAqB,QAOqE,CAAA;AAEvG,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;CAe5B,CAAA;AASD,KAAK,UAAU,GAAG;IAAE,OAAO,EAAE,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAMlF,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CA0C3F"}
@@ -23,9 +23,48 @@ export const findEmailsSchema = {
23
23
  .describe('People to find emails for (max 50)'),
24
24
  use_providers: z.array(z.string()).optional().describe(`Optional ordered list of providers to use. Leave empty to let ColdIQ automatically run the best waterfall — recommended for most use cases. Available providers: ${FIND_EMAILS_PROVIDERS.join(', ')}. Provider names are matched fuzzily, so minor typos are tolerated.`),
25
25
  };
26
+ // Split large batches into sequential sub-batches so each HTTP call stays well
27
+ // under the server's bulk wall-clock budget (and thus Cloudflare's ~100s edge
28
+ // cutoff). A single 50-contact call could run long enough to be reset ("Network
29
+ // error", WF2); two ~25-contact calls each return quickly. Matches the server's
30
+ // bulk concurrency cap so each chunk is a single server wave.
31
+ const FIND_EMAILS_CHUNK_SIZE = 25;
32
+ function toolResult(payload, isError) {
33
+ return { content: [{ type: 'text', text: JSON.stringify(payload) }], isError };
34
+ }
26
35
  export async function findEmailsHandler(input) {
27
- // Bulk verb returns results positionally with no id echo — re-attach each
28
- // person's `id` so callers can still match results back.
29
- return callVerb('/email/find', input, { bulkField: 'people', reattachIdField: 'id' });
36
+ const people = Array.isArray(input.people) ? input.people : [];
37
+ // Small batch (the common case) one call, unchanged. Bulk verb returns results
38
+ // positionally with no id echo, so re-attach each person's `id` to match back.
39
+ if (people.length <= FIND_EMAILS_CHUNK_SIZE) {
40
+ return callVerb('/email/find', input, { bulkField: 'people', reattachIdField: 'id' });
41
+ }
42
+ // Large batch — chunk sequentially and merge the per-contact results in order.
43
+ const merged = [];
44
+ for (let i = 0; i < people.length; i += FIND_EMAILS_CHUNK_SIZE) {
45
+ const chunk = people.slice(i, i + FIND_EMAILS_CHUNK_SIZE);
46
+ const res = (await callVerb('/email/find', { ...input, people: chunk }, { bulkField: 'people', reattachIdField: 'id' }));
47
+ let data;
48
+ try {
49
+ data = JSON.parse(res.content[0].text);
50
+ }
51
+ catch {
52
+ data = undefined;
53
+ }
54
+ const results = data?.results;
55
+ if (!Array.isArray(results)) {
56
+ // Whole-chunk failure (bad request, auth, …) — surface it alongside whatever
57
+ // we already gathered. Spread errorBody first so the accumulated `results`
58
+ // always win, even if the error body carries its own (non-array) results key.
59
+ const errorBody = data && typeof data === 'object' ? data : { error: 'find_emails request failed' };
60
+ return toolResult({ ...errorBody, results: merged }, true);
61
+ }
62
+ merged.push(...results);
63
+ // A transport/billing error on a chunk (e.g. 402 out of credits) is terminal —
64
+ // stop rather than burning the remaining chunks.
65
+ if (res.isError)
66
+ return toolResult({ results: merged }, true);
67
+ }
68
+ return toolResult({ results: merged }, false);
30
69
  }
31
70
  //# sourceMappingURL=find-emails.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-emails.js","sourceRoot":"","sources":["../../src/tools/find-emails.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAErE,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAA;AAE3C,MAAM,CAAC,MAAM,qBAAqB,GAChC,6DAA6D;IAC7D,mEAAmE;IACnE,0EAA0E;IAC1E,uDAAuD;IACvD,0FAA0F;IAC1F,kHAAkH;IAClH,qGAAqG,CAAA;AAEvG,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,MAAM,EAAE,CAAC;SACN,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wEAAwE,CAAC;QACjG,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC;QACxD,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AC,CAAC,CAAC,EAAE,KAAK,EAAE,4BAA4B,EAAE,CAAA;YAC/G,OAAO,UAAU,CAAC,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,CAAA;QAC5D,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAA;QAEvB,+EAA+E;QAC/E,iDAAiD;QACjD,IAAI,GAAG,CAAC,OAAO;YAAE,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,CAAA;IAC/D,CAAC;IAED,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,CAAA;AAC/C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coldiq/mcp",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -30,8 +30,59 @@ export const findEmailsSchema = {
30
30
  use_providers: z.array(z.string()).optional().describe(`Optional ordered list of providers to use. Leave empty to let ColdIQ automatically run the best waterfall — recommended for most use cases. Available providers: ${FIND_EMAILS_PROVIDERS.join(', ')}. Provider names are matched fuzzily, so minor typos are tolerated.`),
31
31
  }
32
32
 
33
- export async function findEmailsHandler(input: Record<string, unknown>) {
34
- // Bulk verb returns results positionally with no id echo re-attach each
35
- // person's `id` so callers can still match results back.
36
- return callVerb('/email/find', input, { bulkField: 'people', reattachIdField: 'id' })
33
+ // Split large batches into sequential sub-batches so each HTTP call stays well
34
+ // under the server's bulk wall-clock budget (and thus Cloudflare's ~100s edge
35
+ // cutoff). A single 50-contact call could run long enough to be reset ("Network
36
+ // error", WF2); two ~25-contact calls each return quickly. Matches the server's
37
+ // bulk concurrency cap so each chunk is a single server wave.
38
+ const FIND_EMAILS_CHUNK_SIZE = 25
39
+
40
+ type ToolResult = { content: [{ type: 'text'; text: string }]; isError?: boolean }
41
+
42
+ function toolResult(payload: unknown, isError: boolean): ToolResult {
43
+ return { content: [{ type: 'text', text: JSON.stringify(payload) }], isError }
44
+ }
45
+
46
+ export async function findEmailsHandler(input: Record<string, unknown>): Promise<ToolResult> {
47
+ const people = Array.isArray(input.people) ? (input.people as unknown[]) : []
48
+
49
+ // Small batch (the common case) — one call, unchanged. Bulk verb returns results
50
+ // positionally with no id echo, so re-attach each person's `id` to match back.
51
+ if (people.length <= FIND_EMAILS_CHUNK_SIZE) {
52
+ return callVerb('/email/find', input, { bulkField: 'people', reattachIdField: 'id' }) as Promise<ToolResult>
53
+ }
54
+
55
+ // Large batch — chunk sequentially and merge the per-contact results in order.
56
+ const merged: unknown[] = []
57
+ for (let i = 0; i < people.length; i += FIND_EMAILS_CHUNK_SIZE) {
58
+ const chunk = people.slice(i, i + FIND_EMAILS_CHUNK_SIZE)
59
+ const res = (await callVerb(
60
+ '/email/find',
61
+ { ...input, people: chunk },
62
+ { bulkField: 'people', reattachIdField: 'id' },
63
+ )) as ToolResult
64
+
65
+ let data: unknown
66
+ try {
67
+ data = JSON.parse(res.content[0].text)
68
+ } catch {
69
+ data = undefined
70
+ }
71
+ const results = (data as { results?: unknown[] } | undefined)?.results
72
+
73
+ if (!Array.isArray(results)) {
74
+ // Whole-chunk failure (bad request, auth, …) — surface it alongside whatever
75
+ // we already gathered. Spread errorBody first so the accumulated `results`
76
+ // always win, even if the error body carries its own (non-array) results key.
77
+ const errorBody = data && typeof data === 'object' ? (data as object) : { error: 'find_emails request failed' }
78
+ return toolResult({ ...errorBody, results: merged }, true)
79
+ }
80
+ merged.push(...results)
81
+
82
+ // A transport/billing error on a chunk (e.g. 402 out of credits) is terminal —
83
+ // stop rather than burning the remaining chunks.
84
+ if (res.isError) return toolResult({ results: merged }, true)
85
+ }
86
+
87
+ return toolResult({ results: merged }, false)
37
88
  }
@@ -0,0 +1,72 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest'
2
+
3
+ // Mock the verb client so we test the handler's chunk/merge logic directly,
4
+ // without building real envelopes or touching the network.
5
+ const callVerbMock = vi.fn()
6
+ vi.mock('../../src/verb-client.js', () => ({
7
+ callVerb: (...args: unknown[]) => callVerbMock(...args),
8
+ }))
9
+
10
+ import { findEmailsHandler } from '../../src/tools/find-emails.js'
11
+
12
+ type Person = { id: string; domain?: string }
13
+ const peopleOf = (n: number): Person[] => Array.from({ length: n }, (_, i) => ({ id: `p${i}`, domain: 'coldiq.com' }))
14
+
15
+ // Build the ToolResult callVerb would return: one result per person in the chunk.
16
+ function chunkResult(input: Record<string, unknown>, opts?: { isError?: boolean }) {
17
+ const people = (input.people as Person[]) ?? []
18
+ return {
19
+ content: [{ type: 'text' as const, text: JSON.stringify({ results: people.map((p) => ({ id: p.id, email: `${p.id}@x.com` })) }) }],
20
+ isError: opts?.isError ?? false,
21
+ }
22
+ }
23
+
24
+ beforeEach(() => {
25
+ callVerbMock.mockReset()
26
+ callVerbMock.mockImplementation((_path: string, input: Record<string, unknown>) => Promise.resolve(chunkResult(input)))
27
+ })
28
+
29
+ describe('find_emails auto-chunking', () => {
30
+ it('≤25 people → a single passthrough call', async () => {
31
+ await findEmailsHandler({ people: peopleOf(25) })
32
+ expect(callVerbMock).toHaveBeenCalledTimes(1)
33
+ expect((callVerbMock.mock.calls[0][1] as { people: Person[] }).people).toHaveLength(25)
34
+ })
35
+
36
+ it('>25 people → sequential chunks of ≤25, merged in order', async () => {
37
+ const res = await findEmailsHandler({ people: peopleOf(60) })
38
+
39
+ // 60 → 25 + 25 + 10
40
+ expect(callVerbMock).toHaveBeenCalledTimes(3)
41
+ expect((callVerbMock.mock.calls[0][1] as { people: Person[] }).people).toHaveLength(25)
42
+ expect((callVerbMock.mock.calls[1][1] as { people: Person[] }).people).toHaveLength(25)
43
+ expect((callVerbMock.mock.calls[2][1] as { people: Person[] }).people).toHaveLength(10)
44
+
45
+ const data = JSON.parse(res.content[0].text)
46
+ expect(data.results).toHaveLength(60)
47
+ // Order preserved across chunks.
48
+ expect(data.results.map((r: { id: string }) => r.id)).toEqual(peopleOf(60).map((p) => p.id))
49
+ expect(res.isError).toBe(false)
50
+ })
51
+
52
+ it('forwards use_providers to every chunk', async () => {
53
+ await findEmailsHandler({ people: peopleOf(30), use_providers: ['limadata-work-email'] })
54
+ expect(callVerbMock).toHaveBeenCalledTimes(2)
55
+ for (const call of callVerbMock.mock.calls) {
56
+ expect((call[1] as { use_providers: string[] }).use_providers).toEqual(['limadata-work-email'])
57
+ }
58
+ })
59
+
60
+ it('stops early and surfaces the error when a chunk fails terminally (e.g. 402)', async () => {
61
+ callVerbMock
62
+ .mockImplementationOnce((_p: string, input: Record<string, unknown>) => Promise.resolve(chunkResult(input)))
63
+ .mockImplementationOnce((_p: string, input: Record<string, unknown>) => Promise.resolve(chunkResult(input, { isError: true })))
64
+ const res = await findEmailsHandler({ people: peopleOf(60) })
65
+
66
+ // 1st chunk ok, 2nd is a terminal error → stop (3rd chunk never sent).
67
+ expect(callVerbMock).toHaveBeenCalledTimes(2)
68
+ expect(res.isError).toBe(true)
69
+ const data = JSON.parse(res.content[0].text)
70
+ expect(data.results).toHaveLength(50) // partial results preserved
71
+ })
72
+ })