Skip to content

About

Mastra starter: find people, verify work emails, draft a campaign that waits for approval. Runs on Layrcake.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Layrcake starter for Mastra

A Mastra agent that turns a one-sentence brief into about 10 people with verified work emails and a draft campaign, then stops at the approval link.

It uses a Mastra Agent with the five tools from @layrcake/mastra, which are built on the official layrcake TypeScript SDK. Nothing is sent. A person approves the campaign in the Layrcake console before any email goes out.

What it does

  1. find_leads finds people who match your brief.
  2. enrich gets each person's work email.
  3. verify_email checks every address. Only valid and catch_all_valid addresses are kept.
  4. create_campaign saves a short draft sequence for the kept people. Drafts never send.
  5. launch_campaign returns a preview and an approval link. The agent stops there.

Why tools instead of MCP for this kit

Mastra's own integrations ship as createTool tools. @layrcake/mastra wraps the layrcake SDK in five of them, which keeps the rules in code:

  • Each tool takes only the arguments this agent needs. launch_campaign has no confirmation_token argument, so the model cannot approve anything.
  • The rules live in @layrcake/mastra, which takes them from layrcake/agent-tools in the layrcake SDK, the one place every Layrcake agent integration gets them from. Every paid call gets budget_credits set to what is left of BUDGET. --dry-run adds dry_run: true to every call. create_campaign refuses any address that did not pass verify_email in this run. Once the approval link appears, every tool refuses.
  • Paid calls run one at a time, so the running total is exact. The tools pass an idempotency key derived from the call, so a repeated call returns the first result instead of charging again.
  • stopWhen turns true once launch_campaign has run, which ends the loop at the approval link.

The hosted MCP server at https://mcp.layrcake.dev/mcp also works with Mastra's MCPClient; the package README shows the setup.

Prerequisites

  • Node.js 22.13 or later.
  • A Layrcake API key. Create one at layrcake.dev/connect. New accounts start with 300 free credits.
  • An Anthropic API key from platform.claude.com, or another model provider (see MODEL below).
  • Sending mailboxes in your Layrcake workspace, for the launch preview. Without them, launch_campaign returns an error that says what is missing, and the run reports it.

Setup

npm install
cp .env.example .env   # then add LAYRCAKE_API_KEY and ANTHROPIC_API_KEY
npm run smoke          # free check of your Layrcake key, no model call

npm run smoke runs the agent's own tools in dry-run mode against the live API. It charges nothing and calls no model. It prints something like this:

Key works for workspace "My workspace". Balance: 300 credits.
find_leads: would cost up to 3 credits
enrich: would cost up to 5 credits
verify_email: would cost up to 1.25 credits
create_campaign: would cost up to 0 credits

Charged: 0 credits. Your key and the Layrcake API work.

If create_campaign says it would trip: sending_capacity, connect mailboxes in the Layrcake console before a live run.

Set SENDER_NAME in .env to the name your emails are signed with. Without it, every draft is signed [Your name] and the report reminds you to fill it in before you approve.

Run

Start with a dry run. Every Layrcake call returns a plan with its cost instead of data, so it is free. It still uses your model key.

npm start -- --dry-run

Then run it for real with your own brief:

npm start -- "Find 10 heads of sales at software companies in London with 20 to 200 staff and draft a short campaign about cutting time spent on lead research."

With no brief, it uses the one above.

What you will see

Each tool call prints as it runs. The run ends with a short report from the tools themselves:

Live run. Budget: 25 credits.
Brief: Find 3 heads of sales at software companies in London with 20 to 200 staff, verify their work emails, and draft a short campaign about cutting time spent on lead research.

-> find_leads
-> enrich
-> enrich
-> enrich
-> verify_email
-> verify_email
-> verify_email
-> create_campaign
-> launch_campaign

Found 10 people. Kept 3 verified emails (1 catch-all).
Layrcake credits spent: 21.75 of 25.
Nothing has been sent. A person approves or declines here: <approval link>

This is our test run on 20 October 2026, with BUDGET=25, the three-person brief above and openrouter/anthropic/claude-sonnet-5.5 through OpenRouter. It took 32 seconds. The search returned 10 people and the agent enriched the 3 the brief asked for. Your run will differ. A dry run ends with the model's cost estimate instead of a link.

How approval works

launch_campaign never sends on its own. Its first answer is a preview, a confirmation_token and an approval_url. The tool returns the link and the loop stops.

A signed-in person in your workspace opens the link, reads the preview and approves or declines. Layrcake can also email an approver in your workspace. After approval, Layrcake starts the campaign itself when the approval says execution: server. Otherwise you repeat the call with the token. This agent never does either: its launch_campaign tool has no token argument.

Cost

A run of the default brief usually costs 45 to 55 Layrcake credits. A credit is $0.01. Finding people costs 0.25 credits each, an email costs 5 credits when found, a verification costs 1.25, and lookups that find nothing are free. Drafting the campaign is free. See pricing.

BUDGET in .env is the ceiling for the whole run (default 100). Model usage is billed separately by your model provider.

Changing the model

MODEL takes a Mastra model router string, provider/model. The default is anthropic/claude-sonnet-5-5, which reads ANTHROPIC_API_KEY. For OpenAI, set MODEL=openai/<model> and OPENAI_API_KEY.

Using OpenRouter

The kit runs through OpenRouter with Mastra's built-in OpenRouter route. Put these in .env instead of a direct model key:

OPENROUTER_API_KEY=<your OpenRouter key>
MODEL=openrouter/anthropic/claude-sonnet-5.5

Project layout

src/agent.ts         the run: brief, budget, stop condition, report
src/prospector.ts    the Mastra agent and its tools from @layrcake/mastra
src/instructions.ts  the system prompt
src/smoke.ts         free setup check, no model call
test/prospector.test.ts  agent loop tests with a mocked Layrcake API and a mock model

Development

npm run lint
npm run typecheck
npm test

The tests pass a mocked fetch to the Layrcake client and run the agent with a mock language model. They need no keys and make no network calls. The tools themselves are tested in @layrcake/mastra and layrcake.

Links

License

MIT. See LICENSE.

About

Mastra starter: find people, verify work emails, draft a campaign that waits for approval. Runs on Layrcake.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages