mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-16 04:02:55 -06:00
fix: timeout issues for mcpstdio server when mcp tools are incorrect.
Fixes https://github.com/google/adk-python/issues/643 PiperOrigin-RevId: 765342572
This commit is contained in:
parent
01965bdd74
commit
45ef668435
@ -149,7 +149,8 @@ class MCPSessionManager:
|
|||||||
"""Initializes the MCP session manager.
|
"""Initializes the MCP session manager.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
connection_params: Parameters for the MCP connection (Stdio, SSE or Streamable HTTP).
|
connection_params: Parameters for the MCP connection (Stdio, SSE or
|
||||||
|
Streamable HTTP).
|
||||||
errlog: (Optional) TextIO stream for error logging. Use only for
|
errlog: (Optional) TextIO stream for error logging. Use only for
|
||||||
initializing a local stdio MCP session.
|
initializing a local stdio MCP session.
|
||||||
"""
|
"""
|
||||||
@ -203,9 +204,23 @@ class MCPSessionManager:
|
|||||||
transports = await self._exit_stack.enter_async_context(client)
|
transports = await self._exit_stack.enter_async_context(client)
|
||||||
# The streamable http client returns a GetSessionCallback in addition to the read/write MemoryObjectStreams
|
# The streamable http client returns a GetSessionCallback in addition to the read/write MemoryObjectStreams
|
||||||
# needed to build the ClientSession, we limit then to the two first values to be compatible with all clients.
|
# needed to build the ClientSession, we limit then to the two first values to be compatible with all clients.
|
||||||
session = await self._exit_stack.enter_async_context(
|
# The StdioServerParameters does not provide a timeout parameter for the
|
||||||
ClientSession(*transports[:2])
|
# session, so we need to set a default timeout for it. Other clients
|
||||||
)
|
# (SseServerParams and StreamableHTTPServerParams) already provide a
|
||||||
|
# timeout parameter in their configuration.
|
||||||
|
if isinstance(self._connection_params, StdioServerParameters):
|
||||||
|
# Default timeout for MCP session is 5 seconds, same as SseServerParams
|
||||||
|
# and StreamableHTTPServerParams.
|
||||||
|
session = await self._exit_stack.enter_async_context(
|
||||||
|
ClientSession(
|
||||||
|
*transports[:2],
|
||||||
|
read_timeout_seconds=timedelta(seconds=5),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
session = await self._exit_stack.enter_async_context(
|
||||||
|
ClientSession(*transports[:2])
|
||||||
|
)
|
||||||
await session.initialize()
|
await session.initialize()
|
||||||
|
|
||||||
self._session = session
|
self._session = session
|
||||||
|
@ -98,10 +98,10 @@ class MCPToolset(BaseToolset):
|
|||||||
`StdioServerParameters` for using local mcp server (e.g. using `npx` or
|
`StdioServerParameters` for using local mcp server (e.g. using `npx` or
|
||||||
`python3`); or `SseServerParams` for a local/remote SSE server; or
|
`python3`); or `SseServerParams` for a local/remote SSE server; or
|
||||||
`StreamableHTTPServerParams` for local/remote Streamable http server.
|
`StreamableHTTPServerParams` for local/remote Streamable http server.
|
||||||
tool_filter: Optional filter to select specific tools. Can be either:
|
tool_filter: Optional filter to select specific tools. Can be either: - A
|
||||||
- A list of tool names to include
|
list of tool names to include - A ToolPredicate function for custom
|
||||||
- A ToolPredicate function for custom filtering logic
|
filtering logic
|
||||||
errlog: TextIO stream for error logging.
|
errlog: TextIO stream for error logging.
|
||||||
"""
|
"""
|
||||||
super().__init__(tool_filter=tool_filter)
|
super().__init__(tool_filter=tool_filter)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user