amotivv cloudflare browser rendering
by amotivv
This project demonstrates how to use Cloudflare Browser Rendering to extract web content for LLM context. It includes experiments with the REST API and Workers Binding API, as well as an MCP server implementation that can be used to provide web context to LLMs.
What is amotivv cloudflare browser rendering
Cloudflare Browser Rendering Experiments & MCP Server
This project demonstrates how to use Cloudflare Browser Rendering to extract web content for LLM context. It includes experiments with the REST API and Workers Binding API, as well as an MCP server implementation that can be used to provide web context to LLMs.
Project Structure
cloudflare-browser-rendering/
āāā examples/ # Example implementations and utilities
ā āāā basic-worker-example.js # Basic Worker with Browser Rendering
ā āāā minimal-worker-example.js # Minimal implementation
ā āāā debugging-tools/ # Tools for debugging
ā ā āāā debug-test.js # Debug test utility
ā āāā testing/ # Testing utilities
ā āāā content-test.js # Content testing utility
āāā experiments/ # Educational experiments
ā āāā basic-rest-api/ # REST API tests
ā āāā puppeteer-binding/ # Workers Binding API tests
ā āāā content-extraction/ # Content processing tests
āāā src/ # MCP server source code
ā āāā index.ts # Main entry point
ā āāā server.ts # MCP server implementation
ā āāā browser-client.ts # Browser Rendering client
ā āāā content-processor.ts # Content processing utilities
āāā puppeteer-worker.js # Cloudflare Worker with Browser Rendering binding
āāā test-puppeteer.js # Tests for the main implementation
āāā wrangler.toml # Wrangler configuration for the Worker
āāā cline_mcp_settings.json.example # Example MCP settings for Cline
āāā .gitignore # Git ignore file
āāā LICENSE # MIT License
Prerequisites
- Node.js (v16 or later)
- A Cloudflare account with Browser Rendering enabled
- TypeScript
- Wrangler CLI (for deploying the Worker)
Installation
- Clone the repository:
git clone https://github.com/yourusername/cloudflare-browser-rendering.git
cd cloudflare-browser-rendering
- Install dependencies:
npm install
Cloudflare Worker Setup
- Install the Cloudflare Puppeteer package:
npm install @cloudflare/puppeteer
- Configure Wrangler:
# wrangler.toml
name = "browser-rendering-api"
main = "puppeteer-worker.js"
compatibility_date = "2023-10-30"
compatibility_flags = ["nodejs_compat"]
[browser]
binding = "browser"
- Deploy the Worker:
npx wrangler deploy
- Test the Worker:
node test-puppeteer.js
Running the Experiments
Basic REST API Experiment
This experiment demonstrates how to use the Cloudflare Browser Rendering REST API to fetch and process web content:
npm run experiment:rest
Puppeteer Binding API Experiment
This experiment demonstrates how to use the Cloudflare Browser Rendering Workers Binding API with Puppeteer for more advanced browser automation:
npm run experiment:puppeteer
Content Extraction Experiment
This experiment demonstrates how to extract and process web content specifically for use as context in LLMs:
npm run experiment:content
MCP Server
The MCP server provides tools for fetching and processing web content using Cloudflare Browser Rendering for use as context in LLMs.
Building the MCP Server
npm run build
Running the MCP Server
npm start
Or, for development:
npm run dev
MCP Server Tools
The MCP server provides the following tools:
fetch_page
- Fetches and processes a web page for LLM contextsearch_documentation
- Searches Cloudflare documentation and returns relevant contentextract_structured_content
- Extracts structured content from a web page using CSS selectorssummarize_content
- Summarizes web content for more concise LLM context
Configuration
To use your Cloudflare Browser Rendering endpoint, set the BROWSER_RENDERING_API
environment variable:
export BROWSER_RENDERING_API=https://YOUR_WORKER_URL_HERE
Replace YOUR_WORKER_URL_HERE
with the URL of your deployed Cloudflare Worker. You'll need to replace this placeholder in several files:
- In test files:
test-puppeteer.js
,examples/debugging-tools/debug-test.js
,examples/testing/content-test.js
- In the MCP server configuration:
cline_mcp_settings.json.example
- In the browser client:
src/browser-client.ts
(as a fallback if the environment variable is not set)
Integrating with Cline
To integrate the MCP server with Cline, copy the cline_mcp_settings.json.example
file to the appropriate location:
cp cline_mcp_settings.json.example ~/Library/Application\ Support/claude-code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
Or add the configuration to your existing cline_mcp_settings.json
file.
Key Learnings
- Cloudflare Browser Rendering requires the
@cloudflare/puppeteer
package to interact with the browser binding. - The correct pattern for using the browser binding is:
import puppeteer from '@cloudflare/puppeteer'; // Then in your handler: const browser = await puppeteer.launch(env.browser); const page = await browser.newPage();
- When deploying a Worker that uses the Browser Rendering binding, you need to enable the
nodejs_compat
compatibility flag. - Always close the browser after use to avoid resource leaks.
License
MIT
Leave a Comment
Frequently Asked Questions
What is MCP?
MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.
What are MCP Servers?
MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.
How do MCP Servers work?
MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.
Are MCP Servers secure?
Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.
Related MCP Servers
Brave Search MCP
Integrate Brave Search capabilities into Claude through MCP. Enables real-time web searches with privacy-focused results and comprehensive web coverage.
AWS Knowledge Base Retrieval
An MCP server implementation for retrieving information from the AWS Knowledge Base using the Bedrock Agent Runtime.
chrisdoc hevy mcp
sylphlab pdf reader mcp
An MCP server built with Node.js/TypeScript that allows AI agents to securely read PDF files (local or URL) and extract text, metadata, or page counts. Uses pdf-parse.
aashari mcp server atlassian bitbucket
Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MCP interface.
aashari mcp server atlassian confluence
Node.js/TypeScript MCP server for Atlassian Confluence. Provides tools enabling AI systems (LLMs) to list/get spaces & pages (content formatted as Markdown) and search via CQL. Connects AI seamlessly to Confluence knowledge bases using the standard MCP interface.
prisma prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
Zzzccs123 mcp sentry
mcp sentry for typescript sdk
zhuzhoulin dify mcp server
zhongmingyuan mcp my mac
Submit Your MCP Server
Share your MCP server with the community
Submit Now