Skip to content

feat: add personal browser targets#14

Open
konard wants to merge 3 commits into
ProverCoderAI:mainfrom
konard:issue-13-80a5d46d646b
Open

feat: add personal browser targets#14
konard wants to merge 3 commits into
ProverCoderAI:mainfrom
konard:issue-13-80a5d46d646b

Conversation

@konard

@konard konard commented Jun 24, 2026

Copy link
Copy Markdown

Summary

  • add named browser targets for the MCP server, including a personal CDP browser endpoint
  • add browser_list and browser_select tools so agents can switch between managed, explicit, and configured browser targets at runtime
  • add CLI/env configuration for --personal-browser, repeated --browser NAME=CDP_ENDPOINT, and --active-browser
  • document personal browser setup and add a minor changelog fragment

Reproduction

Before this change, browser-connection could only use the Docker-managed browser or one startup --cdp-endpoint. There was no MCP tool to register a personal desktop browser or switch back and forth without restarting the MCP server.

Verification

  • cargo fmt --check
  • cargo check --locked --bins
  • cargo test --locked
  • cargo clippy --locked --all-targets -- -D warnings
  • manual file-size check: src/mcp.rs is 989 lines, below the 1000-line hard limit

Fixes #13

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: ProverCoderAI#13
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for connecting to an existing personal browser and switching between browser targets at runtime.
    • Introduced browser listing and browser selection actions so you can see and change the active browser session.
    • Added new command-line options for choosing browser targets and an active browser.
  • Documentation

    • Updated the README with setup examples for personal, managed, and multiple named browser targets.
    • Added a changelog entry for the new browser-target workflow.

Walkthrough

Adds named browser endpoint support (NamedBrowserEndpoint) with a new browser_target module for parsing, normalization, and environment-variable loading. McpServerConfig and McpRuntime are extended to track an active browser target, and two new MCP tools (browser_list, browser_select) are exposed. The CLI gains --browser, --personal-browser, and --active-browser flags.

Changes

Personal browser targets and runtime switching

Layer / File(s) Summary
NamedBrowserEndpoint contract and parsing/normalization
src/browser_target.rs, src/lib.rs
New browser_target module defines MANAGED_BROWSER_NAME, EXPLICIT_BROWSER_NAME, PERSONAL_BROWSER_NAME constants, the NamedBrowserEndpoint struct with a validating constructor, parsers for single/multi-endpoint strings, env-variable loaders, CDP endpoint normalization (stripping /json/version etc.), and an upsert helper. Unit tests cover personal endpoint parsing and rejection of reserved names.
McpServerConfig builder methods and McpRuntime active-browser logic
src/mcp.rs
McpServerConfig gains browser_endpoints and active_browser fields with with_browser_endpoints/with_active_browser builder methods. McpRuntime is reworked to store active_browser: String and managed_cdp_endpoint: Option<String> separately, resolve the effective CDP endpoint by active target name, render browser inventory JSON, and support switching targets.
browser_list and browser_select MCP tool dispatch
src/mcp.rs
tool_definitions() adds browser_list and browser_select with input schemas. handle_tool_call branches for browser_list (returns inventory JSON) and browser_select (registers optional ad-hoc endpoint, switches active_browser), and falls through to CDP dispatch for all other tools.
CLI --browser/--personal-browser/--active-browser wiring
src/bin/browser-connection.rs
Cli struct gains repeatable --browser, optional --personal-browser, and optional --active-browser arguments. main builds browser_endpoints from env plus CLI entries and chains with_browser_endpoints/with_active_browser onto McpServerConfig.
Tests for browser selection and inventory
src/mcp.rs, tests/mcp_stdio.rs
Existing unit tests updated to reference managed_cdp_endpoint/active_browser. New unit tests cover personal browser activation without Docker, ad-hoc endpoint registration via browser_select, and browser_inventory reporting. Stdio integration tests assert new CLI flags and tools are present, and validate a full browser_selectbrowser_list round-trip over framed MCP.
README and changelog
README.md, changelog.d/20260624_071400_personal_browser_targets.md
README adds a Personal browser section with CDP startup instructions, multi-target config examples, env-variable alternatives, and an updated MCP tools list. Changelog entry documents the minor version bump and the new named browser targets feature.

