Skip to content

fix(tools): shim mcp 1.x Server decorators so browser_use constructs under mcp 2.x - #4406

Open
Lin-Artificial wants to merge 1 commit into
OpenHands:mainfrom
Lin-Artificial:fix/browser-use-mcp2-compat
Open

fix(tools): shim mcp 1.x Server decorators so browser_use constructs under mcp 2.x#4406
Lin-Artificial wants to merge 1 commit into
OpenHands:mainfrom
Lin-Artificial:fix/browser-use-mcp2-compat

Conversation

@Lin-Artificial

@Lin-Artificial Lin-Artificial commented Aug 7, 2026

Copy link
Copy Markdown

HUMAN:

We run the SDK in an environment where mcp 2.x is installed; there the browser tool cannot be constructed at all (AttributeError: 'Server' object has no attribute 'list_tools'). This shim has been running locally as a manual patch and is verified working; submitting it upstream so upgrades stop requiring the manual patch. (Submitted by @Lin-Artificial; prepared on his behalf by an AI agent.)


AGENT:

Why

browser_use (<= 0.13.x) pins mcp==1.26.0 and registers MCP handlers in BrowserUseServer.__init__ using the decorator-style API (@server.list_tools(), @server.call_tool(), ...) that mcp 2.x removed in favor of constructor-based handlers plus add_request_handler(). OpenHands never speaks MCP to this server (it calls the server's private methods directly), but construction still executes the decorator registrations, so under mcp 2.x the browser tool fails with AttributeError: 'Server' object has no attribute 'list_tools'.

Summary

  • Re-implement the four removed mcp 1.x decorators (list_tools, call_tool, list_resources, list_prompts) on top of add_request_handler() inside logging_fix, preserving the semantics browser_use relies on (call_tool wraps results in CallToolResult, mirroring mcp 1.x).
  • Under mcp 1.x the shim detects the native decorators and is a no-op; tracked via warn_cleanup(cleanup_by="2.0.0"), alongside the existing browser_use logging workaround (Remove browser_use logging monkey-patch once fixed upstream (deadline: v2.0.0) #4072).
  • Add tests/tools/browser_use/test_logging_fix.py covering handler registration, result wrapping, mcp 1.x no-op detection, and end-to-end CustomBrowserUseServer construction.

Issue Number

Related: #4072 (tracks removal of the browser_use workarounds)

How to Test

Verified in an environment with mcp 2.0.0 installed:

  1. Reproduce on unpatched code:
    from openhands.tools.browser_use.server import CustomBrowserUseServer
    CustomBrowserUseServer(session_timeout_minutes=1)
    # AttributeError: 'Server' object has no attribute 'list_tools'
  2. With the shim applied, the same snippet constructs successfully.
  3. New tests plus existing suite:
    pytest tests/tools/browser_use/test_logging_fix.py -v
    # 4 passed, 1 skipped (mcp-1.x-only case)
    
    pytest tests/tools/browser_use/ --ignore=tests/tools/browser_use/test_browser_executor_e2e.py
    # 132 passed, 1 skipped
    
  4. ruff check / ruff format --check clean (ruff 0.12.10).

CI runs the pinned environment (mcp 1.26.0): shim-functional tests self-skip there, while the no-op and construction tests pass — the suite is green under both mcp majors.

Video/Screenshots

N/A — headless tooling change; see test commands and outputs above.

Type

  • Bug fix

Notes

  • browser_use 0.13.7 (latest release) still pins mcp==1.26.0, so this incompatibility is current.
  • The shim only activates when mcp.server.lowlevel.server.Server lacks the decorator attributes; zero behavior change for existing mcp 1.x installs.

This PR was prepared by an AI agent (OpenHands) on behalf of @Lin-Artificial.

…under mcp 2.x

browser_use (<=0.13.x) pins mcp==1.26.0 and registers MCP handlers in
BrowserUseServer.__init__ with the decorator-style API
(@server.list_tools()/@server.call_tool()/...) that mcp 2.x removed in
favor of constructor-based handlers plus add_request_handler(). OpenHands
never speaks MCP to this server (it calls private methods directly), but
construction still executes the decorator registrations and fails under
mcp 2.x with AttributeError: 'Server' object has no attribute 'list_tools'.

logging_fix now re-implements the four removed decorators on top of
add_request_handler(), preserving the mcp 1.x semantics browser_use
relies on. Under mcp 1.x the shim detects the native decorators and is a
no-op. Tracked via warn_cleanup (cleanup_by 2.0.0), mirroring the
existing browser_use logging workaround (OpenHands#4072).

Co-authored-by: openhands <openhands@all-hands.dev>
@all-hands-bot

Copy link
Copy Markdown
Collaborator

🚦 CI is currently failing on this PR's latest commit.

Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request @all-hands-bot as a reviewer to have it reviewed regardless of CI status.)

This is an automated check - no AI was used to generate this comment.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants