Skip to content
Merged
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions src/strands/tools/mcp/mcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"image/webp": "webp",
}

CLIENT_SESSION_NOT_RUNNING_ERROR_MESSAGE = (
"the client session is not running. Please ensure the agent is used within "
"the MCP client context manager ('with mcp_client:')"
)


class MCPClient:
"""Represents a connection to a Model Context Protocol (MCP) server.
Expand Down Expand Up @@ -145,7 +150,7 @@ def list_tools_sync(self) -> List[MCPAgentTool]:
"""
self._log_debug_with_thread("listing MCP tools synchronously")
if not self._is_session_active():
raise MCPClientInitializationError("the client session is not running")
raise MCPClientInitializationError(CLIENT_SESSION_NOT_RUNNING_ERROR_MESSAGE)

async def _list_tools_async() -> ListToolsResult:
return await self._background_thread_session.list_tools()
Expand Down Expand Up @@ -180,7 +185,7 @@ def call_tool_sync(
"""
self._log_debug_with_thread("calling MCP tool '%s' synchronously with tool_use_id=%s", name, tool_use_id)
if not self._is_session_active():
raise MCPClientInitializationError("the client session is not running")
raise MCPClientInitializationError(CLIENT_SESSION_NOT_RUNNING_ERROR_MESSAGE)

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