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
Open
fix(tools): shim mcp 1.x Server decorators so browser_use constructs under mcp 2.x#4406Lin-Artificial wants to merge 1 commit into
Lin-Artificial wants to merge 1 commit into
Conversation
…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>
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 This is an automated check - no AI was used to generate this comment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) pinsmcp==1.26.0and registers MCP handlers inBrowserUseServer.__init__using the decorator-style API (@server.list_tools(),@server.call_tool(), ...) that mcp 2.x removed in favor of constructor-based handlers plusadd_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 withAttributeError: 'Server' object has no attribute 'list_tools'.Summary
list_tools,call_tool,list_resources,list_prompts) on top ofadd_request_handler()insidelogging_fix, preserving the semanticsbrowser_userelies on (call_toolwraps results inCallToolResult, mirroring mcp 1.x).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).tests/tools/browser_use/test_logging_fix.pycovering handler registration, result wrapping, mcp 1.x no-op detection, and end-to-endCustomBrowserUseServerconstruction.Issue Number
Related: #4072 (tracks removal of the browser_use workarounds)
How to Test
Verified in an environment with
mcp 2.0.0installed:ruff check/ruff format --checkclean (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
Notes
browser_use0.13.7 (latest release) still pinsmcp==1.26.0, so this incompatibility is current.mcp.server.lowlevel.server.Serverlacks 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.