From af2180c6d0c823ec8c8872dae90c10aaf13a4e86 Mon Sep 17 00:00:00 2001 From: "Xiang (Sean) Zhou" Date: Fri, 30 May 2025 21:00:06 -0700 Subject: [PATCH] chore: add more comments to MCPTooset and MCPSessionManager PiperOrigin-RevId: 765448413 --- .../adk/tools/mcp_tool/mcp_session_manager.py | 13 ++++++++++++- src/google/adk/tools/mcp_tool/mcp_toolset.py | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/google/adk/tools/mcp_tool/mcp_session_manager.py b/src/google/adk/tools/mcp_tool/mcp_session_manager.py index 9130148..13a9b61 100644 --- a/src/google/adk/tools/mcp_tool/mcp_session_manager.py +++ b/src/google/adk/tools/mcp_tool/mcp_session_manager.py @@ -150,7 +150,8 @@ class MCPSessionManager: Args: connection_params: Parameters for the MCP connection (Stdio, SSE or - Streamable HTTP). + Streamable HTTP). Stdio by default also has a 5s read timeout as other + parameters but it's not configurable for now. errlog: (Optional) TextIO stream for error logging. Use only for initializing a local stdio MCP session. """ @@ -174,6 +175,9 @@ class MCPSessionManager: try: if isinstance(self._connection_params, StdioServerParameters): + # So far timeout is not configurable. Given MCP is still evolving, we + # would expect stdio_client to evolve to accept timeout parameter like + # other client. client = stdio_client( server=self._connection_params, errlog=self._errlog ) @@ -211,6 +215,13 @@ class MCPSessionManager: if isinstance(self._connection_params, StdioServerParameters): # Default timeout for MCP session is 5 seconds, same as SseServerParams # and StreamableHTTPServerParams. + # TODO : + # 1. make timeout configurable + # 2. Add StdioConnectionParams to include StdioServerParameters as a + # field and rename other two params to XXXXConnetionParams. Ohter + # two params are actually connection params, while stdio is + # special, stdio_client takes the resposibility of starting the + # server and working as a client. session = await self._exit_stack.enter_async_context( ClientSession( *transports[:2], diff --git a/src/google/adk/tools/mcp_tool/mcp_toolset.py b/src/google/adk/tools/mcp_tool/mcp_toolset.py index d05bb8f..56c05ba 100644 --- a/src/google/adk/tools/mcp_tool/mcp_toolset.py +++ b/src/google/adk/tools/mcp_tool/mcp_toolset.py @@ -98,9 +98,9 @@ class MCPToolset(BaseToolset): `StdioServerParameters` for using local mcp server (e.g. using `npx` or `python3`); or `SseServerParams` for a local/remote SSE server; or `StreamableHTTPServerParams` for local/remote Streamable http server. - tool_filter: Optional filter to select specific tools. Can be either: - A - list of tool names to include - A ToolPredicate function for custom - filtering logic + tool_filter: Optional filter to select specific tools. Can be either: + - A list of tool names to include + - A ToolPredicate function for custom filtering logic errlog: TextIO stream for error logging. """ super().__init__(tool_filter=tool_filter)