Sequence Diagram(s)

sequenceDiagram
    participant Agent as MCP Agent
    participant Server as McpRuntime
    participant BrowserTarget as browser_target helpers
    participant CDP as CDP Browser

    Agent->>Server: browser_select(name="personal", cdp_endpoint="http://…:9444")
    Server->>BrowserTarget: normalize_cdp_endpoint("http://…:9444")
    BrowserTarget-->>Server: normalized endpoint
    Server->>BrowserTarget: upsert_browser_endpoint(endpoints, personal)
    Server->>Server: active_browser = "personal"
    Server-->>Agent: OK

    Agent->>Server: browser_list()
    Server->>Server: browser_inventory()
    Server-->>Agent: {active: "personal", browsers: [{name: "personal", active: true, …}]}

    Agent->>Server: browser_navigate(url="…")
    Server->>Server: cdp_endpoint() → lookup "personal" in browser_endpoints
    Server->>CDP: navigate via CDP
    CDP-->>Server: result
    Server-->>Agent: navigation result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐇 Hippity hop, a new browser in sight,
I sniff the CDP port in the morning light.
With --personal-browser I leap to the scene,
browser_select switches targets so clean.
The managed and personal now live side by side,
This rabbit has nowhere left to hide! 🌐

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding personal browser targets.
Description check ✅ Passed The description accurately summarizes the browser target, switching, and config changes in the PR.
Linked Issues check ✅ Passed The PR implements personal browser connections and runtime switching between browser targets as requested in #13.
Out of Scope Changes check ✅ Passed The changes appear focused on browser targets, docs, tests, and supporting config with no unrelated additions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@konard konard changed the title [WIP] Сделать возможность сюда подключать обычный браузер (личный). Что бы агент мог пользоваться так же им. Желатльно что бы между браузерами можно было бы переключаться feat: add personal browser targets Jun 24, 2026
@konard konard marked this pull request as ready for review June 24, 2026 07:26
@konard

konard commented Jun 24, 2026

Copy link
Copy Markdown
Author

Working session summary

Implemented and pushed PR 14: #14

Added named MCP browser targets so agents can attach to a personal CDP browser and switch at runtime with browser_list / browser_select. Also added --personal-browser, repeatable --browser NAME=CDP_ENDPOINT, --active-browser, env support, README docs, tests, and a minor changelog fragment.

Verified locally:

  • cargo fmt --check
  • cargo check --locked --bins
  • cargo test --locked
  • cargo clippy --locked --all-targets -- -D warnings
  • manual file-size check: src/mcp.rs is 989 lines, below the 1000-line hard limit

PR is marked ready. Latest GitHub Actions run for commit ec8968f is action_required with no jobs/logs available, likely awaiting workflow approval. CodeRabbit is still pending.


This summary was automatically extracted from the AI working session output.

@konard

konard commented Jun 24, 2026

Copy link
Copy Markdown
Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Model: GPT-5.5
  • Provider: OpenAI
  • Public pricing estimate: $10.715979

📊 Context and tokens usage:

  • 292.6K / 200K (146%) input tokens, 36.2K / 128K (28%) output tokens

Total: (292.6K + 6.2M cached) input tokens, 36.2K output tokens, $10.715979 cost

🤖 Models used:

  • Tool: OpenAI Codex
  • Requested: gpt-5.5
  • Thinking level: max (~31999 tokens)
  • Model: GPT-5.5 (gpt-5.5)

