@leadbay/mcp 0.22.0 → 0.23.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog — @leadbay/mcp
2
2
 
3
+ ## 0.23.0 — 2026-06-21
4
+
5
+ Guided campaign builder.
6
+
7
+ - **`leadbay_build_campaign`** (new prompt + auto-generated Claude skill) — one guided on-ramp from "build me a campaign" to a ready-to-work campaign: discover on the active lens → qualify → pick an ICP pool → enrich the BUYER PERSONA of the user's product (a sales tool's buyer is the revenue org — VP/Head/Dir Sales, BD, CRO, CMO, growth — not whoever is most senior) → create the campaign → render the `leadbay_campaign_call_sheet` view → hand off to `leadbay_work_campaign`.
8
+ - **Coverage guarantee** — drops/swaps any lead with no enrichable buyer-persona contact for the highest-score in-ICP lead that has one (never trading ICP for coverage), and a ⚠ flag for suspect emails (domain ≠ company, or a contact on >1 lead). Polls enrichment to completion before rendering.
9
+ - Pure orchestration of existing composites — no new tool. Eval workflow #34 added; tuned over 4 live eval cycles (campaign quality 3/7 → 11/11 leads with a real revenue buyer reachable).
10
+
3
11
  ## 0.22.0 — 2026-06-20
4
12
 
5
13
  Headless artifact SDK + two always-on read tools, so the user's Claude (cowork) can build interactive HTML artifacts that call Leadbay.
package/dist/bin.js CHANGED
@@ -22184,6 +22184,204 @@ import {
22184
22184
  } from "@modelcontextprotocol/sdk/types.js";
22185
22185
 
22186
22186
  // src/prompts.generated.ts
22187
+ var leadbay_build_campaign = `
22188
+ ## MEMORY
22189
+
22190
+ Before responding, glance at any \`_meta.agent_memory.summary\` returned by tool calls earlier in this session and reflect its top signals in your reasoning ("Filtering by your stated preference for healthcare"). After any material new signal from the user this conversation (sector, region, deal size, communication style, qualification rule, explicit retraction, or recurrence / scheduling preference such as "I do this every day" or "remind me every morning"), call \`leadbay_agent_memory_capture\` to persist it: \`source:"user_stated"\` if literal, \`source:"inferred"\` with confidence <=6 if inferred.
22191
+
22192
+
22193
+ Build me a Leadbay campaign from scratch{{arg:campaign_name_paren}}. {{arg:audience_block}}
22194
+
22195
+ GATE \u2014 DEFER TO TOOL RENDERING. When you call a Leadbay composite that ships its own RENDERING block (every composite in 0.9.0+ does), render the response using that block's recipe verbatim \u2014 score bars, glyph palette, column order, hide-list, link priorities, all of it. Do NOT substitute prose, a numbered list, or a different column structure even when an orchestrating prompt's body suggests alternate framing. Prompt-specific commentary (motivational nudges, summaries, next-action recommendations) belongs ABOVE or BELOW the canonical table, never in place of it.
22196
+
22197
+ If the prompt's body and the tool's RENDERING appear to conflict, the tool's RENDERING wins for the structural layout; the prompt's voice wins for the commentary that surrounds it.
22198
+
22199
+
22200
+ # Resilience rules for Leadbay long-running tools
22201
+
22202
+ These four rules apply to every Leadbay workflow that calls \`leadbay_pull_leads\`, \`leadbay_bulk_qualify_leads\`, \`leadbay_research_lead_by_id\`, \`leadbay_import_and_qualify\`, or \`leadbay_enrich_titles\`. **Treat timeouts and stream-closed errors as transient, not as signals to replan.**
22203
+
22204
+ ## Rule 1 \u2014 Pin the lens
22205
+
22206
+ After your first \`leadbay_pull_leads\` call, capture \`response.lens.id\` into your working memory and **pass it explicitly as the \`lensId\` argument to every subsequent call** in this session \u2014 including any re-pulls, bulk qualifies, or research calls that accept it. (Field-name caveat: the response nests it as \`lens.id\`; the parameter on subsequent calls is \`lensId\`.) The active lens can shift between calls (5-minute client cache + backend \`last_requested_lens\` can change if the user touches the web UI). A lens shift mid-workflow throws away your top-10 work.
22207
+
22208
+ ## Rule 2 \u2014 Prefer async for bulk operations
22209
+
22210
+ \`leadbay_bulk_qualify_leads\` and \`leadbay_import_and_qualify\` accept \`wait_for_completion:false\`, which returns \`{status:'running', qualify_id}\` immediately. Then poll \`leadbay_qualify_status\` (or \`leadbay_import_status\`) every ~10s until the job completes. **Use the async pattern by default** \u2014 the blocking default can exceed the MCP client's per-call timeout on large batches and produce a misleading \`"Request timed out"\` even though the server is still working.
22211
+
22212
+ ## Rule 3 \u2014 Serialize \`leadbay_research_lead_by_id\` fan-out
22213
+
22214
+ \`leadbay_research_lead_by_id\` is composite and reads many sub-resources. Calling it on 10 leads in parallel can saturate the transport and produce \`"Tool permission stream closed"\` errors that look like permission failures but are really backpressure. **Call it sequentially**, or at most 3 in parallel. If one call fails with a stream/timeout error, retry that one call once before moving on; on a second failure, note the lead and continue \u2014 do not abandon the remaining leads.
22215
+
22216
+ ## Rule 4 \u2014 Retry, don't replan
22217
+
22218
+ If a Leadbay tool returns \`"Request timed out"\`, \`"stream closed"\`, or any other transport-level error (distinct from a Leadbay-issued error payload), the work may still be running server-side. Do this in order:
22219
+
22220
+ 1. For bulk tools \u2014 retry with \`wait_for_completion:false\` and poll the status tool with the returned id. Don't re-pull leads; that can shift the lens.
22221
+ 2. For single-lead tools \u2014 retry the same call once. If it still fails, record the lead id and continue with the rest of the workflow.
22222
+ 3. **Do not** switch strategies (e.g. "the endpoint is broken, let me re-pull from scratch"). The earlier work is still valid; the timeout was the wire.
22223
+
22224
+ If \`pull_leads\` itself fails and you have no prior batch, then yes \u2014 retry it, explicitly pass the lensId you captured (if any), and continue.
22225
+
22226
+
22227
+ # PHASE 0 \u2014 STATE + AUDIENCE
22228
+
22229
+ Call \`leadbay_account_status\` to see my remaining quota, my **enrichment credits**, and my **active lens**. Note \`web_fetch_remaining\` (qualification budget) and the enrichment credit balance \u2014 Phase 3 spends credits.
22230
+
22231
+ Resolve the audience:
22232
+
22233
+ - **Default \u2014 use my active lens.** If I didn't name a fresh audience, the active lens IS the audience. Do NOT create a new lens.
22234
+ - **Fresh-audience fork.** Only if I described a NEW audience the active lens doesn't already cover, set it up first: \`leadbay_adjust_audience\` for sector/size tweaks, or \`leadbay_new_lens\` to create a brand-new named lens \u2014 then continue on that lens. Do NOT silently overwrite my existing lens; confirm once before switching.
22235
+
22236
+ # PHASE 1 \u2014 DISCOVER
22237
+
22238
+ Call \`leadbay_pull_leads\` on the resolved lens. **Capture \`response.lens.id\` and pass it as an explicit \`lensId\` on every later call this session** \u2014 a mid-session lens shift would discard the cohort I'm about to pick. Render the batch with the canonical layout:
22239
+
22240
+ ## RENDERING \u2014 markdown table, three columns, score-bar driven
22241
+
22242
+ Present the response as a markdown table sorted by \`score\` descending, with exactly three columns. Do not summarize in prose. Do not show the numeric score anywhere.
22243
+
22244
+ ## Score-bar (10-segment, inline-code wrapped)
22245
+
22246
+ Wrap a 10-glyph bar in a SINGLE inline-code span (backticks). The inline-code styling is what gives the bar contrast in most chat renderers \u2014 HTML \`<span>\` is stripped inside table cells.
22247
+
22248
+ Glyphs (use these exact characters; do not substitute):
22249
+
22250
+ - \`\u25B0\` \u2014 firmographic-only fill
22251
+ - \`\u2756\` \u2014 AI-booster cap (placed at the RIGHT END of the filled run, never the front)
22252
+ - \`\u25B1\` \u2014 empty
22253
+
22254
+ Computation:
22255
+
22256
+ \`\`\`
22257
+ total_filled = round(score / 10), clamped to 0..10
22258
+ ai_segments = round(qualification_summary.avg_qualification_boost / 3.3),
22259
+ clamped to [0, total_filled]
22260
+ normal_filled = total_filled \u2212 ai_segments
22261
+ bar = "\u25B0" \xD7 normal_filled
22262
+ + "\u2756" \xD7 ai_segments
22263
+ + "\u25B1" \xD7 (10 \u2212 total_filled)
22264
+ \`\`\`
22265
+
22266
+ If \`qualification_summary.answered == 0\` or \`avg_qualification_boost\` is null, set \`ai_segments = 0\` (no \u2756). Always wrap the bar in backticks. Print the legend \`\` \`\u25B0\` firmographic \xB7 \`\u2756\` AI booster cap \xB7 \`\u25B1\` unfilled \`\` once below the table.
22267
+
22268
+
22269
+ **Column 1 \u2014 Company**
22270
+
22271
+ - Line 1: the 10-segment score bar in inline-code backticks (see the score-bar snippet above for the algorithm).
22272
+ - Insert \`<br>\` between lines.
22273
+ - Line 2: linked company name + \` \xB7 \` + short location + \` \xB7 \` + compact size.
22274
+ - Link target: \`website\` (prefix \`https://\` if it's a bare hostname). Don't synthesize an app deep-link.
22275
+ - Location: shorten "City of New York" \u2192 "NYC"; otherwise "City ST"; state alone only when city missing.
22276
+ - Size: \`"Xk+"\` when \`size.min >= 1000\`, \`"min\u2013max"\` otherwise.
22277
+
22278
+ **Column 2 \u2014 Why it fits**
22279
+
22280
+ - One sentence, \u2264 20 words.
22281
+ - Synthesize from (in priority order, whichever is present) the lead's \`short_description\`, top 2 \`tags[].display_name\`, and the gist of \`qualification_summary.best_response_excerpt\`. The trim payload does NOT carry the longer \`description\` field \u2014 for that, agent must call \`leadbay_research_lead_by_id\` or \`leadbay_research_lead_by_name_fuzzy\`.
22282
+ - Do NOT append \`(boost N)\` \u2014 the \u2756 cap in column 1 already carries that signal.
22283
+ - No bullet lists, no line breaks inside the cell.
22284
+
22285
+ **Column 3 \u2014 Contact**
22286
+
22287
+ \`[Contact name](LINK) \xB7 short job title\`. The \`[Contact name](LINK)\` markdown link wrapping is mandatory \u2014 never render the name as plain text. See linking/contact-linkedin for the URL priority (real profile \u2192 constructed people-search) and the \xB0-flag fallback.
22288
+
22289
+ **Hide from the user (never include in any cell):** \`id\`, \`location.pos\`, \`location.country\` (unless city/state both missing), \`sector_id\`, \`is_hq\`, \`web_fetch_in_progress\`, \`enrichment_in_progress\`, \`highlighted_fields\`, \`custom_fields\`, \`contacts_count\` when 0, \`notes_count\` / \`epilogue_actions_count\` / \`prospecting_actions_count\` when 0, \`stale_at\`, \`deal_insights\`, \`social_presence\` booleans (except as the \xB0-flag signal), \`need_attention\` flags, any field whose value is the string \`"null"\`.
22290
+
22291
+ ## Linking a contact's name
22292
+
22293
+ **MANDATORY: every contact name in your output \u2014 table cells, prose, headers, "Reach <Name>" callouts \u2014 MUST be wrapped in markdown link syntax \`[Name](URL)\`. Never render a contact name as bare text. A plain-text name is a broken contact card; the underlined name is the user's primary affordance for "take me to this person's profile". No "no URL available" exception \u2014 the search URL below is always constructable from name + company.**
22294
+
22295
+ URL priority (first applicable wins):
22296
+
22297
+ 1. **Real profile** \u2014 \`contact.linkedin_page\` when it's a string starting with \`https://\` (the MCP coerces the legacy literal \`"null"\` string to real null before you see it).
22298
+ 2. **Constructed people-search** \u2014 \`https://www.linkedin.com/search/results/people/?keywords=<First>+<Last>+<Company>\`. URL-encode params. Strip Inc / LLC / Corp / Ltd / GmbH / Co / S.A. / S.L. / PLC / AG / SAS / SARL suffixes from the company. Append a trailing \` \xB0\` to the rendered name ONLY when this fallback is in use AND \`social_presence.linkedin == false\`. Never append \`\xB0\` when a real \`linkedin_page\` was used.
22299
+
22300
+ Never link a person's name to the company's LinkedIn page (and vice versa) \u2014 the two surfaces are different and conflating them quietly degrades the workflow.
22301
+
22302
+ ## Linking the company
22303
+
22304
+ Use the lead's \`website\` as the company-name link target \u2014 prefix \`https://\` if the value is a bare hostname. (The MCP does NOT synthesize a Leadbay-app deep-link URL; the team has not standardized one. Linking to \`website\` is always real data.)
22305
+
22306
+ When the response carries \`social_urls\` (the post-fix multi-platform URL block on rich-lead responses), render every non-null platform as a pill chip in the company-info row. Iterate over \`social_urls\`'s keys \u2014 never hardcode a fixed list \u2014 and emit each as \`[<platform-label>](<url>)\`. Skip platforms whose URL is null.
22307
+
22308
+ \`social_presence\` carries booleans for the same 6 platforms (crunchbase, facebook, instagram, linkedin, tiktok, twitter) \u2014 useful when you only care that the company has a profile somewhere. Use it as the \xB0-flag signal in the contact people-search fallback (see linking/contact-linkedin).
22309
+
22310
+
22311
+
22312
+ If the batch is thin (fewer than ~10 workable leads) or I ask for more depth, top it up: call \`leadbay_bulk_qualify_leads({lensId:<captured>, count:<deficit, max 25>, wait_for_completion:false})\`, poll \`leadbay_qualify_status\` until done, then re-pull with the same \`lensId\`. Never re-pull without \`lensId\`.
22313
+
22314
+ # PHASE 2 \u2014 PICK AN ICP CANDIDATE POOL
22315
+
22316
+ A campaign is only as good as the leads in it \u2014 AND only as good as whether each lead has a reachable BUYER (see Phase 3). So pick a **generous candidate pool** now, not the final cohort: aim for ~1.5\xD7 the target size of in-ICP leads (highest \`ai_agent_lead_score\`), so Phase 3 can drop any lead that turns out to have no buyer-persona contact and still hit the target. If the batch is short, top up via \`leadbay_bulk_qualify_leads\` / \`leadbay_extend_lens\`.
22317
+
22318
+ If I named specific leads, use those (but still apply the Phase 3 buyer-coverage check and tell me which lack a buyer). Otherwise recommend the pool and show it. Capture the candidate \`leadIds\`. Confirm the count ("12 candidates \u2014 I'll lock the final ~8 after checking each has a buyer"). Do NOT create the campaign yet \u2014 the final cohort is decided after Phase 3's coverage check.
22319
+
22320
+ # PHASE 3 \u2014 ENRICH THE RIGHT CONTACTS (load-bearing)
22321
+
22322
+ This is the phase that decides whether the campaign is worth a salesperson's time. Contacts aren't attached by default and enrichment is paid \u2014 so spend it ONLY on the people who would actually **buy what I sell**, not on whoever is most senior.
22323
+
22324
+ **Step A \u2014 work out MY buyer persona (do this before touching titles).**
22325
+ Figure out what *I* sell and therefore who, inside the target company, owns the decision to buy it:
22326
+
22327
+ - Infer my product / value-prop from my context: my org and account (\`leadbay_account_status\`), and especially my lens's qualification criteria \u2014 the \`qualification_summary\` on the leads tells you *why* these companies are good targets for me, which implies what I'm offering them.
22328
+ - Map value-prop \u2192 the **buying department/persona**, NOT seniority:
22329
+ - A sales / prospecting / lead-gen / outbound / marketing / GTM / revenue tool \u2192 the **revenue org**: VP / Head / Director of Sales, Business Development, Account/Carrier Sales, CRO, CMO / VP Marketing, Head of Growth / Demand Gen, RevOps. (This is Leadbay's own persona.)
22330
+ - An operations / logistics tool \u2192 operations leaders. A finance tool \u2192 finance. A dev tool \u2192 engineering. Etc.
22331
+ - **Company size caveat:** Founder / CEO / Owner is a real buyer at small companies (\u2264~50), but at larger ones they are not \u2014 there the functional leader (e.g. VP Sales) is the buyer.
22332
+ - **State the persona in one line and confirm it with me** before spending (see Step C). I can correct it.
22333
+
22334
+ **ANTI-PATTERN \u2014 do NOT do this:** picking the most senior or most "decision-maker-sounding" title regardless of department. A Director of Operations, COO, Mgr of Logistics, CFO, or CTO will **never** buy a sales tool \u2014 enriching them wastes credits and hands me a useless list. Seniority is not the same as being my buyer.
22335
+
22336
+ **Step B \u2014 find the persona-matching, enrichable contacts.**
22337
+ Call \`leadbay_recall_ordered_titles({leadIds, lensId})\` and \`leadbay_enrich_titles({leadIds, lensId})\` in **discovery mode** (no \`titles\`). These return previously-enriched titles, \`title_suggestions\`, \`auto_included_titles\`, \`available_in_selection\`, \`enrichable_contacts\`, and \`credits_remaining\`. Treat them as a **menu to filter against my persona \u2014 not the answer.** If past-enriched titles or suggestions are off-persona (e.g. operations roles for a sales tool), do NOT repeat them. Select the titles that match my buyer persona AND are actually enrichable.
22338
+
22339
+ **Step B.5 \u2014 coverage guarantee (lock the final cohort here).** A campaign where half the leads have no buyer is a failed campaign. So before enriching, determine for each candidate lead whether it actually has an **enrichable buyer-persona contact** \u2014 use the discovery data plus, where it's ambiguous, a quick \`leadbay_research_lead_by_id\` to see that lead's available contact titles. Then:
22340
+
22341
+ - **KEEP** candidates that have \u22651 enrichable buyer-persona contact.
22342
+ - **SWAP OUT** candidates whose only contacts are off-persona (e.g. ops/dispatch/finance only) or who have no enrichable contact at all. Replace each with the **highest-\`ai_agent_lead_score\` in-ICP candidate** from the pool that DOES have a buyer, until the cohort hits the target size (default 20; here capped by the enrichment budget).
22343
+ - **Do NOT trade ICP fit for coverage.** A lead with a buyer but weak ICP fit (low \`ai_agent_lead_score\`, a vertical that doesn't match what I sell) is still the wrong lead \u2014 coverage is a filter applied AFTER ICP, never a reason to admit an off-ICP company. The final cohort must be both high-ICP AND buyer-covered.
22344
+ - If the lens genuinely can't supply enough buyer-ready, in-ICP leads, say so honestly and offer to widen/extend rather than padding the campaign with no-buyer leads OR with off-ICP ones.
22345
+
22346
+ Tell me what you swapped in one line ("dropped Corbett + RBS \u2014 ops-only; swapped in Acme + Globex which have Sales VPs"). The goal is a final cohort where EVERY lead has a real buyer to call.
22347
+
22348
+ **Step C \u2014 show the spend + persona and confirm.** State the persona, the chosen titles, and "You have {credits_remaining} credits; this enriches {enrichable_contacts} contacts." Confirm via \`ask_user_input_v0\` ("Enrich these {enrichable_contacts} <persona> contacts now?" \u2192 ["Yes, enrich", "No, skip", "Change the persona/titles"]). Never launch a paid run without this. Enrich up to the campaign size (default 20) best persona-matching contacts.
22349
+
22350
+ **Step D \u2014 launch + poll.** On yes: \`leadbay_enrich_titles({leadIds, lensId, titles:[...chosen], email:true, phone:true})\` to launch, then poll \`leadbay_bulk_enrich_status\` until done (enrichment can take several minutes \u2014 keep polling, don't render an empty sheet prematurely). Append one small line at the very end of your reply: \`_(N credits remaining)_\`.
22351
+
22352
+ If I skip enrichment, continue \u2014 the campaign can be enriched later from the call sheet.
22353
+
22354
+ # PHASE 4 \u2014 CREATE THE CAMPAIGN
22355
+
22356
+ Derive a name (\`<lens or audience> \u2013 <today's date>\`) or use the one I gave. Call \`leadbay_create_campaign({name, lead_ids:<final buyer-ready cohort from Phase 3>})\` \u2014 this creates AND seeds in one call. Seed the cohort you actually enriched buyers on, not the original raw pool. Confirm the returned campaign name + id in one line. (If I later ask to add more leads to it, that's \`leadbay_add_leads_to_campaign\`.)
22357
+
22358
+ # PHASE 5 \u2014 THE VIEW (call / email ready)
22359
+
22360
+ If you launched enrichment in Phase 3, **poll \`leadbay_bulk_enrich_status\` until it's actually done before rendering** \u2014 do not render a "still enriching" sheet with empty contact cells; the whole point is the landed phones/emails. Enrichment can take several minutes; keep polling.
22361
+
22362
+ Then call \`leadbay_campaign_call_sheet({campaign_id})\` and render it per its RENDERING block \u2014 one card per lead, contacts with \`[phone](tel:)\` + \`[email](mailto:)\` one-tap links, the readiness chip at the top, map optional. This is the view I work from: scan \u2192 tap to call \u2192 tap to email.
22363
+
22364
+ **Flag suspect contacts** so I don't email the wrong person blind: mark with \u26A0 any enriched contact whose email domain doesn't match the company's website, or who shows up on more than one lead in this campaign (a sign of a mis-attributed enrichment). Keep the phone (it's usually still right) but tell me the email looks off.
22365
+
22366
+ # PHASE 6 \u2014 HANDOFF + STOP
22367
+
22368
+ The campaign exists and is call/email ready. End by offering, via \`ask_user_input_v0\`:
22369
+
22370
+ - "Start working it now" \u2192 run \`leadbay_work_campaign\` on this campaign (the calling/email session + outcome-logging loop).
22371
+ - "See the pulse" \u2192 \`leadbay_campaign_progression\` for per-lead status.
22372
+
22373
+ Then STOP. Building a campaign is NOT outreaching \u2014 do not send anything and do not call \`leadbay_report_outreach\`. When I come back later to log calls, see previous statuses, and do follow-ups, that is \`leadbay_work_campaign\`, not this prompt.
22374
+
22375
+ # Iron laws
22376
+
22377
+ - Enrichment targets MY buyer persona \u2014 the people who would actually buy what *I* sell, derived from my product/ICP \u2014 NOT generic seniority. For a sales/prospecting tool that means the revenue org (sales / BD / growth / marketing leaders); a Director of Operations, COO, or logistics manager is useless no matter how senior. Get the persona right or the campaign is worthless.
22378
+ - Selection is DATA-DRIVEN (\`leadbay_recall_ordered_titles\` + \`leadbay_enrich_titles\` discovery) but FILTERED to the persona \u2014 never blindly repeat past-enriched or suggested titles that don't match who buys my product.
22379
+ - The FINAL cohort must be all buyer-ready: drop/swap any lead with no enrichable buyer-persona contact (Phase 3 Step B.5) rather than shipping it empty. A campaign where half the leads have no buyer to call is a failed campaign. Pick a generous pool in Phase 2 so swaps are possible.
22380
+ - NEVER launch paid enrichment without showing \`credits_remaining\` + \`enrichable_contacts\`, naming the persona, and getting a yes.
22381
+ - Qualify / pick BEFORE \`leadbay_create_campaign\` \u2014 never seed a campaign with unvetted leads.
22382
+ - Carry the captured \`lensId\` on every call. A lens shift loses the cohort.
22383
+ - End at the rendered call sheet, then hand off to \`leadbay_work_campaign\`. Do NOT re-implement the calling / follow-up loop here, and do NOT call \`leadbay_report_outreach\`.
22384
+ `;
22187
22385
  var leadbay_daily_check_in = `
22188
22386
  ## MEMORY
22189
22387
 
@@ -23208,6 +23406,7 @@ Optional: offer to review the \`leadbay_campaign_progression\` for the same camp
23208
23406
  - If the user dictates an outcome that doesn't cleanly map to one of the four epilogue values, ASK ONCE before guessing.
23209
23407
  `;
23210
23408
  var PROMPT_META = {
23409
+ leadbay_build_campaign: { "name": "leadbay_build_campaign", "short_description": 'Build a sales campaign from scratch in one guided flow: discover on the\nactive lens, qualify and pick a cohort, enrich the contacts most likely to\nengage, save it via `leadbay_create_campaign`, then show a one-tap call/email\nview via `leadbay_campaign_call_sheet`. Trigger on "build me a campaign",\n"set up a new campaign", "create a campaign from scratch". WORK an existing\ncampaign with `leadbay_work_campaign`; split leads across reps with\n`leadbay_setup_team_prospecting`.\n', "arguments": [{ "name": "audience", "description": "Optional: a fresh audience to target (e.g. 'dental clinics in Texas'). Omit to build from your ACTIVE lens \u2014 the default.", "required": false }, { "name": "campaign_name", "description": "Optional: a name for the campaign. Omit and one is derived from the lens/audience + date (or the backend AI-names it).", "required": false }], "expected_calls": ["leadbay_account_status", "leadbay_pull_leads", "leadbay_bulk_qualify_leads", "leadbay_qualify_status", "leadbay_recall_ordered_titles", "leadbay_enrich_titles", "leadbay_bulk_enrich_status", "leadbay_create_campaign", "leadbay_add_leads_to_campaign", "leadbay_campaign_call_sheet", "leadbay_campaign_progression", "leadbay_new_lens", "leadbay_adjust_audience"], "failure_modes": ["Enriches by seniority instead of by buyer persona \u2014 picks COO / Director of Operations / Mgr of Logistics / CFO / CTO because they sound senior, when the user sells a SALES tool whose buyer is the revenue org (VP/Head/Director of Sales, BD, growth, marketing). Operations people never buy a sales tool; this hands the salesperson a useless list.", "Fails to derive the user's buyer persona from their product/ICP before choosing titles \u2014 jumps straight to titles without working out who buys what THIS user sells, then defaults to generic exec titles.", "Blindly repeats leadbay_recall_ordered_titles / discovery suggestions even when they are off-persona (e.g. operations roles a prior session wrongly enriched) \u2014 recall is a filtered input, not the answer.", "Poor coverage \u2014 leaves many picked leads with no persona-matching contact (or 0 enrichments on some leads) and doesn't flag it, so the salesperson opens the campaign to half-empty rows.", "Launches paid enrichment without first showing credits_remaining + enrichable_contacts, naming the persona, and getting a yes \u2014 the spend-visibility gate is mandatory.", "Creates the campaign before qualifying / picking \u2014 seeds a campaign with unvetted leads. Qualify and let the user pick (or AI-recommend) FIRST, then leadbay_create_campaign.", "Ends at 'campaign created' without rendering the leadbay_campaign_call_sheet view \u2014 the ready-to-work view IS the deliverable; stopping short is purpose drift.", "Re-implements the calling / outcome / follow-up loop instead of handing off to leadbay_work_campaign \u2014 that prompt already owns it. This prompt BUILDS; work_campaign WORKS.", "Auto-sends outreach or calls leadbay_report_outreach \u2014 building a campaign is not outreaching. No send, no log; the user works it afterward.", "Re-pulls leadbay_pull_leads without the captured lensId \u2014 a mid-session lens shift discards the picked cohort.", "Silently overwrites the user's active lens when forking to a fresh audience \u2014 confirm once before switching lenses.", "Renders the picked leads or the call sheet as prose instead of the canonical per-tool RENDERING layout."] },
23211
23410
  leadbay_daily_check_in: { "name": "leadbay_daily_check_in", "short_description": 'Morning DISCOVERY workflow \u2014 new leads from the lens wishlist. Trigger\non "show me leads", "what\'s new today", "let\'s prospect", "run my check-in",\n"my morning check-in", "I do this every day", "every morning". Recurrence\nlanguage always means this prompt. Do NOT trigger on follow-up phrasings\n("follow up", "before my trip") \u2014 those go to `leadbay_followup_check_in`.\n', "arguments": [], "expected_calls": ["leadbay_account_status", "leadbay_pull_leads", "leadbay_research_lead_by_id", "leadbay_bulk_qualify_leads", "leadbay_enrich_contacts"], "failure_modes": ["Calls leadbay_report_outreach without explicit user authorization", "Surfaces fewer than 10 leads when more are available, or fails to top up via leadbay_qualify_top_n when the batch is short", `Replaces the canonical pull_leads table layout with prose per row (the per-tool RENDERING block is the structural contract; "Today's nudges" goes above it, not in place of it)`, "Skips the nudge paragraph entirely \u2014 the table alone is fine but adding the nudge is the value-add", `Skips deep research on promising leads (Phase 4) \u2014 the agent must call leadbay_research_lead_by_id on each when the user's intent is to research specific leads; Phase 4 is intentionally skipped for batch-view requests ("show me today's leads", "run my morning check-in") per the Phase 4 skip gate`, "Triggers contact enrichment without asking the user first (it consumes quota)", "Skips the STOP byproduct and proposes next actions on its own", 'Fires 10 parallel leadbay_research_lead_by_id calls and treats "stream closed" errors as terminal \u2014 must serialize and retry singletons', "Re-pulls leadbay_pull_leads without passing the captured lensId, allowing a backend lens shift to discard the Phase 2 batch", 'Treats a "Request timed out" from leadbay_bulk_qualify_leads as terminal instead of retrying with wait_for_completion:false + qualify_status polling', 'Triggers on a follow-up query (e.g., "leads I should follow up with") that should have routed to `leadbay_followup_check_in` \u2014 the two entry points are different data sources (Discover wishlist vs Monitor view) per \xA71.6'] },
23212
23411
  leadbay_extend_my_lens: { "name": "leadbay_extend_my_lens", "short_description": "Add more leads to the current lens on demand \u2014 for users whose appetite\nexceeds the standard daily fill. The agent picks seeds silently from\nwhat's already on the lens, fires the extra refill, and surfaces the\nqueue confirmation. The user never reviews the seed list.\n", "arguments": [{ "name": "extra_count", "description": "How many extra leads to add. Optional. Omit to use the backend default.", "required": false }], "expected_calls": ["leadbay_account_status", "leadbay_seed_candidates", "leadbay_extend_lens", "leadbay_pull_leads"], "failure_modes": ["Surfaces the seed candidate list to the user instead of picking silently \u2014 the user asked for MORE LEADS, not a candidate review meeting", "Skips the seeded path and calls `leadbay_extend_lens` with no `seed_lead_ids`, losing the bias signal the recommender needs", "On 429, silently retries instead of surfacing the three options (smaller / wait / upgrade) via your host's choice widget (`ask_user_input_v0` or `AskUserQuestion`)", "Forgets to pre-check `LENS_EXTRA_REFILL` quota in `leadbay_account_status` and burns a wasted API call", "Skips the post-queue pull-leads suggestion, so the user doesn't see what just got added"] },
23213
23412
  leadbay_followup_check_in: { "name": "leadbay_followup_check_in", "short_description": 'Follow-up check-in: surface KNOWN leads from the Monitor view needing\nre-engagement. Trigger on "follow up", "already known leads", "what\'s\noverdue", "before my trip", "who should I re-engage". Do NOT trigger on\n"show me today\'s leads", "my morning check-in", "run my check-in",\n"I do this every day", "every morning" \u2014 those go to\n`leadbay_daily_check_in`.\n', "arguments": [], "expected_calls": ["leadbay_pull_followups", "leadbay_research_lead_by_id", "leadbay_prepare_outreach"], "failure_modes": ["Calls leadbay_pull_leads (the Discover entry point) instead of leadbay_pull_followups \u2014 these are different data sources; the Discover queue does NOT contain Monitor's known-but-cold pipeline", 'Iterates pages of leadbay_pull_leads filtering by engagement_count to "fake" a follow-up view (a real bug observed in 0.9.0 \u2014 the right move is to call pull_followups directly)', "Replaces the canonical pull_followups table layout with prose per row (the per-tool RENDERING block is the structural contract; commentary belongs above or below)", 'Skips the cross-mode pivot offer at the end ("Want to see NEW leads from your wishlist instead?" routes to leadbay_pull_leads)'] },
@@ -23229,6 +23428,7 @@ should I follow up on" to "I'll send via lemlist".
23229
23428
  };
23230
23429
  var PROMPT_CATALOG_HEADER = `This server exposes the following workflow prompts via \`prompts/list\` and \`prompts/get\`. Some MCP clients render them as slash commands; if your client does not, you (the agent) should invoke them directly via \`prompts/get\` when the user's request matches one of the triggers described below.`;
23231
23430
  var PROMPT_CATALOG_BULLETS = {
23431
+ leadbay_build_campaign: `- \`leadbay_build_campaign\` (optional args: audience, campaign_name): Build a sales campaign from scratch in one guided flow: discover on the active lens, qualify and pick a cohort, enrich the contacts most likely to engage, save it via \`leadbay_create_campaign\`, then show a one-tap call/email view via \`leadbay_campaign_call_sheet\`. Trigger on "build me a campaign", "set up a new campaign", "create a campaign from scratch". WORK an existing campaign with \`leadbay_work_campaign\`; split leads across reps with \`leadbay_setup_team_prospecting\`.`,
23232
23432
  leadbay_daily_check_in: `- \`leadbay_daily_check_in\`: Morning DISCOVERY workflow \u2014 new leads from the lens wishlist. Trigger on "show me leads", "what's new today", "let's prospect", "run my check-in", "my morning check-in", "I do this every day", "every morning". Recurrence language always means this prompt. Do NOT trigger on follow-up phrasings ("follow up", "before my trip") \u2014 those go to \`leadbay_followup_check_in\`.`,
23233
23433
  leadbay_extend_my_lens: `- \`leadbay_extend_my_lens\` (optional args: extra_count): Add more leads to the current lens on demand \u2014 for users whose appetite exceeds the standard daily fill. The agent picks seeds silently from what's already on the lens, fires the extra refill, and surfaces the queue confirmation. The user never reviews the seed list.`,
23234
23434
  leadbay_followup_check_in: `- \`leadbay_followup_check_in\`: Follow-up check-in: surface KNOWN leads from the Monitor view needing re-engagement. Trigger on "follow up", "already known leads", "what's overdue", "before my trip", "who should I re-engage". Do NOT trigger on "show me today's leads", "my morning check-in", "run my check-in", "I do this every day", "every morning" \u2014 those go to \`leadbay_daily_check_in\`.`,
@@ -23376,6 +23576,30 @@ var CATALOG = [
23376
23576
  )
23377
23577
  ]
23378
23578
  },
23579
+ {
23580
+ name: "leadbay_build_campaign",
23581
+ description: PROMPT_META.leadbay_build_campaign.short_description,
23582
+ arguments: [
23583
+ {
23584
+ name: "audience",
23585
+ description: "Optional: a fresh audience to target (e.g. 'dental clinics in Texas'). Omit to build from your ACTIVE lens \u2014 the default.",
23586
+ required: false
23587
+ },
23588
+ {
23589
+ name: "campaign_name",
23590
+ description: "Optional: a name for the campaign. Omit and one is derived from the lens/audience + date (or the backend AI-names it).",
23591
+ required: false
23592
+ }
23593
+ ],
23594
+ render: (args) => [
23595
+ userMessage(
23596
+ substitutePlaceholders(leadbay_build_campaign, {
23597
+ audience_block: args.audience ? `Target audience: **${args.audience}** \u2014 if my active lens doesn't already cover it, set it up first (confirm before switching lenses).` : "Use my active Leadbay lens as the audience.",
23598
+ campaign_name_paren: args.campaign_name ? ` named **${args.campaign_name}**` : ""
23599
+ })
23600
+ )
23601
+ ]
23602
+ },
23379
23603
  {
23380
23604
  name: "leadbay_setup_team_prospecting",
23381
23605
  description: PROMPT_META.leadbay_setup_team_prospecting.short_description,
@@ -26424,7 +26648,7 @@ var OAUTH_BASE_URLS = {
26424
26648
  fr: "https://staging.api.leadbay.app"
26425
26649
  }
26426
26650
  };
