mcp-design-comparison 0.1.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/AGENTS.md ADDED
@@ -0,0 +1,57 @@
1
+ # AGENTS.md
2
+
3
+ This file provides guidance to WARP (warp.dev) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ This is an MCP (Model Context Protocol) server that exposes a single tool (`compare_design`) for comparing design screenshots with implementation screenshots using pixelmatch. The server communicates via stdio and is intended to be used by MCP clients like Claude Desktop.
8
+
9
+ ## Development Commands
10
+
11
+ ```bash
12
+ # Install dependencies
13
+ npm install
14
+
15
+ # Build TypeScript to dist/
16
+ npm run build
17
+
18
+ # Watch mode for development
19
+ npm run watch
20
+ ```
21
+
22
+ ## Architecture
23
+
24
+ ### Single-file MCP Server (`src/index.ts`)
25
+
26
+ The entire server is implemented in one file with three main components:
27
+
28
+ 1. **Image Processing Functions**:
29
+ - `loadPNG()`: Reads PNG files using pngjs
30
+ - `compareScreenshots()`: Core comparison logic using pixelmatch, returns metrics and diff image
31
+
32
+ 2. **MCP Server Setup**:
33
+ - Uses `@modelcontextprotocol/sdk` with stdio transport
34
+ - Registers handlers for `ListToolsRequestSchema` and `CallToolRequestSchema`
35
+
36
+ 3. **Tool Implementation** (`compare_design`):
37
+ - Accepts two PNG paths, optional output path, and threshold (0-1)
38
+ - Returns text response with statistics + optional base64 image or saves to file
39
+ - Validates matching image dimensions before comparison
40
+
41
+ ### Key Constraints
42
+
43
+ - Only PNG format is supported (via pngjs library)
44
+ - Images must have identical dimensions
45
+ - Server runs on stdio (not HTTP) - designed for local MCP client communication
46
+ - Uses ES modules (`"type": "module"` in package.json)
47
+ - TypeScript compilation uses `Node16` module resolution
48
+
49
+ ## Testing the Server
50
+
51
+ There is no test framework yet. To test manually:
52
+
53
+ 1. Build the project: `npm run build`
54
+ 2. Configure an MCP client (e.g., Claude Desktop) to point to `dist/index.js`
55
+ 3. Use the `compare_design` tool with two PNG screenshots
56
+
57
+ The server logs to stderr, so startup messages won't interfere with MCP stdio communication.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # MCP Design Comparison Server
2
+
3
+ An MCP (Model Context Protocol) server that allows LLMs to compare design screenshots with implementation screenshots using [pixelmatch](https://github.com/mapbox/pixelmatch). This tool helps identify visual discrepancies between design mockups and actual implementation.
4
+
5
+ ## Features
6
+
7
+ - **Screenshot Comparison**: Compare two PNG images pixel-by-pixel
8
+ - **Visual Diff Output**: Generate a highlighted diff image showing differences
9
+ - **Detailed Metrics**: Get total pixels, different pixels, and percentage difference
10
+ - **Configurable Threshold**: Adjust sensitivity of the comparison
11
+ - **Base64 Support**: Return diff images as base64 or save to file
12
+
13
+ ## Installation
14
+
15
+ ### For End Users
16
+
17
+ Install globally via npm:
18
+
19
+ ```bash
20
+ npm install -g mcp-design-comparison
21
+ ```
22
+
23
+ Or using npx (no installation required):
24
+
25
+ ```bash
26
+ npx mcp-design-comparison
27
+ ```
28
+
29
+ ### For Development
30
+
31
+ ```bash
32
+ git clone https://github.com/w01fgang/mcp-design-comparison.git
33
+ cd mcp-design-comparison
34
+ npm install
35
+ npm run build
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### As an MCP Server
41
+
42
+ Add this server to your MCP client configuration. The server runs on stdio and provides a single tool:
43
+
44
+ #### Tool: `compare_design`
45
+
46
+ Compare a design screenshot with an implementation screenshot.
47
+
48
+ **Parameters:**
49
+ - `design_path` (string, required): Path to the design screenshot (PNG format)
50
+ - `implementation_path` (string, required): Path to the implementation screenshot (PNG format)
51
+ - `output_diff_path` (string, optional): Path to save the diff image. If not provided, the diff image will be returned as base64
52
+ - `threshold` (number, optional): Matching threshold (0-1). Smaller values make the comparison more sensitive. Default is 0.1
53
+
54
+ **Returns:**
55
+ - Total number of pixels
56
+ - Number of different pixels
57
+ - Percentage difference
58
+ - Diff image (as file or base64)
59
+
60
+ ### Configuration Example
61
+
62
+ Add to your MCP settings file:
63
+
64
+ **Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
65
+
66
+ ```json
67
+ {
68
+ "mcpServers": {
69
+ "design-comparison": {
70
+ "command": "npx",
71
+ "args": ["-y", "mcp-design-comparison"]
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ **Cursor** (`~/Library/Application Support/Cursor/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` on macOS):
78
+
79
+ ```json
80
+ {
81
+ "mcpServers": {
82
+ "design-comparison": {
83
+ "command": "npx",
84
+ "args": ["-y", "mcp-design-comparison"]
85
+ }
86
+ }
87
+ }
88
+ ```
89
+
90
+ After adding the configuration, restart Claude Desktop or Cursor.
91
+
92
+ ## How It Works
93
+
94
+ 1. Loads both PNG images into memory
95
+ 2. Validates that dimensions match
96
+ 3. Uses pixelmatch to compare pixel-by-pixel
97
+ 4. Generates a diff image highlighting differences in pink
98
+ 5. Returns statistics and the diff image
99
+
100
+ ## Example Use Cases
101
+
102
+ - **Design QA**: Verify that implementation matches design mockups
103
+ - **Regression Testing**: Compare screenshots before and after changes
104
+ - **Cross-browser Testing**: Compare renders across different browsers
105
+ - **Responsive Design**: Compare layouts at different breakpoints
106
+
107
+ ## Requirements
108
+
109
+ - Node.js 18+
110
+ - PNG images with matching dimensions
111
+
112
+ ## License
113
+
114
+ MIT
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
+ import fs from "fs/promises";
6
+ import pixelmatch from "pixelmatch";
7
+ import { PNG } from "pngjs";
8
+ async function loadPNG(filePath) {
9
+ const data = await fs.readFile(filePath);
10
+ return PNG.sync.read(data);
11
+ }
12
+ async function compareScreenshots(designPath, implementationPath, outputDiffPath, threshold = 0.1) {
13
+ // Load both images
14
+ const design = await loadPNG(designPath);
15
+ const implementation = await loadPNG(implementationPath);
16
+ // Check if dimensions match
17
+ if (design.width !== implementation.width ||
18
+ design.height !== implementation.height) {
19
+ throw new Error(`Image dimensions don't match: design (${design.width}x${design.height}) vs implementation (${implementation.width}x${implementation.height})`);
20
+ }
21
+ // Create a diff image
22
+ const diff = new PNG({ width: design.width, height: design.height });
23
+ // Compare images using pixelmatch
24
+ const differentPixels = pixelmatch(design.data, implementation.data, diff.data, design.width, design.height, { threshold });
25
+ const totalPixels = design.width * design.height;
26
+ const differencePercentage = (differentPixels / totalPixels) * 100;
27
+ const result = {
28
+ totalPixels,
29
+ differentPixels,
30
+ differencePercentage,
31
+ };
32
+ // Save or encode diff image
33
+ if (outputDiffPath) {
34
+ await fs.writeFile(outputDiffPath, PNG.sync.write(diff));
35
+ }
36
+ else {
37
+ // Return base64 encoded diff image
38
+ const buffer = PNG.sync.write(diff);
39
+ result.diffImageBase64 = buffer.toString("base64");
40
+ }
41
+ return result;
42
+ }
43
+ // Create server instance
44
+ const server = new Server({
45
+ name: "mcp-design-comparison",
46
+ version: "0.1.0",
47
+ }, {
48
+ capabilities: {
49
+ tools: {},
50
+ },
51
+ });
52
+ // List available tools
53
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
54
+ return {
55
+ tools: [
56
+ {
57
+ name: "compare_design",
58
+ description: "Compare a design screenshot with an implementation screenshot using pixelmatch. Returns the number and percentage of different pixels, and optionally outputs a diff image highlighting the differences.",
59
+ inputSchema: {
60
+ type: "object",
61
+ properties: {
62
+ design_path: {
63
+ type: "string",
64
+ description: "Path to the design screenshot (PNG format)",
65
+ },
66
+ implementation_path: {
67
+ type: "string",
68
+ description: "Path to the implementation screenshot (PNG format)",
69
+ },
70
+ output_diff_path: {
71
+ type: "string",
72
+ description: "Optional path to save the diff image. If not provided, the diff image will be returned as base64.",
73
+ },
74
+ threshold: {
75
+ type: "number",
76
+ description: "Matching threshold (0-1). Smaller values make the comparison more sensitive. Default is 0.1.",
77
+ default: 0.1,
78
+ },
79
+ },
80
+ required: ["design_path", "implementation_path"],
81
+ },
82
+ },
83
+ ],
84
+ };
85
+ });
86
+ // Handle tool calls
87
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
88
+ if (request.params.name === "compare_design") {
89
+ const { design_path, implementation_path, output_diff_path, threshold = 0.1, } = request.params.arguments;
90
+ try {
91
+ const result = await compareScreenshots(design_path, implementation_path, output_diff_path, threshold);
92
+ let responseText = `Design Comparison Results:\n\n`;
93
+ responseText += `Total Pixels: ${result.totalPixels.toLocaleString()}\n`;
94
+ responseText += `Different Pixels: ${result.differentPixels.toLocaleString()}\n`;
95
+ responseText += `Difference: ${result.differencePercentage.toFixed(2)}%\n`;
96
+ if (output_diff_path) {
97
+ responseText += `\nDiff image saved to: ${output_diff_path}`;
98
+ }
99
+ const content = [
100
+ {
101
+ type: "text",
102
+ text: responseText,
103
+ },
104
+ ];
105
+ // If we have base64 image data, include it
106
+ if (result.diffImageBase64) {
107
+ content.push({
108
+ type: "image",
109
+ data: result.diffImageBase64,
110
+ mimeType: "image/png",
111
+ });
112
+ }
113
+ return {
114
+ content,
115
+ };
116
+ }
117
+ catch (error) {
118
+ return {
119
+ content: [
120
+ {
121
+ type: "text",
122
+ text: `Error comparing screenshots: ${error instanceof Error ? error.message : String(error)}`,
123
+ },
124
+ ],
125
+ isError: true,
126
+ };
127
+ }
128
+ }
129
+ throw new Error(`Unknown tool: ${request.params.name}`);
130
+ });
131
+ // Start the server
132
+ async function main() {
133
+ const transport = new StdioServerTransport();
134
+ await server.connect(transport);
135
+ console.error("MCP Design Comparison Server running on stdio");
136
+ }
137
+ main().catch((error) => {
138
+ console.error("Fatal error:", error);
139
+ process.exit(1);
140
+ });
141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
+ "description": "MCP server for comparing design screenshots with implementation using pixelmatch",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "mcp-design-comparison": "./dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "watch": "tsc --watch",
13
+ "prepare": "npm run build"
14
+ },
15
+ "keywords": [
16
+ "mcp",
17
+ "design",
18
+ "comparison",
19
+ "screenshot",
20
+ "pixelmatch"
21
+ ],
22
+ "author": "wolf",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/w01fgang/mcp-design-comparison.git"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "AGENTS.md"
32
+ ],
33
+ "dependencies": {
34
+ "@modelcontextprotocol/sdk": "^1.0.4",
35
+ "pixelmatch": "^7.0.0",
36
+ "pngjs": "^7.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^22.0.0",
40
+ "@types/pixelmatch": "^5.2.6",
41
+ "@types/pngjs": "^6.0.5",
42
+ "typescript": "^5.7.0"
43
+ }
44
+ }