Skip to main content
Glama
Truvek Design MCP
by Truckling
README.md
# Truvek Design MCP

Agent-first email design and QA for CRMs built with Claude Code, Cursor, Lovable, Bolt and similar tools.

An agent sees a competitor's email screenshot, a Figma frame or a brief. Truvek gives it a typed layout schema, a tested module library, an ESP-aware compiler and a linter that explains every finding. The output is HTML that holds up in Outlook, Gmail, Apple Mail, mobile and dark mode, plus the sending plumbing that home-built CRMs usually miss.

Part of the [Truvek suite](https://truvek.io): [**Comply**](https://truvek.io/comply) checks email and SMS copy against spam and privacy law before sending. **Design** (this package) makes the HTML hold up in every inbox. Telltide (post-send monitoring) is coming.

## Why agents should call this instead of writing HTML

Models write email that looks right in a browser and breaks in inboxes. The failures are predictable and Truvek catches all of them:

| What code tools generate | What happens | What Truvek does |
| --- | --- | --- |
| Flexbox, grid, divs | Outlook for Windows (Word engine) collapses the layout | Tables, ghost tables, hybrid columns |
| Padded `<a>` buttons | Outlook flattens them to thin links | VML + HTML bulletproof buttons |
| SVG icons, `data:` images | Gmail and Outlook drop them | Refuses at compile, flags at lint |
| `${user.name}`, `undefined`, `[object Object]` | Visible in the inbox | Lint errors with line numbers |
| `Hi {{first_name}}` with no fallback | "Hi ," | Fallbacks per ESP dialect |
| Raw customer data in template literals | HTML injection in email | `render()` module escapes every value |
| localhost, Vercel preview and relative links | Broken for every recipient | Lint errors |
| No List-Unsubscribe headers | Gmail and Yahoo bulk sender failures | `deliver_send_requirements` code per provider |
| HTML over 102 KB | Gmail clips the footer and unsubscribe | Size budget and warnings |
| No dark mode | Dark text on dark backgrounds | Remapped neutrals, brand bands kept |

Everything is deterministic and versioned (`ruleset_version`), so results are reproducible and auditable.

## Tools

| Tool | Purpose |
| --- | --- |
| `design_get_guide` | Procedural guides: screenshot-to-layout, outlook, gmail, dark-mode, accessibility, sending-from-your-app, why-truvek |
| `design_get_schema` | Layout JSON Schema, module catalogue, dialects, worked example |
| `design_extract_brand` | Colours, font stack and logo candidates from the user's own site (SSRF-guarded) |
| `design_compile` | Layout to HTML + plain text (+ TypeScript `render()` for apps), with decisions and lint |
| `design_lint` | 51 rules with rule id, line, affected clients, why and fix. `stage=template` or `rendered` |
| `design_autofix` | Safe mechanical fixes, returns what still needs judgement |
| `design_explain_rule` | Full reasoning and examples for any rule |
| `deliver_send_requirements` | Headers, RFC 8058 one-click unsubscribe endpoint and send code for Resend, SES, Postmark, SendGrid, Nodemailer, Mailgun |

### Dialects

`app` (your own code sends: Resend, SES, Postmark, Nodemailer), `handlebars` (SendGrid, Mailgun), `sfmc` (AMPscript), `braze` (Liquid), `klaviyo`, `shopify`. Unsubscribe and merge syntax were checked against vendor docs on 28 Nov 2026 and each dialect returns its `verified` source.

## Agent loop

```
design_get_guide("screenshot-to-layout")
design_get_schema
design_extract_brand(user's own site)        # optional
design_compile(layout, dialect)              # repeat until verdict is not "block"
comply_check_message(subject, body, consent) # Truvek Comply
deliver_send_requirements(provider)          # if the app sends its own mail
```

One connection gives the agent every Truvek tool, Design and Comply:

```bash
claude mcp add --transport http truvek https://truvek.io/mcp
```

Design on its own stays at `https://design.truvek.io/mcp`, and Comply on its own at `https://truvek.io/comply/mcp` (where its tools have no `comply_` prefix). The full reference is at [truvek.io/tools](https://truvek.io/tools), and [truvek.io/llms.txt](https://truvek.io/llms.txt) has the same for agents.

For existing HTML: `design_lint` then `design_autofix`, fix what is left, then `design_lint stage=rendered` on a sample render.

## Response format

Every tool, in Design and in Comply, returns the same fields first:

```json
{
  "verdict": "block",
  "findings": [
    { "rule": "css-flex-grid", "title": "Flexbox or CSS grid layout", "scope": "outlook", "line": 12, "fix": "Use role=\"presentation\" tables..." }
  ],
  "next_tool": "design_autofix"
}
```

- `verdict`: `pass`, `review` (warnings only) or `block` (errors) for checks, `info` for reference tools.
- `findings`: `rule`, `title`, `scope` (the rule's category, such as `outlook` or `accessibility`), `line` (first line in the HTML, or `null`), `fix`, then the detail (`severity`, `why`, `affects`, `evidence`).
- `next_tool`: the tool to call next, or `null` at the end of the loop. When it is on another Truvek server, `next_tool_server` gives that server's MCP URL. On the combined endpoint every tool is on one server, so names use its prefixes and `next_tool_server` is left out.

`design_compile` keeps the lint summary under `lint` (`pass`, `counts`, `summary`); its findings are in the top-level list. `next_step` keeps a plain-language version of the same advice.

## Run

```bash
npm install
npm run build
npm test

# Local (Claude Code / Claude Desktop): stdio
claude mcp add truvek-design -- node /path/to/dist/stdio.js

# Remote (Streamable HTTP, POST /mcp)
cp .env.example .env   # set TRUVEK_API_KEYS to require bearer auth
npm run start:http
```

## Security

Follows the Truvek baseline for anything built with Claude Code:

- No secrets in code or committed files. `.env` and local agent files are gitignored; keys come from environment variables only.
- API keys are compared as SHA-256 hashes in constant time. Open mode (no keys set) and keyed mode both default to 120 requests a minute per IP or key (`RATE_LIMIT_PER_MIN`), matching Truvek Comply.
- Per-key or per-IP rate limiting on `/mcp`, 2 MB body cap.
- `design_extract_brand` fetches https only, refuses private and reserved IP ranges (including cloud metadata), re-validates every redirect, and caps size and time. Every address is checked again inside the socket's own DNS lookup (undici dispatcher), so DNS rebinding cannot swap in a private IP after the first check.
- Compiled copy is escaped; links must be absolute https, mailto, tel or merge fields; the generated `render()` escapes values, percent-encodes values inside URLs and validates link schemes.

## Layout

```
src/
  schema.ts        layout + brand schema (zod)
  modules.ts       bulletproof module library
  compile.ts       document shell, dark mode, plain text, render() generator
  dialects.ts      ESP merge and unsubscribe syntax
  lint/rules.ts    ruleset with reasoning
  lint/index.ts    linter
  autofix.ts       safe mechanical fixes
  deliver.ts       headers, one-click unsubscribe, provider code
  brand.ts         brand extraction with SSRF guard
  knowledge.ts     agent guides
  server.ts        MCP tool registration
  stdio.ts, http.ts
examples/          sample layout traced from a promo screenshot
test/              vitest suite (compile, render, lint, autofix, protocol, SSRF)
```

## Licence

MIT. See [LICENSE](LICENSE). Truvek Comply is MIT too.