Skip to main content
Glama
jamesmurdza

Daytona Playwright MCP Server

by jamesmurdza

Daytona Playwright MCP 服务器

一个 MCP (Model Context Protocol) 服务器,允许你控制在 Daytona 云沙箱中运行的完整 Chrome 浏览器。将其与 Claude Code、Claude Desktop 或任何兼容 MCP 的客户端配合使用,即可浏览网页、截屏、填写表单等。

功能特性

  • 完整 Chromium 浏览器:在虚拟显示器中运行真实的 Chromium 实例(非无头模式)

  • 云沙箱:浏览器安全地运行在 Daytona 沙箱中,与你的本地机器隔离

  • 丰富的工具集:导航、点击、输入、滚动、截图、提取内容、管理标签页

  • 截图支持:将截图作为图像返回,Claude 可以查看并分析这些图像

  • 多种传输方式:支持 stdio(默认)、SSE 或 HTTP

快速入门

1. 安装包

# Using uv (recommended)
uv pip install git+https://github.com/YOUR_USERNAME/daytona-playwright-mcp.git

# Or with pip
pip install git+https://github.com/YOUR_USERNAME/daytona-playwright-mcp.git

# Or install from source
git clone https://github.com/YOUR_USERNAME/daytona-playwright-mcp.git
cd daytona-playwright-mcp
uv pip install -e .

2. 获取 Daytona API 密钥

  1. daytona.io 注册

  2. 进入仪表板并生成 API 密钥

  3. 将其设置为环境变量:

export DAYTONA_API_KEY="your-api-key-here"

3. 配置 Claude Code

添加到你的 Claude Code MCP 设置中(~/.claude/claude_desktop_config.json 或通过 Claude Code 设置):

{
  "mcpServers": {
    "daytona-playwright": {
      "command": "daytona-playwright-mcp",
      "env": {
        "DAYTONA_API_KEY": "your-api-key-here"
      }
    }
  }
}

或者如果使用 uv 从源码运行:

{
  "mcpServers": {
    "daytona-playwright": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/daytona-playwright-mcp", "daytona-playwright-mcp"],
      "env": {
        "DAYTONA_API_KEY": "your-api-key-here"
      }
    }
  }
}

4. 配置 Claude Desktop

对于 Claude Desktop,添加到你的配置文件中:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "daytona-playwright": {
      "command": "daytona-playwright-mcp",
      "env": {
        "DAYTONA_API_KEY": "your-api-key-here"
      }
    }
  }
}

使用方法

配置完成后,你可以要求 Claude 浏览网页:

"Start a browser and go to https://news.ycombinator.com"

"Take a screenshot of the page"

"Click on the first article link"

"Search for 'AI news' on Google and show me the results"

"Fill out the contact form on example.com with test data"

工作流程

  1. 启动浏览器:Claude 将调用 browser_start 创建一个带有 Chromium 的 Daytona 沙箱

  2. 导航与交互:使用导航、点击、输入和其他工具

  3. 截图:使用 browser_screenshot 查看页面内容

  4. 清理:完成后调用 browser_stop 删除沙箱

可用工具

浏览器生命周期

工具

描述

browser_start

在 Daytona 沙箱中启动新的浏览器会话

browser_stop

停止浏览器并清理沙箱

browser_status

检查浏览器是否正在运行

导航

工具

描述

browser_navigate

导航到 URL

browser_back

后退

browser_forward

前进

browser_refresh

刷新当前页面

交互

工具

描述

browser_click

点击元素(CSS、XPath 或文本选择器)

browser_type

在输入框中输入文本

browser_press

按下键盘按键(Enter、Tab 等)

browser_hover

悬停在元素上

browser_select

从下拉菜单中选择

browser_scroll

滚动页面或元素

内容提取

工具

描述

browser_screenshot

截屏(全页或元素)

browser_get_text

获取页面文本内容

browser_get_html

获取 HTML 内容

browser_get_attribute

获取元素的属性

browser_evaluate

运行 JavaScript 并获取结果

等待

工具

描述

browser_wait_for_selector

等待元素出现/消失

browser_wait_for_navigation

等待导航完成

标签页管理

工具

描述

browser_new_tab

打开新标签页

browser_list_tabs

列出所有打开的标签页

browser_switch_tab

切换到其他标签页

browser_close_tab

关闭标签页

文件操作

工具

描述

browser_upload_file

上传文件到文件输入框

使用不同传输方式运行

Stdio(默认 - 适用于 Claude Code/Desktop)

daytona-playwright-mcp
# or
uv run daytona-playwright-mcp

HTTP 传输(适用于远程连接)

daytona-playwright-mcp --transport http --host 0.0.0.0 --port 8765

然后通过以下方式连接:http://localhost:8765/mcp

SSE 传输(旧版)

daytona-playwright-mcp --transport sse --host 0.0.0.0 --port 8765

环境变量

变量

描述

默认值

DAYTONA_API_KEY

你的 Daytona API 密钥(必需)

-

DAYTONA_API_URL

Daytona API 服务器 URL

https://app.daytona.io/api

开发

从源码运行

# Clone the repository
git clone https://github.com/YOUR_USERNAME/daytona-playwright-mcp.git
cd daytona-playwright-mcp

# Install dependencies
uv sync

# Run the server
uv run daytona-playwright-mcp

运行测试

uv run pytest

工作原理

  1. 当你调用 browser_start 时,服务器会:

    • 创建一个 Daytona 沙箱(默认 Python 沙箱预装了 Chromium + Xvfb)

    • 启动启用了远程调试的 Chromium

    • 启动 TCP 代理以在外部暴露 CDP 端口

    • 通过 Daytona 的安全签名 URL,经由 CDP (Chrome DevTools Protocol) 连接到 Chromium

  2. 所有浏览器命令均通过连接到远程浏览器的 Playwright API 执行

  3. 截图作为 PNG 图像捕获,并通过 MCP 的图像内容类型返回

  4. 当你调用 browser_stop 时,沙箱会被删除,所有资源都会被释放

故障排除

"DAYTONA_API_KEY environment variable is not set"

确保你的 API 密钥是在 MCP 服务器设置中配置的,而不仅仅是在你的 shell 中。

浏览器无法启动

  • 检查你的 Daytona API 密钥是否有效

  • 浏览器镜像在首次使用时可能需要 1-2 分钟来配置

  • 如果需要,增加 timeout 参数

截图未显示

  • 确保你使用的是支持 MCP 图像的最新版 Claude Code/Desktop

  • browser_screenshot 工具返回的图像类型应该会自动渲染

连接超时

默认超时时间为 60 秒。对于较慢的连接或首次构建镜像,请增加该值:

"Start a browser with a 120 second timeout"

许可证

MIT

致谢

Install Server
A
security – no known vulnerabilities
F
license - not found
A
quality - A tier

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jamesmurdza/playwright-daytona-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server