Skip to content

Commit 5729261

Browse files
authored
feat: add timeout seconds args option when calling tool (mcp-use#178)
* feat: add timeout seconds args option when calling tool * fix: unit test fix
1 parent befb3a2 commit 5729261

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

mcp_use/connectors/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
from abc import ABC, abstractmethod
9+
from datetime import timedelta
910
from typing import Any
1011

1112
from mcp import ClientSession, Implementation
@@ -266,12 +267,15 @@ async def _ensure_connected(self) -> None:
266267
"Connection to MCP server has been lost. Auto-reconnection is disabled. Please reconnect manually."
267268
)
268269

269-
async def call_tool(self, name: str, arguments: dict[str, Any]) -> CallToolResult:
270+
async def call_tool(
271+
self, name: str, arguments: dict[str, Any], read_timeout_seconds: timedelta | None = None
272+
) -> CallToolResult:
270273
"""Call an MCP tool with automatic reconnection handling.
271274
272275
Args:
273276
name: The name of the tool to call.
274277
arguments: The arguments to pass to the tool.
278+
read_timeout_seconds: timeout seconds when calling tool
275279
276280
Returns:
277281
The result of the tool call.
@@ -285,7 +289,7 @@ async def call_tool(self, name: str, arguments: dict[str, Any]) -> CallToolResul
285289

286290
logger.debug(f"Calling tool '{name}' with arguments: {arguments}")
287291
try:
288-
result = await self.client_session.call_tool(name, arguments)
292+
result = await self.client_session.call_tool(name, arguments, read_timeout_seconds)
289293
logger.debug(f"Tool '{name}' called with result: {result}")
290294
return result
291295
except Exception as e:

tests/unit/test_http_connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ async def test_call_tool(self, _):
316316

317317
result = await self.connector.call_tool("test_tool", {"param": "value"})
318318

319-
self.connector.client_session.call_tool.assert_called_once_with("test_tool", {"param": "value"})
319+
self.connector.client_session.call_tool.assert_called_once_with("test_tool", {"param": "value"}, None)
320320
self.assertEqual(result, {"result": "success"})
321321

322322
async def test_call_tool_no_client(self, _):

tests/unit/test_stdio_connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ async def test_call_tool(self):
280280
result = await connector.call_tool(tool_name, arguments)
281281

282282
# Verify
283-
mock_client.call_tool.assert_called_once_with(tool_name, arguments)
283+
mock_client.call_tool.assert_called_once_with(tool_name, arguments, None)
284284
assert result == mock_result
285285

286286
@pytest.mark.asyncio

0 commit comments

Comments
 (0)