Skip to content

Commit 743a4d7

Browse files
authored
feat: add playwright tool for browser use in local environment; agent… (#428)
* feat: add playwright tool for browser use in local environment; agent in sandbox can use it directly * update format * add license header
1 parent 8a7f970 commit 743a4d7

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.adk.tools.mcp_tool.mcp_toolset import (
16+
MCPToolset,
17+
StdioConnectionParams,
18+
StdioServerParameters,
19+
)
20+
import subprocess
21+
from veadk.utils.logger import get_logger
22+
23+
logger = get_logger(__name__)
24+
25+
26+
def check_env():
27+
try:
28+
result = subprocess.run(
29+
["npx", "-v"], capture_output=True, text=True, check=True
30+
)
31+
version = result.stdout.strip()
32+
logger.info(f"Check `npx` command done, version: {version}")
33+
except Exception as e:
34+
raise Exception(
35+
"Check `npx` command failed. Please install `npx` command manually."
36+
) from e
37+
38+
39+
check_env()
40+
41+
playwright_tools = MCPToolset(
42+
connection_params=StdioConnectionParams(
43+
server_params=StdioServerParameters(
44+
command="npx",
45+
args=[
46+
"-y",
47+
"@playwright/mcp@latest",
48+
],
49+
),
50+
timeout=30,
51+
),
52+
# tool_filter=['browser_navigate', 'browser_screenshot', 'browser_fill', 'browser_click']
53+
)

0 commit comments

Comments
 (0)