---
title: "Add letter mailing to an agent you build"
description: "Give an agent built with the Claude Agent SDK, OpenAI Agents SDK or Vercel AI SDK a mailbox: connect the SendForMe MCP server, or call the REST API from your own code."
url: https://sendforme.co/agents/agent-sdks
updated: 2026-11-29
---

# Add letter mailing to an agent you build

> Connect https://sendforme.co/mcp as a remote MCP server with an Authorization: Bearer sfm_ header, and your agent gets preview_letter, send_letter, get_letter and the rest. If your own code decides what to mail, call the REST API instead: POST https://sendforme.co/v1/letters/preview, then POST https://sendforme.co/v1/letters with an Idempotency-Key.

If your agent runs in your own code, it can still mail letters. Every major agent framework can use a remote MCP server, and SendForMe is one URL plus a key. Or skip the model and call the REST API.

Set your key once:

```bash
export SENDFORME_KEY=sfm_...   # from https://sendforme.co/account
```

Before running anything unattended, set a price limit and an undo window that fit: see [approvals and limits](/docs/approvals-and-limits).

## Calling the REST API from TypeScript

This is the simplest path when your code knows what to send. It previews the letter, checks for warnings, and sends it with an idempotency key so a retry never mails twice.

```typescript
const BASE = "https://sendforme.co";
const headers = {
  "Content-Type": "application/json",
  Authorization: `Bearer ${process.env.SENDFORME_KEY}`,
};

async function call(path: string, body: unknown, extra: Record<string, string> = {}) {
  const res = await fetch(`${BASE}${path}`, { method: "POST", headers: { ...headers, ...extra }, body: JSON.stringify(body) });
  const json = await res.json();
  return { status: res.status, json };
}

const preview = await call("/v1/letters/preview", {
  from: { company: "Ridgeline Print Co", line1: "220 Elm St", city: "Austin", state: "TX", zip: "78701" },
  to: { company: "Acme Corp", name: "Accounts Payable", line1: "1 Market St", city: "San Francisco", state: "CA", zip: "94105" },
  subject: "Invoice 1042, now 30 days past due",
  references: ["Invoice 1042", "PO 7781"],
  body: "Our records show **$2,340.00** for invoice 1042 is 30 days past due...",
  letterhead: "full",
  contact: { phone: "(512) 555-0142", email: "billing@ridgeline.example" },
  label: "Invoice 1042 reminder",
});
if (preview.status !== 200) throw new Error(preview.json.error);

const { letter_id, price, warnings, letter_url } = preview.json;
if (warnings.length) console.warn("Check before sending:", warnings);
console.log(`Proof: ${letter_url} (${price})`);

const sent = await call("/v1/letters", { letter_id }, { "Idempotency-Key": "invoice-1042-reminder-1" });
if (sent.status === 402) {
  // No credit (and no auto-reload): a person has to open the link.
  console.log("Needs setup:", sent.json.setup_url);
} else if (sent.json.status === "awaiting_approval") {
  // Approval mode or over the price limit.
  console.log("Waiting for approval:", sent.json.setup_url);
} else {
  console.log(`Scheduled ${sent.json.letter_id}, cancel until ${sent.json.cancel_until}`);
}
```

Follow it later with `GET /v1/letters/{letter_id}?wait=45`. Every endpoint is in the [REST API docs](/docs/rest-api).

## Claude Agent SDK (TypeScript)

Pass SendForMe in `mcpServers` and allow its tools.

```typescript
import { query } from "@anthropic-ai/claude-agent-sdk";

for await (const msg of query({
  prompt: "Mail a short thank-you letter to Ana Ruiz, 14 Oak Ln, Round Rock, TX 78664, from Jordan Park, 18 Birch Rd, Ames, IA 50010. Use the handwriting font.",
  options: {
    mcpServers: {
      sendforme: {
        type: "http",
        url: "https://sendforme.co/mcp",
        headers: { Authorization: `Bearer ${process.env.SENDFORME_KEY}` },
      },
    },
    allowedTools: ["mcp__sendforme__*"],
    maxTurns: 20,
  },
})) {
  if (msg.type === "result" && msg.subtype === "success") console.log(msg.result);
}
```

With `allowedTools` covering `send_letter`, the agent mails without asking. To review each letter, allow only the read-only tools, or set `approval: "each"` on the account.

## OpenAI Agents SDK (Python)

`MCPServerStreamableHttp` connects the server ([OpenAI Agents SDK MCP docs](https://openai.github.io/openai-agents-python/mcp/)).

```python
import asyncio, os
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp

async def main():
    async with MCPServerStreamableHttp(
        name="sendforme",
        params={
            "url": "https://sendforme.co/mcp",
            "headers": {"Authorization": f"Bearer {os.environ['SENDFORME_KEY']}"},
            "timeout": 60,
        },
        cache_tools_list=True,
    ) as sendforme:
        agent = Agent(
            name="Assistant",
            instructions="Use SendForMe to mail letters. Preview first and report the proof link and price.",
            mcp_servers=[sendforme],
        )
        result = await Runner.run(agent, "What would a 3-page certified letter with a return receipt cost? Preview one to check.", max_turns=20)
        print(result.final_output)

asyncio.run(main())
```

## Vercel AI SDK (TypeScript)

`createMCPClient` from `@ai-sdk/mcp` turns the server into tools ([AI SDK MCP docs](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools)).

```typescript
import { createMCPClient } from "@ai-sdk/mcp";
import { generateText, stepCountIs } from "ai";

const sendforme = await createMCPClient({
  transport: {
    type: "http",
    url: "https://sendforme.co/mcp",
    headers: { Authorization: `Bearer ${process.env.SENDFORME_KEY}` },
  },
});

try {
  const { text } = await generateText({
    model: "anthropic/claude-sonnet-5.5",
    tools: await sendforme.tools(),
    stopWhen: stepCountIs(20),
    prompt: "Check whether 900 Commerce St Ste 300, Dallas TX 75202 is deliverable, then preview a one-page letter to it.",
  });
  console.log(text);
} finally {
  await sendforme.close();
}
```

## Tips

- **Raise the step limit a little.** A letter is usually 2 to 5 tool calls: guide, preview, send, then a get. Set 20 or so.
- **Show the proof.** If a person is in the loop, put `letter_url` in front of them before sending.
- **Handle `needs_setup` and `awaiting_approval`.** Both return a link for a person. Turn on auto-reload on the account so sends don't stop for credit.
- **Use labels.** `label` names the letter in `list_letters` and on the account page.
- **Read `next_step`.** Every response says what to do next, in words a model can follow.

## Related

- [Automations: n8n, Zapier, cron](/agents/automations)
- [MCP reference](/docs/mcp)
- [Any other agent](/agents/any-agent)

## FAQ

### Should I use MCP or the REST API?

MCP when a model decides what to write and who to send it to. The REST API when your own code builds the letter (an invoice, a notice from a template) and the model isn't in the loop.

### Where do I get a key?

Send one letter from any chat agent to add credit, then sign in on the account page and make a key. It starts with sfm_.

### Can I test without mailing anything?

Yes. Previews are free and need no key. Build and check your letters with POST /v1/letters/preview; nothing is printed until you send.

### How do I keep my agent from mailing too much?

Set a per-letter price limit and a longer undo window on the account, or turn on approval for every letter. Letters over the limit return an approval link instead of going out.
