# Envlo agent setup

We have not published `@envlo/core` or `@envlo/mcp` to npm. Use the local monorepo. Paths below assume this site and the library are siblings:

- Library: `../envlo`
- Site: `../envlo.dev`

## Install, build, test

```bash
cd ../envlo
pnpm install
pnpm build
pnpm test
```

The library needs Node.js `>=22.12.0` and pnpm `>=10`. This site builds with Node.js `>=20`.

## MCP server on a laptop

```bash
cd ../envlo
pnpm --filter @envlo/mcp build
pnpm --filter @envlo/mcp exec envlo-mcp --local
```

`--local` opens three inbound paths and does not need a tunnel:

| Transport | Where |
| --- | --- |
| IMAP IDLE | `ENVLO_IMAP_*` (outbound through NAT). First connect defaults to `ENVLO_IMAP_FIRST_RUN=skip`. |
| Local SMTP | `127.0.0.1:1025` (`--smtp-port` to change) |
| Webhook | `POST http://127.0.0.1:8787/webhooks/inbound` — raw MIME, SES SNS, or Resend JSON |

Streamable HTTP without the local inbound bundle:

```bash
pnpm --filter @envlo/mcp exec envlo-mcp --http 8787
```

The MCP endpoint is `http://127.0.0.1:8787/mcp`.

## Tools

`create_inbox`, `wait_for_email`, `list_messages`, `read_thread`, `reply_to_thread`, `list_inboxes`, `send_email`, `forward_thread`.

`reply_to_thread`, `send_email`, and `forward_thread` are side effects. `filterToolsForRisk` holds them when the agent-visible injection risk is medium or high. The approval adapters (`SlackApprovalChannel`, `MagicLinkApprovalChannel`, `WebhookApprovalChannel`, `InteractiveCliApprovalChannel`) are how a person releases a pending draft.

## What the website imports

`envlo.dev` is a Vite app. It aliases `@core/*` to `../envlo/packages/core/src/*` and bundles these modules into the browser:

- `htmlToAgentMarkdown` — sanitize, flatten layout tables, estimate tokens (`compressionRatio`)
- `scoreInjectionRiskSync` and `filterToolsForRisk`
- `extractAuthSignals` — `extractedOtp` and `verificationUrl`
- `stripQuotedReply`, `unwrapForwarding`, `evaluateAttachmentAllowlist`, `policyForTier`
- `evaluateOutboundPolicy`, `evaluateApprovalRules`, and `RunawayLoopBreaker`
- `buildSlackApprovalBlocks`, `interpretSlackInteraction`, `handleSlackApprovalDecision`
- `MagicLinkApprovalChannel`, `handleMagicLinkHttpRequest`
- `WebhookApprovalChannel`, `handleWebhookApprovalRequest`
- `MemoryStateStore` and `ApprovalController`

Do not import `packages/core/src/index.ts` into a browser bundle. That barrel re-exports `store-sqlite`, `tokens-file`, and the local attachment store, which import `node:fs`.

## Sandbox inboxes

The Cloudflare worker in `packages/sandbox` serves ephemeral `@sandbox.envlo.dev` mailboxes. Local worker:

```bash
cd ../envlo
pnpm --filter @envlo/sandbox exec wrangler dev
```

`POST /v1/sandbox/inboxes` mints an inbox with no account. Free limits are 3 inboxes, a 2 hour TTL, and 100 inbound emails a day.
