axo-mvo/puppeteer-mcp-server
If you are the rightful owner of puppeteer-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
Puppeteer MCP Server is a headless Chrome automation server built with Next.js and Puppeteer, designed to run on Vercel with multiple cloud browser options.
Puppeteer MCP Server
A headless Chrome automation server built with Next.js and Puppeteer, designed to run on Vercel with multiple cloud browser options. This project provides RESTful API endpoints for web scraping, screenshot capture, PDF generation, and performance monitoring.
š GitHub Repository: https://github.com/axo-mvo/puppeteer-mcp-server
š Live Demo: https://puppeteer-mcp-server.vercel.app
š® Interactive Demo: https://puppeteer-mcp-server.vercel.app/demo
Quick Test
Try the live API right now:
# Take a screenshot
curl "https://puppeteer-mcp-server.vercel.app/api/screenshot-chromium?url=https://example.com" -o screenshot.png
# Extract text content
curl -X POST "https://puppeteer-mcp-server.vercel.app/api/scrape" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com","action":"text"}'
Project Structure
puppeteer-vercel/
āāā app/
ā āāā api/
ā ā āāā screenshot-browserless/ # Browserless.io API endpoint
ā ā ā āāā route.ts
ā ā āāā screenshot-chromium/ # @sparticuz/chromium API endpoint
ā ā ā āāā route.ts
ā ā āāā scrape/ # Advanced scraping API endpoint
ā ā ā āāā route.ts
ā ā āāā mcp/ # Model Context Protocol endpoint
ā ā āāā route.ts
ā āāā demo/ # Interactive demo page
ā ā āāā page.tsx
ā āāā page.tsx # Main landing page
ā āāā layout.tsx # Root layout
ā āāā globals.css # Global styles
āāā package.json # Dependencies and scripts
āāā next.config.ts # Next.js configuration
āāā tailwind.config.ts # Tailwind CSS configuration
āāā README.md # Project documentation
Architectural Decisions
Browser Execution Options
The project implements two approaches for running headless Chrome in serverless environments:
-
@sparticuz/chromium (
/api/screenshot-chromium
)- Self-contained Chromium binary packaged with the function
- No external dependencies required
- Larger bundle size but more reliable
- Works within Vercel's function size limits
-
Browserless.io (
/api/screenshot-browserless
)- Connects to managed headless Chrome instances in the cloud
- Requires
BLESS_TOKEN
environment variable - Smaller function size
- Better for high-volume usage
API Design
- RESTful endpoints for different functionality
- TypeScript interfaces for request/response validation
- Comprehensive error handling with proper HTTP status codes
- Caching headers for improved performance
- Flexible options for customization
Setup Instructions
Prerequisites
- Node.js 18+
- npm, yarn, or pnpm
Local Development
-
Clone and install dependencies:
git clone https://github.com/axo-mvo/puppeteer-mcp-server.git cd puppeteer-mcp-server npm install
-
Set up environment variables (for Browserless.io): Create
.env.local
file:BLESS_TOKEN=your_browserless_api_token_here
-
Run the development server:
npm run dev
-
Access the application:
- Main page: http://localhost:3000
- Demo page: http://localhost:3000/demo
Deployment to Vercel
-
Push to GitHub:
git init git add . git commit -m "Initial commit" git remote add origin <your-github-repo-url> git push -u origin main
-
Deploy to Vercel:
- Import your GitHub repository in Vercel dashboard
- Add environment variables if using Browserless.io:
BLESS_TOKEN
: Your Browserless.io API token
-
Configure function timeout (optional): Add to
vercel.json
:{ "functions": { "app/api/**/route.ts": { "maxDuration": 30 } } }
MCP (Model Context Protocol) Support
This server now supports the Model Context Protocol (MCP), allowing it to be used as a tool server in AI assistants like Cursor, Claude Desktop, and other MCP-compatible clients.
MCP Endpoints
URL: /api/mcp
(Full-featured for Cursor, Claude Desktop, etc.)
URL: /api/mcp-compliant
(ChatGPT-compliant version with restrictions)
The MCP endpoint provides the following tools:
Tool Name | Description | Parameters |
---|---|---|
take_screenshot | Take a screenshot of a web page | url , fullPage? , viewport? , waitFor? |
generate_pdf | Generate a PDF from a web page | url , format? , landscape? , waitFor? |
extract_text | Extract text content from a web page | url , selector? , waitFor? |
extract_html | Extract HTML content from a web page | url , selector? , waitFor? |
get_performance_metrics | Get performance metrics for a web page | url , waitFor? |
Adding to AI Assistants
For Cursor/Claude Desktop (Full Version)
Add to your ~/.cursor/mcp.json
:
{
"mcpServers": {
"puppeteer-mcp": {
"url": "https://puppeteer-mcp-server.vercel.app/api/mcp",
"transport": "sse"
}
}
}
For ChatGPT (Compliant Version)
Use the compliant endpoint with restricted functionality:
- Go to ChatGPT Settings ā Connectors ā Create
- Add MCP Server URL:
https://puppeteer-mcp-server.vercel.app/api/mcp-compliant
- Only tools named
search
andretrieve
are available (OpenAI requirement) - Access is limited to approved domains for security
Using MCP Tools
Once configured, you can use natural language commands in Cursor:
- "Take a screenshot of example.com"
- "Generate a PDF of the homepage"
- "Extract the title text from this website"
- "Get performance metrics for this URL"
API Endpoints
Screenshot APIs
GET /api/screenshot-chromium
Takes screenshots using @sparticuz/chromium.
Parameters:
url
(required): URL to capture
Example:
curl "https://your-app.vercel.app/api/screenshot-chromium?url=https://example.com"
GET /api/screenshot-browserless
Takes screenshots using Browserless.io.
Parameters:
url
(required): URL to capture
Requires: BLESS_TOKEN
environment variable
Example:
curl "https://your-app.vercel.app/api/screenshot-browserless?url=https://example.com"
Advanced Scraping API
POST /api/scrape
Comprehensive scraping endpoint with multiple actions.
Request Body:
{
url: string;
action: 'screenshot' | 'pdf' | 'text' | 'html' | 'performance';
options?: {
fullPage?: boolean;
selector?: string;
format?: 'A4' | 'Letter';
landscape?: boolean;
waitFor?: number;
viewport?: {
width: number;
height: number;
};
};
}
Examples:
Screenshot with custom viewport:
curl -X POST "https://your-app.vercel.app/api/scrape" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"action": "screenshot",
"options": {
"fullPage": true,
"viewport": {"width": 1200, "height": 800}
}
}'
Generate PDF:
curl -X POST "https://your-app.vercel.app/api/scrape" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"action": "pdf",
"options": {
"format": "A4",
"landscape": false
}
}'
Extract text content:
curl -X POST "https://your-app.vercel.app/api/scrape" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"action": "text",
"options": {
"selector": "h1"
}
}'
Environment Variables
Variable | Required | Description |
---|---|---|
BLESS_TOKEN | No* | Browserless.io API token (*required for browserless endpoints) |
Features
- ā Screenshot capture (full page or viewport)
- ā PDF generation from web pages
- ā Text and HTML content extraction
- ā Performance metrics collection
- ā Custom viewport and wait options
- ā RESTful API endpoints
- ā MCP (Model Context Protocol) support
- ā TypeScript support
- ā Interactive demo interface
- ā Multiple browser execution options
- ā Comprehensive error handling
- ā AI assistant integration (Cursor, Claude Desktop)
Limitations
- Function timeout: Vercel free tier has 10-second timeout
- Function size: @sparticuz/chromium adds ~50MB to function
- Memory usage: Chrome requires significant memory allocation
- Concurrent executions: Consider rate limiting for production use
Troubleshooting
Common Issues
-
Function timeout errors (FUNCTION_INVOCATION_TIMEOUT):
- Fixed in latest version: Optimized Chrome args and faster page loading
- Uses
domcontentloaded
instead ofnetworkidle0
for faster loading - Increased function timeout to 60 seconds in
vercel.json
- Added proper browser cleanup to prevent memory leaks
-
Memory errors:
- Close browser instances properly (handled automatically)
- Avoid concurrent requests to same function
- Function memory set to 1024MB in configuration
-
Browserless.io connection errors:
- Verify
BLESS_TOKEN
is correctly set - Check Browserless.io service status
- Verify
Performance Optimizations
The latest version includes several Vercel-specific optimizations:
- Faster Chrome startup with optimized arguments
- Reduced page load time using
domcontentloaded
- Better error handling with automatic browser cleanup
- Increased timeouts for complex pages (60s function timeout)
- Memory optimization with single-process Chrome mode
Contributing
- Fork the repository
- Create a feature branch
- Make changes and test locally
- Submit a pull request
Change Log
- 2025-06-05: Initial project setup with Next.js 15 and Puppeteer integration
- 2025-06-05: Added @sparticuz/chromium support for self-contained browser execution
- 2025-06-05: Implemented Browserless.io integration for cloud browser instances
- 2025-06-05: Created comprehensive scraping API with multiple action types
- 2025-06-05: Built interactive demo interface with real-time testing
- 2025-06-05: Added TypeScript interfaces and comprehensive error handling
- 2025-06-05: Updated main landing page with feature overview and setup instructions
- 2025-06-05: Fixed Vercel timeout issues with optimized Chrome args and faster loading
- 2025-06-05: Increased function timeout to 60s and improved error handling
- 2025-06-05: Added production URL storage and comprehensive testing suite
- 2025-06-05: Fixed file download issue - PDFs and images now download with proper extensions (.pdf, .png) instead of generic .file extension
- 2025-06-05: Added Model Context Protocol (MCP) support with comprehensive tool definitions for AI assistant integration
- 2025-06-05: Created ChatGPT-compliant MCP endpoint with security restrictions and approved domain whitelist
Testing
Production Testing
Run the comprehensive test suite:
./test-production.sh
Or test individual endpoints:
# Health check
npm run test:prod
# Screenshot test
npm run test:screenshot
# Open demo page
npm run test:demo
Manual Testing
Live Endpoints:
- Main Site: https://puppeteer-mcp-server.vercel.app/
- Demo Page: https://puppeteer-mcp-server.vercel.app/demo
- Screenshot API:
https://puppeteer-mcp-server.vercel.app/api/screenshot-chromium?url=https://example.com
- Advanced Scraping:
POST https://puppeteer-mcp-server.vercel.app/api/scrape