Skip to content

Commit a329c46

Browse files
Romain Sestierclaude
authored andcommitted
feat: add configurable HTTP timeout for tool execution
httpx.request() was called without a timeout, defaulting to 5s. Slow providers (e.g. Workday) regularly exceed this, causing ReadTimeout errors. - Add `timeout` field to `ExecuteConfig` (default 30s) - Pass it through to `httpx.request()` - Add `timeout` to `ExecuteToolsConfig` so users can set it at init: `StackOneToolSet(execute={"account_ids": [...], "timeout": 60})` - Thread timeout from toolset config through `_StackOneRpcTool` Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9643f60 commit a329c46

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

stackone_ai/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ExecuteConfig(BaseModel):
6565
parameter_locations: dict[str, ParameterLocation] = Field(
6666
default_factory=dict, description="Maps parameter names to their location in the request"
6767
)
68+
timeout: float = Field(default=30.0, description="HTTP request timeout in seconds")
6869

6970

7071
class ToolParameters(BaseModel):
@@ -249,7 +250,7 @@ def execute(
249250
if query_params:
250251
request_kwargs["params"] = query_params
251252

252-
response = httpx.request(**request_kwargs)
253+
response = httpx.request(**request_kwargs, timeout=self._execute_config.timeout)
253254
response_status = response.status_code
254255
response.raise_for_status()
255256

stackone_ai/toolset.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class ExecuteToolsConfig(TypedDict, total=False):
6969
account_ids: list[str]
7070
"""Account IDs to scope tool discovery and execution."""
7171

72+
timeout: float
73+
"""HTTP request timeout in seconds for tool execution. Defaults to 30."""
74+
7275

7376
_SEARCH_DEFAULT: SearchConfig = {"method": "auto"}
7477

@@ -415,6 +418,7 @@ def __init__(
415418
api_key: str,
416419
base_url: str,
417420
account_id: str | None,
421+
timeout: float = 30.0,
418422
) -> None:
419423
execute_config = ExecuteConfig(
420424
method="POST",
@@ -423,6 +427,7 @@ def __init__(
423427
headers={},
424428
body_type="json",
425429
parameter_locations=dict(_RPC_PARAMETER_LOCATIONS),
430+
timeout=timeout,
426431
)
427432
super().__init__(
428433
description=description,
@@ -1185,13 +1190,17 @@ def _create_rpc_tool(self, tool_def: _McpToolDefinition, account_id: str | None)
11851190
type=str(schema.get("type") or "object"),
11861191
properties=self._normalize_schema_properties(schema),
11871192
)
1193+
timeout = (
1194+
self._execute_config.get("timeout", 30.0) if self._execute_config else 30.0
1195+
)
11881196
return _StackOneRpcTool(
11891197
name=tool_def.name,
11901198
description=tool_def.description or "",
11911199
parameters=parameters,
11921200
api_key=self.api_key,
11931201
base_url=self.base_url,
11941202
account_id=account_id,
1203+
timeout=timeout,
11951204
)
11961205

11971206
def _normalize_schema_properties(self, schema: dict[str, Any]) -> dict[str, Any]:

0 commit comments

Comments
 (0)