
Puppeteer
STDIOPuppeteerMCP服务器是一个Node.js服务器应用程序,它提供了一个高级API,通过DevTools协议控制Chrome或Chromium。它被设计用于自动化浏览器任务、网页抓取和测试,通过类似Puppeteer的接口,可以远程访问。
PuppeteerMCP服务器是一个Node.js服务器应用程序,它提供了一个高级API,通过DevTools协议控制Chrome或Chromium。它被设计用于自动化浏览器任务、网页抓取和测试,通过类似Puppeteer的接口,可以远程访问。
Developing website UI's with MCP just got a lot easier. A Model Context Protocol (MCP) server that provides screenshot tools for AI assistants using Puppeteer. This server integrates with MCP-compatible hosts like Cursor to enable AI agents to capture and analyze web page screenshots, console logs, errors, and warnings.
PuppeteerMCP implements the Model Context Protocol to bridge AI assistants with web page screenshot capabilities. When working with AI-assisted development, this server allows AI agents to:
This enables more effective AI-assisted development by providing visual context through the standardized MCP protocol.
The screenshot tool now supports executing a sequence of page interactions before capturing screenshots, enabling:
click
- Click an element by CSS selectortype
- Type text into an input fieldclear
- Clear an input field's valuescroll
- Scroll to coordinates or elementhover
- Hover over an elementselect
- Select option from dropdownwait
- Wait for specified durationwaitForElement
- Wait for element to appearnavigate
- Navigate to a different URL{ "url": "https://example.com/login", "actions": [ { "type": "type", "selector": "#username", "text": "[email protected]" }, { "type": "type", "selector": "#password", "text": "password123" }, { "type": "click", "selector": "#login-button" }, { "type": "waitForElement", "selector": ".dashboard", "timeout": 5000 } ] }
Captures screenshots of web pages at one or more viewport breakpoints using Puppeteer.
{ "name": "screenshot", "description": "Capture screenshots of web pages at multiple viewport breakpoints", "inputSchema": { "type": "object", "properties": { "url": { "type": "string", "description": "URL to capture screenshots from" }, "breakpoints": { "type": "array", "items": { "type": "object", "properties": { "width": { "type": "number" } } }, "description": "Viewport breakpoints (optional, defaults to mobile/tablet/desktop)" }, "headless": { "type": "boolean", "description": "Run browser in headless mode", "default": true }, "waitFor": { "type": "string", "enum": ["load", "domcontentloaded", "networkidle0", "networkidle2"], "description": "Wait condition before capturing", "default": "networkidle0" }, "timeout": { "type": "number", "description": "Navigation timeout in milliseconds", "default": 30000 }, "actions": { "type": "array", "items": { "type": "object", "properties": { "type": { "type": "string", "enum": ["click", "type", "scroll", "wait", "hover", "select", "clear", "navigate", "waitForElement"], "description": "Type of action to perform" }, "selector": { "type": "string", "description": "CSS selector for element-based actions" }, "text": { "type": "string", "description": "Text to type (for type action)" }, "value": { "type": "string", "description": "Value to select (for select action)" }, "x": { "type": "number", "description": "X coordinate (for scroll action)" }, "y": { "type": "number", "description": "Y coordinate (for scroll action)" }, "duration": { "type": "number", "description": "Duration in milliseconds (for wait action)", "default": 1000 }, "url": { "type": "string", "description": "URL to navigate to (for navigate action)" }, "timeout": { "type": "number", "description": "Timeout in milliseconds (for waitForElement action)", "default": 5000 } }, "required": ["type"] }, "description": "Array of page interactions to perform before taking screenshots" } }, "required": ["url"] } }
If no breakpoints are specified, the tool uses these standard responsive breakpoints:
{ "screenshots": [ { "width": 375, "height": 2340, "screenshot": "data:image/jpeg;base64,/9j/4AAQ...", "format": "jpeg", "metadata": { "viewport": { "width": 375, "height": 800 }, "actualContentSize": { "width": 375, "height": 2340 }, "loadTime": 1250, "timestamp": "2024-01-15T10:30:00Z", "optimized": false } } ], "pageErrors": [ { "type": "console", "level": "info", "message": "User clicked login button", "source": "https://example.com/app.js", "line": 42, "column": 8, "timestamp": "2024-01-15T10:30:01Z" }, { "type": "network", "level": "warning", "message": "Failed to load resource: 404 Not Found", "url": "https://example.com/missing-image.png", "statusCode": 404, "timestamp": "2024-01-15T10:30:02Z" } ], "errorSummary": { "totalErrors": 0, "totalWarnings": 1, "totalLogs": 1, "hasJavaScriptErrors": false, "hasNetworkErrors": false, "hasConsoleLogs": true } }
The screenshot tool now captures and reports all page activity, making it perfect for debugging web applications:
console.log()
, console.warn()
, console.error()
outputinterface PageError { type: "javascript" | "console" | "network" | "security"; level: "error" | "warning" | "info"; message: string; source?: string; // File/URL where error occurred line?: number; // Line number (for JS errors) column?: number; // Column number (for JS errors) timestamp: string; // When the error occurred url?: string; // Request URL (for network errors) statusCode?: number; // HTTP status code (for network errors) }
When you take a screenshot, Cursor will show:
This makes the screenshot tool incredibly powerful for debugging, development, and code review - you can literally see what's happening on the page while viewing how it looks!
# Clone the repository git clone <repository-url> cd PuppeteerMCP # Install dependencies npm install # Build the server npm run build # Test with MCP inspector npx @modelcontextprotocol/inspector build/index.js
To use this MCP server with Cursor:
npm run build
Add the MCP server to your Cursor configuration. The exact location depends on your OS:
macOS: ~/.cursor/mcp.json
Windows: %APPDATA%\Cursor\mcp.json
Linux: ~/.config/cursor/mcp.json
{ "mcpServers": { "puppeteer": { "command": "node", "args": ["/absolute/path/to/PuppeteerMCP/build/index.js"] } } }
Important: Use the absolute path to your built JavaScript file.
Restart Cursor to load the MCP server. You should see the screenshot tool available in Cursor's AI interface.
You can now ask Cursor to take screenshots and they will appear as inline images in the chat:
The screenshots will appear directly in Cursor's chat interface with comprehensive error reporting, allowing multimodal AI models (GPT-4o, Claude 3, Gemini Pro) to analyze them visually AND provide feedback on both design/layout AND technical issues like JavaScript errors, failed network requests, and console warnings.
PuppeteerMCP/
├── src/
│ ├── index.ts # Main MCP server entry point
│ ├── tools/
│ │ └── screenshotTools.ts # Screenshot tool implementations
│ ├── services/
│ │ └── puppeteerService.ts # Puppeteer business logic
│ ├── types/
│ │ └── index.ts # TypeScript type definitions
│ └── utils/
│ └── logger.ts # Logging utilities
├── build/ # Compiled JavaScript (for Cursor)
├── package.json
├── tsconfig.json
└── README.md
npm run build
: Build TypeScript to JavaScriptnpm run watch
: Build in watch mode during developmentnpm run test
: Run test suite (when implemented)npm run lint
: Run ESLint (when configured)The MCP inspector is the primary tool for testing MCP servers:
# After building npx @modelcontextprotocol/inspector build/index.js
This opens a web interface where you can:
@modelcontextprotocol/sdk
Cursor AI → MCP Protocol → stdio Transport → PuppeteerMCP Server → Puppeteer → Browser → Screenshots → Response
Aspect | HTTP API | MCP Server |
---|---|---|
Communication | HTTP requests/responses | stdio + JSON-RPC 2.0 |
Discovery | Documentation | Tool schema registration |
Integration | Manual API calls | Native MCP protocol support |
AI Usage | Requires custom code | Direct tool calling |
Transport | Network-based | Process-based (subprocess) |
PUPPETEER_EXECUTABLE_PATH
: Custom Chrome/Chromium pathNODE_ENV
: Environment mode (development/production)Tools can be configured through their input parameters:
The server uses MCP's structured error handling:
InvalidParams
: Invalid tool parametersInternalError
: Server-side errors (browser failures, timeouts)MethodNotFound
: Unknown tool namesAll errors include descriptive messages for debugging.
Server not appearing in Cursor:
Tool calls failing:
Browser launch failures:
MIT License - see LICENSE file for details.
For issues and questions:
Name | Width | Description |
---|---|---|
Mobile | 375px | Typical smartphone width |
Tablet | 768px | Standard tablet width |
Desktop | 1280px | Common desktop width |
All screenshots automatically detect page height for full content capture.
To ensure screenshots work well with Cursor's chat interface and don't exceed token limits:
// High quality PNG (larger files) { "imageFormat": "png" } // Custom JPEG quality { "imageFormat": "jpeg", "quality": 90 } // Custom width limit { "maxWidth": 1920 }