Skip to content

Commit de79bf1

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: log exception details before re-raising in MCP session execution
Adds a logger.exception call to capture traceback and error details when an exception occurs during the execution of a coroutine within an MCP session, before re-raising it as a ConnectionError. PiperOrigin-RevId: 868253547
1 parent 80ff067 commit de79bf1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/google/adk/tools/mcp_tool/mcp_toolset.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,14 @@ def __init__(
139139
header_provider: A callable that takes a ReadonlyContext and returns a
140140
dictionary of headers to be used for the MCP session.
141141
progress_callback: Optional callback to receive progress notifications
142-
from MCP server during long-running tool execution. Can be either:
143-
144-
- A ``ProgressFnT`` callback that receives (progress, total, message).
145-
This callback will be shared by all tools in the toolset.
146-
147-
- A ``ProgressCallbackFactory`` that creates per-tool callbacks. The
148-
factory receives (tool_name, callback_context, **kwargs) and returns
149-
a ProgressFnT or None. This allows different tools to have different
150-
progress handling logic and access/modify session state via the
151-
CallbackContext. The **kwargs parameter allows for future
152-
extensibility.
142+
from MCP server during long-running tool execution. Can be either: - A
143+
``ProgressFnT`` callback that receives (progress, total, message). This
144+
callback will be shared by all tools in the toolset. - A
145+
``ProgressCallbackFactory`` that creates per-tool callbacks. The factory
146+
receives (tool_name, callback_context, **kwargs) and returns a
147+
ProgressFnT or None. This allows different tools to have different
148+
progress handling logic and access/modify session state via the
149+
CallbackContext. The **kwargs parameter allows for future extensibility.
153150
use_mcp_resources: Whether the agent should have access to MCP resources.
154151
This will add a `load_mcp_resource` tool to the toolset and include
155152
available resources in the agent context. Defaults to False.
@@ -284,6 +281,9 @@ async def _execute_with_session(
284281
coroutine_func(session), timeout=timeout_in_seconds
285282
)
286283
except Exception as e:
284+
logger.exception(
285+
f"Exception during MCP session execution: {error_message}: {e}"
286+
)
287287
raise ConnectionError(f"{error_message}: {e}") from e
288288

289289
@retry_on_errors

0 commit comments

Comments
 (0)