📎 Log file uploaded as Repository (46375KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mcp.rs`:
- Around line 134-147: McpRuntime::new currently accepts any
config.active_browser value and can mark an unavailable browser as active,
creating an inconsistent startup state. Add validation in McpRuntime::new (or
the browser-selection helper it uses) to verify the requested target exists in
the available browser set, including rejecting explicit when
has_explicit_cdp_endpoint(&config) is false and any unknown custom name. If the
selection is invalid, fail initialization immediately instead of building
McpRuntime with active_browser set to a missing entry.
- Around line 317-325: The explicit CDP endpoint lookup is swallowing
normalization failures and turning a malformed value into None, which can
incorrectly fall back to the managed browser path. Update
explicit_cdp_endpoint() to propagate the normalize_cdp_endpoint() error instead
of calling ok(), and adjust has_explicit_cdp_endpoint() and any callers in the
McpServerConfig flow to handle/report the invalid --cdp-endpoint or env value
rather than treating it as absent. If you prefer central validation, enforce it
when constructing McpServerConfig so invalid endpoints are rejected once.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: aec2bd6d-c049-4615-8e30-639a7a9317d4

📥 Commits

Reviewing files that changed from the base of the PR and between 8f0aa06 and ec8968f.

📒 Files selected for processing (8)
  • .gitkeep
  • README.md
  • changelog.d/20260624_071400_personal_browser_targets.md
  • src/bin/browser-connection.rs
  • src/browser_target.rs
  • src/lib.rs
  • src/mcp.rs
  • tests/mcp_stdio.rs

Comment thread src/mcp.rs
Comment on lines 134 to 147
fn new(config: McpServerConfig) -> Self {
let active_browser = config.active_browser.clone().unwrap_or_else(|| {
if has_explicit_cdp_endpoint(&config) {
EXPLICIT_BROWSER_NAME.to_string()
} else {
MANAGED_BROWSER_NAME.to_string()
}
});

Self {
config,
cdp_endpoint: None,
managed_cdp_endpoint: None,
active_browser,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Reject invalid startup browser selections.

If config.active_browser names a target that is not actually available (for example explicit without cdp_endpoint, or a typoed custom name), McpRuntime::new still marks it active. That leaves browser_list reporting an active browser that is missing from browsers, and the first browser tool fails only later. Please validate the chosen target during runtime construction and fail initialization instead of creating this inconsistent state.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mcp.rs` around lines 134 - 147, McpRuntime::new currently accepts any
config.active_browser value and can mark an unavailable browser as active,
creating an inconsistent startup state. Add validation in McpRuntime::new (or
the browser-selection helper it uses) to verify the requested target exists in
the available browser set, including rejecting explicit when
has_explicit_cdp_endpoint(&config) is false and any unknown custom name. If the
selection is invalid, fail initialization immediately instead of building
McpRuntime with active_browser set to a missing entry.

Comment thread src/mcp.rs
Comment on lines +317 to +325
fn explicit_cdp_endpoint(config: &McpServerConfig) -> Option<String> {
config
.cdp_endpoint
.as_deref()
.and_then(|endpoint| normalize_cdp_endpoint(endpoint).ok())
}

fn has_explicit_cdp_endpoint(config: &McpServerConfig) -> bool {
explicit_cdp_endpoint(config).is_some()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not silently ignore malformed explicit CDP endpoints.

explicit_cdp_endpoint() turns normalization failures into None, so a bad --cdp-endpoint / env value quietly falls back to the managed browser path instead of rejecting the configuration. That can send commands to the wrong browser. Propagate the normalization error here (or validate once when building McpServerConfig) rather than swallowing it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mcp.rs` around lines 317 - 325, The explicit CDP endpoint lookup is
swallowing normalization failures and turning a malformed value into None, which
can incorrectly fall back to the managed browser path. Update
explicit_cdp_endpoint() to propagate the normalize_cdp_endpoint() error instead
of calling ok(), and adjust has_explicit_cdp_endpoint() and any callers in the
McpServerConfig flow to handle/report the invalid --cdp-endpoint or env value
rather than treating it as absent. If you prefer central validation, enforce it
when constructing McpServerConfig so invalid endpoints are rejected once.

@konard

konard commented Jun 24, 2026

Copy link
Copy Markdown
Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant