<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Mailbase Engineering]]></title><description><![CDATA[Mailbase Engineering]]></description><link>https://mailbase.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 28 Nov 2026 21:00:18 GMT</lastBuildDate><atom:link href="https://mailbase.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Code Mode for In-App SaaS AI Agents: Why 150 Tools Wreck Prompt Caching]]></title><description><![CDATA[Collapsing 150+ tools into 2 sandboxed tools keeps prompt prefixes byte-identical, raises cache hit rates and cuts per-user LLM cost in a B2B SaaS.]]></description><link>https://mailbase.hashnode.dev/code-mode-for-in-app-saas-ai-agents-why-150-tools-wreck-prompt-caching</link><guid isPermaLink="true">https://mailbase.hashnode.dev/code-mode-for-in-app-saas-ai-agents-why-150-tools-wreck-prompt-caching</guid><category><![CDATA[AI]]></category><category><![CDATA[llm]]></category><category><![CDATA[SaaS]]></category><category><![CDATA[architecture]]></category><dc:creator><![CDATA[Tahar Amin Touzi]]></dc:creator><pubDate>Thu, 26 Nov 2026 14:14:00 GMT</pubDate><content:encoded><![CDATA[<p>Most write-ups on MCP code mode focus on external developer clients connecting to a remote server. Inside a real B2B SaaS product, there is an even bigger payoff that almost nobody talks about: running code mode for your <strong>own in-app AI assistant</strong> so your prompt cache hit rate stays near its ceiling and your per-user LLM cost stops scaling linearly with your feature count.</p>
<p>When we built <a href="https://mailbase.studio/features/ai-mcp">Mailbase</a> (an email workflow SaaS covering transactional sending, campaigns, audiences, inbox triage, prospecting, and API keys), our tool catalog grew past 150 operations. That is the exact point where classic tool-calling breaks unit economics.</p>
<h2>Why 150 tool definitions quietly wreck prompt caching</h2>
<p>Modern LLM providers discount cached input tokens by 75% to 90% — <strong>only when the prompt prefix is byte-identical</strong>.</p>
<p>If you dynamically filter tool schemas per route, plan, or user role (<code>if (user.isAdmin) tools.push(...)</code>), every permutation invalidates the cache prefix for the entire tool block. On the flip side, if you pin all 150+ JSON Schemas on every turn so they cache, you still pay for 25,000+ prefix tokens on turn one, dilute tool-selection accuracy, and pay full price every time multi-step read loops dump raw JSON arrays into conversation history.</p>
<p>Ask an in-app assistant <em>"Which of my last 10 campaigns had a bounce rate above 2%?"</em> under classic tool calling: the model runs 11 sequential turns and stuffs every raw response into the context window just to output two lines.</p>
<h2>The two-tool split: <code>search_tools</code> + QuickJS <code>run_program</code></h2>
<p>We collapsed the entire catalog into two stable tools whose definitions are <strong>byte-identical across every user, role, and page</strong>:</p>
<ol>
<li><strong><code>search_tools(query, family, detail)</code></strong> — progressive disclosure:<ul>
<li><code>detail: "names"</code> returns only tool names</li>
<li><code>detail: "descriptions"</code> adds titles, read-only/destructive flags, and sandbox eligibility</li>
<li><code>detail: "full"</code> loads Zod-derived JSON Schemas for only the few tools needed right now</li>
</ul>
</li>
<li><strong><code>run_program(code)</code></strong> — executes a short async JavaScript function inside an isolated <strong>QuickJS</strong> sandbox (no network, no filesystem, no timers, no env vars, hard wall-clock/CPU/memory/call caps):</li>
</ol>
<pre><code class="language-js">const campaigns = await mailbase.list_campaigns({});
const stats = await Promise.all(
  campaigns.slice(0, 10).map((c) =&gt; mailbase.get_campaign_stats({ id: c.id }))
);
return stats
  .filter((s) =&gt; s.bounce_rate &gt; 0.02)
  .map((s) =&gt; ({ id: s.id, name: s.name, bounce_rate: s.bounce_rate }));
</code></pre>
<p>One LLM turn. 200 bytes back into context instead of 40 KB of raw JSON.</p>
<h2>Multi-tenant security inside the bridge</h2>
<p>The obvious objection: <em>if the model writes JS, can it bypass RBAC or send 500 emails in a loop?</em></p>
<p>Not if the host bridge refuses to be a shortcut:</p>
<ul>
<li><strong>Static read-only allowlist:</strong> write and send tools are rejected inside <code>run_program</code>. To mutate state or send an email, the model must invoke the tool directly outside the sandbox so the UI asks the user to confirm.</li>
<li><strong>Same guarded handler on every inner call:</strong> every <code>await mailbase.&lt;tool&gt;(args)</code> passes through Zod argument validation, OAuth/session scopes, workspace isolation, and the member's live role check.</li>
</ul>
<p>Full deep-dive and comparison table originally published on the Mailbase engineering blog: <a href="https://mailbase.studio/blog/code-mode-prompt-caching-saas-agents">Code Mode for In-App SaaS Agents: Prompt Caching &amp; Cost Math</a>.</p>
]]></content:encoded></item><item><title><![CDATA[How We Verified 50,000 Email Probes for 10,000 Contacts Without Paying $400/mo]]></title><description><![CDATA[Verifying 10,000 B2B emails takes ~50,000 SMTP probes. The cascade, domain cache and slow pacing that run them for pennies instead of $400/mo.]]></description><link>https://mailbase.hashnode.dev/how-we-verified-50-000-email-probes-for-10-000-contacts-without-paying-400-mo</link><guid isPermaLink="true">https://mailbase.hashnode.dev/how-we-verified-50-000-email-probes-for-10-000-contacts-without-paying-400-mo</guid><category><![CDATA[email]]></category><category><![CDATA[backend]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[architecture]]></category><dc:creator><![CDATA[Tahar Amin Touzi]]></dc:creator><pubDate>Thu, 26 Nov 2026 14:11:12 GMT</pubDate><content:encoded><![CDATA[<p>If you build B2B prospecting or lead-enrichment software, you hit an uncomfortable math problem early: verifying 10,000 real business emails rarely means running 10,000 checks.</p>
<p>When you test common personal patterns for a contact (<code>first.last@</code>, <code>f.last@</code>, <code>first@</code>, <code>last@</code>, <code>contact@</code>), you easily run <strong>~5 checks per contact — 50,000 probes to land 10,000 verified emails</strong>. At typical instant email-verification API rates ($0.008–$0.01/check), 50,000 checks cost <strong>$400–$500 per run</strong>.</p>
<p>Here is the exact architecture we built at <a href="https://mailbase.studio/blog/verify-50000-emails-smtp-without-paying-400">Mailbase</a> to run 50,000 probes cleanly at minimal cost without burning our sending IP.</p>
<h2>1. Kill 40% of dead work before opening a single port 25 socket</h2>
<p>We run a strict cheap-to-expensive cascade:</p>
<ol>
<li><strong>Syntax + placeholder filter (0 ms):</strong> discards typos, disposable domains, and theme leftovers (<code>contact@yoursite.com</code>).</li>
<li><strong>Cached DNS MX lookup (~15 ms, free):</strong> kills expired domains and RFC 7505 null MX (<code>0 .</code>).</li>
<li><strong>Persistent domain-facts cache (~2 ms, Postgres):</strong><ul>
<li>Known <strong>catch-all</strong> domains are cached for <strong>30 days</strong> (no point re-probing guessed patterns — a <code>250 OK</code> proves nothing).</li>
<li>Unreachable / refusing servers get a <strong>6-hour</strong> cooldown so we never hammer a grumpy MX.</li>
</ul>
</li>
</ol>
<h2>2. One SMTP session per domain + random control mailbox first</h2>
<p>Opening 5 separate TCP sockets to test 5 name permutations at <code>acme.example</code> looks like a dictionary attack. Instead, open <strong>one</strong> session per domain:</p>
<pre><code class="language-text">EHLO → MAIL FROM → RCPT TO:&lt;zz-nonexistent-9f3a@acme.example&gt;
                 → RCPT TO:&lt;alice.martin@acme.example&gt;
                 → RCPT TO:&lt;a.martin@acme.example&gt;
                 → QUIT (never DATA)
</code></pre>
<p>If the random impossible address returns <code>250 OK</code>, the domain is a <strong>catch-all</strong> — every guessed candidate stays <code>unknown</code>, never <code>verified</code>. We only keep an address on a catch-all domain when it was explicitly published on the company's own site.</p>
<h2>3. Why slow pacing (~5 probes/min) breaks the $400/mo pricing model</h2>
<p>Commercial verification APIs are expensive because customers demand 400 ms synchronous answers at high concurrency, which forces huge rotating IP pools and constant blocklist remediation.</p>
<p>Most B2B lists and nightly hygiene jobs do not need an answer in 400 ms — they need a clean list by tomorrow morning. Running probes on an <strong>isolated dedicated probe server</strong> with clean reverse DNS (completely separate from our Amazon SES sending infrastructure) paced gently at <strong>~5 addresses per minute</strong> respects remote MX limits, handles greylisting (<code>450</code>/<code>451</code>) cleanly, and gets through 50,000 probes for pennies instead of $400.</p>
<p>Full architectural breakdown originally published on Mailbase: <a href="https://mailbase.studio/blog/verify-50000-emails-smtp-without-paying-400">How We Verified 50,000 Email Probes Without Paying $400/mo</a>.</p>
]]></content:encoded></item></channel></rss>