Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fix: report unknown MCP tools as errors

MagMuellerafbc714a60ca
diff --git a/browser_use/mcp/server.py b/browser_use/mcp/server.py
index 3b5672822..8aa5222b4 100644
--- a/browser_use/mcp/server.py
+++ b/browser_use/mcp/server.py
@@ -580,7 +580,7 @@ class BrowserUseServer:
elif tool_name == 'browser_close_tab':
return await self._close_tab(arguments['tab_id'])
- return f'Unknown tool: {tool_name}'
+ raise ValueError(f'Unknown tool: {tool_name}')
async def _init_browser_session(self, allowed_domains: list[str] | None = None, **kwargs):
"""Initialize browser session using config"""
diff --git a/tests/ci/test_mcp_tool_annotations.py b/tests/ci/test_mcp_tool_annotations.py
index 2e1ab2272..057124891 100644
--- a/tests/ci/test_mcp_tool_annotations.py
+++ b/tests/ci/test_mcp_tool_annotations.py
@@ -72,3 +72,20 @@ async def test_mutating_tools_never_advertise_read_only_hint(server: BrowserUseS
mislabeled = sorted(tool.name for tool in tools if tool.name not in EXPECTED_READ_ONLY_TOOLS and _is_read_only(tool))
assert not mislabeled, f'state-changing tools wrongly advertise readOnlyHint=True: {mislabeled}'
+
+
+async def test_unknown_tool_is_reported_as_mcp_error(server: BrowserUseServer) -> None:
+ """Unknown tool calls must not be returned as successful MCP results."""
+ handler = server.server.get_request_handler('tools/call')
+ assert handler is not None, 'tools/call handler is not registered'
+
+ result = await handler.handler( # type: ignore[arg-type]
+ None,
+ types.CallToolRequestParams(name='does_not_exist', arguments={}),
+ )
+
+ assert isinstance(result, types.CallToolResult)
+ assert result.is_error is True
+ assert len(result.content) == 1
+ assert isinstance(result.content[0], types.TextContent)
+ assert 'Unknown tool: does_not_exist' in result.content[0].text