26427
- var VERSION = "0.22.0";
26651
+ var VERSION = "0.23.0";
26428
26652
  var HELP = `
26429
26653
  leadbay-mcp ${VERSION} \u2014 Leadbay Model Context Protocol server
26430
26654
 
@@ -33,6 +33,204 @@ import {
33
33
  } from "@modelcontextprotocol/sdk/types.js";
34
34
 
35
35
  // src/prompts.generated.ts
36
+ var leadbay_build_campaign = `
37
+ ## MEMORY
38
+
39
+ Before responding, glance at any \`_meta.agent_memory.summary\` returned by tool calls earlier in this session and reflect its top signals in your reasoning ("Filtering by your stated preference for healthcare"). After any material new signal from the user this conversation (sector, region, deal size, communication style, qualification rule, explicit retraction, or recurrence / scheduling preference such as "I do this every day" or "remind me every morning"), call \`leadbay_agent_memory_capture\` to persist it: \`source:"user_stated"\` if literal, \`source:"inferred"\` with confidence <=6 if inferred.
40
+
41
+
42
+ Build me a Leadbay campaign from scratch{{arg:campaign_name_paren}}. {{arg:audience_block}}
43
+
44
+ GATE \u2014 DEFER TO TOOL RENDERING. When you call a Leadbay composite that ships its own RENDERING block (every composite in 0.9.0+ does), render the response using that block's recipe verbatim \u2014 score bars, glyph palette, column order, hide-list, link priorities, all of it. Do NOT substitute prose, a numbered list, or a different column structure even when an orchestrating prompt's body suggests alternate framing. Prompt-specific commentary (motivational nudges, summaries, next-action recommendations) belongs ABOVE or BELOW the canonical table, never in place of it.
45
+
46
+ If the prompt's body and the tool's RENDERING appear to conflict, the tool's RENDERING wins for the structural layout; the prompt's voice wins for the commentary that surrounds it.
47
+
48
+
49
+ # Resilience rules for Leadbay long-running tools
50
+
51
+ These four rules apply to every Leadbay workflow that calls \`leadbay_pull_leads\`, \`leadbay_bulk_qualify_leads\`, \`leadbay_research_lead_by_id\`, \`leadbay_import_and_qualify\`, or \`leadbay_enrich_titles\`. **Treat timeouts and stream-closed errors as transient, not as signals to replan.**
52
+
53
+ ## Rule 1 \u2014 Pin the lens
54
+
55
+ After your first \`leadbay_pull_leads\` call, capture \`response.lens.id\` into your working memory and **pass it explicitly as the \`lensId\` argument to every subsequent call** in this session \u2014 including any re-pulls, bulk qualifies, or research calls that accept it. (Field-name caveat: the response nests it as \`lens.id\`; the parameter on subsequent calls is \`lensId\`.) The active lens can shift between calls (5-minute client cache + backend \`last_requested_lens\` can change if the user touches the web UI). A lens shift mid-workflow throws away your top-10 work.
56
+
57
+ ## Rule 2 \u2014 Prefer async for bulk operations
58
+
59
+ \`leadbay_bulk_qualify_leads\` and \`leadbay_import_and_qualify\` accept \`wait_for_completion:false\`, which returns \`{status:'running', qualify_id}\` immediately. Then poll \`leadbay_qualify_status\` (or \`leadbay_import_status\`) every ~10s until the job completes. **Use the async pattern by default** \u2014 the blocking default can exceed the MCP client's per-call timeout on large batches and produce a misleading \`"Request timed out"\` even though the server is still working.
60
+
61
+ ## Rule 3 \u2014 Serialize \`leadbay_research_lead_by_id\` fan-out
62
+
63
+ \`leadbay_research_lead_by_id\` is composite and reads many sub-resources. Calling it on 10 leads in parallel can saturate the transport and produce \`"Tool permission stream closed"\` errors that look like permission failures but are really backpressure. **Call it sequentially**, or at most 3 in parallel. If one call fails with a stream/timeout error, retry that one call once before moving on; on a second failure, note the lead and continue \u2014 do not abandon the remaining leads.
64
+
65
+ ## Rule 4 \u2014 Retry, don't replan
66
+
67
+ If a Leadbay tool returns \`"Request timed out"\`, \`"stream closed"\`, or any other transport-level error (distinct from a Leadbay-issued error payload), the work may still be running server-side. Do this in order:
68
+
69
+ 1. For bulk tools \u2014 retry with \`wait_for_completion:false\` and poll the status tool with the returned id. Don't re-pull leads; that can shift the lens.
70
+ 2. For single-lead tools \u2014 retry the same call once. If it still fails, record the lead id and continue with the rest of the workflow.
71
+ 3. **Do not** switch strategies (e.g. "the endpoint is broken, let me re-pull from scratch"). The earlier work is still valid; the timeout was the wire.
72
+
73
+ If \`pull_leads\` itself fails and you have no prior batch, then yes \u2014 retry it, explicitly pass the lensId you captured (if any), and continue.
74
+
75
+
76
+ # PHASE 0 \u2014 STATE + AUDIENCE
77
+
78
+ Call \`leadbay_account_status\` to see my remaining quota, my **enrichment credits**, and my **active lens**. Note \`web_fetch_remaining\` (qualification budget) and the enrichment credit balance \u2014 Phase 3 spends credits.
79
+
80
+ Resolve the audience:
81
+
82
+ - **Default \u2014 use my active lens.** If I didn't name a fresh audience, the active lens IS the audience. Do NOT create a new lens.
83
+ - **Fresh-audience fork.** Only if I described a NEW audience the active lens doesn't already cover, set it up first: \`leadbay_adjust_audience\` for sector/size tweaks, or \`leadbay_new_lens\` to create a brand-new named lens \u2014 then continue on that lens. Do NOT silently overwrite my existing lens; confirm once before switching.
84
+
85
+ # PHASE 1 \u2014 DISCOVER
86
+
87
+ Call \`leadbay_pull_leads\` on the resolved lens. **Capture \`response.lens.id\` and pass it as an explicit \`lensId\` on every later call this session** \u2014 a mid-session lens shift would discard the cohort I'm about to pick. Render the batch with the canonical layout:
88
+
89
+ ## RENDERING \u2014 markdown table, three columns, score-bar driven
90
+
91
+ Present the response as a markdown table sorted by \`score\` descending, with exactly three columns. Do not summarize in prose. Do not show the numeric score anywhere.
92
+
93
+ ## Score-bar (10-segment, inline-code wrapped)
94
+
95
+ Wrap a 10-glyph bar in a SINGLE inline-code span (backticks). The inline-code styling is what gives the bar contrast in most chat renderers \u2014 HTML \`<span>\` is stripped inside table cells.
96
+
97
+ Glyphs (use these exact characters; do not substitute):
98
+
99
+ - \`\u25B0\` \u2014 firmographic-only fill
100
+ - \`\u2756\` \u2014 AI-booster cap (placed at the RIGHT END of the filled run, never the front)
101
+ - \`\u25B1\` \u2014 empty
102
+
103
+ Computation:
104
+
105
+ \`\`\`
106
+ total_filled = round(score / 10), clamped to 0..10
107
+ ai_segments = round(qualification_summary.avg_qualification_boost / 3.3),
108
+ clamped to [0, total_filled]
109
+ normal_filled = total_filled \u2212 ai_segments
110
+ bar = "\u25B0" \xD7 normal_filled
111
+ + "\u2756" \xD7 ai_segments
112
+ + "\u25B1" \xD7 (10 \u2212 total_filled)
113
+ \`\`\`
114
+
115
+ If \`qualification_summary.answered == 0\` or \`avg_qualification_boost\` is null, set \`ai_segments = 0\` (no \u2756). Always wrap the bar in backticks. Print the legend \`\` \`\u25B0\` firmographic \xB7 \`\u2756\` AI booster cap \xB7 \`\u25B1\` unfilled \`\` once below the table.
116
+
117
+
118
+ **Column 1 \u2014 Company**
119
+
120
+ - Line 1: the 10-segment score bar in inline-code backticks (see the score-bar snippet above for the algorithm).
121
+ - Insert \`<br>\` between lines.
122
+ - Line 2: linked company name + \` \xB7 \` + short location + \` \xB7 \` + compact size.
123
+ - Link target: \`website\` (prefix \`https://\` if it's a bare hostname). Don't synthesize an app deep-link.
124
+ - Location: shorten "City of New York" \u2192 "NYC"; otherwise "City ST"; state alone only when city missing.
125
+ - Size: \`"Xk+"\` when \`size.min >= 1000\`, \`"min\u2013max"\` otherwise.
126
+
127
+ **Column 2 \u2014 Why it fits**
128
+
129
+ - One sentence, \u2264 20 words.
130
+ - Synthesize from (in priority order, whichever is present) the lead's \`short_description\`, top 2 \`tags[].display_name\`, and the gist of \`qualification_summary.best_response_excerpt\`. The trim payload does NOT carry the longer \`description\` field \u2014 for that, agent must call \`leadbay_research_lead_by_id\` or \`leadbay_research_lead_by_name_fuzzy\`.
131
+ - Do NOT append \`(boost N)\` \u2014 the \u2756 cap in column 1 already carries that signal.
132
+ - No bullet lists, no line breaks inside the cell.
133
+
134
+ **Column 3 \u2014 Contact**
135
+
136
+ \`[Contact name](LINK) \xB7 short job title\`. The \`[Contact name](LINK)\` markdown link wrapping is mandatory \u2014 never render the name as plain text. See linking/contact-linkedin for the URL priority (real profile \u2192 constructed people-search) and the \xB0-flag fallback.
137
+
138
+ **Hide from the user (never include in any cell):** \`id\`, \`location.pos\`, \`location.country\` (unless city/state both missing), \`sector_id\`, \`is_hq\`, \`web_fetch_in_progress\`, \`enrichment_in_progress\`, \`highlighted_fields\`, \`custom_fields\`, \`contacts_count\` when 0, \`notes_count\` / \`epilogue_actions_count\` / \`prospecting_actions_count\` when 0, \`stale_at\`, \`deal_insights\`, \`social_presence\` booleans (except as the \xB0-flag signal), \`need_attention\` flags, any field whose value is the string \`"null"\`.
139
+
140
+ ## Linking a contact's name
141
+
142
+ **MANDATORY: every contact name in your output \u2014 table cells, prose, headers, "Reach <Name>" callouts \u2014 MUST be wrapped in markdown link syntax \`[Name](URL)\`. Never render a contact name as bare text. A plain-text name is a broken contact card; the underlined name is the user's primary affordance for "take me to this person's profile". No "no URL available" exception \u2014 the search URL below is always constructable from name + company.**
143
+
144
+ URL priority (first applicable wins):
145
+
146
+ 1. **Real profile** \u2014 \`contact.linkedin_page\` when it's a string starting with \`https://\` (the MCP coerces the legacy literal \`"null"\` string to real null before you see it).
147
+ 2. **Constructed people-search** \u2014 \`https://www.linkedin.com/search/results/people/?keywords=<First>+<Last>+<Company>\`. URL-encode params. Strip Inc / LLC / Corp / Ltd / GmbH / Co / S.A. / S.L. / PLC / AG / SAS / SARL suffixes from the company. Append a trailing \` \xB0\` to the rendered name ONLY when this fallback is in use AND \`social_presence.linkedin == false\`. Never append \`\xB0\` when a real \`linkedin_page\` was used.
148
+
149
+ Never link a person's name to the company's LinkedIn page (and vice versa) \u2014 the two surfaces are different and conflating them quietly degrades the workflow.
150
+
151
+ ## Linking the company
152
+
153
+ Use the lead's \`website\` as the company-name link target \u2014 prefix \`https://\` if the value is a bare hostname. (The MCP does NOT synthesize a Leadbay-app deep-link URL; the team has not standardized one. Linking to \`website\` is always real data.)
154
+
155
+ When the response carries \`social_urls\` (the post-fix multi-platform URL block on rich-lead responses), render every non-null platform as a pill chip in the company-info row. Iterate over \`social_urls\`'s keys \u2014 never hardcode a fixed list \u2014 and emit each as \`[<platform-label>](<url>)\`. Skip platforms whose URL is null.
156
+
157
+ \`social_presence\` carries booleans for the same 6 platforms (crunchbase, facebook, instagram, linkedin, tiktok, twitter) \u2014 useful when you only care that the company has a profile somewhere. Use it as the \xB0-flag signal in the contact people-search fallback (see linking/contact-linkedin).
158
+
159
+
160
+
161
+ If the batch is thin (fewer than ~10 workable leads) or I ask for more depth, top it up: call \`leadbay_bulk_qualify_leads({lensId:<captured>, count:<deficit, max 25>, wait_for_completion:false})\`, poll \`leadbay_qualify_status\` until done, then re-pull with the same \`lensId\`. Never re-pull without \`lensId\`.
162
+
163
+ # PHASE 2 \u2014 PICK AN ICP CANDIDATE POOL
164
+
165
+ A campaign is only as good as the leads in it \u2014 AND only as good as whether each lead has a reachable BUYER (see Phase 3). So pick a **generous candidate pool** now, not the final cohort: aim for ~1.5\xD7 the target size of in-ICP leads (highest \`ai_agent_lead_score\`), so Phase 3 can drop any lead that turns out to have no buyer-persona contact and still hit the target. If the batch is short, top up via \`leadbay_bulk_qualify_leads\` / \`leadbay_extend_lens\`.
166
+
167
+ If I named specific leads, use those (but still apply the Phase 3 buyer-coverage check and tell me which lack a buyer). Otherwise recommend the pool and show it. Capture the candidate \`leadIds\`. Confirm the count ("12 candidates \u2014 I'll lock the final ~8 after checking each has a buyer"). Do NOT create the campaign yet \u2014 the final cohort is decided after Phase 3's coverage check.
168
+
169
+ # PHASE 3 \u2014 ENRICH THE RIGHT CONTACTS (load-bearing)
170
+
171
+ This is the phase that decides whether the campaign is worth a salesperson's time. Contacts aren't attached by default and enrichment is paid \u2014 so spend it ONLY on the people who would actually **buy what I sell**, not on whoever is most senior.
172
+
173
+ **Step A \u2014 work out MY buyer persona (do this before touching titles).**
174
+ Figure out what *I* sell and therefore who, inside the target company, owns the decision to buy it:
175
+
176
+ - Infer my product / value-prop from my context: my org and account (\`leadbay_account_status\`), and especially my lens's qualification criteria \u2014 the \`qualification_summary\` on the leads tells you *why* these companies are good targets for me, which implies what I'm offering them.
177
+ - Map value-prop \u2192 the **buying department/persona**, NOT seniority:
178
+ - A sales / prospecting / lead-gen / outbound / marketing / GTM / revenue tool \u2192 the **revenue org**: VP / Head / Director of Sales, Business Development, Account/Carrier Sales, CRO, CMO / VP Marketing, Head of Growth / Demand Gen, RevOps. (This is Leadbay's own persona.)
179
+ - An operations / logistics tool \u2192 operations leaders. A finance tool \u2192 finance. A dev tool \u2192 engineering. Etc.
180
+ - **Company size caveat:** Founder / CEO / Owner is a real buyer at small companies (\u2264~50), but at larger ones they are not \u2014 there the functional leader (e.g. VP Sales) is the buyer.
181
+ - **State the persona in one line and confirm it with me** before spending (see Step C). I can correct it.
182
+
183
+ **ANTI-PATTERN \u2014 do NOT do this:** picking the most senior or most "decision-maker-sounding" title regardless of department. A Director of Operations, COO, Mgr of Logistics, CFO, or CTO will **never** buy a sales tool \u2014 enriching them wastes credits and hands me a useless list. Seniority is not the same as being my buyer.
184
+
185
+ **Step B \u2014 find the persona-matching, enrichable contacts.**
186
+ Call \`leadbay_recall_ordered_titles({leadIds, lensId})\` and \`leadbay_enrich_titles({leadIds, lensId})\` in **discovery mode** (no \`titles\`). These return previously-enriched titles, \`title_suggestions\`, \`auto_included_titles\`, \`available_in_selection\`, \`enrichable_contacts\`, and \`credits_remaining\`. Treat them as a **menu to filter against my persona \u2014 not the answer.** If past-enriched titles or suggestions are off-persona (e.g. operations roles for a sales tool), do NOT repeat them. Select the titles that match my buyer persona AND are actually enrichable.
187
+
188
+ **Step B.5 \u2014 coverage guarantee (lock the final cohort here).** A campaign where half the leads have no buyer is a failed campaign. So before enriching, determine for each candidate lead whether it actually has an **enrichable buyer-persona contact** \u2014 use the discovery data plus, where it's ambiguous, a quick \`leadbay_research_lead_by_id\` to see that lead's available contact titles. Then:
189
+
190
+ - **KEEP** candidates that have \u22651 enrichable buyer-persona contact.
191
+ - **SWAP OUT** candidates whose only contacts are off-persona (e.g. ops/dispatch/finance only) or who have no enrichable contact at all. Replace each with the **highest-\`ai_agent_lead_score\` in-ICP candidate** from the pool that DOES have a buyer, until the cohort hits the target size (default 20; here capped by the enrichment budget).
192
+ - **Do NOT trade ICP fit for coverage.** A lead with a buyer but weak ICP fit (low \`ai_agent_lead_score\`, a vertical that doesn't match what I sell) is still the wrong lead \u2014 coverage is a filter applied AFTER ICP, never a reason to admit an off-ICP company. The final cohort must be both high-ICP AND buyer-covered.
193
+ - If the lens genuinely can't supply enough buyer-ready, in-ICP leads, say so honestly and offer to widen/extend rather than padding the campaign with no-buyer leads OR with off-ICP ones.
194
+
195
+ Tell me what you swapped in one line ("dropped Corbett + RBS \u2014 ops-only; swapped in Acme + Globex which have Sales VPs"). The goal is a final cohort where EVERY lead has a real buyer to call.
196
+
197
+ **Step C \u2014 show the spend + persona and confirm.** State the persona, the chosen titles, and "You have {credits_remaining} credits; this enriches {enrichable_contacts} contacts." Confirm via \`ask_user_input_v0\` ("Enrich these {enrichable_contacts} <persona> contacts now?" \u2192 ["Yes, enrich", "No, skip", "Change the persona/titles"]). Never launch a paid run without this. Enrich up to the campaign size (default 20) best persona-matching contacts.
198
+
199
+ **Step D \u2014 launch + poll.** On yes: \`leadbay_enrich_titles({leadIds, lensId, titles:[...chosen], email:true, phone:true})\` to launch, then poll \`leadbay_bulk_enrich_status\` until done (enrichment can take several minutes \u2014 keep polling, don't render an empty sheet prematurely). Append one small line at the very end of your reply: \`_(N credits remaining)_\`.
200
+
201
+ If I skip enrichment, continue \u2014 the campaign can be enriched later from the call sheet.
202
+
203
+ # PHASE 4 \u2014 CREATE THE CAMPAIGN
204
+
205
+ Derive a name (\`<lens or audience> \u2013 <today's date>\`) or use the one I gave. Call \`leadbay_create_campaign({name, lead_ids:<final buyer-ready cohort from Phase 3>})\` \u2014 this creates AND seeds in one call. Seed the cohort you actually enriched buyers on, not the original raw pool. Confirm the returned campaign name + id in one line. (If I later ask to add more leads to it, that's \`leadbay_add_leads_to_campaign\`.)
206
+
207
+ # PHASE 5 \u2014 THE VIEW (call / email ready)
208
+
209
+ If you launched enrichment in Phase 3, **poll \`leadbay_bulk_enrich_status\` until it's actually done before rendering** \u2014 do not render a "still enriching" sheet with empty contact cells; the whole point is the landed phones/emails. Enrichment can take several minutes; keep polling.
210
+
211
+ Then call \`leadbay_campaign_call_sheet({campaign_id})\` and render it per its RENDERING block \u2014 one card per lead, contacts with \`[phone](tel:)\` + \`[email](mailto:)\` one-tap links, the readiness chip at the top, map optional. This is the view I work from: scan \u2192 tap to call \u2192 tap to email.
212
+
213
+ **Flag suspect contacts** so I don't email the wrong person blind: mark with \u26A0 any enriched contact whose email domain doesn't match the company's website, or who shows up on more than one lead in this campaign (a sign of a mis-attributed enrichment). Keep the phone (it's usually still right) but tell me the email looks off.
214
+
215
+ # PHASE 6 \u2014 HANDOFF + STOP
216
+
217
+ The campaign exists and is call/email ready. End by offering, via \`ask_user_input_v0\`:
218
+
219
+ - "Start working it now" \u2192 run \`leadbay_work_campaign\` on this campaign (the calling/email session + outcome-logging loop).
220
+ - "See the pulse" \u2192 \`leadbay_campaign_progression\` for per-lead status.
221
+
222
+ Then STOP. Building a campaign is NOT outreaching \u2014 do not send anything and do not call \`leadbay_report_outreach\`. When I come back later to log calls, see previous statuses, and do follow-ups, that is \`leadbay_work_campaign\`, not this prompt.
223
+
224
+ # Iron laws
225
+
226
+ - Enrichment targets MY buyer persona \u2014 the people who would actually buy what *I* sell, derived from my product/ICP \u2014 NOT generic seniority. For a sales/prospecting tool that means the revenue org (sales / BD / growth / marketing leaders); a Director of Operations, COO, or logistics manager is useless no matter how senior. Get the persona right or the campaign is worthless.
227
+ - Selection is DATA-DRIVEN (\`leadbay_recall_ordered_titles\` + \`leadbay_enrich_titles\` discovery) but FILTERED to the persona \u2014 never blindly repeat past-enriched or suggested titles that don't match who buys my product.
228
+ - The FINAL cohort must be all buyer-ready: drop/swap any lead with no enrichable buyer-persona contact (Phase 3 Step B.5) rather than shipping it empty. A campaign where half the leads have no buyer to call is a failed campaign. Pick a generous pool in Phase 2 so swaps are possible.
229
+ - NEVER launch paid enrichment without showing \`credits_remaining\` + \`enrichable_contacts\`, naming the persona, and getting a yes.
230
+ - Qualify / pick BEFORE \`leadbay_create_campaign\` \u2014 never seed a campaign with unvetted leads.
231
+ - Carry the captured \`lensId\` on every call. A lens shift loses the cohort.
232
+ - End at the rendered call sheet, then hand off to \`leadbay_work_campaign\`. Do NOT re-implement the calling / follow-up loop here, and do NOT call \`leadbay_report_outreach\`.
233
+ `;
36
234
  var leadbay_daily_check_in = `
37
235
  ## MEMORY
38
236
 
@@ -1057,6 +1255,7 @@ Optional: offer to review the \`leadbay_campaign_progression\` for the same camp
1057
1255
  - If the user dictates an outcome that doesn't cleanly map to one of the four epilogue values, ASK ONCE before guessing.
1058
1256
  `;
