For developers
Give your agent money it can spend, and nothing more.
Three ways in: a TypeScript SDK, an MCP server and a command line. All three sign with the agent’s own key and send the request to a gateway, which is the only thing that talks to PayPal. Your agent never holds a PayPal credential.
SDK
First payment in twenty lines.
An owner seals an envelope. PayPal holds the money. The agent pays from it, and the receipt can be verified on any machine.
- One ES moduleno dependencies
- Typed end to endTypeScript strict
- Amounts"45.00", never a float
- Runs onNode 20+
The package is built from this repository (npm run sdk:pack) and is not on npm. The full guide is docs/SDK.md; a program with three agents is in examples/hire-an-agent.
import { Agent, Owner } from "@envelope/sdk";
const gateway = "http://localhost:3000";
const owner = await Owner.generate({ gateway, label: "Ada" });
const agent = await Agent.generate({ gateway, label: "ops-agent" });
// The owner signs the limits. PayPal places a hold for the whole amount.
const { chain, root } = await owner.seal({
to: agent.identity, limit: "50.00", perPayment: "20.00",
payees: ["designer@example.com"], purposes: ["design"], hours: 1,
});
await agent.hold(chain); // every signature checked here, back to the owner
// The agent pays. PayPal captures exactly this much and pays the payee.
const payment = await agent.pay({
amount: "12.50", payee: "designer@example.com", purpose: "design",
});
// Anyone can check the receipt without trusting the gateway.
const receipt = await agent.receipt(payment.spendId);
console.log(root.authorizationId, payment.paypal?.captureId);
console.log((await receipt.verify()).ok);try {
await agent.pay({
amount: "12.50", purpose: "design",
payee: "attacker@evil.example",
});
} catch (e) {
e.denied; // true: nothing moved
e.codes; // ["PAYEE_NOT_ALLOWED"]
}A refusal is an error with a reason code.
It comes from the gateway, by signatures and arithmetic. Nothing your code or its model does can turn it into a payment.
MCP server
Hand any model fifteen tools and a budget.
The server runs beside the model, holds the agent’s key on that machine and speaks MCP over stdio. Tools that only read are marked as such; tools that move money are marked too, so a client can ask a person first.
{
"mcpServers": {
"envelope": {
"command": "npx",
"args": ["tsx", "scripts/mcp.ts"],
"env": {
"GATEWAY": "http://localhost:3000",
"ENVELOPE_AGENT": "ops-agent"
}
}
}
}ENVELOPE_MCP_READ_ONLY=1 serves only the reading tools.
Read · moves nothing
envelope_show
What this agent may spend, and what is left at every level above it
envelope_balance
Its account: balance and ledger
envelope_card_list
The cards it has issued
envelope_introduce
A signed introduction a payee can check. Moves nothing
envelope_check_agent
Is another agent good for the money? Verified with the gateway and PayPal
envelope_receipt
A receipt, checked against PayPal and re-verified locally
Act · signed, then judged by the gateway
envelope_split
Cut a narrower envelope for another agent
envelope_pay
Pay a payee the envelope allows
envelope_promise
Set money aside for a payee before the work
envelope_keep
Pay what was set aside
envelope_accept
Sign that work was delivered, which releases its payment
envelope_transfer
Send money from its balance
envelope_refund
Give back a payment it was paid. PayPal refunds the payer
envelope_card_issue
Let one merchant charge its balance, within limits
envelope_card_cancel
End a card
Command line
The same calls, from a shell.
For agents that run commands, and for trying things by hand. The MCP server and the command line are both built on the SDK, so the three always agree.
# the agent's key, made and kept on its own disk
npx tsx scripts/agent.ts keygen ops-agent
# what it may spend, level by level
npx tsx scripts/agent.ts show --as ops-agent
# a narrower envelope for an agent it hires
npx tsx scripts/agent.ts split --as ops-agent --to helper \
--limit 30 --per 30 --payees designer@example.com --purposes design
npx tsx scripts/agent.ts pay --as helper --amount 12.50 \
--payee designer@example.com --purpose design
# asks PayPal through the gateway, and re-checks every signature here
npx tsx scripts/agent.ts receipt <payment id>Guardrails you do not have to build
What an agent using this cannot do, whatever its prompt says.
Spend more than its envelope, or any envelope above it
Every payment is debited at every level before PayPal is called.
Pay anyone the owner did not list
The payee list is signed by the owner. The SDK cannot edit it and the gateway reads it from the signature.
Give another agent more than it has
A wider envelope is refused before it is signed, and does not verify if signed by hand.
See or use PayPal credentials
Only the gateway holds them. The SDK has no PayPal code in it.
Approve its own request above the owner's threshold
That takes the owner's signature, made with a key the agent never has.
Send the same payment twice
A repeated request returns the first answer. PayPal is given the same idempotency key.
Sandbox only. The SDK has 19 tests against the gateway on the PayPal simulator, and its example program has run against the real PayPal sandbox (docs/evidence/sdk-run.md). The MCP server and command line have 13 tests that speak the real MCP protocol over stdio on the simulator; an earlier version of the MCP server was driven by a language model on the sandbox.