Skip to main content
Glama

PuppeteerMCP Server

by hushaudio
progress.md6.97 kB
# PuppeteerMCP Development Progress ## Project Status: ✅ FULLY WORKING IN CURSOR ### ✅ Latest Update - PAGE INTERACTION CAPABILITIES - [x] **Click interactions** - Click buttons, links, and other elements by CSS selector - [x] **Form input handling** - Type text into input fields and text areas - [x] **Form field management** - Clear fields, select dropdown options - [x] **Scrolling controls** - Scroll to specific coordinates or elements - [x] **Hover effects** - Trigger hover states on elements - [x] **Wait conditions** - Wait for specific durations or elements to appear - [x] **Page navigation** - Navigate to different URLs during interaction flow - [x] **Action sequencing** - Execute multiple actions in order before screenshot - [x] **Error handling** - Proper error reporting for failed actions ### ✅ Previous Update - ERROR REPORTING ENHANCEMENT - [x] **JavaScript error collection** - Captures page JavaScript errors with stack traces - [x] **Console log capture** - All console.log, console.warn, console.error messages - [x] **Network error detection** - Failed requests, 404s, 500s, CORS issues - [x] **Security error monitoring** - CORS violations and request failures - [x] **Error categorization** - Groups by type (JavaScript, console, network, security) - [x] **Detailed error reporting** - Line numbers, sources, timestamps, status codes - [x] **Error summary stats** - Quick overview of total errors, warnings, and logs ### ✅ Previous Update - IMAGE FORMAT FIX - [x] **Fixed Cursor image display** - Images now appear inline in chat - [x] **Proper MCP content format** - Using content array with type:"image" blocks - [x] **Image optimization** - JPEG format with quality control - [x] **Width limiting** - Auto-clip images wider than maxWidth - [x] **Multi-format support** - Both PNG and JPEG options - [x] **Token optimization** - Smaller file sizes to avoid 10MB limit ### ✅ Completed - CORRECT MCP APPROACH - [x] **Proper MCP server implementation using @modelcontextprotocol/sdk** - [x] **stdio transport communication** - [x] **Screenshot tool implementation** with Puppeteer - [x] **Multi-breakpoint support** (375px, 768px, 1280px defaults) - [x] **Full-page auto-height detection** - [x] **Base64 image encoding for data URLs** - [x] **TypeScript compilation successful** - [x] **MCP Inspector testing available** - [x] **Browser instance management and cleanup** - [x] **Error handling and validation** ### Current Implementation Details #### Files Structure ``` src/ ├── index.ts # Main MCP server with stdio transport └── tools/ └── screenshotTool.ts # Puppeteer screenshot implementation build/ # Compiled JavaScript for Cursor ``` #### Tool Available - **screenshot**: Takes URL, captures at multiple breakpoints, returns base64 images with metadata #### Scripts Working - ✅ `npm run build` - Compiles TypeScript successfully - ✅ `npm run inspector` - MCP Inspector running on http://127.0.0.1:6274 - ✅ `npm start` - Runs MCP server directly ## How to Test in Cursor ### 1. Configuration Required Create `~/.cursor/mcp.json`: ```json { "mcpServers": { "puppeteer-mcp": { "command": "node", "args": ["/Users/aaronshier/Documents/GitHub/PuppeteerMCP/build/index.js"], "env": {} } } } ``` ### 2. Steps to Use 1. Create the mcp.json file with your actual path 2. Restart Cursor 3. In Cursor chat, ask: "Take a screenshot of https://example.com" 4. The AI will use the screenshot tool and show you the captured images ### 3. Verification - MCP Inspector shows the tool is working: http://127.0.0.1:6274 - TypeScript compiles without errors - Server starts and listens on stdio transport ### Image Format Solution **Problem:** Screenshots weren't showing in Cursor chat **Solution:** Updated response format from JSON text to MCP content blocks: ```typescript // OLD (Wrong - JSON as text) return { content: [{ type: "text", text: JSON.stringify(result) }] }; // NEW (Correct - Images as content blocks) return { content: [ { type: "text", text: "Screenshot captured:" }, { type: "image", data: base64Data, mimeType: "image/jpeg" } ] }; ``` ### New Optimization Features - **Default JPEG format** (80% quality) for smaller files - **Auto width limiting** - clips images > 1280px wide - **Configurable quality** - 1-100 for JPEG compression - **Format selection** - PNG or JPEG options - **Size optimization** - prevents hitting 10MB message limits ## Next Steps - ✅ **FULLY WORKING IN CURSOR** - Images appear inline in chat - ✅ **Optimized for performance** - JPEG compression and width limiting - 📋 Future: Add more viewport options - 📋 Future: Add element-specific screenshots - 📋 Future: Add page interaction capabilities ## Technical Success - ✅ Proper MCP protocol implementation - ✅ stdio transport working - ✅ Tool schema validation - ✅ Puppeteer integration functional - ✅ Multi-breakpoint screenshot capture - ✅ Base64 encoding for immediate use - ✅ Error handling and graceful cleanup ## Configuration for Cursor The proper way to integrate with Cursor is via mcp.json configuration: **Location:** `~/.cursor/mcp.json` (create if doesn't exist) **Format:** ```json { "mcpServers": { "puppeteer": { "command": "node", "args": ["/absolute/path/to/PuppeteerMCP/build/index.js"] } } } ``` ## Key Differences: HTTP API vs MCP | Aspect | HTTP API (WRONG) | MCP Server (CORRECT) | |--------|------------------|----------------------| | Communication | HTTP requests | stdio + JSON-RPC | | Framework | Express.js | MCP SDK | | Interface | REST endpoints | Tools | | Integration | Manual API calls | Native protocol | | Discovery | Documentation | Tool schema | | Testing | curl/Postman | MCP inspector | ## Next Steps 1. **STOP** current HTTP approach 2. **START** fresh MCP implementation 3. **REUSE** Puppeteer business logic 4. **TEST** with MCP inspector first 5. **CONFIGURE** Cursor integration 6. **DOCUMENT** proper usage ## Commands for MCP Development ```bash # Remove wrong dependencies npm uninstall express cors helmet morgan # Install MCP dependencies npm install @modelcontextprotocol/sdk # Build for Cursor npm run build # Test with MCP inspector npx @modelcontextprotocol/inspector build/index.js # Debug MCP server node build/index.js ``` ## Lessons Learned - **MCP is NOT an HTTP API** - it's a protocol for tool communication - **stdio transport** is used for local AI integration (like Cursor) - **Tools are discovered via protocol**, not documentation - **Always test with MCP inspector** before integrating with AI hosts - **Absolute paths required** in Cursor configuration - **Restart required** after configuration changes --- **Status:** Ready to restart with proper MCP implementation **Next Action:** Remove HTTP code and implement MCP server **Priority:** High - Core architecture change needed

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hushaudio/PuppeteerMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server