1059
1257
  var PROMPT_META = {
1258
+ leadbay_build_campaign: { "name": "leadbay_build_campaign", "short_description": 'Build a sales campaign from scratch in one guided flow: discover on the\nactive lens, qualify and pick a cohort, enrich the contacts most likely to\nengage, save it via `leadbay_create_campaign`, then show a one-tap call/email\nview via `leadbay_campaign_call_sheet`. Trigger on "build me a campaign",\n"set up a new campaign", "create a campaign from scratch". WORK an existing\ncampaign with `leadbay_work_campaign`; split leads across reps with\n`leadbay_setup_team_prospecting`.\n', "arguments": [{ "name": "audience", "description": "Optional: a fresh audience to target (e.g. 'dental clinics in Texas'). Omit to build from your ACTIVE lens \u2014 the default.", "required": false }, { "name": "campaign_name", "description": "Optional: a name for the campaign. Omit and one is derived from the lens/audience + date (or the backend AI-names it).", "required": false }], "expected_calls": ["leadbay_account_status", "leadbay_pull_leads", "leadbay_bulk_qualify_leads", "leadbay_qualify_status", "leadbay_recall_ordered_titles", "leadbay_enrich_titles", "leadbay_bulk_enrich_status", "leadbay_create_campaign", "leadbay_add_leads_to_campaign", "leadbay_campaign_call_sheet", "leadbay_campaign_progression", "leadbay_new_lens", "leadbay_adjust_audience"], "failure_modes": ["Enriches by seniority instead of by buyer persona \u2014 picks COO / Director of Operations / Mgr of Logistics / CFO / CTO because they sound senior, when the user sells a SALES tool whose buyer is the revenue org (VP/Head/Director of Sales, BD, growth, marketing). Operations people never buy a sales tool; this hands the salesperson a useless list.", "Fails to derive the user's buyer persona from their product/ICP before choosing titles \u2014 jumps straight to titles without working out who buys what THIS user sells, then defaults to generic exec titles.", "Blindly repeats leadbay_recall_ordered_titles / discovery suggestions even when they are off-persona (e.g. operations roles a prior session wrongly enriched) \u2014 recall is a filtered input, not the answer.", "Poor coverage \u2014 leaves many picked leads with no persona-matching contact (or 0 enrichments on some leads) and doesn't flag it, so the salesperson opens the campaign to half-empty rows.", "Launches paid enrichment without first showing credits_remaining + enrichable_contacts, naming the persona, and getting a yes \u2014 the spend-visibility gate is mandatory.", "Creates the campaign before qualifying / picking \u2014 seeds a campaign with unvetted leads. Qualify and let the user pick (or AI-recommend) FIRST, then leadbay_create_campaign.", "Ends at 'campaign created' without rendering the leadbay_campaign_call_sheet view \u2014 the ready-to-work view IS the deliverable; stopping short is purpose drift.", "Re-implements the calling / outcome / follow-up loop instead of handing off to leadbay_work_campaign \u2014 that prompt already owns it. This prompt BUILDS; work_campaign WORKS.", "Auto-sends outreach or calls leadbay_report_outreach \u2014 building a campaign is not outreaching. No send, no log; the user works it afterward.", "Re-pulls leadbay_pull_leads without the captured lensId \u2014 a mid-session lens shift discards the picked cohort.", "Silently overwrites the user's active lens when forking to a fresh audience \u2014 confirm once before switching lenses.", "Renders the picked leads or the call sheet as prose instead of the canonical per-tool RENDERING layout."] },
1060
1259
  leadbay_daily_check_in: { "name": "leadbay_daily_check_in", "short_description": 'Morning DISCOVERY workflow \u2014 new leads from the lens wishlist. Trigger\non "show me leads", "what\'s new today", "let\'s prospect", "run my check-in",\n"my morning check-in", "I do this every day", "every morning". Recurrence\nlanguage always means this prompt. Do NOT trigger on follow-up phrasings\n("follow up", "before my trip") \u2014 those go to `leadbay_followup_check_in`.\n', "arguments": [], "expected_calls": ["leadbay_account_status", "leadbay_pull_leads", "leadbay_research_lead_by_id", "leadbay_bulk_qualify_leads", "leadbay_enrich_contacts"], "failure_modes": ["Calls leadbay_report_outreach without explicit user authorization", "Surfaces fewer than 10 leads when more are available, or fails to top up via leadbay_qualify_top_n when the batch is short", `Replaces the canonical pull_leads table layout with prose per row (the per-tool RENDERING block is the structural contract; "Today's nudges" goes above it, not in place of it)`, "Skips the nudge paragraph entirely \u2014 the table alone is fine but adding the nudge is the value-add", `Skips deep research on promising leads (Phase 4) \u2014 the agent must call leadbay_research_lead_by_id on each when the user's intent is to research specific leads; Phase 4 is intentionally skipped for batch-view requests ("show me today's leads", "run my morning check-in") per the Phase 4 skip gate`, "Triggers contact enrichment without asking the user first (it consumes quota)", "Skips the STOP byproduct and proposes next actions on its own", 'Fires 10 parallel leadbay_research_lead_by_id calls and treats "stream closed" errors as terminal \u2014 must serialize and retry singletons', "Re-pulls leadbay_pull_leads without passing the captured lensId, allowing a backend lens shift to discard the Phase 2 batch", 'Treats a "Request timed out" from leadbay_bulk_qualify_leads as terminal instead of retrying with wait_for_completion:false + qualify_status polling', 'Triggers on a follow-up query (e.g., "leads I should follow up with") that should have routed to `leadbay_followup_check_in` \u2014 the two entry points are different data sources (Discover wishlist vs Monitor view) per \xA71.6'] },
1061
1260
  leadbay_extend_my_lens: { "name": "leadbay_extend_my_lens", "short_description": "Add more leads to the current lens on demand \u2014 for users whose appetite\nexceeds the standard daily fill. The agent picks seeds silently from\nwhat's already on the lens, fires the extra refill, and surfaces the\nqueue confirmation. The user never reviews the seed list.\n", "arguments": [{ "name": "extra_count", "description": "How many extra leads to add. Optional. Omit to use the backend default.", "required": false }], "expected_calls": ["leadbay_account_status", "leadbay_seed_candidates", "leadbay_extend_lens", "leadbay_pull_leads"], "failure_modes": ["Surfaces the seed candidate list to the user instead of picking silently \u2014 the user asked for MORE LEADS, not a candidate review meeting", "Skips the seeded path and calls `leadbay_extend_lens` with no `seed_lead_ids`, losing the bias signal the recommender needs", "On 429, silently retries instead of surfacing the three options (smaller / wait / upgrade) via your host's choice widget (`ask_user_input_v0` or `AskUserQuestion`)", "Forgets to pre-check `LENS_EXTRA_REFILL` quota in `leadbay_account_status` and burns a wasted API call", "Skips the post-queue pull-leads suggestion, so the user doesn't see what just got added"] },
1062
1261
  leadbay_followup_check_in: { "name": "leadbay_followup_check_in", "short_description": 'Follow-up check-in: surface KNOWN leads from the Monitor view needing\nre-engagement. Trigger on "follow up", "already known leads", "what\'s\noverdue", "before my trip", "who should I re-engage". Do NOT trigger on\n"show me today\'s leads", "my morning check-in", "run my check-in",\n"I do this every day", "every morning" \u2014 those go to\n`leadbay_daily_check_in`.\n', "arguments": [], "expected_calls": ["leadbay_pull_followups", "leadbay_research_lead_by_id", "leadbay_prepare_outreach"], "failure_modes": ["Calls leadbay_pull_leads (the Discover entry point) instead of leadbay_pull_followups \u2014 these are different data sources; the Discover queue does NOT contain Monitor's known-but-cold pipeline", 'Iterates pages of leadbay_pull_leads filtering by engagement_count to "fake" a follow-up view (a real bug observed in 0.9.0 \u2014 the right move is to call pull_followups directly)', "Replaces the canonical pull_followups table layout with prose per row (the per-tool RENDERING block is the structural contract; commentary belongs above or below)", 'Skips the cross-mode pivot offer at the end ("Want to see NEW leads from your wishlist instead?" routes to leadbay_pull_leads)'] },
@@ -1078,6 +1277,7 @@ should I follow up on" to "I'll send via lemlist".
1078
1277
  };
