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.
find_leadsfinds people who match your brief.enrichgets each person's work email.verify_emailchecks every address. Onlyvalidandcatch_all_validaddresses are kept.create_campaignsaves a short draft sequence for the kept people. Drafts never send.launch_campaignreturns a preview and an approval link. The agent stops there.
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_campaignhas noconfirmation_tokenargument, so the model cannot approve anything. - The rules live in
@layrcake/mastra, which takes them fromlayrcake/agent-toolsin thelayrcakeSDK, the one place every Layrcake agent integration gets them from. Every paid call getsbudget_creditsset to what is left ofBUDGET.--dry-runaddsdry_run: trueto every call.create_campaignrefuses any address that did not passverify_emailin 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.
stopWhenturns true oncelaunch_campaignhas 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.
- 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
MODELbelow). - Sending mailboxes in your Layrcake workspace, for the launch preview. Without them,
launch_campaignreturns an error that says what is missing, and the run reports it.
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 callnpm 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.
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-runThen 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.
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.
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.
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.
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.
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
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
npm run lint
npm run typecheck
npm testThe 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.
- Layrcake docs: docs.layrcake.dev
- Rules for agents: layrcake.dev/agents.md
- TypeScript SDK: github.com/Layrcake-dev/layrcake-js
- Mastra tools package: github.com/Layrcake-dev/layrcake-mastra
- MCP server:
https://mcp.layrcake.dev/mcp - Mastra: mastra.ai
MIT. See LICENSE.