Skip to main content
Glama

ruyipage-mcp

Exposes the Firefox BiDi automation capabilities of ruyiPage as a set of tools callable by AI via the MCP (Model Context Protocol).

Supports any MCP client such as Claude Code, Cursor, etc.


Features

  • 34 tools covering the entire browser automation workflow: launching/attaching to browsers, page navigation, DOM lookup and interaction, screenshots/PDFs, Cookies/Storage, JS execution, network interception/listening/data collection, tab management, device emulation, and BiDi event subscription.

  • Native BiDi action priority — Actions like clicking, typing, and dragging maintain isTrusted=true, making them more suitable for high-risk control scenarios.

  • Support for taking over fingerprint browsers — Automatically detects and attaches to Firefox-based fingerprint browsers like ADS / FlowerBrowser.

  • Intelligent element management — LRU element registry with automatic recycling and automatic re-lookup for expired elements.

  • Automatic screenshot compression — Automatic scaling for ultra-wide images, JPEG compression, and automatic disk saving for large images.

  • stdio transport — Standard JSON-RPC 2.0, ready to use out of the box.


Related MCP server: MCP Selenium Server

Installation

Prerequisites

Install from Source

git clone https://github.com/LoseNine/ruyipage-mcp.git
cd ruyipage-mcp
pip install -e .

Configuration

Claude Code

Method 1: Project-level .mcp.json (Recommended)

{
  "mcpServers": {
    "ruyipage": {
      "command": "python",
      "args": ["-m", "ruyipage_mcp"]
    }
  }
}

Cursor / Other MCP Clients

Add the following to your corresponding MCP configuration file:

{
  "mcpServers": {
    "ruyipage": {
      "command": "python",
      "args": ["-m", "ruyipage_mcp"]
    }
  }
}

Standalone Execution

python -m ruyipage_mcp

The server transmits JSON-RPC messages via stdin/stdout and outputs logs to stderr.


Configuration

Configuration File

Copy ruyipage_mcp.example.json to ruyipage_mcp.json and modify as needed:

cp ruyipage_mcp.example.json ruyipage_mcp.json
{
  "browser_path": "E:\\ruyi_firefox\\firefox.exe",
  "disable_run_js": false,
  "disable_extensions": false,
  "browser_path_whitelist": [],
  "max_elements": 512,
  "event_buffer_size": 500,
  "wait_timeout_ceiling": 60
}

Configuration file lookup order:

  1. Path specified by the RUYIPAGE_MCP_CONFIG environment variable

  2. ruyipage_mcp.json in the current working directory

  3. If no configuration file is found, built-in defaults are used

Configuration Item

Type

Default Value

Description

browser_path

string

E:\ruyi_firefox\firefox.exe

Path to the Firefox executable

disable_run_js

bool

false

Set to true to disable the js_run tool

disable_extensions

bool

false

Set to true to disable extension-related capabilities

browser_path_whitelist

list

[] (allows any path)

List of allowed browser paths

max_elements

int

512

LRU capacity of the element registry per session

event_buffer_size

int

500

BiDi event buffer size

wait_timeout_ceiling

int

60

Timeout limit for all wait-type tools (seconds)

Environment Variable Overrides

Environment variables have higher priority than the configuration file, suitable for CI or temporary override scenarios:

Environment Variable

Corresponding Config Item

RUYIPAGE_MCP_BROWSER_PATH

browser_path

RUYIPAGE_MCP_DISABLE_RUN_JS

disable_run_js (1 = true)

RUYIPAGE_MCP_DISABLE_EXTENSIONS

disable_extensions (1 = true)

RUYIPAGE_MCP_BROWSER_PATH_WHITELIST

browser_path_whitelist (comma-separated)

RUYIPAGE_MCP_MAX_ELEMENTS

max_elements

RUYIPAGE_MCP_EVENT_BUFFER_SIZE

event_buffer_size

RUYIPAGE_MCP_WAIT_TIMEOUT_CEILING

wait_timeout_ceiling

RUYIPAGE_MCP_CONFIG

Specify configuration file path


Tool Overview (34 total)

session — Browser Lifecycle

Tool

Description

session_launch

