@designlatch/mcp
v0.1.0
Published
`@designlatch/mcp` is the MCP adapter for DesignLatch.
Maintainers
Readme
DesignLatch MCP
@designlatch/mcp is the MCP adapter for DesignLatch.
It exposes DesignLatch validation and compliance scanning over stdio so an AI agent can send inline JSON directly to the server without relying on file-based CLI workflows.
What It Does
This package exposes three MCP tools:
validate_inputsscan_compliancecompare_live_ui_to_figma
Use MCP when your agent already has, or can generate, these JSON inputs in memory:
configtokenssnapshots
Use the CLI instead when you want:
- file-based workflows
- Playwright collection
- local HTML reports and report serving
Install
npm install -D @designlatch/mcpRun the server:
npx designlatch-mcpAdd It To An AI Agent
Most MCP-capable AI clients connect to local tools over stdio using a server config.
The common pattern is:
{
"mcpServers": {
"designlatch": {
"command": "npx",
"args": ["-y", "@designlatch/[email protected]"]
}
}
}Codex
- Via Codex CLI
codex mcp add designlatch npx -- -y @designlatch/mcp- Codex reads MCP server entries from
~/.codex/config.toml.
On Windows, that is typically:
C:\Users\<your-user>\.codex\config.tomlThen add this block to your Codex config:
[mcp_servers.designlatch]
command = "npx"
args = ["-y", "@designlatch/mcp"]Claude Code
Via Claude Code
claude mcp add --transport stdio designlatch npx -- -y @designlatch/mcpIf you want the high-level compare_live_ui_to_figma workflow to work in Codex, make sure Codex also has:
- a Playwright MCP entry
- a Figma MCP entry
- working Figma authentication
After updating config.toml, restart Codex and open a new session. The agent should then see:
validate_inputsscan_compliancecompare_live_ui_to_figma
What the user does in practice:
- Install
@designlatch/mcp - Open the AI client's MCP/server configuration
- Add a
designlatchserver entry using one of the examples above - Restart or reload the AI client
- Ask the agent to call
compare_live_ui_to_figma,validate_inputs, orscan_compliance
Once connected, the AI agent should see these tools:
validate_inputsscan_compliancecompare_live_ui_to_figma
MCP Model
DesignLatch MCP currently supports:
- transport:
stdio - input mode: inline JSON only
- output mode: JSON tool responses
- tools:
validate_inputs,scan_compliance,compare_live_ui_to_figma
It does not provide a collect tool. Snapshot collection remains a CLI concern.
Tool Inputs
validate_inputs
Use this when you want to verify the shape of the incoming JSON before a full scan.
Input shape:
{
"config": {},
"tokens": {},
"snapshots": [],
"urlOverride": "https://example.com"
}Notes:
configis requiredtokensis optionalsnapshotsis optionalurlOverrideis optional
scan_compliance
Use this when you want a full report and evaluation.
Input shape:
{
"config": {},
"tokens": {},
"snapshots": [],
"urlOverride": "https://example.com"
}Notes:
configis requiredtokensis requiredsnapshotsis requiredurlOverrideis optional
compare_live_ui_to_figma
Use this when the user wants a higher-level workflow such as:
Compare google.com's search bar UI with this Figma search bar componentThis tool does three things:
- Checks whether the agent confirms
Playwright MCP,Figma MCP, andFigma authare available - If those prerequisites are missing, returns a
blockedresponse with setup guidance and exits - If prerequisites are available and
liveCaptureplusfigmaDesignare provided, synthesizes DesignLatchconfig,tokens, andsnapshots, validates them, runs the scan, and returns the summary plus report output paths
Important limitation:
- DesignLatch MCP does not auto-install or auto-register other MCP servers
- The host agent must gather live data from Playwright MCP and design data from Figma MCP
- If prerequisite status is present but external data has not been gathered yet, the tool returns a
validatedresponse telling the agent what to collect next
Input shape:
{
"request": "Compare google.com's search bar UI with this Figma search bar component",
"liveUrl": "https://google.com",
"selector": "textarea[name='q']",
"figmaFileOrUrl": "https://www.figma.com/file/abc123/search-bar",
"figmaNodeIdOrComponentName": "Search Bar",
"prerequisites": {
"playwrightMcpConfigured": true,
"figmaMcpConfigured": true,
"figmaAuthenticated": true
},
"liveCapture": {
"text": "Google Search",
"computed": {
"backgroundColor": "rgb(255, 255, 255)",
"color": "rgb(32, 33, 36)",
"padding": "0px 16px"
}
},
"figmaDesign": {
"componentName": "Search Bar",
"properties": {
"backgroundColor": { "expected": "rgb(255, 255, 255)" },
"color": { "expected": "rgb(32, 33, 36)" },
"padding": { "expected": "0px 16px" }
}
}
}Response states:
blocked: missing Playwright MCP, Figma MCP, or Figma authvalidated: prerequisites confirmed, but the agent still needs to gatherliveCaptureorfigmaDesigncompleted: scan finished and report files were writtenfailed: payload synthesis, validation, or scan failed
JSON Structures
config
The config describes selectors and the token-backed CSS expectations to compare.
Example:
{
"url": "https://app.example.com",
"rules": [
{
"id": "primary-button",
"selector": ".btn-primary",
"properties": {
"backgroundColor": {
"token": "button.primary.background",
"tolerance": { "kind": "rgba", "value": 0 },
"severity": "error"
},
"padding": {
"token": "button.primary.padding",
"tolerance": { "kind": "px", "value": 1 },
"severity": "warn"
}
}
}
],
"thresholds": {
"minScore": 90,
"failOnSeverity": "error"
}
}Useful fields:
url: the product page the rules refer torules[].id: stable rule identifierrules[].selector: CSS selectorrules[].properties: CSS property checksproperties.<cssProp>.token: token key to resolve fromtokensproperties.<cssProp>.tolerance: optional comparison toleranceproperties.<cssProp>.severity:errororwarnthresholds: optional pass/fail evaluation settings
tokens
Tokens define the expected design values. These must match the token keys referenced in config.rules[*].properties[*].token.
Example:
{
"button.primary.background": {
"kind": "color",
"rgba": { "r": 0, "g": 114, "b": 216, "a": 1 }
},
"button.primary.padding": {
"kind": "box",
"unit": "px",
"top": 12,
"right": 20,
"bottom": 12,
"left": 20
},
"button.primary.radius": {
"kind": "number",
"value": 8,
"unit": "px"
},
"button.primary.labelWeight": {
"kind": "string",
"value": "600"
}
}Supported token styles used in this repo:
colornumberstringbox
snapshots
Snapshots are the observed runtime styles for the selectors being evaluated.
Example:
[
{
"selector": ".btn-primary",
"url": "https://app.example.com",
"computed": {
"backgroundColor": "rgb(0, 114, 216)",
"padding": "12px 20px",
"borderRadius": "8px"
},
"text": "Continue"
}
]Useful fields:
selector: must match the selector in configurl: runtime page URLcomputed: CSS property map from the live UItext: optional element text
Agent Prompting Guide
If you want an AI agent to generate the inline JSON for MCP, be explicit about:
- which object(s) you want back
- that the response must be valid JSON only
- that no prose or Markdown fences should be included
- which CSS properties and token names should be used
Good instruction pattern:
Return valid JSON only. Do not include prose. Do not wrap the answer in Markdown code fences.Example Prompts
1. Generate config, tokens, and snapshots for a simple button
Generate three JSON values for DesignLatch MCP: config, tokens, and snapshots.
The component is a primary button with selector ".btn-primary".
Expected styles:
- background color rgb(0, 114, 216)
- text color rgb(255, 255, 255)
- padding 12px 20px
- border radius 8px
- font weight 600
- button text "Continue"
Use token keys starting with "button.primary.".
Add a threshold with minScore 95 and failOnSeverity "error".
Return valid JSON only with this exact top-level shape:
{
"config": {},
"tokens": {},
"snapshots": []
}
Do not include explanations or Markdown fences.2. Generate only a config object for a card with header and footer
Create a DesignLatch config JSON object only.
The target page URL is "https://app.example.com/profile".
I need rules for:
- ".profile-card"
- ".profile-card .card-header"
- ".profile-card .card-body"
- ".profile-card .card-footer"
Use token names under the "card." namespace.
For backgroundColor and padding use severity "error".
For boxShadow, display, justifyContent, and gap use severity "warn".
Use px tolerance 0 for padding and radius. Use rgba tolerance 0 for colors.
Add thresholds with minScore 90 and failOnSeverity "error".
Return valid JSON only. No prose. No Markdown.3. Generate only tokens for a described component style system
Generate a DesignLatch tokens JSON object only.
Create tokens for a modal dialog using these values:
- overlay background rgba(0, 0, 0, 0.6)
- panel background rgba(255, 255, 255, 1)
- panel radius 16px
- panel shadow "rgba(0, 0, 0, 0.18) 0px 12px 32px 0px"
- title font size 24px
- title line height 32px
- title font weight 700
- body padding 24px 28px 24px 28px
- footer gap 12px
Use valid DesignLatch token shapes only. Prefer:
- kind=color for colors
- kind=number for single numeric values
- kind=string for shadow and font weight
- kind=box for four-sided padding
Return valid JSON only. No comments. No Markdown.4. Generate only snapshots from observed CSS values
Generate a DesignLatch snapshots JSON array only.
I observed these runtime values on https://app.example.com/settings:
Selector ".settings-save-btn":
- backgroundColor: "rgb(0, 114, 216)"
- color: "rgb(255, 255, 255)"
- padding: "12px 20px"
- borderRadius: "8px"
- text: "Save Changes"
Selector ".settings-panel":
- backgroundColor: "rgb(255, 255, 255)"
- boxShadow: "rgba(0, 0, 0, 0.1) 0px 2px 8px 0px"
- padding: "24px 24px 24px 24px"
Return valid JSON only as an array of snapshot objects with selector, url, computed, and optional text.
Do not include any explanation.5. Use Playwright MCP plus Figma MCP before calling DesignLatch MCP
Use Playwright MCP to open https://live-site-url and get the computed styles for the ".btn-primary" selector.
Then use Figma MCP to inspect the component or design token data for "btn-primary" in this Figma file:
https://www.figma.com/file/your-figma-file-id/example
From those two sources, generate three valid JSON values for DesignLatch:
- config
- tokens
- snapshots
Requirements:
- the config must include a rule for ".btn-primary"
- the token names should use the "button.primary." namespace
- the snapshots array must contain the observed computed styles from the live site
- the tokens object must contain the expected design values from Figma
After generating the JSON:
1. call DesignLatch MCP tool `validate_inputs`
2. if validation passes, call DesignLatch MCP tool `scan_compliance`
3. summarize any failures, score, and top mismatches
Return valid JSON only when generating config/tokens/snapshots.
Do not wrap JSON in Markdown fences.6. Use compare_live_ui_to_figma as the high-level MCP workflow
Call DesignLatch MCP tool compare_live_ui_to_figma.
User request:
"Compare google.com's search bar UI with this Figma search bar component"
First, confirm whether Playwright MCP and Figma MCP are configured and whether Figma auth is working.
If any prerequisite is missing, return the blocked guidance from DesignLatch and stop.
If prerequisites are available:
1. Use Playwright MCP to capture computed styles for selector "textarea[name='q']" on https://google.com
2. Use Figma MCP to inspect the "Search Bar" node/component in the provided Figma file
3. Call compare_live_ui_to_figma again with:
- prerequisites
- liveCapture
- figmaDesign
Then summarize:
- pass/fail
- score
- top mismatches
- report pathCommon Mistakes
- Referencing token keys in
configthat do not exist intokens - Using token shapes that DesignLatch does not understand
- Passing
snapshotsas an object instead of an array - Omitting the
computedobject inside a snapshot - Using selector names in snapshots that do not match the selectors in config
- Confusing CLI file paths with MCP inline JSON payloads
Typical MCP Flow
- Call
compare_live_ui_to_figmafor the user-facing workflow, or generate rawconfig,tokens, andsnapshotsyourself - If the compare tool returns
blocked, configure the missing prerequisite MCPs or fix Figma auth - If the compare tool returns
validated, gatherliveCaptureandfigmaDesignfrom Playwright MCP and Figma MCP - Call
validate_inputsfirst when working directly with raw DesignLatch payloads - Call
scan_complianceonce the payloads are valid - Use the returned report and evaluation in your agent workflow
Example multi-tool agent flow:
- Use Playwright MCP to inspect a live selector and capture computed styles
- Use Figma MCP to retrieve the expected design token values for the same component
- Convert those results into DesignLatch
config,tokens, andsnapshots - Call
validate_inputs - Call
scan_compliance - Return the score, fail reasons, and property-level mismatches
When To Use MCP vs CLI
Use MCP when:
- an AI agent is already orchestrating the workflow
- inputs are already in memory as JSON
- you want tool-call results instead of file-based commands
Use CLI when:
- you need Playwright collection
- you want HTML report generation and serving
- you want local files as the primary interface
