MCP Web Browser Server

MCP Web Browser Server

一个先进的网页浏览服务器,通过安全的 API 实现无头浏览器交互,提供诸如导航、内容提取、元素交互和屏幕截图捕获等功能。

网络自动化与隐身
访问服务器

Tools

browse_to

Navigate to a specific URL and return the page's HTML content. Args: url: The full URL to navigate to context: Optional context object for logging (ignored) Returns: The full HTML content of the page

extract_text_content

Extract text content from the current page, optionally using a CSS selector. Args: selector: Optional CSS selector to target specific elements context: Optional context object for logging (ignored) Returns: Extracted text content

click_element

Click an element on the current page. Args: selector: CSS selector for the element to click context: Optional context object for logging (ignored) Returns: Confirmation message or error details

get_page_screenshots

Capture screenshot of the current page. Args: full_page: Whether to capture the entire page or just the viewport selector: Optional CSS selector to screenshot a specific element context: Optional context object for logging (ignored) Returns: Base64 encoded screenshot image

get_page_links

Extract all links from the current page. Args: context: Optional context object for logging (ignored) Returns: List of links found on the page

input_text

Input text into a specific element on the page. Args: selector: CSS selector for the input element text: Text to input context: Optional context object for logging (ignored) Returns: Confirmation message

README

MCP Web 浏览器服务器

一个为模型上下文协议 (MCP) 提供支持的高级 Web 浏览服务器,由 Playwright 驱动,通过灵活、安全的 API 实现无头浏览器交互。

<a href="https://glama.ai/mcp/servers/lwqlaw6k6d"><img width="380" height="200" src="https://glama.ai/mcp/servers/lwqlaw6k6d/badge" alt="Web Browser Server MCP server" /></a>

🌐 功能

  • 无头 Web 浏览: 导航到任何网站,并绕过 SSL 证书验证
  • 完整页面内容提取: 检索完整的 HTML 内容,包括动态加载的 JavaScript
  • 多标签页支持: 创建、管理和切换多个浏览器标签页
  • 高级 Web 交互工具:
    • 提取文本内容
    • 点击页面元素
    • 将文本输入到表单字段中
    • 捕获屏幕截图
    • 提取具有过滤功能的页面链接
    • 在任何方向上滚动页面
    • 在页面上执行 JavaScript
    • 刷新页面
    • 等待导航完成
  • 资源管理: 不活动后自动清理未使用的资源
  • 增强的页面信息: 获取有关当前页面的详细元数据

🚀 快速开始

前提条件

  • Python 3.10+
  • MCP SDK
  • Playwright

安装

# 安装 MCP 和 Playwright
pip install mcp playwright

# 安装浏览器依赖项
playwright install

Claude Desktop 配置

添加到你的 claude_desktop_config.json:

{
  "mcpServers": {
    "web-browser": {
      "command": "python",
      "args": [
        "/path/to/your/server.py"
      ]
    }
  }
}

💡 使用示例

基本 Web 导航

# 浏览到网站
page_content = browse_to("https://example.com")

# 提取页面文本
text_content = extract_text_content()

# 从特定元素提取文本
title_text = extract_text_content("h1.title")

Web 交互

# 导航到页面
browse_to("https://example.com/login")

# 将文本输入到表单
input_text("#username", "your_username")
input_text("#password", "your_password")

# 点击登录按钮
click_element("#login-button")

屏幕截图捕获

# 捕获完整页面屏幕截图
full_page_screenshot = get_page_screenshots(full_page=True)

# 捕获特定元素屏幕截图
element_screenshot = get_page_screenshots(selector="#main-content")

链接提取

# 获取页面上的所有链接
page_links = get_page_links()

# 获取匹配模式的链接
filtered_links = get_page_links(filter_pattern="contact")

多标签页浏览

# 创建一个新标签页
tab_id = create_new_tab("https://example.com")

# 创建另一个标签页
another_tab_id = create_new_tab("https://example.org")

# 列出所有打开的标签页
tabs = list_tabs()

# 在标签页之间切换
switch_tab(tab_id)

# 关闭一个标签页
close_tab(another_tab_id)

高级交互

# 滚动页面
scroll_page(direction="down", amount="page")

# 在页面上执行 JavaScript
result = execute_javascript("return document.title")

# 获取详细的页面信息
page_info = get_page_info()

# 刷新当前页面
refresh_page()

# 等待导航完成
wait_for_navigation(timeout_ms=5000)

🛡️ 安全特性

  • SSL 证书验证绕过
  • 安全的浏览器上下文管理
  • 自定义用户代理配置
  • 错误处理和全面的日志记录
  • 可配置的超时设置
  • CSP 绕过控制
  • 防止 cookie 窃取

🔧 故障排除

常见问题

  • SSL 证书错误: 自动绕过
  • 页面加载缓慢: 在 browse_to() 方法中调整超时
  • 找不到元素: 仔细验证选择器
  • 浏览器资源使用: 在不活动一段时间后自动清理

日志记录

所有重要事件都会记录详细信息,以便于调试。

📋 工具参数

browse_to(url: str, context: Optional[Any] = None)

  • url: 要导航到的网站
  • context: 可选的上下文对象(当前未使用)

extract_text_content(selector: Optional[str] = None, context: Optional[Any] = None)

  • selector: 可选的 CSS 选择器,用于提取特定内容
  • context: 可选的上下文对象(当前未使用)

click_element(selector: str, context: Optional[Any] = None)

  • selector: 要点击的元素的 CSS 选择器
  • context: 可选的上下文对象(当前未使用)

get_page_screenshots(full_page: bool = False, selector: Optional[str] = None, context: Optional[Any] = None)

  • full_page: 捕获整个页面屏幕截图
  • selector: 要截图的可选元素
  • context: 可选的上下文对象(当前未使用)

get_page_links(filter_pattern: Optional[str] = None, context: Optional[Any] = None)

  • filter_pattern: 用于过滤链接的可选文本模式
  • context: 可选的上下文对象(当前未使用)

input_text(selector: str, text: str, context: Optional[Any] = None)

  • selector: 输入元素的 CSS 选择器
  • text: 要输入的文本
  • context: 可选的上下文对象(当前未使用)

create_new_tab(url: Optional[str] = None, context: Optional[Any] = None)

  • url: 可选的 URL,用于在新标签页中导航
  • context: 可选的上下文对象(当前未使用)

switch_tab(tab_id: str, context: Optional[Any] = None)

  • tab_id: 要切换到的标签页的 ID
  • context: 可选的上下文对象(当前未使用)

list_tabs(context: Optional[Any] = None)

  • context: 可选的上下文对象(当前未使用)

close_tab(tab_id: Optional[str] = None, context: Optional[Any] = None)

  • tab_id: 要关闭的标签页的可选 ID(默认为当前标签页)
  • context: 可选的上下文对象(当前未使用)

refresh_page(context: Optional[Any] = None)

  • context: 可选的上下文对象(当前未使用)

get_page_info(context: Optional[Any] = None)

  • context: 可选的上下文对象(当前未使用)

scroll_page(direction: str = "down", amount: str = "page", context: Optional[Any] = None)

  • direction: 滚动方向('up'、'down'、'left'、'right')
  • amount: 滚动量('page'、'half' 或一个数字)
  • context: 可选的上下文对象(当前未使用)

wait_for_navigation(timeout_ms: int = 10000, context: Optional[Any] = None)

  • timeout_ms: 最长等待时间,以毫秒为单位
  • context: 可选的上下文对象(当前未使用)

execute_javascript(script: str, context: Optional[Any] = None)

  • script: 要执行的 JavaScript 代码
  • context: 可选的上下文对象(当前未使用)

🤝 贡献

欢迎贡献!请随时提交 Pull Request。

开发设置

# 克隆存储库
git clone https://github.com/random-robbie/mcp-web-browser.git

# 创建虚拟环境
python -m venv venv
source venv/bin/activate  # 在 Windows 上使用 `venv\Scripts\activate`

# 安装依赖项
pip install -e .[dev]

📄 许可证

MIT 许可证

🔗 相关项目

💬 支持

如有问题,请在 GitHub 上打开一个 issue

推荐服务器

Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
mult-fetch-mcp-server

mult-fetch-mcp-server

一个多功能的、符合 MCP 规范的网页内容抓取工具,支持多种模式(浏览器/Node)、格式(HTML/JSON/Markdown/文本)和智能代理检测,并提供双语界面(英语/中文)。

精选
本地
Hyperbrowser

Hyperbrowser

欢迎来到 Hyperbrowser,人工智能的互联网。Hyperbrowser 是下一代平台,旨在增强人工智能代理的能力,并实现轻松、可扩展的浏览器自动化。它专为人工智能开发者打造,消除了本地基础设施和性能瓶颈带来的麻烦,让您能够:

精选
本地
https://github.com/Streen9/react-mcp

https://github.com/Streen9/react-mcp

react-mcp 与 Claude Desktop 集成,能够根据用户提示创建和修改 React 应用程序。

精选
本地
Exa MCP Server

Exa MCP Server

一个模型上下文协议服务器,它使像 Claude 这样的人工智能助手能够以安全和受控的方式,使用 Exa AI 搜索 API 执行实时网络搜索。

精选
mcp-perplexity

mcp-perplexity

Perplexity API 的 MCP 服务器。

精选
MCP Web Research Server

MCP Web Research Server

一个模型上下文协议服务器,使 Claude 能够通过集成 Google 搜索、提取网页内容和捕获屏幕截图来进行网络研究。

精选
browser-use MCP server

browser-use MCP server

一个由人工智能驱动的浏览器自动化服务器,它实现了模型上下文协议,从而能够使用自然语言控制网页浏览器,以执行诸如导航、表单填写和视觉交互等任务。

精选
mcp-codex-keeper

mcp-codex-keeper

作为开发知识的守护者,为 AI 助手提供精心策划的最新文档和最佳实践访问权限。

精选
Perplexity Deep Research MCP

Perplexity Deep Research MCP

一个服务器,它允许 AI 助手使用 Perplexity 的 sonar-deep-research 模型进行网络搜索,并提供引用支持。

精选