Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/tutorial/en/src/task_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#
# .. note:: - The StdIO MCP server only has stateful client, when ``connect()`` is called, it will start the MCP server locally and then connect to it.
# - For stateful clients, developers must ensure the client is connected when calling the tool functions.
# - When multiple `HttpStatefulClients` or `StdIOStatefulClients` are connected, they should be closed in Last In First Out (LIFO) order to prevent errors.
#
# Taking Gaode map MCP server as an example, the creation of stateful and stateless clients are very similar:
#
Expand Down
1 change: 1 addition & 0 deletions docs/tutorial/zh_CN/src/task_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#
# .. note:: - StdIO MCP 服务器只有有状态客户端,当调用 ``connect()`` 时,它将在本地启动 MCP 服务器然后连接到它。
# - 对于有状态客户端,开发者必须确保在调用工具函数时客户端已连接。
# - 当有多个 `HttpStatefulClient` 或 `StdIOStatefulClient` 建立连接时,应按照后进先出 (LIFO) 的顺序关闭它们以避免引发错误。
#
# 以高德地图 MCP 服务器为例,有状态和无状态客户端的创建非常相似:
#
Expand Down
2 changes: 1 addition & 1 deletion examples/agent_deep_research/deep_research_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ async def generate_response( #
you have done so far.

Args:
_response (`str`):
response (`str`):
Your response to the user.
"""
checklist = self.current_subtask[0].knowledge_gaps
Expand Down
7 changes: 7 additions & 0 deletions src/agentscope/mcp/_http_stateful_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class HttpStatefulClient(StatefulClientBase):
.. note:: The stateful client will maintain one session across multiple
tool calls, until the client is closed by explicitly calling the
`close()` method.

.. note:: When multiple HttpStatefulClient instances are connected,
they should be closed following the Last In First Out (LIFO) principle
to avoid potential errors. Always close the most recently registered
client first, then work backwards to the first one.
For more details, please refer to this `issue
<https://github.com/modelcontextprotocol/python-sdk/issues/577>`_.
"""

def __init__(
Expand Down
9 changes: 8 additions & 1 deletion src/agentscope/mcp/_stdio_stateful_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class StdIOStatefulClient(StatefulClientBase):
.. note:: The stateful client will maintain one session across multiple
tool calls, until the client is closed by explicitly calling the
`close()` method.

.. note:: When multiple StdIOStatefulClient instances are connected,
they should be closed following the Last In First Out (LIFO) principle
to avoid potential errors. Always close the most recently registered
client first, then work backwards to the first one.
For more details, please refer to this `issue
<https://github.com/modelcontextprotocol/python-sdk/issues/577>`_.
"""

def __init__(
Expand Down Expand Up @@ -52,7 +59,7 @@ def __init__(
encoding (`str`, optional):
The text encoding used when sending/receiving messages to the
server. Defaults to "utf-8".
encoding_error_handler (`Literal["strict", "ignore", "replace"]`,
encoding_error_handler (`Literal["strict", "ignore", "replace"]`, \
defaults to "strict"):
The text encoding error handler.
"""
Expand Down
Loading