@mscode-pl/email-lint 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,24 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 MSCode
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
23
- Support data in data/caniemail.json comes from caniemail.com
24
- (https://github.com/hteumeuleu/caniemail), MIT License, Copyright (c) Rémi Parmentier.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MSCode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -6,11 +6,11 @@
6
6
  </p>
7
7
 
8
8
  <p align="center">
9
- <a href="https://www.npmjs.com/package/@mscode-pl/email-lint"><img src="https://img.shields.io/npm/v/@mscode-pl/email-lint?style=flat-square&color=1A5BB5" alt="npm version"></a>
10
- <a href="https://www.npmjs.com/package/@mscode-pl/email-lint"><img src="https://img.shields.io/npm/dm/@mscode-pl/email-lint?style=flat-square&color=1A5BB5" alt="npm downloads"></a>
11
- <a href="https://github.com/mscode-pl/email-lint/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/mscode-pl/email-lint/ci.yml?branch=master&style=flat-square&label=tests" alt="Tests"></a>
12
- <img src="https://img.shields.io/badge/node-22%2B-339933?style=flat-square" alt="Node 22+">
13
- <a href="LICENSE"><img src="https://img.shields.io/npm/l/@mscode-pl/email-lint?style=flat-square" alt="License"></a>
9
+ <a href="https://www.npmjs.com/package/@mscode-pl/email-lint"><img src="https://badges.mscode.pl/npm/v/@mscode-pl/email-lint" alt="npm version"></a>
10
+ <a href="https://www.npmjs.com/package/@mscode-pl/email-lint"><img src="https://badges.mscode.pl/npm/dm/@mscode-pl/email-lint" alt="npm downloads"></a>
11
+ <a href="https://github.com/mscode-pl/email-lint/actions/workflows/ci.yml"><img src="https://badges.mscode.pl/github/actions/mscode-pl/email-lint/ci.yml?branch=master&label=tests" alt="Tests"></a>
12
+ <img src="https://badges.mscode.pl/badge/node/22+/339933?icon=nodejs" alt="Node 22+">
13
+ <a href="LICENSE"><img src="https://badges.mscode.pl/npm/l/@mscode-pl/email-lint" alt="License"></a>
14
14
  </p>
15
15
 
16
16
  <p align="center">
@@ -57,6 +57,7 @@ caniemail.com already tracks which client supports what. email-lint applies that
57
57
  | **Outlook conditionals understood** | Content inside `<!--[if !mso]><!-->` is hidden from Outlook for Windows, so it is not blamed for it. That is the hybrid layout most email frameworks generate. |
58
58
  | **Low noise by default** | `<body>`, `<style>`, tables, class selectors, `role` and `aria-*` are not reported, because the only fix would be removing them. `--strict` shows everything. |
59
59
  | **Reports you can share** | Markdown for a pull request, JSON for scripts, GitHub annotations on the pull request. |
60
+ | **GitHub Action and MCP server** | One pull request comment that updates itself, and two tools your AI agent can call while it writes the email. |
60
61
 
61
62
  ## Works with your stack
62
63
 
@@ -106,10 +107,51 @@ Commit a config file so everyone on the team runs the same check:
106
107
 
107
108
  Save it as `email-lint.config.json`, and `email-lint` with no arguments uses it. The interactive mode can write it for you.
108
109
 
109
- In GitHub Actions, `--format github` turns every finding into an annotation on the pull request:
110
+ ### GitHub Action
111
+
112
+ The action marks every finding on the line it is on in the pull request diff, and posts the full report as one comment that it updates on every push instead of adding a new one. When the issues are fixed, the comment says so.
110
113
 
111
114
  ```yaml
112
- - run: npx @mscode-pl/email-lint --format github
115
+ name: Emails
116
+
117
+ on: pull_request
118
+
119
+ permissions:
120
+ contents: read
121
+ pull-requests: write
122
+
123
+ jobs:
124
+ email-lint:
125
+ runs-on: ubuntu-latest
126
+ steps:
127
+ - uses: actions/checkout@v4
128
+ # Build your templates first, e.g. npx email export --outDir out
129
+ - uses: mscode-pl/email-lint@v1
130
+ with:
131
+ files: out
132
+ clients: gmail,outlook,apple-mail
133
+ ```
134
+
135
+ | Input | Default | |
136
+ | --- | --- | --- |
137
+ | `files` | `files` from the config | Files, folders or globs, separated by spaces or new lines |
138
+ | `clients` | config, then the defaults | Comma separated, e.g. `gmail,outlook.windows` |
139
+ | `ignore` | | Feature slugs to skip, comma separated |
140
+ | `strict` | `false` | Also report baseline features |
141
+ | `fail-on` | config, then `error` | `error`, `warning` or `never` |
142
+ | `config` | `email-lint.config.json` | Config file to read |
143
+ | `comment` | `true` | Post the report as a pull request comment |
144
+ | `github-token` | `github.token` | Token for the comment |
145
+ | `version` | the action's release | email-lint version from npm |
146
+
147
+ Outputs: `report` (path to the Markdown report, also shown in the job summary) and `exit-code`. The step needs Node 22; on an older runner the action installs it. Pull requests from forks get a read-only token, so they get the annotations and the job summary but no comment. GitHub shows at most 10 annotations of each level per step, and the comment lists the rest.
148
+
149
+ ### Any other CI
150
+
151
+ `--format github` prints GitHub annotations, `-o report.md` saves a Markdown report:
152
+
153
+ ```yaml
154
+ - run: npx @mscode-pl/email-lint --format github -o email-report.md
113
155
  ```
114
156
 
115
157
  The exit code is `1` when there are errors (or warnings with `--fail-on warning`), `0` otherwise, and `2` for bad arguments or no matching files.
@@ -144,6 +186,40 @@ for (const issue of issues) {
144
186
 
145
187
  ## Use it from an AI agent
146
188
 
189
+ ### MCP server
190
+
191
+ `email-lint mcp` starts an [MCP](https://modelcontextprotocol.io) server on stdio, so Claude, Cursor, VS Code and other MCP clients can check a template while they write it. It has two read-only tools:
192
+
193
+ | Tool | What it does |
194
+ | --- | --- |
195
+ | `lint_email` | Lints `html` passed inline or a `path` (file, folder or glob) and returns every issue with its line, the affected clients and caniemail's notes. With neither, it lints the files from `email-lint.config.json`. |
196
+ | `explain_feature` | For one slug, says which clients lack support, whether that breaks the email or only drops decoration, and how to fix it. |
197
+
198
+ Paths are relative to the folder the client starts the server in, usually your project, and `email-lint.config.json` there sets the default clients and ignored features.
199
+
200
+ Claude Code:
201
+
202
+ ```bash
203
+ claude mcp add email-lint -- npx -y @mscode-pl/email-lint mcp
204
+ ```
205
+
206
+ Cursor, VS Code, Claude Desktop and others take the same command in their MCP config:
207
+
208
+ ```json
209
+ {
210
+ "mcpServers": {
211
+ "email-lint": {
212
+ "command": "npx",
213
+ "args": ["-y", "@mscode-pl/email-lint", "mcp"]
214
+ }
215
+ }
216
+ }
217
+ ```
218
+
219
+ To lint a folder that is named `mcp`, write it as `./mcp`.
220
+
221
+ ### Agent Skill
222
+
147
223
  The repo ships an [Agent Skill](skills/email-lint/SKILL.md) for Claude Code, Codex, Cursor and other agents. It runs email-lint on your templates, sorts the findings into must-fix and acceptable degradation, and proposes fixes in your source files (a table instead of flexbox, VML for rounded Outlook buttons, PNG instead of WebP).
148
224
 
149
225
  ```bash
@@ -176,7 +252,7 @@ pnpm build && node dist/cli/main.js examples
176
252
 
177
253
  ## License
178
254
 
179
- MIT. Support data from [caniemail](https://github.com/hteumeuleu/caniemail) by Rémi Parmentier, MIT License.
255
+ MIT. Support data from [caniemail](https://github.com/hteumeuleu/caniemail) by Rémi Parmentier, MIT License, see [data/LICENSE-caniemail](data/LICENSE-caniemail).
180
256
 
181
257
  ---
182
258
 
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Rémi Parmentier
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/cli/main.js CHANGED
@@ -11,6 +11,7 @@ import { resolveFiles } from './files.js';
11
11
  import { FORMATS, formatFromPath, onlyErrors, render } from './format.js';
12
12
  import { runInteractive } from './interactive.js';
13
13
  const HELP = `Usage: email-lint [files, folders or globs...] [options]
14
+ email-lint mcp Start an MCP server on stdio for AI agents
14
15
 
15
16
  Checks email HTML against caniemail.com support data.
16
17
  Run without arguments in a terminal for an interactive mode.
@@ -49,6 +50,11 @@ function version() {
49
50
  return `${pkg.version} (caniemail data: ${loadDataset().last_update_date})`;
50
51
  }
51
52
  async function main() {
53
+ if (process.argv[2] === 'mcp' && process.argv.length === 3) {
54
+ const { serve } = await import('../mcp/server.js');
55
+ await serve();
56
+ return 0;
57
+ }
52
58
  const { values, positionals } = parseArgs({
53
59
  allowPositionals: true,
54
60
  options: {
@@ -0,0 +1,16 @@
1
+ export type FixKind = 'must-fix' | 'degradation';
2
+ export interface Fix {
3
+ kind: FixKind;
4
+ text: string;
5
+ }
6
+ interface FixTable {
7
+ rows: {
8
+ pattern: RegExp;
9
+ fix: Fix;
10
+ }[];
11
+ fallback: string;
12
+ }
13
+ export declare function parseFixes(markdown: string): FixTable;
14
+ export declare function findFix(slug: string): Fix | undefined;
15
+ export declare function fallbackAdvice(): string;
16
+ export {};
@@ -0,0 +1,48 @@
1
+ import { readFileSync } from 'node:fs';
2
+ let cached;
3
+ export function parseFixes(markdown) {
4
+ const rows = [];
5
+ const fallback = [];
6
+ let section;
7
+ for (const line of markdown.split(/\r?\n/)) {
8
+ const heading = line.match(/^## (.+)$/);
9
+ if (heading) {
10
+ const title = heading[1].toLowerCase();
11
+ section = title.startsWith('must fix')
12
+ ? 'must-fix'
13
+ : title.startsWith('acceptable')
14
+ ? 'degradation'
15
+ : title.startsWith('anything not listed')
16
+ ? 'fallback'
17
+ : undefined;
18
+ continue;
19
+ }
20
+ if (section === 'fallback') {
21
+ if (line.trim())
22
+ fallback.push(line.trim());
23
+ continue;
24
+ }
25
+ if (!section || !line.startsWith('|'))
26
+ continue;
27
+ const [first, ...rest] = line.slice(1, line.lastIndexOf('|')).split('|');
28
+ const slugs = [...first.matchAll(/`([^`]+)`/g)].map((m) => m[1]);
29
+ const text = rest.join('|').trim();
30
+ if (!slugs.length || !text)
31
+ continue;
32
+ for (const slug of slugs) {
33
+ const source = slug.replace(/[.+?^${}()[\]\\]/g, '\\$&').replaceAll('*', '.*');
34
+ rows.push({ pattern: new RegExp(`^${source}$`), fix: { kind: section, text } });
35
+ }
36
+ }
37
+ return { rows, fallback: fallback.join(' ') };
38
+ }
39
+ function table() {
40
+ cached ??= parseFixes(readFileSync(new URL('../../skills/email-lint/references/fixes.md', import.meta.url), 'utf8'));
41
+ return cached;
42
+ }
43
+ export function findFix(slug) {
44
+ return table().rows.find((row) => row.pattern.test(slug))?.fix;
45
+ }
46
+ export function fallbackAdvice() {
47
+ return table().fallback;
48
+ }
@@ -0,0 +1,19 @@
1
+ export declare const PROTOCOL_VERSIONS: string[];
2
+ type Id = string | number | null;
3
+ interface JsonRpcError {
4
+ code: number;
5
+ message: string;
6
+ }
7
+ export type Response = {
8
+ jsonrpc: '2.0';
9
+ id: Id;
10
+ result: unknown;
11
+ } | {
12
+ jsonrpc: '2.0';
13
+ id: Id;
14
+ error: JsonRpcError;
15
+ };
16
+ export declare function handle(message: unknown): Promise<Response | Response[] | undefined>;
17
+ export declare function handleLine(line: string): Promise<Response | Response[] | undefined>;
18
+ export declare function serve(input?: NodeJS.ReadableStream, output?: Pick<NodeJS.WritableStream, 'write'>): Promise<void>;
19
+ export {};
@@ -0,0 +1,118 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { createInterface } from 'node:readline';
3
+ import { callTool, ToolInputError, TOOLS } from './tools.js';
4
+ // Newest first. The tools use nothing that differs between these versions.
5
+ export const PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
6
+ const PARSE_ERROR = -32700;
7
+ const INVALID_REQUEST = -32600;
8
+ const METHOD_NOT_FOUND = -32601;
9
+ const INVALID_PARAMS = -32602;
10
+ class RpcError extends Error {
11
+ code;
12
+ constructor(code, message) {
13
+ super(message);
14
+ this.code = code;
15
+ }
16
+ }
17
+ function packageVersion() {
18
+ const pkg = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
19
+ return pkg.version;
20
+ }
21
+ const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
22
+ async function dispatch(method, params) {
23
+ switch (method) {
24
+ case 'initialize': {
25
+ const requested = params.protocolVersion;
26
+ return {
27
+ protocolVersion: typeof requested === 'string' && PROTOCOL_VERSIONS.includes(requested)
28
+ ? requested
29
+ : PROTOCOL_VERSIONS[0],
30
+ capabilities: { tools: { listChanged: false } },
31
+ serverInfo: { name: 'email-lint', title: 'email-lint', version: packageVersion() },
32
+ instructions: 'Checks rendered email HTML against caniemail.com data. Call lint_email on the built HTML, then explain_feature for each issue that affects clients the audience uses. Fix layout breakage first; decoration that a client drops is acceptable.',
33
+ };
34
+ }
35
+ case 'ping':
36
+ return {};
37
+ case 'tools/list':
38
+ return { tools: TOOLS };
39
+ case 'tools/call': {
40
+ if (typeof params.name !== 'string')
41
+ throw new RpcError(INVALID_PARAMS, '"name" must be a string.');
42
+ const args = params.arguments ?? {};
43
+ if (!isObject(args))
44
+ throw new RpcError(INVALID_PARAMS, '"arguments" must be an object.');
45
+ try {
46
+ return await callTool(params.name, args);
47
+ }
48
+ catch (error) {
49
+ if (error instanceof ToolInputError)
50
+ throw new RpcError(INVALID_PARAMS, error.message);
51
+ throw error;
52
+ }
53
+ }
54
+ default:
55
+ throw new RpcError(METHOD_NOT_FOUND, `Method not found: ${method}`);
56
+ }
57
+ }
58
+ async function handleOne(message) {
59
+ if (!isObject(message) || message.jsonrpc !== '2.0' || typeof message.method !== 'string') {
60
+ const id = isObject(message) && (typeof message.id === 'string' || typeof message.id === 'number') ? message.id : null;
61
+ // Responses from the client (to requests this server never sends) are ignored.
62
+ if (isObject(message) && ('result' in message || 'error' in message))
63
+ return undefined;
64
+ return { jsonrpc: '2.0', id, error: { code: INVALID_REQUEST, message: 'Invalid request.' } };
65
+ }
66
+ const isNotification = !('id' in message);
67
+ const id = (message.id ?? null);
68
+ const params = isObject(message.params) ? message.params : {};
69
+ try {
70
+ const result = await dispatch(message.method, params);
71
+ return isNotification ? undefined : { jsonrpc: '2.0', id, result };
72
+ }
73
+ catch (error) {
74
+ if (isNotification)
75
+ return undefined;
76
+ const code = error instanceof RpcError ? error.code : -32603;
77
+ const text = error instanceof Error ? error.message : String(error);
78
+ return { jsonrpc: '2.0', id, error: { code, message: text } };
79
+ }
80
+ }
81
+ export async function handle(message) {
82
+ if (!Array.isArray(message))
83
+ return handleOne(message);
84
+ if (!message.length) {
85
+ return { jsonrpc: '2.0', id: null, error: { code: INVALID_REQUEST, message: 'Empty batch.' } };
86
+ }
87
+ const responses = (await Promise.all(message.map(handleOne))).filter((r) => r !== undefined);
88
+ return responses.length ? responses : undefined;
89
+ }
90
+ export async function handleLine(line) {
91
+ if (!line.trim())
92
+ return undefined;
93
+ let message;
94
+ try {
95
+ message = JSON.parse(line);
96
+ }
97
+ catch {
98
+ return { jsonrpc: '2.0', id: null, error: { code: PARSE_ERROR, message: 'Parse error.' } };
99
+ }
100
+ return handle(message);
101
+ }
102
+ export function serve(input = process.stdin, output = process.stdout) {
103
+ const pending = new Set();
104
+ const lines = createInterface({ input, crlfDelay: Infinity });
105
+ lines.on('line', (line) => {
106
+ const task = handleLine(line).then((response) => {
107
+ if (response)
108
+ output.write(`${JSON.stringify(response)}\n`);
109
+ });
110
+ pending.add(task);
111
+ void task.finally(() => pending.delete(task));
112
+ });
113
+ return new Promise((resolve) => {
114
+ lines.on('close', () => {
115
+ void Promise.allSettled([...pending]).then(() => resolve());
116
+ });
117
+ });
118
+ }
@@ -0,0 +1,83 @@
1
+ export interface ToolResult {
2
+ content: {
3
+ type: 'text';
4
+ text: string;
5
+ }[];
6
+ isError?: boolean;
7
+ }
8
+ export declare class ToolInputError extends Error {
9
+ }
10
+ export declare const TOOLS: ({
11
+ name: string;
12
+ title: string;
13
+ description: string;
14
+ inputSchema: {
15
+ type: string;
16
+ properties: {
17
+ html: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ path: {
22
+ type: string;
23
+ description: string;
24
+ };
25
+ clients: {
26
+ type: string;
27
+ items: {
28
+ type: string;
29
+ };
30
+ description: string;
31
+ };
32
+ ignore: {
33
+ type: string;
34
+ items: {
35
+ type: string;
36
+ };
37
+ description: string;
38
+ };
39
+ strict: {
40
+ type: string;
41
+ description: string;
42
+ };
43
+ slug?: undefined;
44
+ };
45
+ additionalProperties: boolean;
46
+ required?: undefined;
47
+ };
48
+ annotations: {
49
+ readOnlyHint: boolean;
50
+ openWorldHint: boolean;
51
+ };
52
+ } | {
53
+ name: string;
54
+ title: string;
55
+ description: string;
56
+ inputSchema: {
57
+ type: string;
58
+ properties: {
59
+ slug: {
60
+ type: string;
61
+ description: string;
62
+ };
63
+ clients: {
64
+ type: string;
65
+ items: {
66
+ type: string;
67
+ };
68
+ description: string;
69
+ };
70
+ html?: undefined;
71
+ path?: undefined;
72
+ ignore?: undefined;
73
+ strict?: undefined;
74
+ };
75
+ required: string[];
76
+ additionalProperties: boolean;
77
+ };
78
+ annotations: {
79
+ readOnlyHint: boolean;
80
+ openWorldHint: boolean;
81
+ };
82
+ })[];
83
+ export declare function callTool(name: string, args: Record<string, unknown>): Promise<ToolResult>;
@@ -0,0 +1,161 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { painter } from '../cli/colors.js';
3
+ import { loadConfig } from '../cli/config.js';
4
+ import { resolveFiles } from '../cli/files.js';
5
+ import { formatText, groupClients } from '../cli/format.js';
6
+ import { DEFAULT_CLIENTS, parseClients, unsupportedClients } from '../core/clients.js';
7
+ import { loadDataset } from '../core/data.js';
8
+ import { lint } from '../core/lint.js';
9
+ import { fallbackAdvice, findFix } from './fixes.js';
10
+ export class ToolInputError extends Error {
11
+ }
12
+ const CLIENTS_DESCRIPTION = 'Email clients to check: a family (gmail, outlook, apple-mail, yahoo, samsung-email, thunderbird, protonmail, wp-pl, ...), a family and platform (outlook.windows) or "all". Defaults to email-lint.config.json, then to ' +
13
+ `${DEFAULT_CLIENTS.join(', ')}. Pass only clients the audience of the email uses.`;
14
+ export const TOOLS = [
15
+ {
16
+ name: 'lint_email',
17
+ title: 'Lint email HTML',
18
+ description: 'Check email HTML against caniemail.com support data and list the CSS and HTML features that Outlook, Gmail, Apple Mail and other clients do not support, with line numbers, affected clients and caniemail notes. Pass rendered HTML (React Email, MJML and Maizzle must be built first; laravel-react-email Blade output and plain HTML can be linted directly). With neither html nor path, lints the files from email-lint.config.json. Follow up with explain_feature for a fix.',
19
+ inputSchema: {
20
+ type: 'object',
21
+ properties: {
22
+ html: { type: 'string', description: 'Email HTML to check. Use this or path.' },
23
+ path: {
24
+ type: 'string',
25
+ description: 'File, folder or glob relative to the working directory, e.g. "emails/out" or "resources/views/react-email/**/*.blade.php". Folders are searched for .html and .htm files. Use this or html.',
26
+ },
27
+ clients: { type: 'array', items: { type: 'string' }, description: CLIENTS_DESCRIPTION },
28
+ ignore: {
29
+ type: 'array',
30
+ items: { type: 'string' },
31
+ description: 'Feature slugs to skip, e.g. ["css-border-radius"].',
32
+ },
33
+ strict: {
34
+ type: 'boolean',
35
+ description: 'Also report baseline features every email needs (doctype, <style>, class selectors) and Gmail in a mobile browser. Leave off unless a full audit is asked for.',
36
+ },
37
+ },
38
+ additionalProperties: false,
39
+ },
40
+ annotations: { readOnlyHint: true, openWorldHint: false },
41
+ },
42
+ {
43
+ name: 'explain_feature',
44
+ title: 'Explain an email feature',
45
+ description: 'Explain one feature reported by lint_email: which clients lack support, the caniemail notes, whether it breaks the email (must fix) or only drops decoration (acceptable degradation), and how to fix it.',
46
+ inputSchema: {
47
+ type: 'object',
48
+ properties: {
49
+ slug: { type: 'string', description: 'Feature slug from lint_email, e.g. "css-display-flex".' },
50
+ clients: { type: 'array', items: { type: 'string' }, description: CLIENTS_DESCRIPTION },
51
+ },
52
+ required: ['slug'],
53
+ additionalProperties: false,
54
+ },
55
+ annotations: { readOnlyHint: true, openWorldHint: false },
56
+ },
57
+ ];
58
+ const text = (value, extra = {}) => ({
59
+ content: [{ type: 'text', text: value }],
60
+ ...extra,
61
+ });
62
+ function optionalString(args, key) {
63
+ const value = args[key];
64
+ if (value === undefined)
65
+ return undefined;
66
+ if (typeof value !== 'string' || !value.trim())
67
+ throw new ToolInputError(`"${key}" must be a non-empty string.`);
68
+ return value;
69
+ }
70
+ function optionalList(args, key) {
71
+ const value = args[key];
72
+ if (value === undefined)
73
+ return undefined;
74
+ if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
75
+ throw new ToolInputError(`"${key}" must be an array of strings.`);
76
+ }
77
+ return value;
78
+ }
79
+ async function lintEmail(args) {
80
+ const html = optionalString(args, 'html');
81
+ const path = optionalString(args, 'path');
82
+ if (html && path)
83
+ throw new ToolInputError('Pass either "html" or "path", not both.');
84
+ if (args.strict !== undefined && typeof args.strict !== 'boolean') {
85
+ throw new ToolInputError('"strict" must be true or false.');
86
+ }
87
+ const config = await loadConfig();
88
+ const options = {
89
+ clients: optionalList(args, 'clients') ?? config.clients,
90
+ ignore: optionalList(args, 'ignore') ?? config.ignore,
91
+ strict: args.strict ?? config.strict,
92
+ };
93
+ const results = [];
94
+ if (html) {
95
+ results.push({ file: '<html>', ...lint(html, options) });
96
+ }
97
+ else {
98
+ const patterns = path ? [path] : (config.files ?? []);
99
+ if (!patterns.length) {
100
+ throw new ToolInputError('Pass "html" or "path". There is no email-lint.config.json with "files" to fall back on.');
101
+ }
102
+ const files = await resolveFiles(patterns);
103
+ if (!files.length) {
104
+ throw new ToolInputError(`No HTML files found for ${patterns.join(' ')} in ${process.cwd()}.`);
105
+ }
106
+ for (const file of files)
107
+ results.push({ file, ...lint(await readFile(file, 'utf8'), options) });
108
+ }
109
+ return text(formatText(results, { verbose: true, paint: painter(false) }));
110
+ }
111
+ async function explainFeature(args) {
112
+ const slug = optionalString(args, 'slug');
113
+ if (!slug)
114
+ throw new ToolInputError('"slug" is required.');
115
+ const dataset = loadDataset();
116
+ const feature = dataset.data.find((f) => f.slug === slug);
117
+ if (!feature) {
118
+ const words = slug.split('-').filter((w) => w.length > 2 && !['css', 'html'].includes(w));
119
+ const similar = dataset.data
120
+ .filter((f) => words.some((w) => f.slug.includes(w)))
121
+ .slice(0, 8)
122
+ .map((f) => f.slug);
123
+ throw new ToolInputError(`Unknown feature "${slug}".${similar.length ? ` Similar: ${similar.join(', ')}.` : ''}`);
124
+ }
125
+ const config = await loadConfig();
126
+ const selection = parseClients(optionalList(args, 'clients') ?? config.clients, dataset, config.strict);
127
+ const clients = unsupportedClients(feature, dataset, selection);
128
+ const unsupported = groupClients(clients, 'unsupported');
129
+ const partial = groupClients(clients, 'partial');
130
+ const notes = [...new Set(clients.flatMap((c) => c.notes))];
131
+ const fix = findFix(slug);
132
+ const out = [`${feature.title.trim()} (${slug})`, feature.url, ''];
133
+ if (!clients.length)
134
+ out.push('Supported in every selected client.');
135
+ if (unsupported)
136
+ out.push(`Not supported: ${unsupported}`);
137
+ if (partial)
138
+ out.push(`Partial support: ${partial}`);
139
+ if (notes.length)
140
+ out.push('', 'Notes:', ...notes.map((n) => `- ${n}`));
141
+ out.push('');
142
+ if (fix?.kind === 'must-fix')
143
+ out.push('Must fix: the email breaks or loses content without support.', fix.text);
144
+ else if (fix)
145
+ out.push('Acceptable degradation: only decoration is lost without support.', fix.text);
146
+ else
147
+ out.push('No stock fix for this feature.', fallbackAdvice());
148
+ return text(out.join('\n'));
149
+ }
150
+ export async function callTool(name, args) {
151
+ try {
152
+ if (name === 'lint_email')
153
+ return await lintEmail(args);
154
+ if (name === 'explain_feature')
155
+ return await explainFeature(args);
156
+ }
157
+ catch (error) {
158
+ return text(error instanceof Error ? error.message : String(error), { isError: true });
159
+ }
160
+ throw new ToolInputError(`Unknown tool "${name}".`);
161
+ }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@mscode-pl/email-lint",
3
- "version": "0.1.0",
4
- "description": "Find the CSS and HTML in your emails that Outlook, Gmail, Apple Mail and other clients will break, with line numbers. Works with React Email, MJML, Maizzle, Laravel and plain HTML.",
3
+ "version": "0.2.1",
4
+ "description": "Find the CSS and HTML in your emails that Outlook, Gmail, Apple Mail and other clients will break, with line numbers. Ships an MCP server and a GitHub Action. Works with React Email, MJML, Maizzle, Laravel and plain HTML.",
5
+ "mcpName": "io.github.mscode-pl/email-lint",
5
6
  "license": "MIT",
6
7
  "author": "MSCode (https://mscode.pl)",
7
8
  "type": "module",
@@ -22,7 +23,10 @@
22
23
  "react-email",
23
24
  "mjml",
24
25
  "maizzle",
25
- "cli"
26
+ "cli",
27
+ "mcp",
28
+ "mcp-server",
29
+ "github-action"
26
30
  ],
27
31
  "bin": {
28
32
  "email-lint": "dist/cli/main.js"
@@ -35,7 +39,8 @@
35
39
  },
36
40
  "files": [
37
41
  "dist",
38
- "data"
42
+ "data",
43
+ "skills"
39
44
  ],
40
45
  "engines": {
41
46
  "node": ">=22"
@@ -0,0 +1,68 @@
1
+ ---
2
+ name: email-lint
3
+ description: Review HTML email templates for email client compatibility with email-lint and the caniemail.com dataset, then propose concrete fixes. Use when the user asks whether an email will render in Outlook, Gmail, Apple Mail or Yahoo, wants an email template reviewed or audited, or is building emails with React Email, MJML, Maizzle, Laravel Blade or plain HTML.
4
+ ---
5
+
6
+ # email-lint review
7
+
8
+ email-lint reports which CSS and HTML features in an email are unsupported or only partly supported in each email client, with line numbers. Your job is to run it, decide which findings matter, and propose fixes in the template source.
9
+
10
+ ## 1. Get HTML to lint
11
+
12
+ email-lint reads rendered HTML. Find the templates and render them if needed:
13
+
14
+ | Stack | How to get HTML |
15
+ | --- | --- |
16
+ | Plain HTML | Lint the files directly |
17
+ | React Email | `npx email export --outDir .email-lint-out`, then lint `.email-lint-out` |
18
+ | MJML | `npx mjml "emails/**/*.mjml" -o .email-lint-out/`, then lint `.email-lint-out` |
19
+ | Maizzle | `npx maizzle build production`, then lint the output folder from `config.production.js` |
20
+ | laravel-react-email | `php artisan react-email:build`, then lint `"resources/views/react-email/**/*.blade.php"` |
21
+ | Other Laravel mailables | Render with `(new App\Mail\Welcome(...))->render()` in `php artisan tinker`, save to a `.html` file |
22
+
23
+ Blade syntax (`{{ }}`, `@if`) is read as text and does not cause false reports. Delete any output folder you created once the review is done.
24
+
25
+ ## 2. Run the linter
26
+
27
+ If the `lint_email` and `explain_feature` tools from the email-lint MCP server are available, use them instead of the command below: `lint_email` takes the same `clients`, `ignore` and `strict` options plus `html` or `path`, and `explain_feature` returns the fix for one slug.
28
+
29
+ ```bash
30
+ npx -y @mscode-pl/email-lint <files, folders or globs> --format json
31
+ ```
32
+
33
+ - If the user named their audience ("our customers use Outlook at work"), pass `--clients`, e.g. `--clients outlook,gmail`. Valid values: a family (`gmail`, `outlook`, `apple-mail`, `yahoo`, `samsung-email`, `thunderbird`, `protonmail`, `wp-pl`, ...), a family and platform (`outlook.windows`), or `all`.
34
+ - Without `--strict`, features every email needs (doctype, `<body>`, `<style>`, tables, class selectors, generic `@media`, `role`/`aria-*`) and Gmail in a mobile browser are skipped. Leave it that way unless the user asks for a full audit.
35
+ - Exit code 1 means errors were found, which is expected during a review. Exit code 2 means bad arguments or no files matched.
36
+
37
+ The JSON is an array with one entry per file:
38
+
39
+ ```
40
+ { file, errors, warnings, parseErrors: [{ line, message }],
41
+ issues: [{ slug, title, url, level, lines,
42
+ clients: [{ family, platform, familyName, platformName, status, notes }] }] }
43
+ ```
44
+
45
+ `level` is `error` when at least one selected client does not support the feature, `warning` when support is partial. Always read `notes`: they often say the real limitation (for example "not supported with non Google accounts" or "only on `<td>`").
46
+
47
+ ## 3. Triage
48
+
49
+ Open [references/fixes.md](references/fixes.md) and sort every issue into one of two groups:
50
+
51
+ - **Must fix**: the email breaks or loses content in a client the user cares about (layout collapses, images do not show, text is unreadable).
52
+ - **Acceptable degradation**: the client drops a visual extra and the email still works (rounded corners, shadows, hover effects, animation, dark mode tweaks). Name it, but do not push the user to remove it.
53
+
54
+ An issue is only worth raising if it affects a client the user's audience uses. Outlook for Windows matters for B2B senders, much less for a consumer newsletter.
55
+
56
+ ## 4. Report
57
+
58
+ Per template, list must-fix issues first, then acceptable degradation, then parse errors. For each issue give:
59
+
60
+ - the feature and where it is used (source file and line, not only the built file)
61
+ - which clients are affected, grouped by family
62
+ - the fix from `references/fixes.md`, adapted to the user's stack (a React Email component, an MJML tag, a Tailwind class)
63
+
64
+ Keep it short. Do not repeat the caniemail notes word for word when one sentence covers them; link the `url` for details.
65
+
66
+ ## 5. Fixing
67
+
68
+ Edit only when the user asks. Fix the source template (`.tsx`, `.mjml`, `.blade.php`), never the generated HTML, then rebuild and run email-lint again to confirm the issue is gone. If a fix needs VML or MSO conditional comments, say that it can only be verified by rendering in Outlook for Windows (Litmus, Email on Acid, or a real client).
@@ -0,0 +1,58 @@
1
+ # Fixes by feature
2
+
3
+ Keyed by the `slug` email-lint reports. "Outlook" without a platform means Outlook for Windows (Word rendering engine), the client behind most layout breakage.
4
+
5
+ ## Must fix
6
+
7
+ ### Layout
8
+
9
+ | Slug | Fix |
10
+ | --- | --- |
11
+ | `css-display-flex`, `css-display-grid`, `css-flex-direction`, `css-flex-wrap`, `css-gap`, `css-grid-template` | Build the layout with `<table role="presentation">` and `<td>` columns. Replace `gap` with padding on the cells or an empty spacer `<td>`. For columns that stack on mobile, use inline-block `<div>`s wrapped in an MSO conditional table (the "hybrid" or "fluid" pattern). |
12
+ | `css-max-width` | Outlook ignores it on `<div>`. Keep the `max-width` and add a fixed-width ghost table around the content: `<!--[if mso]><table role="presentation" width="600"><tr><td><![endif]-->` ... `<!--[if mso]></td></tr></table><![endif]-->`. |
13
+ | `css-margin`, `css-padding` | Outlook applies them unreliably on `<div>` and `<p>`. Put spacing as `padding` on a `<td>`. |
14
+ | `css-width`, `css-height` | Partial in Outlook on `<div>`, `<p>` and `<img>`. Set sizes with the `width`/`height` HTML attributes on `<img>` and `<td>`, keep CSS for other clients. |
15
+ | `css-float` | Use table cells, or the `align` attribute on `<table>`/`<img>`. |
16
+ | `css-position`, `css-left-right-top-bottom`, `css-inset` | No reliable support. Rebuild the overlap with tables, or bake it into an image. |
17
+ | `css-unit-calc` | Replace with a fixed `px` or `%` value. |
18
+ | `css-unit-rem`, `css-unit-vw`, `css-unit-vh` | Convert to `px`. With Tailwind, use a theme whose spacing and font sizes are in `px`. |
19
+ | `css-variables` | Inline the resolved values. Most email builders and Tailwind configs can do this at build time. |
20
+
21
+ ### Images and media
22
+
23
+ | Slug | Fix |
24
+ | --- | --- |
25
+ | `image-webp`, `image-avif`, `image-heif` | Serve PNG or JPG. |
26
+ | `image-svg`, `html-svg` | Export to PNG at 2x resolution and set the display size with the `width` attribute. |
27
+ | `image-base64` | Host the image and link it by URL. Several clients block or strip data URIs. |
28
+ | `css-background-image` | Always set a `background-color` fallback. For Outlook, add a VML `<v:rect>` with `<v:fill type="frame">` in an MSO conditional (generator: backgrounds.cm). |
29
+ | `css-linear-gradient`, `css-radial-gradient` | Put a solid `background-color` before the gradient so clients without support still get a readable background. |
30
+ | `css-object-fit`, `css-object-position` | Crop the image to the exact size before sending. |
31
+ | `html-picture`, `html-srcset` | Keep a plain `<img src>` (inside `<picture>` it is the fallback) pointing at a PNG or JPG. |
32
+ | `html-video`, `html-audio` | Use a static image or an animated GIF linked to the hosted video. |
33
+
34
+ ### Forms and fonts
35
+
36
+ | Slug | Fix |
37
+ | --- | --- |
38
+ | `html-form`, `html-input-*`, `html-select`, `html-textarea`, `html-button-*` | Link to a hosted form instead. Interactive form controls fail or are disabled in most clients. |
39
+ | `css-at-font-face`, `css-at-import` | Always end `font-family` with a safe stack (`Arial, Helvetica, sans-serif`). Outlook falls back to Times New Roman otherwise; force the fallback with `<!--[if mso]><style>body, table, td { font-family: Arial, sans-serif !important; }</style><![endif]-->`. |
40
+
41
+ ## Acceptable degradation
42
+
43
+ These drop a visual extra. The email keeps working, so report them as information, and check only that the design still reads well without them.
44
+
45
+ | Slug | Without support |
46
+ | --- | --- |
47
+ | `css-border-radius` | Square corners. For a rounded button in Outlook, use a VML `<v:roundrect>` (generator: buttons.cm). |
48
+ | `css-box-shadow`, `css-text-shadow`, `css-opacity`, `css-filter`, `css-transform`, `css-mix-blend-mode`, `css-backdrop-filter` | The effect is not shown. Make sure no text relies on it for contrast. |
49
+ | `css-pseudo-class-hover`, `css-transition`, `css-animation`, `css-at-keyframes` | No hover state or motion. The static state must be complete on its own. |
50
+ | `css-at-media-prefers-color-scheme` | No custom dark mode. Gmail and Outlook may still invert colors themselves, so check that logos and text stay readable on both light and dark backgrounds (transparent PNG logos with a light outline help). |
51
+ | `css-at-media-hover`, `css-at-media-orientation`, `css-at-media-prefers-reduced-motion` | The media query is ignored and base styles apply. |
52
+ | `html-meta-color-scheme` | The client decides the color scheme. |
53
+ | `css-text-decoration`, `css-text-decoration-*`, `css-text-underline-offset` | Plain underline or none. Do not rely on custom underline styles to mark links. |
54
+ | `html-mailto-links` | Some query parameters (often `bcc`) are dropped. Keep the address itself complete. |
55
+
56
+ ## Anything not listed
57
+
58
+ Read the issue `notes` and the caniemail page at `url`. Ask: does the email lose content or become unusable in that client? If yes, it is a must fix; propose the closest table-based or attribute-based alternative. If only decoration is lost, it is acceptable degradation.