|
| 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