1079
1278
  var PROMPT_CATALOG_HEADER = `This server exposes the following workflow prompts via \`prompts/list\` and \`prompts/get\`. Some MCP clients render them as slash commands; if your client does not, you (the agent) should invoke them directly via \`prompts/get\` when the user's request matches one of the triggers described below.`;
1080
1279
  var PROMPT_CATALOG_BULLETS = {
1280
+ leadbay_build_campaign: `- \`leadbay_build_campaign\` (optional args: audience, campaign_name): Build a sales campaign from scratch in one guided flow: discover on the active lens, qualify and pick a cohort, enrich the contacts most likely to engage, save it via \`leadbay_create_campaign\`, then show a one-tap call/email view via \`leadbay_campaign_call_sheet\`. Trigger on "build me a campaign", "set up a new campaign", "create a campaign from scratch". WORK an existing campaign with \`leadbay_work_campaign\`; split leads across reps with \`leadbay_setup_team_prospecting\`.`,
1081
1281
  leadbay_daily_check_in: `- \`leadbay_daily_check_in\`: Morning DISCOVERY workflow \u2014 new leads from the lens wishlist. Trigger on "show me leads", "what's new today", "let's prospect", "run my check-in", "my morning check-in", "I do this every day", "every morning". Recurrence language always means this prompt. Do NOT trigger on follow-up phrasings ("follow up", "before my trip") \u2014 those go to \`leadbay_followup_check_in\`.`,
1082
1282
  leadbay_extend_my_lens: `- \`leadbay_extend_my_lens\` (optional args: extra_count): Add more leads to the current lens on demand \u2014 for users whose appetite exceeds the standard daily fill. The agent picks seeds silently from what's already on the lens, fires the extra refill, and surfaces the queue confirmation. The user never reviews the seed list.`,
1083
1283
  leadbay_followup_check_in: `- \`leadbay_followup_check_in\`: Follow-up check-in: surface KNOWN leads from the Monitor view needing re-engagement. Trigger on "follow up", "already known leads", "what's overdue", "before my trip", "who should I re-engage". Do NOT trigger on "show me today's leads", "my morning check-in", "run my check-in", "I do this every day", "every morning" \u2014 those go to \`leadbay_daily_check_in\`.`,
@@ -1225,6 +1425,30 @@ var CATALOG = [
1225
1425
  )
1226
1426
  ]
