red-design-mcp 0.1.0 → 0.2.0
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/README.md +45 -11
- package/dist/a11y.js +20 -7
- package/dist/agents.js +24 -0
- package/dist/cli.js +108 -28
- package/dist/colorparse.js +277 -0
- package/dist/csp.js +242 -0
- package/dist/cssparse.js +163 -50
- package/dist/gateway.js +7 -0
- package/dist/htmlscan.js +159 -0
- package/dist/playbooks.js +9 -0
- package/dist/secrets.js +113 -0
- package/dist/security.js +271 -0
- package/dist/server.js +166 -44
- package/dist/toolsets.js +4 -3
- package/dist/vision.js +70 -13
- package/dist/web.js +213 -3
- package/package.json +9 -1
package/dist/server.js
CHANGED
|
@@ -19,7 +19,11 @@ import { findToolsText, runTool } from "./gateway.js";
|
|
|
19
19
|
import { auditCss } from "./siteaudit.js";
|
|
20
20
|
import { generateFavicon, generateFormStyles } from "./ui.js";
|
|
21
21
|
import { registerPrompts } from "./prompts.js";
|
|
22
|
-
import {
|
|
22
|
+
import { assertPublicUrl, collectCss, fetchPage } from "./web.js";
|
|
23
|
+
import { scanSecrets, formatSecretsReport } from "./secrets.js";
|
|
24
|
+
import { auditHtml, formatHtmlAudit } from "./htmlscan.js";
|
|
25
|
+
import { analyzeSecurity, formatSecurityReport } from "./security.js";
|
|
26
|
+
import { HEADER_PLATFORMS, formatCsp, formatSecurityHeaders, generateCsp, generateSecurityHeaders } from "./csp.js";
|
|
23
27
|
import { lintCss } from "./lint.js";
|
|
24
28
|
import { VARIANTS, generateComponentStates } from "./states.js";
|
|
25
29
|
import { generateGradient } from "./gradient.js";
|
|
@@ -31,11 +35,12 @@ const server = new McpServer({ name: "red-design-mcp", version: pkg.version });
|
|
|
31
35
|
// Add "auto" to let the host model discover the remaining tools with find_tools and run_tool.
|
|
32
36
|
const toolEnabled = parseToolset(process.env.RED_TOOLS);
|
|
33
37
|
const registry = [];
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
/** Register a tool with the MCP server (if enabled) and remember it for the find_tools/run_tool gateway. */
|
|
39
|
+
function defineTool(name, config, handler) {
|
|
36
40
|
registry.push({ name, config, handler });
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
if (toolEnabled(name))
|
|
42
|
+
server.registerTool(name, config, handler);
|
|
43
|
+
}
|
|
39
44
|
/**
|
|
40
45
|
* Host mode: with no API key configured, return the image(s) plus instructions so the
|
|
41
46
|
* host model (Claude Code, Codex, ...) does the visual work itself. No second key needed.
|
|
@@ -64,7 +69,7 @@ const ANALYZE_PROMPT = `You are a senior UI/UX designer. Analyze this design and
|
|
|
64
69
|
"accessibility_issues": []
|
|
65
70
|
}
|
|
66
71
|
Use hex values for colors. Be specific and measurable.`;
|
|
67
|
-
|
|
72
|
+
defineTool("analyze_design", {
|
|
68
73
|
title: "Analyze Design",
|
|
69
74
|
description: "Analyze a design image (local file path or URL) and return a structured JSON spec: layout, colors, typography, spacing, components and style keywords.",
|
|
70
75
|
inputSchema: {
|
|
@@ -90,7 +95,8 @@ const FORMATS = {
|
|
|
90
95
|
react: "a single React functional component (default export) using CSS modules-free inline <style> or plain CSS classes",
|
|
91
96
|
tailwind: "a single HTML file using Tailwind utility classes via the Tailwind CDN script",
|
|
92
97
|
};
|
|
93
|
-
|
|
98
|
+
const TOKEN_CONVERTERS = { css: toCss, tailwind: toTailwind, json: toDtcg, figma: toFigma };
|
|
99
|
+
defineTool("recreate", {
|
|
94
100
|
title: "Recreate Design",
|
|
95
101
|
description: "Recreate a design as production-quality code. Provide an image (path or URL), a JSON spec from analyze_design, or both. Returns code only.",
|
|
96
102
|
inputSchema: {
|
|
@@ -143,7 +149,7 @@ const DIRECTIONS = [
|
|
|
143
149
|
"Direction B: lead with color, shape and bold visual rhythm.",
|
|
144
150
|
"Direction C: lead with unconventional layout and interaction details.",
|
|
145
151
|
];
|
|
146
|
-
|
|
152
|
+
defineTool("reimagine", {
|
|
147
153
|
title: "Reimagine Design",
|
|
148
154
|
description: "Reimagine a design in a new style as code. Control how far it departs from the original with the inspiration dial (0 = faithful, 100 = wild), optionally remix with a second design, and get up to 3 variations.",
|
|
149
155
|
inputSchema: {
|
|
@@ -191,7 +197,7 @@ Rules:
|
|
|
191
197
|
};
|
|
192
198
|
}
|
|
193
199
|
});
|
|
194
|
-
|
|
200
|
+
defineTool("extract_tokens", {
|
|
195
201
|
title: "Extract Design Tokens",
|
|
196
202
|
description: "Extract design tokens (colors, fonts, spacing, radii, shadows) from a design and export them as CSS variables, a Tailwind config, W3C design tokens JSON, or Figma (Tokens Studio) JSON.",
|
|
197
203
|
inputSchema: {
|
|
@@ -209,7 +215,7 @@ server.registerTool("extract_tokens", {
|
|
|
209
215
|
return hostMode(img ? [img] : [], `${prompt}\n\nThen call the convert_tokens tool with that JSON and format "${format}" to get the final export.`);
|
|
210
216
|
}
|
|
211
217
|
const tokens = parseTokens(await askVision(img, prompt));
|
|
212
|
-
const convert =
|
|
218
|
+
const convert = TOKEN_CONVERTERS[format];
|
|
213
219
|
return { content: [{ type: "text", text: convert(tokens) }] };
|
|
214
220
|
}
|
|
215
221
|
catch (err) {
|
|
@@ -219,7 +225,7 @@ server.registerTool("extract_tokens", {
|
|
|
219
225
|
};
|
|
220
226
|
}
|
|
221
227
|
});
|
|
222
|
-
|
|
228
|
+
defineTool("convert_tokens", {
|
|
223
229
|
title: "Convert Design Tokens",
|
|
224
230
|
description: "Convert a design-tokens JSON object (colors, fontFamilies, fontSizes, fontWeights, spacing, radii, shadows) into CSS variables, a Tailwind config, W3C tokens JSON, or Figma (Tokens Studio) JSON. Deterministic, no API key needed.",
|
|
225
231
|
inputSchema: {
|
|
@@ -228,27 +234,34 @@ server.registerTool("convert_tokens", {
|
|
|
228
234
|
},
|
|
229
235
|
}, async ({ tokens, format }) => {
|
|
230
236
|
try {
|
|
231
|
-
const convert =
|
|
237
|
+
const convert = TOKEN_CONVERTERS[format];
|
|
232
238
|
return { content: [{ type: "text", text: convert(parseTokens(tokens)) }] };
|
|
233
239
|
}
|
|
234
240
|
catch (err) {
|
|
235
241
|
return { isError: true, content: [{ type: "text", text: `convert_tokens failed: ${err.message}` }] };
|
|
236
242
|
}
|
|
237
243
|
});
|
|
238
|
-
|
|
244
|
+
defineTool("check_contrast", {
|
|
239
245
|
title: "Check Contrast",
|
|
240
246
|
description: "Compute exact WCAG contrast ratios for color pairs and suggest the closest passing color for failures. Deterministic, no API key needed.",
|
|
241
247
|
inputSchema: {
|
|
242
248
|
pairs: z.array(z.object({
|
|
243
249
|
element: z.string().describe("What the pair is, e.g. 'body text'"),
|
|
244
|
-
foreground: z.string().describe("
|
|
245
|
-
background: z.string().describe("
|
|
250
|
+
foreground: z.string().describe("Color: hex, rgb(), hsl(), hwb(), oklch(), oklab() or a CSS name (opaque)"),
|
|
251
|
+
background: z.string().describe("Color: hex, rgb(), hsl(), hwb(), oklch(), oklab() or a CSS name (opaque)"),
|
|
246
252
|
large_text: z.boolean().default(false),
|
|
247
253
|
kind: z.enum(["text", "ui"]).default("text"),
|
|
248
254
|
})),
|
|
249
255
|
},
|
|
250
|
-
}, async ({ pairs }) =>
|
|
251
|
-
|
|
256
|
+
}, async ({ pairs }) => {
|
|
257
|
+
try {
|
|
258
|
+
return { content: [{ type: "text", text: formatReport(evaluatePairs(pairs)) }] };
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
return fail("check_contrast", err);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
defineTool("audit_accessibility", {
|
|
252
265
|
title: "Audit Accessibility",
|
|
253
266
|
description: "Audit a design image against WCAG 2.2: exact contrast ratios with suggested fixes, plus tap targets, text size, focus, labels and color-only meaning. Returns a scored report.",
|
|
254
267
|
inputSchema: {
|
|
@@ -272,7 +285,7 @@ const fail = (tool, err) => ({
|
|
|
272
285
|
isError: true,
|
|
273
286
|
content: [{ type: "text", text: `${tool} failed: ${err.message}` }],
|
|
274
287
|
});
|
|
275
|
-
|
|
288
|
+
defineTool("generate_palette", {
|
|
276
289
|
title: "Generate Color Palette",
|
|
277
290
|
description: "Generate a complete, accessible color system from one base color: a 50-950 primary scale, harmony accents, tinted neutrals, semantic colors (success, warning, danger, info) and the best label color on each primary step and each semantic color. Deterministic, no API key needed.",
|
|
278
291
|
inputSchema: {
|
|
@@ -292,7 +305,7 @@ server.registerTool("generate_palette", {
|
|
|
292
305
|
return fail("generate_palette", err);
|
|
293
306
|
}
|
|
294
307
|
});
|
|
295
|
-
|
|
308
|
+
defineTool("simulate_colorblind", {
|
|
296
309
|
title: "Simulate Color Blindness",
|
|
297
310
|
description: "Simulate protanopia, deuteranopia, tritanopia and achromatopsia for a list of colors and flag pairs that look different normally but become hard to tell apart (like red vs green status badges). Deterministic, no API key needed.",
|
|
298
311
|
inputSchema: {
|
|
@@ -309,7 +322,7 @@ server.registerTool("simulate_colorblind", {
|
|
|
309
322
|
return fail("simulate_colorblind", err);
|
|
310
323
|
}
|
|
311
324
|
});
|
|
312
|
-
|
|
325
|
+
defineTool("generate_type_scale", {
|
|
313
326
|
title: "Generate Type Scale",
|
|
314
327
|
description: "Generate a modular typography scale with matching line heights, optionally fluid (CSS clamp) so text scales smoothly between a mobile and desktop viewport. Deterministic, no API key needed.",
|
|
315
328
|
inputSchema: {
|
|
@@ -334,7 +347,7 @@ server.registerTool("generate_type_scale", {
|
|
|
334
347
|
return fail("generate_type_scale", err);
|
|
335
348
|
}
|
|
336
349
|
});
|
|
337
|
-
|
|
350
|
+
defineTool("originality_check", {
|
|
338
351
|
title: "Originality Check",
|
|
339
352
|
description: "Compare two designs (the source and your recreation or reimagination) and score how similar their palette, typography, shape and spacing are, with tips to differentiate. Pass the JSON from extract_tokens or analyze_design for each. Deterministic, no API key needed.",
|
|
340
353
|
inputSchema: {
|
|
@@ -350,7 +363,7 @@ server.registerTool("originality_check", {
|
|
|
350
363
|
}
|
|
351
364
|
});
|
|
352
365
|
/* ---------------------------------- Vision tools --------------------------------- */
|
|
353
|
-
|
|
366
|
+
defineTool("critique_design", {
|
|
354
367
|
title: "Critique Design",
|
|
355
368
|
description: "Get a rigorous senior-designer critique of a design: scores for hierarchy, spacing, color, typography, consistency and usability, plus strengths, prioritized issues with fixes, and quick wins.",
|
|
356
369
|
inputSchema: {
|
|
@@ -369,7 +382,7 @@ server.registerTool("critique_design", {
|
|
|
369
382
|
return fail("critique_design", err);
|
|
370
383
|
}
|
|
371
384
|
});
|
|
372
|
-
|
|
385
|
+
defineTool("design_to_prompt", {
|
|
373
386
|
title: "Design to Prompt",
|
|
374
387
|
description: "Turn a design image into a ready-to-paste prompt for an AI UI generator (v0, Lovable, Bolt), an image model, or a developer handoff spec.",
|
|
375
388
|
inputSchema: {
|
|
@@ -389,7 +402,7 @@ server.registerTool("design_to_prompt", {
|
|
|
389
402
|
}
|
|
390
403
|
});
|
|
391
404
|
/* ------------------------------ Design system toolkit ------------------------------ */
|
|
392
|
-
|
|
405
|
+
defineTool("generate_design_system", {
|
|
393
406
|
title: "Generate Design System",
|
|
394
407
|
description: "One call, a complete starter design system from a brand color and a mood: color scales, light and dark semantic themes, font pairing, fluid type scale, spacing, radii, layered shadows, base styles, and verified contrast checks. Deterministic, no API key needed.",
|
|
395
408
|
inputSchema: {
|
|
@@ -424,7 +437,7 @@ server.registerTool("generate_design_system", {
|
|
|
424
437
|
return fail("generate_design_system", err);
|
|
425
438
|
}
|
|
426
439
|
});
|
|
427
|
-
|
|
440
|
+
defineTool("suggest_font_pairings", {
|
|
428
441
|
title: "Suggest Font Pairings",
|
|
429
442
|
description: "Curated Google Fonts pairings for a mood, with the @import and CSS font stacks (with safe fallbacks) ready to paste. Deterministic, no API key needed.",
|
|
430
443
|
inputSchema: {
|
|
@@ -432,7 +445,7 @@ server.registerTool("suggest_font_pairings", {
|
|
|
432
445
|
count: z.number().int().min(1).max(5).default(3),
|
|
433
446
|
},
|
|
434
447
|
}, async ({ mood, count }) => ({ content: [{ type: "text", text: formatPairings(mood, count) }] }));
|
|
435
|
-
|
|
448
|
+
defineTool("generate_shadows", {
|
|
436
449
|
title: "Generate Shadow Scale",
|
|
437
450
|
description: "Layered elevation shadows (xs to 2xl) in a soft or crisp style, tinted to a base color. Deterministic, no API key needed.",
|
|
438
451
|
inputSchema: {
|
|
@@ -451,7 +464,7 @@ server.registerTool("generate_shadows", {
|
|
|
451
464
|
return fail("generate_shadows", err);
|
|
452
465
|
}
|
|
453
466
|
});
|
|
454
|
-
|
|
467
|
+
defineTool("generate_spacing_scale", {
|
|
455
468
|
title: "Generate Spacing Scale",
|
|
456
469
|
description: "A consistent spacing scale from a base unit (4 or 8 are common), in rem or px. Deterministic, no API key needed.",
|
|
457
470
|
inputSchema: {
|
|
@@ -464,7 +477,7 @@ server.registerTool("generate_spacing_scale", {
|
|
|
464
477
|
const text = format === "json" ? JSON.stringify(list, null, 2) : [":root {", ...list.map((s) => ` --space-${s.key}: ${s.value};`), "}"].join("\n");
|
|
465
478
|
return { content: [{ type: "text", text }] };
|
|
466
479
|
});
|
|
467
|
-
|
|
480
|
+
defineTool("generate_dark_theme", {
|
|
468
481
|
title: "Generate Dark Theme",
|
|
469
482
|
description: "Turn a light design's tokens JSON into a dark theme (data-theme and prefers-color-scheme), re-checking text and accent contrast against the new background and fixing failures. Deterministic, no API key needed.",
|
|
470
483
|
inputSchema: {
|
|
@@ -478,7 +491,7 @@ server.registerTool("generate_dark_theme", {
|
|
|
478
491
|
return fail("generate_dark_theme", err);
|
|
479
492
|
}
|
|
480
493
|
});
|
|
481
|
-
|
|
494
|
+
defineTool("contrast_matrix", {
|
|
482
495
|
title: "Contrast Matrix",
|
|
483
496
|
description: "Check every text-on-background combination across a set of colors at once, with AA/AAA labels and the best accessible combos. Deterministic, no API key needed.",
|
|
484
497
|
inputSchema: {
|
|
@@ -492,7 +505,7 @@ server.registerTool("contrast_matrix", {
|
|
|
492
505
|
return fail("contrast_matrix", err);
|
|
493
506
|
}
|
|
494
507
|
});
|
|
495
|
-
|
|
508
|
+
defineTool("compare_designs", {
|
|
496
509
|
title: "Compare Designs",
|
|
497
510
|
description: "Compare two design images: what is the same, what differs, a verdict, and the top 5 changes to either match the first design or differentiate from it.",
|
|
498
511
|
inputSchema: {
|
|
@@ -515,7 +528,7 @@ server.registerTool("compare_designs", {
|
|
|
515
528
|
});
|
|
516
529
|
/* --------------------------- Web, lint and UI-state tools --------------------------- */
|
|
517
530
|
const fenceOf = (lang, body) => `${"`".repeat(3)}${lang}\n${body}\n${"`".repeat(3)}`;
|
|
518
|
-
|
|
531
|
+
defineTool("extract_css_tokens", {
|
|
519
532
|
title: "Extract Tokens from CSS or a Website",
|
|
520
533
|
description: "Read a live website's stylesheets (or CSS you paste) and extract design tokens: colors, fonts, font sizes, radii, spacing and shadows. No screenshot or API key needed. Best on sites with real stylesheets; for pages styled by JavaScript, use capture_url with the vision tools.",
|
|
521
534
|
inputSchema: {
|
|
@@ -547,7 +560,7 @@ server.registerTool("extract_css_tokens", {
|
|
|
547
560
|
return fail("extract_css_tokens", err);
|
|
548
561
|
}
|
|
549
562
|
});
|
|
550
|
-
|
|
563
|
+
defineTool("lint_css", {
|
|
551
564
|
title: "Lint CSS for Design Quality",
|
|
552
565
|
description: "Lint CSS (pasted or from a URL) for design-system problems: low text contrast, removed focus outlines, tiny text, too many colors, font sizes or families, off-grid spacing, missing reduced-motion support, and colors that drift from your tokens. Returns a score. Deterministic, no API key needed.",
|
|
553
566
|
inputSchema: {
|
|
@@ -566,7 +579,7 @@ server.registerTool("lint_css", {
|
|
|
566
579
|
return fail("lint_css", err);
|
|
567
580
|
}
|
|
568
581
|
});
|
|
569
|
-
|
|
582
|
+
defineTool("generate_component_states", {
|
|
570
583
|
title: "Generate Button States",
|
|
571
584
|
description: "Generate complete, accessible button CSS from one brand color: default, hover, active, focus-visible and disabled for primary, secondary, ghost and danger variants, with every state's contrast verified. Deterministic, no API key needed.",
|
|
572
585
|
inputSchema: {
|
|
@@ -582,7 +595,7 @@ server.registerTool("generate_component_states", {
|
|
|
582
595
|
return fail("generate_component_states", err);
|
|
583
596
|
}
|
|
584
597
|
});
|
|
585
|
-
|
|
598
|
+
defineTool("generate_gradient", {
|
|
586
599
|
title: "Generate Smooth Gradient",
|
|
587
600
|
description: "Build a smooth gradient from 2 to 5 colors, interpolated in OKLab so the middle never turns muddy. Returns CSS with a fallback plus a modern `in oklab` version, and tells you whether white or black text stays readable across the whole gradient. Deterministic, no API key needed.",
|
|
588
601
|
inputSchema: {
|
|
@@ -600,12 +613,12 @@ server.registerTool("generate_gradient", {
|
|
|
600
613
|
return fail("generate_gradient", err);
|
|
601
614
|
}
|
|
602
615
|
});
|
|
603
|
-
|
|
616
|
+
defineTool("generate_motion_tokens", {
|
|
604
617
|
title: "Generate Motion Tokens",
|
|
605
618
|
description: "Duration and easing tokens (instant to slower; standard, enter, exit, spring) in a snappy, balanced or relaxed feel, with an automatic prefers-reduced-motion override. Deterministic, no API key needed.",
|
|
606
619
|
inputSchema: { style: z.enum(["snappy", "balanced", "relaxed"]).default("balanced") },
|
|
607
620
|
}, async ({ style }) => ({ content: [{ type: "text", text: fenceOf("css", motionCss(style)) }] }));
|
|
608
|
-
|
|
621
|
+
defineTool("generate_layout_system", {
|
|
609
622
|
title: "Generate Layout System",
|
|
610
623
|
description: "A responsive container and column grid in plain CSS (mobile-first, stacks below the chosen breakpoint) using Tailwind, Bootstrap or Material breakpoints. Deterministic, no API key needed.",
|
|
611
624
|
inputSchema: {
|
|
@@ -623,7 +636,7 @@ server.registerTool("generate_layout_system", {
|
|
|
623
636
|
return fail("generate_layout_system", err);
|
|
624
637
|
}
|
|
625
638
|
});
|
|
626
|
-
|
|
639
|
+
defineTool("capture_url", {
|
|
627
640
|
title: "Capture Website Screenshot",
|
|
628
641
|
description: "Take a screenshot of a web page and return it as an image. It is also saved to a file whose path you can pass to analyze_design, recreate, reimagine and the other vision tools. Needs Google Chrome installed, or Chromium via `npx playwright-core install chromium`.",
|
|
629
642
|
inputSchema: {
|
|
@@ -636,7 +649,7 @@ server.registerTool("capture_url", {
|
|
|
636
649
|
}, async ({ url, width, height, full_page, mobile }) => {
|
|
637
650
|
let browser;
|
|
638
651
|
try {
|
|
639
|
-
const target =
|
|
652
|
+
const target = await assertPublicUrl(url);
|
|
640
653
|
const spec = "playwright-core";
|
|
641
654
|
const pw = await import(spec).catch(() => null);
|
|
642
655
|
if (!pw)
|
|
@@ -658,6 +671,17 @@ server.registerTool("capture_url", {
|
|
|
658
671
|
deviceScaleFactor: mobile ? 2 : 1,
|
|
659
672
|
isMobile: mobile,
|
|
660
673
|
});
|
|
674
|
+
// The browser follows redirects and loads sub-resources on its own, so check each request's host too.
|
|
675
|
+
const verdicts = new Map();
|
|
676
|
+
await page.route("**/*", async (route) => {
|
|
677
|
+
const reqUrl = route.request().url();
|
|
678
|
+
if (!/^https?:/i.test(reqUrl))
|
|
679
|
+
return route.continue();
|
|
680
|
+
const host = new URL(reqUrl).hostname;
|
|
681
|
+
if (!verdicts.has(host))
|
|
682
|
+
verdicts.set(host, assertPublicUrl(reqUrl).then(() => true, () => false));
|
|
683
|
+
return (await verdicts.get(host)) ? route.continue() : route.abort("blockedbyclient");
|
|
684
|
+
});
|
|
661
685
|
await page.goto(target.href, { waitUntil: "load", timeout: 30000 });
|
|
662
686
|
await page.waitForTimeout(800);
|
|
663
687
|
const buf = await page.screenshot({ type: "jpeg", quality: 80, fullPage: full_page });
|
|
@@ -679,7 +703,7 @@ server.registerTool("capture_url", {
|
|
|
679
703
|
await browser?.close().catch(() => undefined);
|
|
680
704
|
}
|
|
681
705
|
});
|
|
682
|
-
|
|
706
|
+
defineTool("audit_site", {
|
|
683
707
|
title: "Audit Site",
|
|
684
708
|
description: "An autonomous design audit of a live website (or pasted CSS) in one call: extracts the design language, lints quality, checks palette contrast, finds color-blind risks, analyzes the type scale, and ends with a scored list of the top fixes. Deterministic, no API key needed.",
|
|
685
709
|
inputSchema: {
|
|
@@ -697,7 +721,7 @@ server.registerTool("audit_site", {
|
|
|
697
721
|
return fail("audit_site", err);
|
|
698
722
|
}
|
|
699
723
|
});
|
|
700
|
-
|
|
724
|
+
defineTool("generate_form_styles", {
|
|
701
725
|
title: "Generate Form Styles",
|
|
702
726
|
description: "Accessible form CSS from one brand color: labels, inputs, placeholders, hover, focus-visible, error and disabled states, help and error text, and checkbox/radio accents, with every contrast requirement verified. Deterministic, no API key needed.",
|
|
703
727
|
inputSchema: {
|
|
@@ -713,7 +737,7 @@ server.registerTool("generate_form_styles", {
|
|
|
713
737
|
return fail("generate_form_styles", err);
|
|
714
738
|
}
|
|
715
739
|
});
|
|
716
|
-
|
|
740
|
+
defineTool("generate_favicon", {
|
|
717
741
|
title: "Generate Favicon",
|
|
718
742
|
description: "Create a crisp SVG monogram favicon (1 or 2 letters) on a square, rounded or circle shape in your brand color, with the letter color chosen for readable contrast, plus the HTML tags to use it. Deterministic, no API key needed.",
|
|
719
743
|
inputSchema: {
|
|
@@ -738,7 +762,7 @@ server.registerTool("generate_favicon", {
|
|
|
738
762
|
return fail("generate_favicon", err);
|
|
739
763
|
}
|
|
740
764
|
});
|
|
741
|
-
|
|
765
|
+
defineTool("generate_chart_palette", {
|
|
742
766
|
title: "Generate Chart Palette",
|
|
743
767
|
description: "Data-visualization colors that stay readable for everyone: a colorblind-safe categorical palette (up to 8), a sequential ramp from one color with steadily falling lightness, or a diverging palette with a neutral midpoint. Includes verification notes. Deterministic, no API key needed.",
|
|
744
768
|
inputSchema: {
|
|
@@ -762,6 +786,104 @@ server.registerTool("generate_chart_palette", {
|
|
|
762
786
|
return fail("generate_chart_palette", err);
|
|
763
787
|
}
|
|
764
788
|
});
|
|
789
|
+
/* ------------------------------ Red Chex: security tools ------------------------------ */
|
|
790
|
+
defineTool("audit_security", {
|
|
791
|
+
title: "Security and Privacy Check",
|
|
792
|
+
description: "Red Chex: a passive security and privacy review of one public web page. Sends a single normal GET request, then checks HTTPS and redirects, HSTS, Content-Security-Policy, clickjacking and other security headers, cookie flags, mixed content, forms, third-party scripts without Subresource Integrity, leaked credentials in the markup, trackers and information disclosure. Returns a grade and fixes. It inspects only what any visitor receives and does not test for vulnerabilities. Only check sites you own or may review. Deterministic, no API key needed.",
|
|
793
|
+
inputSchema: { url: z.string().describe("Page URL, for example https://example.com (https:// is assumed if omitted)") },
|
|
794
|
+
}, async ({ url }) => {
|
|
795
|
+
try {
|
|
796
|
+
const page = await fetchPage(url);
|
|
797
|
+
const input = { url: page.requestedUrl, finalUrl: page.finalUrl, status: page.status, chain: page.chain, headers: page.headers, setCookies: page.setCookies, body: page.body, contentType: page.contentType };
|
|
798
|
+
return { content: [{ type: "text", text: formatSecurityReport(analyzeSecurity(input), input) }] };
|
|
799
|
+
}
|
|
800
|
+
catch (err) {
|
|
801
|
+
return fail("audit_security", err);
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
defineTool("scan_secrets", {
|
|
805
|
+
title: "Scan for Leaked Secrets",
|
|
806
|
+
description: "Red Chex: scan text you pass in (file contents, config, HTML, JavaScript, CSS) for credentials that must not be committed or served: API keys for AWS, GitHub, Stripe, Slack, Anthropic, OpenAI, Groq, Google and others, private keys, JWTs, passwords in connection strings and hard-coded secret assignments. Findings show the line, the kind and a redacted preview; a full secret is never returned. Deterministic, no API key needed.",
|
|
807
|
+
inputSchema: {
|
|
808
|
+
text: z.string().describe("The text or file contents to scan (up to 1 MB)"),
|
|
809
|
+
label: z.string().optional().describe("What this text is, for the report, for example .env.example or app.js"),
|
|
810
|
+
},
|
|
811
|
+
}, async ({ text, label }) => ({ content: [{ type: "text", text: formatSecretsReport(scanSecrets(text), label ?? "the text") }] }));
|
|
812
|
+
defineTool("generate_csp", {
|
|
813
|
+
title: "Generate Content-Security-Policy",
|
|
814
|
+
description: "Red Chex: build a Content-Security-Policy from a page's real markup. Reads the scripts, styles, images, fonts, frames and forms it uses, computes SHA-256 hashes for inline scripts and styles so you can avoid 'unsafe-inline', and starts in report-only mode. Give a url or paste html. Only discovers resources written in the HTML. Deterministic, no API key needed.",
|
|
815
|
+
inputSchema: {
|
|
816
|
+
url: z.string().optional().describe("Page URL to read the markup from"),
|
|
817
|
+
html: z.string().optional().describe("HTML to analyze instead of a URL"),
|
|
818
|
+
page_url: z.string().optional().describe("With html: the page's own URL, so same-origin resources become 'self'"),
|
|
819
|
+
mode: z.enum(["report-only", "enforce"]).default("report-only"),
|
|
820
|
+
allow_inline_style_attributes: z.boolean().default(true).describe("Allow style=\"\" attributes via style-src-attr"),
|
|
821
|
+
},
|
|
822
|
+
}, async ({ url, html, page_url, mode, allow_inline_style_attributes }) => {
|
|
823
|
+
try {
|
|
824
|
+
if (!url && !html)
|
|
825
|
+
throw new Error("Provide a url or html.");
|
|
826
|
+
let markup = html ?? "";
|
|
827
|
+
let pageUrl = page_url;
|
|
828
|
+
if (!html && url) {
|
|
829
|
+
const page = await fetchPage(url);
|
|
830
|
+
if (!page.body)
|
|
831
|
+
throw new Error(`That URL did not return an HTML page (content-type: ${page.contentType || "unknown"}).`);
|
|
832
|
+
markup = page.body;
|
|
833
|
+
pageUrl = page.finalUrl;
|
|
834
|
+
}
|
|
835
|
+
return { content: [{ type: "text", text: formatCsp(generateCsp(markup, { pageUrl, mode, allowInlineStyleAttributes: allow_inline_style_attributes })) }] };
|
|
836
|
+
}
|
|
837
|
+
catch (err) {
|
|
838
|
+
return fail("generate_csp", err);
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
defineTool("generate_security_headers", {
|
|
842
|
+
title: "Generate Security Headers",
|
|
843
|
+
description: "Red Chex: write the recommended security headers (HSTS, nosniff, clickjacking protection, Referrer-Policy, Permissions-Policy, Cross-Origin-Opener-Policy and optionally your CSP) as ready-to-paste config for Netlify, Cloudflare Pages, Vercel, nginx, Apache, Caddy or Express. Rejects input that could break out of the config file. Deterministic, no API key needed.",
|
|
844
|
+
inputSchema: {
|
|
845
|
+
platform: z.enum(HEADER_PLATFORMS),
|
|
846
|
+
csp: z.string().optional().describe("A Content-Security-Policy value, for example from generate_csp"),
|
|
847
|
+
csp_mode: z.enum(["report-only", "enforce"]).default("report-only"),
|
|
848
|
+
hsts_preload: z.boolean().default(false).describe("Adds the preload flag. Very hard to undo, so off by default"),
|
|
849
|
+
frame: z.enum(["deny", "sameorigin"]).default("deny"),
|
|
850
|
+
isolate_cross_origin: z.boolean().default(false).describe("Adds Cross-Origin-Resource-Policy: same-site, which stops other sites embedding your assets"),
|
|
851
|
+
},
|
|
852
|
+
}, async ({ platform, csp, csp_mode, hsts_preload, frame, isolate_cross_origin }) => {
|
|
853
|
+
try {
|
|
854
|
+
const out = generateSecurityHeaders(platform, { csp, cspMode: csp_mode, hstsPreload: hsts_preload, frame, isolateCrossOrigin: isolate_cross_origin });
|
|
855
|
+
return { content: [{ type: "text", text: formatSecurityHeaders(platform, out) }] };
|
|
856
|
+
}
|
|
857
|
+
catch (err) {
|
|
858
|
+
return fail("generate_security_headers", err);
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
defineTool("audit_html", {
|
|
862
|
+
title: "Audit HTML",
|
|
863
|
+
description: "Static audit of HTML markup (pasted or from a URL) for accessibility and quality: lang, title, viewport zoom, image alt text, unlabeled form fields, empty buttons and links, heading order, duplicate ids, positive tabindex, iframe titles, autoplay, table headers and render-blocking scripts. Returns a score and fixes. It cannot judge color contrast; use audit_accessibility or lint_css for that. Deterministic, no API key needed.",
|
|
864
|
+
inputSchema: {
|
|
865
|
+
html: z.string().optional().describe("HTML to audit"),
|
|
866
|
+
url: z.string().optional().describe("Page URL to read the HTML from"),
|
|
867
|
+
},
|
|
868
|
+
}, async ({ html, url }) => {
|
|
869
|
+
try {
|
|
870
|
+
if (!html && !url)
|
|
871
|
+
throw new Error("Provide html or a url.");
|
|
872
|
+
let markup = html ?? "";
|
|
873
|
+
let label = "the pasted HTML";
|
|
874
|
+
if (!html && url) {
|
|
875
|
+
const page = await fetchPage(url);
|
|
876
|
+
if (!page.body)
|
|
877
|
+
throw new Error(`That URL did not return an HTML page (content-type: ${page.contentType || "unknown"}).`);
|
|
878
|
+
markup = page.body;
|
|
879
|
+
label = page.finalUrl;
|
|
880
|
+
}
|
|
881
|
+
return { content: [{ type: "text", text: formatHtmlAudit(auditHtml(markup), label) }] };
|
|
882
|
+
}
|
|
883
|
+
catch (err) {
|
|
884
|
+
return fail("audit_html", err);
|
|
885
|
+
}
|
|
886
|
+
});
|
|
765
887
|
function registerGateway(hidden) {
|
|
766
888
|
const validate = (shape, args) => {
|
|
767
889
|
const r = z.object(shape).safeParse(args);
|
|
@@ -779,7 +901,7 @@ function registerGateway(hidden) {
|
|
|
779
901
|
return {};
|
|
780
902
|
}
|
|
781
903
|
};
|
|
782
|
-
registerTool("find_tools", {
|
|
904
|
+
server.registerTool("find_tools", {
|
|
783
905
|
title: "Find red design tools",
|
|
784
906
|
description: "Describe what you want to do in plain words (for example: check a website's accessibility, build a color palette, turn a screenshot into code) and get the best-matching red design tools with their parameters. Call this first, then use run_tool. Call with no task to list every area.",
|
|
785
907
|
inputSchema: {
|
|
@@ -789,7 +911,7 @@ function registerGateway(hidden) {
|
|
|
789
911
|
}, async ({ task, limit }) => ({
|
|
790
912
|
content: [{ type: "text", text: findToolsText(hidden, task, limit) }],
|
|
791
913
|
}));
|
|
792
|
-
registerTool("run_tool", {
|
|
914
|
+
server.registerTool("run_tool", {
|
|
793
915
|
title: "Run a red design tool",
|
|
794
916
|
description: "Run a red design tool by name with an args object. Get names and parameters from find_tools.",
|
|
795
917
|
inputSchema: {
|
package/dist/toolsets.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export const GROUPS = {
|
|
2
2
|
core: ["analyze_design", "recreate", "reimagine", "extract_tokens", "critique_design", "audit_accessibility", "audit_site", "check_contrast", "generate_design_system"],
|
|
3
3
|
vision: ["analyze_design", "recreate", "reimagine", "extract_tokens", "critique_design", "audit_accessibility", "design_to_prompt", "compare_designs"],
|
|
4
|
-
web: ["capture_url", "extract_css_tokens", "lint_css", "audit_site"],
|
|
4
|
+
web: ["capture_url", "extract_css_tokens", "lint_css", "audit_site", "audit_security", "generate_csp", "audit_html"],
|
|
5
5
|
color: ["generate_palette", "simulate_colorblind", "check_contrast", "contrast_matrix", "generate_gradient", "generate_chart_palette"],
|
|
6
6
|
system: ["generate_design_system", "generate_type_scale", "generate_shadows", "generate_spacing_scale", "generate_dark_theme", "generate_motion_tokens", "generate_layout_system", "suggest_font_pairings", "convert_tokens", "extract_tokens"],
|
|
7
7
|
components: ["generate_component_states", "generate_form_styles", "generate_favicon"],
|
|
8
|
-
quality: ["audit_accessibility", "check_contrast", "contrast_matrix", "simulate_colorblind", "lint_css", "audit_site", "originality_check", "critique_design"],
|
|
8
|
+
quality: ["audit_accessibility", "check_contrast", "contrast_matrix", "simulate_colorblind", "lint_css", "audit_site", "originality_check", "critique_design", "audit_html"],
|
|
9
|
+
security: ["audit_security", "scan_secrets", "generate_csp", "generate_security_headers", "audit_html"],
|
|
9
10
|
};
|
|
10
11
|
export const ALL_TOOLS = [
|
|
11
12
|
"analyze_design", "recreate", "reimagine", "extract_tokens", "convert_tokens", "audit_accessibility", "check_contrast",
|
|
@@ -13,7 +14,7 @@ export const ALL_TOOLS = [
|
|
|
13
14
|
"generate_design_system", "suggest_font_pairings", "generate_shadows", "generate_spacing_scale", "generate_dark_theme",
|
|
14
15
|
"contrast_matrix", "compare_designs", "extract_css_tokens", "lint_css", "generate_component_states", "generate_gradient",
|
|
15
16
|
"generate_motion_tokens", "generate_layout_system", "capture_url", "audit_site", "generate_form_styles", "generate_favicon",
|
|
16
|
-
"generate_chart_palette",
|
|
17
|
+
"generate_chart_palette", "audit_security", "scan_secrets", "generate_csp", "generate_security_headers", "audit_html",
|
|
17
18
|
];
|
|
18
19
|
/**
|
|
19
20
|
* RED_TOOLS controls which tools load. Comma-separated groups or tool names; prefix with - to exclude.
|
package/dist/vision.js
CHANGED
|
@@ -1,23 +1,80 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { readFile, realpath, stat } from "node:fs/promises";
|
|
2
|
+
import { homedir, tmpdir } from "node:os";
|
|
3
|
+
import { basename, delimiter, extname, join, resolve, sep } from "node:path";
|
|
4
|
+
import { readBytes, safeFetch } from "./web.js";
|
|
5
|
+
const IMAGE_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp"]);
|
|
6
|
+
const MAX_IMAGE_BYTES = 20 * 1024 * 1024;
|
|
7
|
+
/** Identify an image by its file signature, never by its name. Returns null for anything else. */
|
|
8
|
+
export function sniffImage(buf) {
|
|
9
|
+
if (buf.length >= 8 && buf.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])))
|
|
10
|
+
return "image/png";
|
|
11
|
+
if (buf.length >= 3 && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff)
|
|
12
|
+
return "image/jpeg";
|
|
13
|
+
const head6 = buf.subarray(0, 6).toString("latin1");
|
|
14
|
+
if (head6 === "GIF87a" || head6 === "GIF89a")
|
|
15
|
+
return "image/gif";
|
|
16
|
+
if (buf.length >= 12 && buf.subarray(0, 4).toString("latin1") === "RIFF" && buf.subarray(8, 12).toString("latin1") === "WEBP")
|
|
17
|
+
return "image/webp";
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const isInside = (child, root) => {
|
|
21
|
+
const norm = (p) => (process.platform === "win32" || process.platform === "darwin" ? p.toLowerCase() : p);
|
|
22
|
+
const c = norm(child);
|
|
23
|
+
const r = norm(root);
|
|
24
|
+
return c === r || c.startsWith(r.endsWith(sep) ? r : r + sep);
|
|
9
25
|
};
|
|
26
|
+
/** Folders the server may read images from. Unset means anywhere, but only real image files. */
|
|
27
|
+
async function allowedRoots() {
|
|
28
|
+
const raw = process.env.RED_ALLOWED_DIRS?.trim();
|
|
29
|
+
if (!raw)
|
|
30
|
+
return null;
|
|
31
|
+
const roots = [...raw.split(delimiter).filter(Boolean), join(tmpdir(), "red-design-mcp")];
|
|
32
|
+
const real = [];
|
|
33
|
+
for (const r of roots) {
|
|
34
|
+
try {
|
|
35
|
+
real.push(await realpath(resolve(r)));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
/* folder does not exist yet */
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return real;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Load an image from a URL or a local path. Local reads are limited to PNG, JPEG, GIF and WebP files
|
|
45
|
+
* (checked by extension and by file signature), so a prompt cannot use this to read arbitrary files.
|
|
46
|
+
* Set RED_ALLOWED_DIRS to also confine reads to specific folders.
|
|
47
|
+
*/
|
|
10
48
|
export async function loadImage(source) {
|
|
11
49
|
if (/^https?:\/\//i.test(source)) {
|
|
12
|
-
const res = await
|
|
50
|
+
const res = await safeFetch(source);
|
|
13
51
|
if (!res.ok)
|
|
14
52
|
throw new Error(`Could not fetch image (${res.status})`);
|
|
15
|
-
const
|
|
16
|
-
const
|
|
53
|
+
const buf = await readBytes(res, MAX_IMAGE_BYTES);
|
|
54
|
+
const mediaType = sniffImage(buf);
|
|
55
|
+
if (!mediaType)
|
|
56
|
+
throw new Error("That URL did not return a PNG, JPEG, GIF or WebP image.");
|
|
17
57
|
return { base64: buf.toString("base64"), mediaType };
|
|
18
58
|
}
|
|
19
|
-
const
|
|
20
|
-
const
|
|
59
|
+
const expanded = source.startsWith("~/") || source.startsWith("~\\") ? join(homedir(), source.slice(2)) : source;
|
|
60
|
+
const real = await realpath(resolve(expanded)); // follows symlinks, so a link cannot point outside
|
|
61
|
+
const name = basename(real);
|
|
62
|
+
if (!IMAGE_EXTENSIONS.has(extname(real).toLowerCase())) {
|
|
63
|
+
throw new Error(`Only image files (png, jpg, jpeg, gif, webp) can be read. "${name}" is not one.`);
|
|
64
|
+
}
|
|
65
|
+
const roots = await allowedRoots();
|
|
66
|
+
if (roots && !roots.some((r) => isInside(real, r))) {
|
|
67
|
+
throw new Error(`"${name}" is outside the folders allowed by RED_ALLOWED_DIRS.`);
|
|
68
|
+
}
|
|
69
|
+
const info = await stat(real);
|
|
70
|
+
if (!info.isFile())
|
|
71
|
+
throw new Error(`"${name}" is not a file.`);
|
|
72
|
+
if (info.size > MAX_IMAGE_BYTES)
|
|
73
|
+
throw new Error(`"${name}" is larger than ${MAX_IMAGE_BYTES / 1024 / 1024} MB.`);
|
|
74
|
+
const buf = await readFile(real);
|
|
75
|
+
const mediaType = sniffImage(buf);
|
|
76
|
+
if (!mediaType)
|
|
77
|
+
throw new Error(`"${name}" is not a PNG, JPEG, GIF or WebP image.`);
|
|
21
78
|
return { base64: buf.toString("base64"), mediaType };
|
|
22
79
|
}
|
|
23
80
|
// Everything except Anthropic speaks the OpenAI chat-completions format.
|