@coldiq/mcp 0.2.8 → 0.3.1
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/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/registry.d.ts +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +102 -16
- package/dist/registry.js.map +1 -1
- package/dist/tools/extract-post-engagement.d.ts +21 -0
- package/dist/tools/extract-post-engagement.d.ts.map +1 -0
- package/dist/tools/extract-post-engagement.js +117 -0
- package/dist/tools/extract-post-engagement.js.map +1 -0
- package/dist/tools/find-influencers.d.ts +1 -1
- package/dist/tools/find-influencers.d.ts.map +1 -1
- package/dist/tools/find-influencers.js +2 -1
- package/dist/tools/find-influencers.js.map +1 -1
- package/dist/tools/find-signals.d.ts.map +1 -1
- package/dist/tools/find-signals.js +27 -10
- package/dist/tools/find-signals.js.map +1 -1
- package/dist/tools/get-place-reviews.d.ts +24 -0
- package/dist/tools/get-place-reviews.d.ts.map +1 -0
- package/dist/tools/get-place-reviews.js +46 -0
- package/dist/tools/get-place-reviews.js.map +1 -0
- package/dist/tools/search-ads.d.ts +1 -1
- package/dist/tools/search-ads.d.ts.map +1 -1
- package/dist/tools/search-ads.js +1 -1
- package/dist/tools/search-ads.js.map +1 -1
- package/dist/tools/search-companies.d.ts.map +1 -1
- package/dist/tools/search-companies.js +8 -1
- package/dist/tools/search-companies.js.map +1 -1
- package/dist/tools/search-places.d.ts +1 -1
- package/dist/tools/search-places.d.ts.map +1 -1
- package/dist/tools/search-places.js +23 -3
- package/dist/tools/search-places.js.map +1 -1
- package/dist/tools/search-reddit.js +1 -1
- package/dist/tools/search-reddit.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +16 -0
- package/src/registry.ts +93 -5
- package/src/tools/extract-post-engagement.ts +135 -0
- package/src/tools/find-influencers.ts +2 -1
- package/src/tools/find-signals.ts +28 -11
- package/src/tools/get-place-reviews.ts +50 -0
- package/src/tools/search-ads.ts +1 -1
- package/src/tools/search-companies.ts +7 -1
- package/src/tools/search-places.ts +22 -3
- package/src/tools/search-reddit.ts +1 -1
- package/tests/registry-find-signals.test.ts +66 -0
- package/tests/registry-search-companies.test.ts +16 -0
- package/tests/registry.test.ts +3 -3
- package/tests/tools/extract-post-engagement.test.ts +76 -0
- package/tests/tools/find-signals.test.ts +5 -2
- package/tests/tools/get-place-reviews.test.ts +73 -0
- package/tests/tools/search-companies.test.ts +19 -1
- package/tests/tools/search-reddit.test.ts +69 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-reddit.js","sourceRoot":"","sources":["../../src/tools/search-reddit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAA;AAEpG,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAA;AAE/C,MAAM,CAAC,MAAM,uBAAuB,GAClC,0SAA0S,CAAA;AAE5S,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;SACrD,QAAQ,CAAC,iJAAiJ,CAAC;IAC9J,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SACzB,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"search-reddit.js","sourceRoot":"","sources":["../../src/tools/search-reddit.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -130,6 +130,20 @@ import {
|
|
|
130
130
|
getCreditBalanceHandler,
|
|
131
131
|
} from './tools/get-credit-balance.js'
|
|
132
132
|
|
|
133
|
+
import {
|
|
134
|
+
extractPostEngagementName,
|
|
135
|
+
extractPostEngagementDescription,
|
|
136
|
+
extractPostEngagementSchema,
|
|
137
|
+
extractPostEngagementHandler,
|
|
138
|
+
} from './tools/extract-post-engagement.js'
|
|
139
|
+
|
|
140
|
+
import {
|
|
141
|
+
getPlaceReviewsName,
|
|
142
|
+
getPlaceReviewsDescription,
|
|
143
|
+
getPlaceReviewsSchema,
|
|
144
|
+
getPlaceReviewsHandler,
|
|
145
|
+
} from './tools/get-place-reviews.js'
|
|
146
|
+
|
|
133
147
|
// Initialize HTTP client (reads env vars)
|
|
134
148
|
initClient()
|
|
135
149
|
|
|
@@ -157,6 +171,8 @@ server.tool(searchSeoName, searchSeoDescription, searchSeoSchema, searchSeoHandl
|
|
|
157
171
|
server.tool(findSignalsName, findSignalsDescription, findSignalsSchema, findSignalsHandler)
|
|
158
172
|
server.tool(fetchPageContentName, fetchPageContentDescription, fetchPageContentSchema, fetchPageContentHandler)
|
|
159
173
|
server.tool(getCreditBalanceName, getCreditBalanceDescription, getCreditBalanceSchema, getCreditBalanceHandler)
|
|
174
|
+
server.tool(extractPostEngagementName, extractPostEngagementDescription, extractPostEngagementSchema, extractPostEngagementHandler)
|
|
175
|
+
server.tool(getPlaceReviewsName, getPlaceReviewsDescription, getPlaceReviewsSchema, getPlaceReviewsHandler)
|
|
160
176
|
|
|
161
177
|
// Connect via stdio transport
|
|
162
178
|
const transport = new StdioServerTransport()
|
package/src/registry.ts
CHANGED
|
@@ -54,6 +54,7 @@ export type Capability =
|
|
|
54
54
|
| 'search_jobs'
|
|
55
55
|
| 'search_ads'
|
|
56
56
|
| 'search_places'
|
|
57
|
+
| 'get_place_reviews'
|
|
57
58
|
| 'find_influencers'
|
|
58
59
|
| 'search_reddit'
|
|
59
60
|
| 'search_seo'
|
|
@@ -366,7 +367,9 @@ const searchCompaniesProviders: ProviderEntry[] = [
|
|
|
366
367
|
input.min_employees || input.max_employees
|
|
367
368
|
? [`${(input.min_employees as number) ?? 0},${(input.max_employees as number) ?? 1000000}`]
|
|
368
369
|
: undefined,
|
|
369
|
-
|
|
370
|
+
// Backend auto-paginates `limit` over Apollo pages (100/page = 1 credit) and
|
|
371
|
+
// bills only the pages actually fetched.
|
|
372
|
+
limit: (input.limit as number) ?? 25,
|
|
370
373
|
},
|
|
371
374
|
}
|
|
372
375
|
},
|
|
@@ -2468,6 +2471,31 @@ const searchPlacesProviders: ProviderEntry[] = [
|
|
|
2468
2471
|
},
|
|
2469
2472
|
]
|
|
2470
2473
|
|
|
2474
|
+
// ---------------------------------------------------------------------------
|
|
2475
|
+
// get_place_reviews
|
|
2476
|
+
// ---------------------------------------------------------------------------
|
|
2477
|
+
|
|
2478
|
+
const getPlaceReviewsProviders: ProviderEntry[] = [
|
|
2479
|
+
{
|
|
2480
|
+
id: 'google_maps_reviews',
|
|
2481
|
+
endpoint: '/google-maps/reviews',
|
|
2482
|
+
method: 'POST',
|
|
2483
|
+
priority: 1,
|
|
2484
|
+
mapParams: (input) => ({
|
|
2485
|
+
body: {
|
|
2486
|
+
startUrls: (input.place_urls as string[]).map((url) => ({ url })),
|
|
2487
|
+
maxReviews: input.max_reviews,
|
|
2488
|
+
reviewsSort: input.sort,
|
|
2489
|
+
language: input.language,
|
|
2490
|
+
},
|
|
2491
|
+
}),
|
|
2492
|
+
// A completed job is a valid result even with an empty reviews array (a place
|
|
2493
|
+
// may genuinely have no reviews) — only failed/timed_out should fall through.
|
|
2494
|
+
hasResult: (data) => (data as { status?: string }).status === 'done',
|
|
2495
|
+
async: { ..._placesSharedAsync, pollEndpoint: (id) => `/google-maps/reviews/${id}` },
|
|
2496
|
+
},
|
|
2497
|
+
]
|
|
2498
|
+
|
|
2471
2499
|
// ---------------------------------------------------------------------------
|
|
2472
2500
|
// find_influencers
|
|
2473
2501
|
// ---------------------------------------------------------------------------
|
|
@@ -2543,6 +2571,22 @@ const _redditSharedAsync = {
|
|
|
2543
2571
|
},
|
|
2544
2572
|
}
|
|
2545
2573
|
|
|
2574
|
+
// A bare subreddit URL (e.g. https://www.reddit.com/r/sales or .../r/sales/)
|
|
2575
|
+
// makes the Apify actor ENUMERATE that subreddit's feed and ignore the search
|
|
2576
|
+
// keyword entirely. When the caller also passes a `query`, rewrite bare
|
|
2577
|
+
// subreddit URLs into in-subreddit search URLs so the keyword is actually
|
|
2578
|
+
// applied. Already-formed search/post URLs are left untouched.
|
|
2579
|
+
const _BARE_SUBREDDIT_RE = /^(https?:\/\/(?:www\.)?reddit\.com\/r\/[A-Za-z0-9_]+)\/?$/i
|
|
2580
|
+
|
|
2581
|
+
function _toRedditSearchUrl(url: string, query: string, opts: { sort?: unknown; time?: unknown }): string {
|
|
2582
|
+
const m = url.match(_BARE_SUBREDDIT_RE)
|
|
2583
|
+
if (!m) return url
|
|
2584
|
+
const params = new URLSearchParams({ q: query, restrict_sr: '1' })
|
|
2585
|
+
if (typeof opts.sort === 'string' && opts.sort) params.set('sort', opts.sort)
|
|
2586
|
+
if (typeof opts.time === 'string' && opts.time) params.set('t', opts.time)
|
|
2587
|
+
return `${m[1]}/search/?${params.toString()}`
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2546
2590
|
const searchRedditProviders: ProviderEntry[] = [
|
|
2547
2591
|
{
|
|
2548
2592
|
id: 'reddit',
|
|
@@ -2550,10 +2594,26 @@ const searchRedditProviders: ProviderEntry[] = [
|
|
|
2550
2594
|
method: 'POST',
|
|
2551
2595
|
priority: 1,
|
|
2552
2596
|
isApplicable: (input) => isNonEmptyArray(input.start_urls) || typeof input.query === 'string',
|
|
2553
|
-
mapParams: (input) =>
|
|
2597
|
+
mapParams: (input) => {
|
|
2598
|
+
const query = typeof input.query === 'string' && input.query ? input.query : undefined
|
|
2599
|
+
const rawStartUrls = input.start_urls as string[] | undefined
|
|
2600
|
+
let startUrls = rawStartUrls?.map((url) => ({ url }))
|
|
2601
|
+
let searchQueries = query ? [query] : undefined
|
|
2602
|
+
// If a query is provided alongside start_urls, embed it into any bare
|
|
2603
|
+
// subreddit URLs (which would otherwise ignore it). The keyword then lives
|
|
2604
|
+
// in the URL, so drop the top-level searchQueries to avoid a conflicting
|
|
2605
|
+
// global search.
|
|
2606
|
+
if (query && rawStartUrls && rawStartUrls.length > 0) {
|
|
2607
|
+
const rewritten = rawStartUrls.map((u) => _toRedditSearchUrl(u, query, { sort: input.sort, time: input.time }))
|
|
2608
|
+
if (rewritten.some((u, i) => u !== rawStartUrls[i])) {
|
|
2609
|
+
startUrls = rewritten.map((url) => ({ url }))
|
|
2610
|
+
searchQueries = undefined
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
return {
|
|
2554
2614
|
body: {
|
|
2555
|
-
searchQueries
|
|
2556
|
-
startUrls
|
|
2615
|
+
searchQueries,
|
|
2616
|
+
startUrls,
|
|
2557
2617
|
searchType: input.search_type ?? 'posts',
|
|
2558
2618
|
searchCommunityName: input.search_community_name,
|
|
2559
2619
|
sort: input.sort,
|
|
@@ -2564,7 +2624,7 @@ const searchRedditProviders: ProviderEntry[] = [
|
|
|
2564
2624
|
postDateLimit: input.post_date_limit,
|
|
2565
2625
|
commentDateLimit: input.comment_date_limit,
|
|
2566
2626
|
},
|
|
2567
|
-
}
|
|
2627
|
+
}},
|
|
2568
2628
|
hasResult: (data) => isNonEmptyArray((data as { items?: unknown[] }).items),
|
|
2569
2629
|
async: {
|
|
2570
2630
|
..._redditSharedAsync,
|
|
@@ -3164,6 +3224,33 @@ const findSignalsProviders: ProviderEntry[] = [
|
|
|
3164
3224
|
hasResult: (data) => isNonEmptyArray((data as Record<string, unknown>).data),
|
|
3165
3225
|
},
|
|
3166
3226
|
{
|
|
3227
|
+
// Topic-based DISCOVERY: "which companies show intent on topic X" with no
|
|
3228
|
+
// company list known in advance. Routes to /theirstack/companies/search,
|
|
3229
|
+
// which returns a list of companies filtered by buying-intent keyword slugs.
|
|
3230
|
+
// This is the GTM-primary use case (find prospects by intent), distinct from
|
|
3231
|
+
// theirstack-buying-intents which verifies intent on companies you already have.
|
|
3232
|
+
id: 'theirstack-intent-discovery',
|
|
3233
|
+
endpoint: '/theirstack/companies/search',
|
|
3234
|
+
method: 'POST',
|
|
3235
|
+
priority: 5,
|
|
3236
|
+
isApplicable: (input) =>
|
|
3237
|
+
input.signal_type === 'intent' &&
|
|
3238
|
+
isNonEmptyArray(input.topics) &&
|
|
3239
|
+
!isNonEmptyArray(input.companies) &&
|
|
3240
|
+
!isNonEmptyArray(input.domains),
|
|
3241
|
+
mapParams: (input) => ({
|
|
3242
|
+
body: {
|
|
3243
|
+
company_keyword_slug_or: input.topics,
|
|
3244
|
+
...(isNonEmptyArray(input.industries) && { industry_or: input.industries }),
|
|
3245
|
+
...(isNonEmptyArray(input.countries) && { company_country_code_or: input.countries }),
|
|
3246
|
+
limit: Math.min((input.limit as number | undefined) ?? 25, 100),
|
|
3247
|
+
include_total_results: true,
|
|
3248
|
+
},
|
|
3249
|
+
}),
|
|
3250
|
+
hasResult: (data) => isNonEmptyArray((data as Record<string, unknown>).data),
|
|
3251
|
+
},
|
|
3252
|
+
{
|
|
3253
|
+
// Verify intent on KNOWN companies/domains.
|
|
3167
3254
|
id: 'theirstack-buying-intents',
|
|
3168
3255
|
endpoint: '/theirstack/companies/buying_intents',
|
|
3169
3256
|
method: 'POST',
|
|
@@ -3262,6 +3349,7 @@ const registry: Record<Capability, ProviderEntry[]> = {
|
|
|
3262
3349
|
search_jobs: searchJobsProviders,
|
|
3263
3350
|
search_ads: searchAdsProviders,
|
|
3264
3351
|
search_places: searchPlacesProviders,
|
|
3352
|
+
get_place_reviews: getPlaceReviewsProviders,
|
|
3265
3353
|
find_influencers: findInfluencersProviders,
|
|
3266
3354
|
search_reddit: searchRedditProviders,
|
|
3267
3355
|
search_seo: searchSeoProviders,
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { callApi } from '../client.js'
|
|
3
|
+
|
|
4
|
+
export const extractPostEngagementName = 'extract_post_engagement'
|
|
5
|
+
|
|
6
|
+
export const extractPostEngagementDescription =
|
|
7
|
+
'Extract the people who engaged with a LinkedIn post — commenters and/or reactors — as a deduplicated list of contacts (name, profile URL, headline). ' +
|
|
8
|
+
'Use this for social-signal prospecting: pull everyone who engaged with a viral post, then chain the results into enrich_person / find_email to get roles and work emails. ' +
|
|
9
|
+
'Runs an async extraction job (typically ~30–120s) and returns once the people are ready. Costs 10 credits per post.'
|
|
10
|
+
|
|
11
|
+
export const extractPostEngagementSchema = {
|
|
12
|
+
post_url: z
|
|
13
|
+
.string()
|
|
14
|
+
.url()
|
|
15
|
+
.describe('LinkedIn post URL to extract engagement from (e.g. "https://www.linkedin.com/feed/update/urn:li:activity:7234567890123456789" or a /posts/ permalink).'),
|
|
16
|
+
type: z
|
|
17
|
+
.enum(['comments', 'reactions', 'both'])
|
|
18
|
+
.default('both')
|
|
19
|
+
.describe('Which engagement to extract: "comments" (people who commented), "reactions" (people who reacted), or "both" (default — deduplicated across both).'),
|
|
20
|
+
include_replies: z
|
|
21
|
+
.boolean()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('When extracting comments, also include people who replied to comments. Defaults to true upstream.'),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function sleep(ms: number): Promise<void> {
|
|
27
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function errorResult(error: string, extra?: Record<string, unknown>) {
|
|
31
|
+
return {
|
|
32
|
+
content: [{ type: 'text' as const, text: JSON.stringify({ error, ...extra }) }],
|
|
33
|
+
isError: true,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function extractErrorMessage(data: unknown): string | undefined {
|
|
38
|
+
if (data && typeof data === 'object' && 'error' in data) {
|
|
39
|
+
const e = (data as Record<string, unknown>).error
|
|
40
|
+
return typeof e === 'string' ? e : JSON.stringify(e)
|
|
41
|
+
}
|
|
42
|
+
return undefined
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function extractPostEngagementHandler(input: Record<string, unknown>) {
|
|
46
|
+
const postUrl = input.post_url as string
|
|
47
|
+
const type = (input.type as 'comments' | 'reactions' | 'both' | undefined) ?? 'both'
|
|
48
|
+
const includeReplies = input.include_replies as boolean | undefined
|
|
49
|
+
|
|
50
|
+
const dataTypes =
|
|
51
|
+
type === 'comments' ? ['comment'] : type === 'reactions' ? ['reaction'] : ['comment', 'reaction']
|
|
52
|
+
|
|
53
|
+
// Step 1 — create the extraction task. Billing (10 credits) happens here.
|
|
54
|
+
const createRes = await callApi('POST', '/jungler/workbooks', {
|
|
55
|
+
post_url: postUrl,
|
|
56
|
+
data_types: dataTypes,
|
|
57
|
+
})
|
|
58
|
+
if (!createRes.ok) {
|
|
59
|
+
return errorResult(extractErrorMessage(createRes.data) ?? `Failed to start extraction (status ${createRes.status})`)
|
|
60
|
+
}
|
|
61
|
+
const createData = createRes.data as { task_id?: string }
|
|
62
|
+
const taskId = createData.task_id
|
|
63
|
+
if (!taskId) {
|
|
64
|
+
return errorResult('Extraction job did not return a task id')
|
|
65
|
+
}
|
|
66
|
+
// Credit headers are emitted on the create call (the only billed step).
|
|
67
|
+
const creditsCharged = Number(createRes.headers['x-coldiq-credits-charged'])
|
|
68
|
+
const creditsRemaining = Number(createRes.headers['x-coldiq-credits-remaining'])
|
|
69
|
+
|
|
70
|
+
// Step 2 — poll task status until it resolves. The status endpoint is free, so
|
|
71
|
+
// polling does not bill; only the create call above charged credits.
|
|
72
|
+
const pollIntervalMs = parseInt(process.env.COLDIQ_ENGAGEMENT_POLL_MS ?? '2000', 10)
|
|
73
|
+
const timeoutMs = parseInt(process.env.COLDIQ_ENGAGEMENT_TIMEOUT_MS ?? '180000', 10)
|
|
74
|
+
const maxPollErrors = 3
|
|
75
|
+
const deadline = Date.now() + timeoutMs
|
|
76
|
+
|
|
77
|
+
let workbookId: string | undefined
|
|
78
|
+
let consecutivePollErrors = 0
|
|
79
|
+
|
|
80
|
+
while (Date.now() < deadline) {
|
|
81
|
+
await sleep(pollIntervalMs)
|
|
82
|
+
const statusRes = await callApi('GET', `/jungler/tasks/${taskId}/status`)
|
|
83
|
+
if (!statusRes.ok) {
|
|
84
|
+
consecutivePollErrors++
|
|
85
|
+
if (consecutivePollErrors >= maxPollErrors) {
|
|
86
|
+
return errorResult('Could not read extraction status — please retry', { post_url: postUrl })
|
|
87
|
+
}
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
consecutivePollErrors = 0
|
|
91
|
+
const status = (statusRes.data as { status?: string; workbook_id?: string }).status
|
|
92
|
+
if (status === 'success') {
|
|
93
|
+
workbookId = (statusRes.data as { workbook_id?: string }).workbook_id
|
|
94
|
+
break
|
|
95
|
+
}
|
|
96
|
+
if (status === 'failure') {
|
|
97
|
+
return errorResult('Engagement extraction failed upstream — the post may be private, deleted, or have no engagement', { post_url: postUrl })
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!workbookId) {
|
|
102
|
+
return errorResult(`Engagement extraction did not complete within ${Math.round(timeoutMs / 1000)}s — try again shortly`, { post_url: postUrl })
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Step 3 — fetch the deduplicated people. activity_filter narrows to commenters
|
|
106
|
+
// or reactors; omitted for "both" so the upstream returns all unique contacts.
|
|
107
|
+
const queryParams: Record<string, string> = {}
|
|
108
|
+
if (type === 'comments') queryParams.activity_filter = 'commenters'
|
|
109
|
+
else if (type === 'reactions') queryParams.activity_filter = 'reactors'
|
|
110
|
+
if (includeReplies !== undefined) queryParams.include_replies = String(includeReplies)
|
|
111
|
+
|
|
112
|
+
const contactsRes = await callApi(
|
|
113
|
+
'GET',
|
|
114
|
+
`/jungler/workbooks/${workbookId}/contacts`,
|
|
115
|
+
undefined,
|
|
116
|
+
Object.keys(queryParams).length > 0 ? queryParams : undefined,
|
|
117
|
+
)
|
|
118
|
+
if (!contactsRes.ok) {
|
|
119
|
+
return errorResult(extractErrorMessage(contactsRes.data) ?? 'Failed to fetch extracted people', { post_url: postUrl })
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const meta: Record<string, unknown> = {}
|
|
123
|
+
if (Number.isFinite(creditsCharged)) meta.credits_charged = creditsCharged
|
|
124
|
+
if (Number.isFinite(creditsRemaining)) meta.credits_remaining = creditsRemaining
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
content: [{
|
|
128
|
+
type: 'text' as const,
|
|
129
|
+
text: JSON.stringify({
|
|
130
|
+
data: { post_url: postUrl, type, people: contactsRes.data },
|
|
131
|
+
_meta: meta,
|
|
132
|
+
}),
|
|
133
|
+
}],
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -5,7 +5,8 @@ import { resolvePreferredProviders, getProvidersForCapability } from '../utils/p
|
|
|
5
5
|
export const findInfluencersName = 'find_influencers'
|
|
6
6
|
|
|
7
7
|
export const findInfluencersDescription =
|
|
8
|
-
'Discover and find influencers/creators on Instagram, YouTube, TikTok, Twitch, Twitter, and OnlyFans via 2 providers (Influencers Club Similar, Influencers Club Discovery). Routes by input: handle set → lookalike search (influencers_similar) runs first; no handle → keyword/filter discovery. Filters: location, gender, type (creator/business), AI natural language search, sort. Cost: 1 credit per result returned.'
|
|
8
|
+
'Discover and find influencers/creators on Instagram, YouTube, TikTok, Twitch, Twitter, and OnlyFans via 2 providers (Influencers Club Similar, Influencers Club Discovery). Routes by input: handle set → lookalike search (influencers_similar) runs first; no handle → keyword/filter discovery. Filters: location, gender, type (creator/business), AI natural language search, sort. Cost: 1 credit per result returned. ' +
|
|
9
|
+
'LIMITATIONS: LinkedIn is not a supported platform (the underlying creator index has no LinkedIn coverage) — for B2B/LinkedIn prospecting use extract_post_engagement to pull engagers off a specific LinkedIn post instead. There is no follower-count range filter; to bias toward a follower tier, set sort_by="number_of_followers" and filter the returned list client-side.'
|
|
9
10
|
|
|
10
11
|
export const findInfluencersSchema = {
|
|
11
12
|
platform: z.enum(['instagram', 'youtube', 'tiktok', 'twitch', 'twitter', 'onlyfans'])
|
|
@@ -9,7 +9,7 @@ export const findSignalsDescription =
|
|
|
9
9
|
'Each call targets one signal type. Two modes: ' +
|
|
10
10
|
'Company-targeted (funding | acquisition | hiring | job_change | intent): accepts companies/domains/industries/countries/since filters. ' +
|
|
11
11
|
'funding additionally accepts `round_type` (e.g. ["Series A", "Seed"]). ' +
|
|
12
|
-
'intent
|
|
12
|
+
'intent has two modes: (a) DISCOVERY — pass `topics` (e.g. ["sales-automation"]) with no companies/domains to find companies showing intent on those topics; (b) VERIFY — pass companies/domains to check intent on known companies. Requires topics OR companies/domains. ' +
|
|
13
13
|
'Feed-style (news | startup_post): country and since only — does NOT filter by company. Passing companies/domains for these types is rejected. ' +
|
|
14
14
|
'hiring returns individual job postings with company context (title, location, descriptionText, company industries) — for richer job-board queries with description/seniority/easy-apply filters use search_jobs instead.'
|
|
15
15
|
|
|
@@ -19,7 +19,7 @@ export const findSignalsSchema = {
|
|
|
19
19
|
.describe(
|
|
20
20
|
'Signal type to retrieve. ' +
|
|
21
21
|
'Company-targeted: "funding" (fundraising rounds), "acquisition" (M&A), "hiring" (individual job postings indexed by Signalbase, with company context), ' +
|
|
22
|
-
'"job_change" (people who recently changed roles), "intent" (companies showing buying intent). ' +
|
|
22
|
+
'"job_change" (people who recently changed roles), "intent" (companies showing buying intent — discover by `topics` or verify on known companies/domains). ' +
|
|
23
23
|
'Feed-style (country/date filter only — company filter not supported): "news" (company news events), "startup_post" (Product Hunt, Hacker News, etc.)'
|
|
24
24
|
),
|
|
25
25
|
companies: z
|
|
@@ -29,15 +29,15 @@ export const findSignalsSchema = {
|
|
|
29
29
|
domains: z
|
|
30
30
|
.array(z.string())
|
|
31
31
|
.optional()
|
|
32
|
-
.describe('Company domains to filter signals for (e.g. ["coldiq.com"]). Only used by company-targeted types.
|
|
32
|
+
.describe('Company domains to filter signals for (e.g. ["coldiq.com"]). Only used by company-targeted types. For intent VERIFY mode: pass companies or domains. For intent DISCOVERY mode: omit both and pass topics instead.'),
|
|
33
33
|
since: z
|
|
34
34
|
.string()
|
|
35
35
|
.optional()
|
|
36
|
-
.describe('Return signals after this date. ISO date format, e.g. "2026-01-01".'),
|
|
36
|
+
.describe('Return signals after this date. ISO date format, e.g. "2026-01-01". Honored by funding, acquisition, hiring, job_change, and startup_post. NOT supported for intent (TheirStack has no date filter on intent) — passing it has no effect.'),
|
|
37
37
|
industries: z
|
|
38
38
|
.array(z.string())
|
|
39
39
|
.optional()
|
|
40
|
-
.describe('Industry names to filter by (e.g. ["Software", "SaaS"]). Forwarded to upstream for funding and acquisition. For hiring, filtered client-side against each row\'s `industries` field (case-insensitive substring match).
|
|
40
|
+
.describe('Industry names to filter by (e.g. ["Software", "SaaS"]). Forwarded to upstream for funding and acquisition. For hiring, filtered client-side against each row\'s `industries` field (case-insensitive substring match); Signalbase uses coarse labels (e.g. "Financial Services"), so prefer those over narrow terms like "Fintech" — if nothing matches, rows are returned UNFILTERED with a `_industry_filter` note rather than an empty set. For intent DISCOVERY, forwarded to TheirStack as `industry_or`. Ignored for job_change, news, startup_post.'),
|
|
41
41
|
countries: z
|
|
42
42
|
.array(z.string())
|
|
43
43
|
.optional()
|
|
@@ -49,7 +49,7 @@ export const findSignalsSchema = {
|
|
|
49
49
|
topics: z
|
|
50
50
|
.array(z.string())
|
|
51
51
|
.optional()
|
|
52
|
-
.describe('Intent topic / keyword slugs (e.g. ["sales-automation", "lead-generation"]). Only honored by signal_type=intent
|
|
52
|
+
.describe('Intent topic / keyword slugs (e.g. ["sales-automation", "lead-generation"]). Only honored by signal_type=intent. DISCOVERY mode: pass topics WITHOUT companies/domains to find companies showing intent on these topics (forwarded to TheirStack company search as `company_keyword_slug_or`, returns a company list). VERIFY mode: pass topics WITH companies/domains to narrow intent results for those known companies (forwarded as `keyword_slug_or`).'),
|
|
53
53
|
limit: z
|
|
54
54
|
.number()
|
|
55
55
|
.int()
|
|
@@ -65,11 +65,13 @@ export async function findSignalsHandler(input: Record<string, unknown>) {
|
|
|
65
65
|
const hasCompanies = Array.isArray(restInput.companies) && (restInput.companies as unknown[]).length > 0
|
|
66
66
|
const hasDomains = Array.isArray(restInput.domains) && (restInput.domains as unknown[]).length > 0
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
const hasTopics = Array.isArray(restInput.topics) && (restInput.topics as unknown[]).length > 0
|
|
69
|
+
|
|
70
|
+
if (restInput.signal_type === 'intent' && !hasCompanies && !hasDomains && !hasTopics) {
|
|
69
71
|
return {
|
|
70
72
|
content: [{
|
|
71
73
|
type: 'text' as const,
|
|
72
|
-
text: JSON.stringify({ error: 'intent signal_type requires at least one of: companies or domains' }),
|
|
74
|
+
text: JSON.stringify({ error: 'intent signal_type requires at least one of: topics (to discover companies by intent topic), or companies/domains (to verify intent on known companies)' }),
|
|
73
75
|
}],
|
|
74
76
|
isError: true,
|
|
75
77
|
}
|
|
@@ -110,21 +112,36 @@ export async function findSignalsHandler(input: Record<string, unknown>) {
|
|
|
110
112
|
// `industries` param would otherwise be silently dropped. Filter client-side:
|
|
111
113
|
// each hiring row carries an `industries` string (e.g. "Law Practice and Legal
|
|
112
114
|
// Services") which we substring-match against the user-supplied list.
|
|
115
|
+
//
|
|
116
|
+
// Non-destructive fallback: Signalbase has no industry facet and tags rows with
|
|
117
|
+
// coarse labels (e.g. "Financial Services"), so a user term like "Fintech" can
|
|
118
|
+
// match nothing even when relevant rows exist. Rather than return a misleading
|
|
119
|
+
// empty set (which reads as "no companies are hiring"), when the filter would
|
|
120
|
+
// drop every row we keep the unfiltered rows and attach a note explaining that
|
|
121
|
+
// the industry filter matched nothing.
|
|
113
122
|
if (restInput.signal_type === 'hiring' && Array.isArray(restInput.industries) && restInput.industries.length > 0) {
|
|
114
123
|
const wanted = (restInput.industries as unknown[])
|
|
115
124
|
.map((s) => (typeof s === 'string' ? s.toLowerCase() : ''))
|
|
116
125
|
.filter((s) => s.length > 0)
|
|
117
126
|
if (wanted.length > 0) {
|
|
118
|
-
const typed = result as { data?: { data?: unknown[] } }
|
|
127
|
+
const typed = result as { data?: { data?: unknown[]; _industry_filter?: string } }
|
|
119
128
|
const rows = typed.data?.data
|
|
120
|
-
if (Array.isArray(rows)) {
|
|
121
|
-
|
|
129
|
+
if (Array.isArray(rows) && rows.length > 0) {
|
|
130
|
+
const filtered = rows.filter((row) => {
|
|
122
131
|
if (!row || typeof row !== 'object') return false
|
|
123
132
|
const industriesField = (row as Record<string, unknown>).industries
|
|
124
133
|
if (typeof industriesField !== 'string' || industriesField.length === 0) return false
|
|
125
134
|
const haystack = industriesField.toLowerCase()
|
|
126
135
|
return wanted.some((needle) => haystack.includes(needle))
|
|
127
136
|
})
|
|
137
|
+
if (filtered.length > 0) {
|
|
138
|
+
typed.data!.data = filtered
|
|
139
|
+
} else {
|
|
140
|
+
typed.data!._industry_filter =
|
|
141
|
+
`No hiring rows matched industries [${(restInput.industries as string[]).join(', ')}]. ` +
|
|
142
|
+
'Signalbase tags hiring rows with coarse industry labels (e.g. "Financial Services"), so a narrow term may match nothing — results are returned UNFILTERED. ' +
|
|
143
|
+
'Narrow with countries or a broader/more exact industry label (e.g. "Financial Services" instead of "Fintech").'
|
|
144
|
+
}
|
|
128
145
|
}
|
|
129
146
|
}
|
|
130
147
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { executeWithFallback, isExecutionError } from '../executor.js'
|
|
3
|
+
import { resolvePreferredProviders, getProvidersForCapability } from '../utils/provider-resolver.js'
|
|
4
|
+
|
|
5
|
+
export const getPlaceReviewsName = 'get_place_reviews'
|
|
6
|
+
|
|
7
|
+
export const getPlaceReviewsDescription =
|
|
8
|
+
'Fetch Google Maps reviews for one or more places. Pass the Google Maps place URLs (from search_places results, the `url` field) and get back each place\'s reviews — useful for reputation management, local-services prospecting, and surfacing negative-review signals. ' +
|
|
9
|
+
'search_places returns place listings WITHOUT review text; use this tool to get the actual review content. ' +
|
|
10
|
+
'Runs an async job (~30–120s). Cost: 1 credit per review returned.'
|
|
11
|
+
|
|
12
|
+
export const getPlaceReviewsSchema = {
|
|
13
|
+
place_urls: z
|
|
14
|
+
.array(z.string().url())
|
|
15
|
+
.min(1)
|
|
16
|
+
.max(10)
|
|
17
|
+
.describe('Google Maps place URLs to scrape reviews from (1–10). Use the `url` field from search_places results, or a maps.google.com place/search URL.'),
|
|
18
|
+
max_reviews: z
|
|
19
|
+
.number()
|
|
20
|
+
.int()
|
|
21
|
+
.min(1)
|
|
22
|
+
.max(300)
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('Maximum reviews to fetch per place (default 5, max 300). Each returned review costs 1 credit, so keep this tight.'),
|
|
25
|
+
sort: z
|
|
26
|
+
.enum(['mostRelevant', 'newest', 'highestRanking', 'lowestRanking'])
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('Review sort order. Use "newest" for recent reviews or "lowestRanking" to surface negative reviews first. Default "mostRelevant".'),
|
|
29
|
+
language: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('ISO 639-1 language code to filter reviews by language (e.g. "en", "fr").'),
|
|
33
|
+
use_providers: z
|
|
34
|
+
.array(z.string())
|
|
35
|
+
.optional()
|
|
36
|
+
.describe(`Optional ordered list of providers to use. Leave empty to let ColdIQ automatically pick — recommended. Available providers: ${getProvidersForCapability('get_place_reviews').join(', ')}. Provider names are matched fuzzily.`),
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function getPlaceReviewsHandler(input: Record<string, unknown>) {
|
|
40
|
+
const { use_providers: rawUseProviders, ...restInput } = input
|
|
41
|
+
const resolved = resolvePreferredProviders('get_place_reviews', restInput, rawUseProviders)
|
|
42
|
+
if (!resolved.ok) {
|
|
43
|
+
return { content: [{ type: 'text' as const, text: JSON.stringify(resolved.error) }], isError: true }
|
|
44
|
+
}
|
|
45
|
+
const result = await executeWithFallback('get_place_reviews', restInput, { providers: resolved.providers, matchedFrom: resolved.matchedFrom })
|
|
46
|
+
if (isExecutionError(result)) {
|
|
47
|
+
return { content: [{ type: 'text' as const, text: JSON.stringify(result) }], isError: true }
|
|
48
|
+
}
|
|
49
|
+
return { content: [{ type: 'text' as const, text: JSON.stringify(result) }] }
|
|
50
|
+
}
|
package/src/tools/search-ads.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { resolvePreferredProviders, getProvidersForCapability } from '../utils/p
|
|
|
5
5
|
export const searchAdsName = 'search_ads'
|
|
6
6
|
|
|
7
7
|
export const searchAdsDescription =
|
|
8
|
-
'Search live ad creatives across 5 ad libraries (Google Ads Transparency, LinkedIn Ad Library, Meta Ads Library, Twitter/X Ads, Reddit Ads) — a high-signal GTM input for competitive intelligence, ICP refinement, and pitch personalization. Routes by input: domains/advertiser_ids → Google only; search_urls → LinkedIn only; bare query → Google → Meta → Twitter → Reddit waterfall. Use platform="google"|"linkedin"|"meta"|"twitter"|"reddit" to pin to one platform. All providers are async (~10–60s). Cost: ~5 credits per call (Twitter charges 1 credit per ad returned
|
|
8
|
+
'Search live ad creatives across 5 ad libraries (Google Ads Transparency, LinkedIn Ad Library, Meta Ads Library, Twitter/X Ads, Reddit Ads) — a high-signal GTM input for competitive intelligence, ICP refinement, and pitch personalization. Routes by input: domains/advertiser_ids → Google only; search_urls → LinkedIn only; bare query → Google → Meta → Twitter → Reddit waterfall. Use platform="google"|"linkedin"|"meta"|"twitter"|"reddit" to pin to one platform. All providers are async (~10–60s). Cost: ~5 credits per call (Twitter charges 1 credit per ad returned). Credits are fully refunded when a run returns zero ads. NOTE: Google Ads creatives return image URLs + creative IDs, not ad copy text — open the image URLs to read the ad. There is no "currently running only" filter; results can span past campaigns.'
|
|
9
9
|
|
|
10
10
|
export const searchAdsSchema = {
|
|
11
11
|
query: z.string().optional().describe('Advertiser/company name or keyword. Routes to Google→Meta→Twitter→Reddit when no platform-specific input is set.'),
|
|
@@ -30,7 +30,7 @@ export const searchCompaniesSchema = {
|
|
|
30
30
|
is_hiring: z.boolean().optional().describe('Filter to companies currently posting jobs'),
|
|
31
31
|
min_workforce_growth_pct: z.number().optional().describe('Minimum workforce growth % over the past 12 months (e.g. 10 for 10%)'),
|
|
32
32
|
linkedin_search_url: z.string().optional().describe('LinkedIn Sales Navigator company search URL — when provided, enables URL-based prospect discovery as a final fallback. Most users should leave this unset.'),
|
|
33
|
-
limit: z.number().min(1).max(
|
|
33
|
+
limit: z.number().min(1).max(500).default(25).describe('Max results to return (default: 25, max: 500). Pulls above 100 auto-paginate the underlying provider; on Apollo each 100 companies costs 1 credit, billed only for pages actually returned.'),
|
|
34
34
|
use_providers: z.array(z.string()).optional().describe(`Optional ordered list of providers to use. Leave empty to let ColdIQ automatically pick the best tool for your inputs — recommended for most use cases. Available providers: ${getProvidersForCapability('search_companies').join(', ')}. Provider names are matched fuzzily, so minor typos are tolerated.`),
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -44,5 +44,11 @@ export async function searchCompaniesHandler(input: Record<string, unknown>) {
|
|
|
44
44
|
if (isExecutionError(result)) {
|
|
45
45
|
return { content: [{ type: 'text' as const, text: JSON.stringify(result) }], isError: true }
|
|
46
46
|
}
|
|
47
|
+
// Surface the upstream match count (e.g. Apollo's pagination.total_entries) as the
|
|
48
|
+
// total-addressable-market signal, so clients see "matched N, returned M".
|
|
49
|
+
const totalEntries = (result.data as { pagination?: { total_entries?: unknown } })?.pagination?.total_entries
|
|
50
|
+
if (typeof totalEntries === 'number') {
|
|
51
|
+
;(result._meta as Record<string, unknown>).total_entries = totalEntries
|
|
52
|
+
}
|
|
47
53
|
return { content: [{ type: 'text' as const, text: JSON.stringify(result) }] }
|
|
48
54
|
}
|
|
@@ -5,7 +5,7 @@ import { resolvePreferredProviders, getProvidersForCapability } from '../utils/p
|
|
|
5
5
|
export const searchPlacesName = 'search_places'
|
|
6
6
|
|
|
7
7
|
export const searchPlacesDescription =
|
|
8
|
-
'Search local businesses and places via 2 providers (Openmart Search, Google Maps Scraper) — useful for territory mapping, local-services prospecting, restaurant/retail/vertical research. Routes by input: structured filters or country in {US,CA,AU,PR,NZ} → Openmart (sync, ~1s) first, then Google Maps Scraper (async, ~30–120s) as fallback or for global coverage. Use provider="openmart"|"google_maps" to pin to one. Cost: 1 credit per place returned (both providers).'
|
|
8
|
+
'Search local businesses and places via 2 providers (Openmart Search, Google Maps Scraper) — useful for territory mapping, local-services prospecting, restaurant/retail/vertical research. Routes by input: structured filters or country in {US,CA,AU,PR,NZ} → Openmart (sync, ~1s) first, then Google Maps Scraper (async, ~30–120s) as fallback or for global coverage. Use provider="openmart"|"google_maps" to pin to one. Cost: 1 credit per place returned (both providers). Results do NOT include review text — to fetch a place\'s reviews, pass its `url` to get_place_reviews.'
|
|
9
9
|
|
|
10
10
|
export const searchPlacesSchema = {
|
|
11
11
|
query: z.string().optional().describe('Free-text query (e.g. "coffee shops in Brooklyn", "law firm New York"). Used by both providers.'),
|
|
@@ -90,11 +90,30 @@ export async function searchPlacesHandler(input: Record<string, unknown>) {
|
|
|
90
90
|
if (isExecutionError(result)) {
|
|
91
91
|
return { content: [{ type: 'text' as const, text: JSON.stringify(result) }], isError: true }
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
const filters = {
|
|
94
94
|
minRating: asNumber(restInput.min_overall_rating),
|
|
95
95
|
maxRating: asNumber(restInput.max_overall_rating),
|
|
96
96
|
minReviews: asNumber(restInput.min_total_reviews),
|
|
97
97
|
maxReviews: asNumber(restInput.max_total_reviews),
|
|
98
|
-
}
|
|
98
|
+
}
|
|
99
|
+
const scraped = placesCount(result.data)
|
|
100
|
+
result.data = applyPlaceFilters(result.data, filters)
|
|
101
|
+
const matched = placesCount(result.data)
|
|
102
|
+
// Google Maps bills per place scraped upstream (what ColdIQ pays the provider),
|
|
103
|
+
// but rating/review filters are applied here client-side. When the filter trims
|
|
104
|
+
// the set, make the gap explicit so the credit charge isn't surprising.
|
|
105
|
+
if (scraped !== undefined && matched !== undefined && matched < scraped) {
|
|
106
|
+
;(result._meta as Record<string, unknown>).filtered = {
|
|
107
|
+
scraped,
|
|
108
|
+
matched,
|
|
109
|
+
note: 'Rating/review filters are applied client-side. You are billed per place scraped upstream (scraped), not per matched place.',
|
|
110
|
+
}
|
|
111
|
+
}
|
|
99
112
|
return { content: [{ type: 'text' as const, text: JSON.stringify(result) }] }
|
|
100
113
|
}
|
|
114
|
+
|
|
115
|
+
function placesCount(data: unknown): number | undefined {
|
|
116
|
+
if (!data || typeof data !== 'object') return undefined
|
|
117
|
+
const places = (data as Record<string, unknown>).places
|
|
118
|
+
return Array.isArray(places) ? places.length : undefined
|
|
119
|
+
}
|
|
@@ -11,7 +11,7 @@ export const searchRedditSchema = {
|
|
|
11
11
|
start_urls: z.array(z.string().url()).max(25).optional()
|
|
12
12
|
.describe('Reddit URLs to scrape (subreddit, post, user, or search URL). Up to 25. Provide this and/or query. Example: ["https://www.reddit.com/r/sales/"]'),
|
|
13
13
|
query: z.string().optional()
|
|
14
|
-
.describe('Keyword search query
|
|
14
|
+
.describe('Keyword search query e.g. "best CRM for startups". Provide this and/or start_urls. When combined with a bare subreddit start_url (e.g. ".../r/sales/"), the query is applied as an in-subreddit search so only matching posts are returned (a bare subreddit URL alone would otherwise return its whole feed, ignoring the keyword).'),
|
|
15
15
|
search_type: z.enum(['posts', 'comments', 'communities', 'users']).default('posts')
|
|
16
16
|
.describe('What the search query returns: posts, comments, communities, or users.'),
|
|
17
17
|
search_community_name: z.string().optional()
|