# ThreatFlux
## 基本信息
- Slug: `threatflux-playwright-fetch`
- Source: modelscope
- Publisher: @ThreatFlux/playwright-fetch
- Categories: browser-automation / web-scraping / rag-systems
- Hosted: No
- License: MIT License
- Source URL: https://www.modelscope.cn/mcp/servers/@ThreatFlux/playwright-fetch
## 简介
暂无描述。
## MCP Server 详情

# Playwright Fetch MCP 服务器

[![GitHub release (latest by date)](https://img.shields.io/github/v/release/ThreatFlux/playwright-fetch)](https://github.com/ThreatFlux/playwright-fetch/releases)
[![CI](https://github.com/ThreatFlux/playwright-fetch/workflows/CI/badge.svg)](https://github.com/ThreatFlux/playwright-fetch/actions)
[![codecov](https://codecov.io/gh/ThreatFlux/playwright-fetch/branch/main/graph/badge.svg)](https://codecov.io/gh/ThreatFlux/playwright-fetch)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python Version](https://img.shields.io/badge/python-3.13-blue)](https://www.python.org/downloads/)
[![Playwright](https://img.shields.io/badge/Playwright-1.40.0-4ead85)](https://playwright.dev/)
[![MCP](https://img.shields.io/badge/MCP-Integrated-blueviolet)](https://docs.anthropic.com/claude/docs/model-context-protocol)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

这是一个使用 Playwright 进行浏览器自动化的 Model Context Protocol 服务器。该服务器使 LLM 能够从网页中检索和处理由 JavaScript 渲染的内容，并将 HTML 转换为 Markdown 以便更易于阅读。

## 作者

由 [Wyatt Roersma](https://github.com/wyroersma) 创建，Claude Code 提供协助。

## 主要功能

- **浏览器自动化**：使用 Playwright 渲染网页，支持完整的 JavaScript
- **内容提取**：自动识别并从网页中提取主要内容区域
- **Markdown 转换**：将 HTML 转换为干净、可读的 Markdown
- **分页支持**：通过分页处理大量内容
- **Robots.txt 遵守**：遵守 robots.txt 指令进行自主抓取
- **代理支持**：允许通过代理服务器路由请求
- **Docker 就绪**：通过 [Docker Hub](https://hub.docker.com/r/threatflux/playwright-fetch) 和 [GitHub Container Registry](https://github.com/threatflux/playwright-fetch/pkgs/container/playwright-fetch) 提供预构建的 Docker 镜像

## 可用工具

- `playwright-fetch` - 使用 Playwright 浏览器自动化抓取 URL 并将其内容提取为 Markdown。
  - `url` (字符串, 必需): 要抓取的 URL
  - `max_length` (整数, 可选): 返回的最大字符数 (默认: 5000)
  - `start_index` (整数, 可选): 从这个字符索引开始内容 (默认: 0)
  - `raw` (布尔值, 可选): 获取未经 Markdown 转换的原始内容 (默认: false)
  - `wait_for_js` (布尔值, 可选): 等待 JavaScript 执行 (默认: true)

## 提示

- **playwright-fetch**
  - 使用 Playwright 抓取 URL 并将其内容提取为 Markdown
  - 参数:
    - `url` (字符串, 必需): 要抓取的 URL

## 要求

- Python 3.13.2 或更新版本
- [uv](https://docs.astral.sh/uv/) 包管理器
- 安装了 Playwright 浏览器

## 安装

### 1. 使用 uv 安装（推荐）

bash
uv pip install git+https://github.com/ThreatFlux/playwright-fetch.git
# 安装 Playwright 浏览器
uv pip exec playwright install


或者，克隆仓库并安装：

bash
git clone https://github.com/ThreatFlux/playwright-fetch.git
cd playwright-fetch
uv pip install -e .
# 安装 Playwright 浏览器
uv pip exec playwright install


### 2. 使用 Docker

您可以使用来自 Docker Hub 或 GitHub Container Registry 的预构建 Docker 镜像：

bash
# 从 Docker Hub
docker pull threatflux/playwright-fetch:latest

# 从 GitHub Container Registry
docker pull ghcr.io/threatflux/playwright-fetch:latest


或者自己构建：

bash
docker build -t threatflux/playwright-fetch .


## 配置

### 配置 Claude.app

在您的 Claude 设置中添加以下内容：

<details>
<summary>使用 uvx</summary>

json
"mcpServers": {
  "playwright-fetch": {
    "command": "uvx",
    "args": ["mcp-server-playwright-fetch"]
  }
}

</details>

<details><summary>使用 Docker</summary>

json
"mcpServers": {
  "playwright-fetch": {
    "command": "docker",
    "args": ["run", "-i", "--rm", "threatflux/playwright-fetch"]
  }
}

</details>

### 配置 VS Code

对于手动安装，请将以下 JSON 块添加到您的 VS Code 用户设置（JSON）文件中。

<details>
<summary>使用 uvx</summary>

json
{
  "mcp": {
    "servers": {
      "playwright-fetch": {
        "command": "uvx",
        "args": ["mcp-server-playwright-fetch"]
      }
    }
  }
}

</details>

<details>
<summary>使用 Docker</summary>

json
{
  "mcp": {
    "servers": {
      "playwright-fetch": {
        "command": "docker",
        "args": ["run", "-i", "--rm", "threatflux/playwright-fetch"]
      }
    }
  }
}

</details>

## 命令行选项

服务器支持以下命令行选项：

- `--user-agent`：自定义 User-Agent 字符串
- `--ignore-robots-txt`：忽略 robots.txt 限制
- `--proxy-url`：用于请求的代理 URL
- `--headless`：以无头模式运行浏览器（默认值：True）
- `--wait-until`：何时认为导航成功（可选值："load", "domcontentloaded", "networkidle", "commit"，默认值："networkidle"）

## 示例用法

bash
# 使用默认设置运行
uv run mcp-server-playwright-fetch

# 使用自定义用户代理和代理运行
uv run mcp-server-playwright-fetch --user-agent="MyCustomAgent/1.0" --proxy-url="http://myproxy:8080"

# 为调试目的以可见浏览器模式运行
uv run mcp-server-playwright-fetch --headless=false


## 调试

您可以使用 MCP 检查器来调试服务器：

bash
npx @modelcontextprotocol/inspector uvx mcp-server-playwright-fetch


## 与标准 Fetch 服务器的区别

此实现与标准 fetch MCP 服务器在以下几个方面有所不同：

1. **浏览器自动化**：使用 Playwright 渲染 JavaScript 密集型页面
2. **内容提取**：尝试从常见的页面结构中提取主要内容
3. **等待选项**：可配置的页面加载策略（等待加载、DOM 内容、网络空闲）
4. **可见浏览器选项**：可以以可见浏览器模式运行以便于调试

## 许可证

本项目根据 MIT 许可证发布。有关详细信息，请参阅 [LICENSE](LICENSE) 文件。