Launch a new Firefox browser. Supports custom ports, headless mode, private mode, XPath Picker, window size, etc.

session_attach

Take over a running Firefox instance via host:port

session_auto_attach

Automatically detect and take over Firefox / ADS / FlowerBrowser based on process characteristics

session_quit

Close the browser session. owned sessions terminate the process, attached sessions only release the connection

Typical workflow:

session_launch(port=9222)
  → 操作页面...
  → session_quit()
# 接管已打开的指纹浏览器
session_auto_attach(latest_tab=true)
  → 操作页面...
  → session_quit()  # 仅释放连接,浏览器继续运行

nav — Page Navigation

Tool

Description

nav_get

Open a URL, supports complete / interactive / none wait strategies

nav_back

Go back

nav_forward

Go forward

nav_refresh

Refresh

nav_info

Get the current page's URL, title, and ready state

dom — Element Lookup and Reading

Tool

Description

dom_find

Find a single element, returns element_id. Supports #id, css:, xpath:, text:, tag: locators

dom_find_all

Find all matching elements, returns a list (default limit 20, max 100)

dom_read

Read element properties: text / html / inner_html / outer_html / value / attrs / rect / all

dom_query_in

Continue searching for child elements within an existing element

dom_wait_for

Wait for an element to appear (with timeout)

dom_release

Release element handle, reclaim registry space

Locator format:

Format

Example

Description

#id

#search-box

ID selector

css:

css:div.card > a

CSS selector

xpath:

xpath://button[text()='Login']

XPath

text:

text:Login

Text match

tag:

tag:input

Tag name

act — Element Interaction

Tool

Description

act_click

Click an element. Supports left/right click, double click, optional JS click. Defaults to native BiDi actions (isTrusted=true)

act_input

Input text. Native BiDi keyboard input, optional clear existing content. Supports JS fallback

act_simple

Simple operations: hover / clear / focus / scroll_into_view

act_chain

Execute BiDi action chains (JSON array), supports key presses, clicks, moves, drags, scrolling, pauses, etc.

Actions supported by act_chain:

[
  {"action": "press", "key": "Enter"},
  {"action": "click"},
  {"action": "click", "element_id": "el_abc123"},
  {"action": "move_to", "element_id": "el_abc123"},
  {"action": "move_to", "x": 100, "y": 200},
  {"action": "double_click"},
  {"action": "right_click"},
  {"action": "key_down", "key": "Shift"},
  {"action": "key_up", "key": "Shift"},
  {"action": "type", "text": "hello"},
  {"action": "scroll", "x": 0, "y": -300},
  {"action": "pause", "duration": 500}
]

state — Page State

Tool

Description

state_screenshot

Screenshot. Supports full-page, element-specific, and saving to file. Automatic compression, large images saved to disk automatically

state_save_pdf

Save current page as PDF

state_cookies

Cookie management: get / set / delete. Supports filtering by name/domain

state_storage

localStorage / sessionStorage management: items / get / set / delete / clear

js — JavaScript Execution

Tool

Description

js_run

Execute JS code on the page. Can be evaluated as an expression (as_expr=true) or executed as a function body. Can be disabled via environment variables

js_preload

Manage preload scripts: add (injected before every page load) / remove

net — Network Control

Tool

Description

net_intercept

Request interception: startwait_and_resolve (continue/mock/fail) → stop

net_listen

Network listening: startwait (filter by URL/method) → stop

net_collector

Data collector: addget (get request/response body by request_id) → remove

net_headers

Set/clear extra request headers

net_cache

Set cache behavior: default (normal cache) / bypass (force re-request)

Typical request interception workflow:

net_intercept(op="start", url_patterns="api/login")
  → 触发页面操作
  → net_intercept(op="wait_and_resolve", action='{"mode":"mock","status":200,"body":"{}"}')
  → net_intercept(op="stop")

Typical network listening workflow:

net_listen(op="start", targets="api/data", method="POST")
  → 触发页面操作
  → net_listen(op="wait", timeout=10)
  → net_listen(op="stop")

ctx — Context Management

Tool

Description

ctx_tabs

Tab management: list / create / close / activate / reload

ctx_emulation

Device emulation: geolocation, timezone, language, mobile device presets, offline mode, JS toggle

ctx_events

BiDi event subscription: unified entry point for managing page.events / page.navigation / page.downloads

Emulation example:

ctx_emulation(op="set_geolocation", latitude=39.9, longitude=116.4)
ctx_emulation(op="set_timezone", timezone_id="Asia/Tokyo")
ctx_emulation(op="set_locale", locales="ja-JP,ja")
ctx_emulation(op="apply_mobile_preset", width=390, height=844, device_pixel_ratio=3)
ctx_emulation(op="set_offline", enabled=true)
ctx_emulation(op="set_offline", enabled=false)

meta — Server Information

Tool

Description

ruyipage_describe_capabilities

Returns current server status: active sessions, element count, configuration toggles, tool namespace list


Core Concepts

Session Management

Each browser connection corresponds to a session, identified by host:port (e.g., 127.0.0.1:9222).

  • When there is only one active session, the session_id parameter for all tools can be omitted and is resolved automatically.

  • When there are multiple sessions, session_id must be explicitly passed.

  • session_launch creates an owned session; session_quit will terminate the browser process.

  • session_attach / session_auto_attach create an attached session; session_quit only releases the connection.

Element Registry

Elements found via dom_find / dom_find_all are registered in the current session's element registry, returning a short ID (e.g., el_a3f2b1).

  • LRU Recycling — When the capacity limit (default 512) is reached, the least recently used element is automatically recycled.

  • Automatic Recovery — When accessing an expired element, it automatically attempts to re-find it using the original locator.

  • Element IDs can be passed to all tools requiring element references, such as act_click, act_input, dom_read, act_chain, etc.

  • All tools accepting a target parameter can also directly accept a locator string (e.g., css:button.submit) without needing to call dom_find first.

Response Format

All tools (except state_screenshot) return a unified JSON envelope:

// 成功
{"ok": true, "data": ...}

// 失败
{"ok": false, "error": "error message"}

state_screenshot returns an MCP Image object directly when the screenshot size permits; if it exceeds 800KB, it is saved to disk and the file path is returned.



Architecture

python -m ruyipage_mcp
  → __main__.py → server.run()
    → 导入 tools/*.py(触发 @mcp.tool() 注册 34 个工具)
    → 注册 atexit 清理(退出时关闭 owned 浏览器)
    → mcp.run(transport="stdio")

ruyipage_mcp/
├── app.py          # FastMCP("ruyipage-mcp") 单例
├── config.py       # 环境变量配置
├── registries.py   # SessionRegistry + ElementRegistry (LRU)
├── runtime.py      # async/sync 桥接 + 响应封装 + 元素解析
├── server.py       # 入口 + atexit 清理
└── tools/
    ├── session.py  # 浏览器启动/接管/关闭
    ├── nav.py      # 页面导航
    ├── dom.py      # 元素查找/读取
    ├── act.py      # 元素交互/动作链
    ├── state.py    # 截图/PDF/Cookie/Storage
    ├── js.py       # JS 执行/预加载脚本
    ├── net.py      # 网络拦截/监听/采集
    ├── ctx.py      # 标签页/模拟/事件
    └── meta.py     # 服务器状态

ruyiPage is a synchronous library, while MCP FastMCP is asyncio-based. All ruyiPage calls are bridged via asyncio.to_thread() to ensure the MCP event loop is not blocked.


Usage Statement

This project follows the usage statement of ruyiPage and is intended solely for legal, compliant, and non-profit personal research and technical exchange purposes.

License

BSD-3-Clause

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    An MCP server paired with a Firefox extension that enables LLM clients to control the user's browser, supporting tab management, history search, and content reading.
    6 npm
    322
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server implementation that enables browser automation through standardized MCP clients, supporting features like navigation, element interaction, and screenshots across Chrome, Firefox, and Edge browsers.
    558 npm
    MIT
  • A
    license
    C
    quality
    B
    maintenance
    Enables AI assistants to read and drive a real, logged-in Firefox browser, including tabs, cookies, history, and site interactions, all through the Model Context Protocol.
    52
    6 npm
    MIT