Cloudflareブラウザレンダリング実験とMCPサーバー
このプロジェクトでは、Cloudflare Browser Renderingを用いてLLMコンテキスト用のWebコンテンツを抽出する方法を紹介します。REST APIとWorkers Binding APIを用いた実験に加え、LLMにWebコンテキストを提供するために使用できるMCPサーバー実装も含まれています。
プロジェクト構造
前提条件
Node.js (v16以降)
ブラウザレンダリングが有効になっているCloudflareアカウント
タイプスクリプト
Wrangler CLI (ワーカーのデプロイ用)
インストール
リポジトリをクローンします。
依存関係をインストールします:
Cloudflareワーカーのセットアップ
Cloudflare Puppeteer パッケージをインストールします。
Wrangler を設定します。
ワーカーをデプロイする:
ワーカーをテストする:
実験の実行
基本的なREST API実験
この実験では、Cloudflare ブラウザ レンダリング REST API を使用して Web コンテンツを取得および処理する方法を示します。
Puppeteer バインディング API 実験
この実験では、より高度なブラウザ自動化を実現するために、Puppeteer で Cloudflare Browser Rendering Workers Binding API を使用する方法を示します。
コンテンツ抽出実験
この実験では、LLM のコンテキストとして使用するために Web コンテンツを抽出して処理する方法を示します。
MCPサーバー
MCP サーバーは、LLM のコンテキストとして使用するために、Cloudflare ブラウザ レンダリングを使用して Web コンテンツを取得および処理するためのツールを提供します。
MCPサーバーの構築
MCPサーバーの実行
あるいは、開発の場合:
MCP サーバーツール
MCP サーバーは次のツールを提供します。
fetch_page- LLMコンテキストのWebページを取得して処理しますsearch_documentation- Cloudflareのドキュメントを検索し、関連するコンテンツを返しますextract_structured_content- CSSセレクターを使用してWebページから構造化コンテンツを抽出しますsummarize_content- LLM コンテキストをより簡潔にするために Web コンテンツを要約します
構成
Cloudflare ブラウザ レンダリング エンドポイントを使用するには、 BROWSER_RENDERING_API環境変数を設定します。
YOUR_WORKER_URL_HERE 、デプロイしたCloudflare WorkerのURLに置き換えてください。このプレースホルダは、以下のファイルで置き換える必要があります。
テストファイル内:
test-puppeteer.js、examples/debugging-tools/debug-test.js、examples/testing/content-test.jsMCP サーバー構成:
cline_mcp_settings.json.exampleブラウザクライアントの場合:
src/browser-client.ts(環境変数が設定されていない場合のフォールバックとして)
Clineとの統合
MCP サーバーを Cline と統合するには、 cline_mcp_settings.json.exampleファイルを適切な場所にコピーします。
または、既存のcline_mcp_settings.jsonファイルに構成を追加します。
主な学び
Cloudflare ブラウザ レンダリングでは、ブラウザ バインディングと対話するために
@cloudflare/puppeteerパッケージが必要です。ブラウザ バインディングを使用する正しいパターンは次のとおりです。
import puppeteer from '@cloudflare/puppeteer'; // Then in your handler: const browser = await puppeteer.launch(env.browser); const page = await browser.newPage();ブラウザ レンダリング バインディングを使用するワーカーをデプロイする場合は、
nodejs_compat互換性フラグを有効にする必要があります。リソースの漏洩を防ぐため、使用後は必ずブラウザを閉じてください。
ライセンス
マサチューセッツ工科大学
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Cloudflare ブラウザレンダリングを活用して、LLM のコンテキストとして使用するために Web コンテンツを抽出および処理し、ページの取得、ドキュメントの検索、構造化コンテンツの抽出、コンテンツの要約を行うツールを提供するサーバー。
Related Resources
Related MCP Servers
- Asecurity-licenseAqualityThis server enables LLMs to retrieve and process content from web pages, converting HTML to markdown for easier consumption.Last updated -171,192MIT License
- Asecurity-licenseAqualityEnables retrieval and processing of web page content for LLMs by converting HTML to markdown, with support for content truncation and pagination.Last updated -12MIT License
- -security-license-qualityA Model Context Protocol server that allows LLMs to interact with web content through standardized tools, currently supporting web scraping functionality.Last updated -1MIT License
- Asecurity-licenseAqualityThis MCP server provides tools for interacting with Cloudflare Browser Rendering, allowing you to fetch and process web content for use as context in LLMs directly from Cline or Claude Desktop.Last updated -510MIT License