3535# Default credential path for Kyma production deployments
3636_CREDENTIALS_DEFAULT_PATH = "/etc/ums/credentials/credentials"
3737
38- # HTTP timeout for token requests and MCP server calls (seconds)
39- _HTTP_TIMEOUT = 60.0
40-
4138# Resource URN for Agent Gateway token scope (hardcoded - production value)
4239_AGW_RESOURCE_URN = "urn:sap:identity:application:provider:name:agent-gateway"
4340
@@ -213,6 +210,7 @@ def _create_ssl_context(certificate: str, private_key: str) -> ssl.SSLContext:
213210def _request_token_mtls (
214211 credentials : CustomerCredentials ,
215212 grant_type : str ,
213+ timeout : float ,
216214 app_tid : str | None = None ,
217215 extra_data : dict | None = None ,
218216) -> str :
@@ -255,7 +253,7 @@ def _request_token_mtls(
255253 try :
256254 with httpx .Client (
257255 verify = ssl_context ,
258- timeout = _HTTP_TIMEOUT ,
256+ timeout = timeout ,
259257 ) as client :
260258 response = client .post (
261259 credentials .token_service_url ,
@@ -293,6 +291,7 @@ def _request_token_mtls(
293291
294292def get_system_token_mtls (
295293 credentials : CustomerCredentials ,
294+ timeout : float ,
296295 app_tid : str | None = None ,
297296) -> str :
298297 """Get system-scoped token using mTLS client credentials flow.
@@ -301,6 +300,7 @@ def get_system_token_mtls(
301300
302301 Args:
303302 credentials: Customer credentials.
303+ timeout: HTTP timeout in seconds.
304304 app_tid: BTP Application Tenant ID of subscriber (optional).
305305
306306 Returns:
@@ -310,6 +310,7 @@ def get_system_token_mtls(
310310 return _request_token_mtls (
311311 credentials ,
312312 grant_type = _GRANT_TYPE_CLIENT_CREDENTIALS ,
313+ timeout = timeout ,
313314 app_tid = app_tid ,
314315 extra_data = {"response_type" : "token" },
315316 )
@@ -318,6 +319,7 @@ def get_system_token_mtls(
318319def exchange_user_token (
319320 credentials : CustomerCredentials ,
320321 user_token : str ,
322+ timeout : float ,
321323 app_tid : str | None = None ,
322324) -> str :
323325 """Exchange user token for AGW-scoped token using jwt-bearer grant.
@@ -328,6 +330,7 @@ def exchange_user_token(
328330 Args:
329331 credentials: Customer credentials.
330332 user_token: User's JWT token to exchange.
333+ timeout: HTTP timeout in seconds.
331334 app_tid: BTP Application Tenant ID of subscriber (optional).
332335
333336 Returns:
@@ -337,6 +340,7 @@ def exchange_user_token(
337340 return _request_token_mtls (
338341 credentials ,
339342 grant_type = _GRANT_TYPE_JWT_BEARER ,
343+ timeout = timeout ,
340344 app_tid = app_tid ,
341345 extra_data = {
342346 "assertion" : user_token ,
@@ -371,7 +375,7 @@ async def _list_server_tools(
371375 url : str ,
372376 auth_token : str ,
373377 dependency : IntegrationDependency ,
374- timeout : float = _HTTP_TIMEOUT ,
378+ timeout : float ,
375379) -> list [MCPTool ]:
376380 """List tools from a single MCP server.
377381
@@ -428,8 +432,8 @@ async def _list_server_tools(
428432
429433async def get_mcp_tools_customer (
430434 credentials : CustomerCredentials ,
435+ timeout : float ,
431436 app_tid : str | None = None ,
432- timeout : float = _HTTP_TIMEOUT ,
433437) -> list [MCPTool ]:
434438 """List all MCP tools from servers defined in credentials.
435439
@@ -458,7 +462,7 @@ async def get_mcp_tools_customer(
458462 # Get system token for discovery
459463 loop = asyncio .get_running_loop ()
460464 system_token = await loop .run_in_executor (
461- None , get_system_token_mtls , credentials , app_tid
465+ None , get_system_token_mtls , credentials , timeout , app_tid
462466 )
463467
464468 tools : list [MCPTool ] = []
@@ -489,8 +493,8 @@ async def call_mcp_tool_customer(
489493 credentials : CustomerCredentials ,
490494 tool : MCPTool ,
491495 user_token : str | None ,
496+ timeout : float ,
492497 app_tid : str | None = None ,
493- timeout : float = _HTTP_TIMEOUT ,
494498 ** kwargs ,
495499) -> str :
496500 """Invoke an MCP tool using customer flow.
@@ -516,7 +520,7 @@ async def call_mcp_tool_customer(
516520 if user_token :
517521 # Exchange user token for AGW-scoped token (with principal propagation)
518522 agw_token = await loop .run_in_executor (
519- None , exchange_user_token , credentials , user_token , app_tid
523+ None , exchange_user_token , credentials , user_token , timeout , app_tid
520524 )
521525 else :
522526 # TODO: IBD workaround - use system token when user_token is not available.
@@ -527,7 +531,7 @@ async def call_mcp_tool_customer(
527531 "Principal propagation will NOT work."
528532 )
529533 agw_token = await loop .run_in_executor (
530- None , get_system_token_mtls , credentials , app_tid
534+ None , get_system_token_mtls , credentials , timeout , app_tid
531535 )
532536
533537 async with httpx .AsyncClient (
0 commit comments