8000 chore: enhance MCP error message for use outside context manager (#175) · lgigit200/sdk-python@9006105 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9006105

Browse files
chore: enhance MCP error message for use outside context manager (strands-agents#175)
1 parent 2d0e441 commit 9006105

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/strands/tools/mcp/mcp_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
"image/webp": "webp",
4242
}
4343

44+
CLIENT_SESSION_NOT_RUNNING_ERROR_MESSAGE = (
45+
"the client session is not running. Ensure the agent is used within "
46+
"the MCP client context manager. For more information see: "
47+
"https://strandsagents.com/latest/user-guide/concepts/tools/mcp-tools/#mcpclientinitializationerror"
48+
)
49+
4450

4551
class MCPClient:
4652
"""Represents a connection to a Model Context Protocol (MCP) server.
@@ -145,7 +151,7 @@ def list_tools_sync(self) -> List[MCPAgentTool]:
145151
"""
146152
self._log_debug_with_thread("listing MCP tools synchronously")
147153
if not self._is_session_active():
148-
raise MCPClientInitializationError("the client session is not running")
154+
raise MCPClientInitializationError(CLIENT_SESSION_NOT_RUNNING_ERROR_MESSAGE)
149155

150156
async def _list_tools_async() -> ListToolsResult:
151157
return await self._background_thread_session.list_tools()
@@ -180,7 +186,7 @@ def call_tool_sync(
180186
"""
181187
self._log_debug_with_thread("calling MCP tool '%s' synchronously with tool_use_id=%s", name, tool_use_id)
182188
if not self._is_session_active():
183-
raise MCPClientInitializationError("the client session is not running")
189+
raise MCPClientInitializationError(CLIENT_SESSION_NOT_RUNNING_ERROR_MESSAGE)
184190

185191
async def _call_tool_async() -> MCPCallToolResult:
186192
return await self._background_thread_session.call_tool(name, arguments, read_timeout_seconds)

0 commit comments

Comments
 (0)
0