chore: add more comments to MCPTooset and MCPSessionManager

PiperOrigin-RevId: 765448413
This commit is contained in:
Xiang (Sean) Zhou 2025-05-30 21:00:06 -07:00 committed by Copybara-Service
parent 5d297169d0
commit af2180c6d0
2 changed files with 15 additions and 4 deletions

View File

@ -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],

View File

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