1227
1427
  },
1428
+ {
1429
+ name: "leadbay_build_campaign",
1430
+ description: PROMPT_META.leadbay_build_campaign.short_description,
1431
+ arguments: [
1432
+ {
1433
+ name: "audience",
1434
+ description: "Optional: a fresh audience to target (e.g. 'dental clinics in Texas'). Omit to build from your ACTIVE lens \u2014 the default.",
1435
+ required: false
1436
+ },
1437
+ {
1438
+ name: "campaign_name",
1439
+ description: "Optional: a name for the campaign. Omit and one is derived from the lens/audience + date (or the backend AI-names it).",
1440
+ required: false
1441
+ }
1442
+ ],
1443
+ render: (args) => [
1444
+ userMessage(
1445
+ substitutePlaceholders(leadbay_build_campaign, {
1446
+ audience_block: args.audience ? `Target audience: **${args.audience}** \u2014 if my active lens doesn't already cover it, set it up first (confirm before switching lenses).` : "Use my active Leadbay lens as the audience.",
1447
+ campaign_name_paren: args.campaign_name ? ` named **${args.campaign_name}**` : ""
1448
+ })
1449
+ )
1450
+ ]
1451
+ },
1228
1452
  {
1229
1453
  name: "leadbay_setup_team_prospecting",
1230
1454
  description: PROMPT_META.leadbay_setup_team_prospecting.short_description,
@@ -22831,7 +23055,7 @@ function parseWriteEnv(env = process.env) {
22831
23055
  }
22832
23056
 
22833
23057
  // src/http-server.ts
22834
- var VERSION = true ? "0.22.0" : "0.0.0-dev";
23058
+ var VERSION = true ? "0.23.0" : "0.0.0-dev";
22835
23059
  var PORT = Number(process.env.PORT ?? 8080);
22836
23060
  var HOST = process.env.HOST ?? "0.0.0.0";
22837
23061
  var sseSessions = /* @__PURE__ */ new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leadbay/mcp",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "mcpName": "io.github.leadbay/leadbay-mcp",
5
5
  "description": "Model Context Protocol (MCP) server for Leadbay — AI lead discovery, qualification, and enrichment for Claude Desktop, Cursor, and Claude Code.",
6
6
  "type": "module",