Skip to content

Commit f230fdf

Browse files
committed
add auto params in mcp
1 parent 0caa1cc commit f230fdf

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

veadk/tools/builtin_tools/las.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, SseConnectionParams
15+
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
1616

1717
from veadk.config import getenv
18+
from veadk.utils.mcp_utils import get_mcp_params
1819

1920
url = getenv("TOOL_LAS_URL")
2021
dataset_id = getenv("TOOL_LAS_DATASET_ID")
2122

2223

23-
las = MCPToolset(connection_params=SseConnectionParams(url=url))
24+
las = MCPToolset(connection_params=get_mcp_params(url=url))

veadk/utils/mcp_utils.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 typing import Any
16+
17+
from google.adk.tools.mcp_tool.mcp_toolset import (
18+
SseConnectionParams,
19+
StreamableHTTPConnectionParams,
20+
)
21+
22+
from veadk.utils.logger import get_logger
23+
24+
logger = get_logger(__name__)
25+
26+
27+
def get_mcp_params(url: str) -> Any:
28+
"""Automatically set MCP connection params according to url.
29+
30+
Only support http and sse protocol.
31+
32+
Args:
33+
url (str): MCP server url
34+
"""
35+
if "/mcp" in url:
36+
logger.info("MCP url detected, use StreamableHTTPConnectionParams.")
37+
return StreamableHTTPConnectionParams(url=url)
38+
elif "/sse" in url:
39+
logger.info("SSE url detected, use SseConnectionParams.")
40+
return SseConnectionParams(url=url)
41+
else:
42+
raise ValueError(
43+
"Unsupported MCP url, because it has no `/mcp` or `/sse` field in your url. Please specify your connection params manually."
44+
)

0 commit comments

Comments
 (0)